blob: 2542f1f8bf86583df36fba43ddbfb2c26e0d5120 [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 Smart88a2cfb2011-07-22 18:36:33 -0400758 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
759 * @phba: lpfc_hba pointer.
760 *
761 * Description:
762 * SLI4 interface type-2 device to wait on the sliport status register for
763 * the readyness after performing a firmware reset.
764 *
765 * Returns:
766 * zero for success
767 **/
768static int
769lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
770{
771 struct lpfc_register portstat_reg;
772 int i;
773
774
775 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
776 &portstat_reg.word0);
777
778 /* wait for the SLI port firmware ready after firmware reset */
779 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
780 msleep(10);
781 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
782 &portstat_reg.word0);
783 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
784 continue;
785 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
786 continue;
787 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
788 continue;
789 break;
790 }
791
792 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
793 return 0;
794 else
795 return -EIO;
796}
797
798/**
James Smart52d52442011-05-24 11:42:45 -0400799 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400800 * @phba: lpfc_hba pointer.
801 *
802 * Description:
James Smart52d52442011-05-24 11:42:45 -0400803 * Request SLI4 interface type-2 device to perform a physical register set
804 * access.
James Smartc0c11512011-05-24 11:41:34 -0400805 *
806 * Returns:
807 * zero for success
808 **/
809static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400810lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400811{
812 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400813 struct pci_dev *pdev = phba->pcidev;
James Smartc0c11512011-05-24 11:41:34 -0400814 uint32_t reg_val;
815 int status = 0;
816 int rc;
817
818 if (!phba->cfg_enable_hba_reset)
819 return -EIO;
820
James Smart52d52442011-05-24 11:42:45 -0400821 if ((phba->sli_rev < LPFC_SLI_REV4) ||
822 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
823 LPFC_SLI_INTF_IF_TYPE_2))
824 return -EPERM;
825
James Smartb76f2dc2011-07-22 18:37:42 -0400826 if (!pdev->is_physfn)
827 return -EPERM;
828
829 /* Disable SR-IOV virtual functions if enabled */
830 if (phba->cfg_sriov_nr_virtfn) {
831 pci_disable_sriov(pdev);
832 phba->cfg_sriov_nr_virtfn = 0;
833 }
James Smartc0c11512011-05-24 11:41:34 -0400834 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
835
836 if (status != 0)
837 return status;
838
839 /* wait for the device to be quiesced before firmware reset */
840 msleep(100);
841
842 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
843 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400844
845 if (opcode == LPFC_FW_DUMP)
846 reg_val |= LPFC_FW_DUMP_REQUEST;
847 else if (opcode == LPFC_FW_RESET)
848 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
849 else if (opcode == LPFC_DV_RESET)
850 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
851
James Smartc0c11512011-05-24 11:41:34 -0400852 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
853 LPFC_CTL_PDEV_CTL_OFFSET);
854 /* flush */
855 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
856
857 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400858 rc = lpfc_sli4_pdev_status_reg_wait(phba);
859
860 if (rc)
861 return -EIO;
James Smartc0c11512011-05-24 11:41:34 -0400862
863 init_completion(&online_compl);
864 rc = lpfc_workq_post_event(phba, &status, &online_compl,
865 LPFC_EVT_ONLINE);
866 if (rc == 0)
867 return -ENOMEM;
868
869 wait_for_completion(&online_compl);
870
871 if (status != 0)
872 return -EIO;
873
874 return 0;
875}
876
877/**
James Smart3621a712009-04-06 18:47:14 -0400878 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400879 * @dev: class device that is converted into a Scsi_host.
880 * @attr: device attribute, not used.
881 * @buf: on return contains the ascii number of nport events.
882 *
883 * Returns: size of formatted string.
884 **/
dea31012005-04-17 16:05:31 -0500885static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100886lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
887 char *buf)
dea31012005-04-17 16:05:31 -0500888{
Tony Jonesee959b02008-02-22 00:13:36 +0100889 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
891 struct lpfc_hba *phba = vport->phba;
892
dea31012005-04-17 16:05:31 -0500893 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
894}
895
James Smarte59058c2008-08-24 21:49:00 -0400896/**
James Smart3621a712009-04-06 18:47:14 -0400897 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400898 * @dev: class device that is converted into a Scsi_host.
899 * @attr: device attribute, not used.
900 * @buf: on return contains the state of the adapter.
901 *
902 * Returns: size of formatted string.
903 **/
dea31012005-04-17 16:05:31 -0500904static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100905lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
906 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500907{
Tony Jonesee959b02008-02-22 00:13:36 +0100908 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
910 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500911 char * state;
912
James Smart2e0fef82007-06-17 19:56:36 -0500913 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500914 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500915 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500916 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500917 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500918 state = "offline";
919 else
920 state = "online";
921
922 return snprintf(buf, PAGE_SIZE, "%s\n", state);
923}
924
James Smarte59058c2008-08-24 21:49:00 -0400925/**
James Smart3621a712009-04-06 18:47:14 -0400926 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400927 * @dev: class device that is converted into a Scsi_host.
928 * @attr: device attribute, not used.
929 * @buf: containing one of the strings "online", "offline", "warm" or "error".
930 * @count: unused variable.
931 *
932 * Returns:
933 * -EACCES if enable hba reset not enabled
934 * -EINVAL if the buffer does not contain a valid string (see above)
935 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
936 * buf length greater than zero indicates success
937 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500938static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100939lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
940 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500941{
Tony Jonesee959b02008-02-22 00:13:36 +0100942 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500943 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
944 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500945 struct completion online_compl;
946 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500947 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500948
James Smart13815c82008-01-11 01:52:48 -0500949 if (!phba->cfg_enable_hba_reset)
950 return -EACCES;
James Smart88a2cfb2011-07-22 18:36:33 -0400951
952 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
953 "3050 lpfc_board_mode set to %s\n", buf);
954
Jamie Wellnitz41415862006-02-28 19:25:27 -0500955 init_completion(&online_compl);
956
James Smart46fa3112007-04-25 09:51:45 -0400957 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500958 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500959 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500960 if (rc == 0)
961 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400962 wait_for_completion(&online_compl);
963 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
964 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500965 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400966 if (phba->sli_rev == LPFC_SLI_REV4)
967 return -EINVAL;
968 else
969 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400970 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400971 if (phba->sli_rev == LPFC_SLI_REV4)
972 return -EINVAL;
973 else
974 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -0400975 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -0400976 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
977 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
978 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
979 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
980 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500981 else
982 return -EINVAL;
983
Jamie Wellnitz41415862006-02-28 19:25:27 -0500984 if (!status)
985 return strlen(buf);
986 else
987 return -EIO;
988}
989
James Smarte59058c2008-08-24 21:49:00 -0400990/**
James Smart3621a712009-04-06 18:47:14 -0400991 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400992 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400993 * @mxri: max xri count.
994 * @axri: available xri count.
995 * @mrpi: max rpi count.
996 * @arpi: available rpi count.
997 * @mvpi: max vpi count.
998 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400999 *
1000 * Description:
1001 * If an integer pointer for an count is not null then the value for the
1002 * count is returned.
1003 *
1004 * Returns:
1005 * zero on error
1006 * one for success
1007 **/
James Smart311464e2007-08-02 11:10:37 -04001008static int
James Smart858c9f62007-06-17 19:56:39 -05001009lpfc_get_hba_info(struct lpfc_hba *phba,
1010 uint32_t *mxri, uint32_t *axri,
1011 uint32_t *mrpi, uint32_t *arpi,
1012 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001013{
James Smart04c68492009-05-22 14:52:52 -04001014 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001015 LPFC_MBOXQ_t *pmboxq;
1016 MAILBOX_t *pmb;
1017 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001018 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001019
1020 /*
1021 * prevent udev from issuing mailbox commands until the port is
1022 * configured.
1023 */
1024 if (phba->link_state < LPFC_LINK_DOWN ||
1025 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001026 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001027 return 0;
1028
1029 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1030 return 0;
1031
1032 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1033 if (!pmboxq)
1034 return 0;
1035 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1036
James Smart04c68492009-05-22 14:52:52 -04001037 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001038 pmb->mbxCommand = MBX_READ_CONFIG;
1039 pmb->mbxOwner = OWN_HOST;
1040 pmboxq->context1 = NULL;
1041
James Smart75baf692010-06-08 18:31:21 -04001042 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001043 rc = MBX_NOT_FINISHED;
1044 else
1045 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1046
1047 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001048 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001049 mempool_free(pmboxq, phba->mbox_mem_pool);
1050 return 0;
1051 }
1052
James Smartda0436e2009-05-22 14:51:39 -04001053 if (phba->sli_rev == LPFC_SLI_REV4) {
1054 rd_config = &pmboxq->u.mqe.un.rd_config;
1055 if (mrpi)
1056 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1057 if (arpi)
1058 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1059 phba->sli4_hba.max_cfg_param.rpi_used;
1060 if (mxri)
1061 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1062 if (axri)
1063 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1064 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001065
1066 /* Account for differences with SLI-3. Get vpi count from
1067 * mailbox data and subtract one for max vpi value.
1068 */
1069 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1070 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1071
James Smartda0436e2009-05-22 14:51:39 -04001072 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001073 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001074 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001075 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001076 } else {
1077 if (mrpi)
1078 *mrpi = pmb->un.varRdConfig.max_rpi;
1079 if (arpi)
1080 *arpi = pmb->un.varRdConfig.avail_rpi;
1081 if (mxri)
1082 *mxri = pmb->un.varRdConfig.max_xri;
1083 if (axri)
1084 *axri = pmb->un.varRdConfig.avail_xri;
1085 if (mvpi)
1086 *mvpi = pmb->un.varRdConfig.max_vpi;
1087 if (avpi)
1088 *avpi = pmb->un.varRdConfig.avail_vpi;
1089 }
James Smart92d7f7b2007-06-17 19:56:38 -05001090
1091 mempool_free(pmboxq, phba->mbox_mem_pool);
1092 return 1;
1093}
1094
James Smarte59058c2008-08-24 21:49:00 -04001095/**
James Smart3621a712009-04-06 18:47:14 -04001096 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001097 * @dev: class device that is converted into a Scsi_host.
1098 * @attr: device attribute, not used.
1099 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1100 *
1101 * Description:
1102 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1103 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1104 * to "Unknown" and the buffer length is returned, therefore the caller
1105 * must check for "Unknown" in the buffer to detect a failure.
1106 *
1107 * Returns: size of formatted string.
1108 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001109static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001110lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1111 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001112{
Tony Jonesee959b02008-02-22 00:13:36 +01001113 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1115 struct lpfc_hba *phba = vport->phba;
1116 uint32_t cnt;
1117
James Smart858c9f62007-06-17 19:56:39 -05001118 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001119 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1120 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1121}
1122
James Smarte59058c2008-08-24 21:49:00 -04001123/**
James Smart3621a712009-04-06 18:47:14 -04001124 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001125 * @dev: class device that is converted into a Scsi_host.
1126 * @attr: device attribute, not used.
1127 * @buf: containing the used rpi count in decimal or "Unknown".
1128 *
1129 * Description:
1130 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1131 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1132 * to "Unknown" and the buffer length is returned, therefore the caller
1133 * must check for "Unknown" in the buffer to detect a failure.
1134 *
1135 * Returns: size of formatted string.
1136 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001137static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001138lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1139 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001140{
Tony Jonesee959b02008-02-22 00:13:36 +01001141 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001142 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1143 struct lpfc_hba *phba = vport->phba;
1144 uint32_t cnt, acnt;
1145
James Smart858c9f62007-06-17 19:56:39 -05001146 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001147 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1148 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1149}
1150
James Smarte59058c2008-08-24 21:49:00 -04001151/**
James Smart3621a712009-04-06 18:47:14 -04001152 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001153 * @dev: class device that is converted into a Scsi_host.
1154 * @attr: device attribute, not used.
1155 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1156 *
1157 * Description:
1158 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1159 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1160 * to "Unknown" and the buffer length is returned, therefore the caller
1161 * must check for "Unknown" in the buffer to detect a failure.
1162 *
1163 * Returns: size of formatted string.
1164 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001165static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001166lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1167 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001168{
Tony Jonesee959b02008-02-22 00:13:36 +01001169 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1171 struct lpfc_hba *phba = vport->phba;
1172 uint32_t cnt;
1173
James Smart858c9f62007-06-17 19:56:39 -05001174 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001175 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1176 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1177}
1178
James Smarte59058c2008-08-24 21:49:00 -04001179/**
James Smart3621a712009-04-06 18:47:14 -04001180 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001181 * @dev: class device that is converted into a Scsi_host.
1182 * @attr: device attribute, not used.
1183 * @buf: on return contains the used xri count in decimal or "Unknown".
1184 *
1185 * Description:
1186 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1187 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1188 * to "Unknown" and the buffer length is returned, therefore the caller
1189 * must check for "Unknown" in the buffer to detect a failure.
1190 *
1191 * Returns: size of formatted string.
1192 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001193static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001194lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1195 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001196{
Tony Jonesee959b02008-02-22 00:13:36 +01001197 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001198 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1199 struct lpfc_hba *phba = vport->phba;
1200 uint32_t cnt, acnt;
1201
James Smart858c9f62007-06-17 19:56:39 -05001202 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1203 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1204 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1205}
1206
James Smarte59058c2008-08-24 21:49:00 -04001207/**
James Smart3621a712009-04-06 18:47:14 -04001208 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001209 * @dev: class device that is converted into a Scsi_host.
1210 * @attr: device attribute, not used.
1211 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1212 *
1213 * Description:
1214 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1215 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1216 * to "Unknown" and the buffer length is returned, therefore the caller
1217 * must check for "Unknown" in the buffer to detect a failure.
1218 *
1219 * Returns: size of formatted string.
1220 **/
James Smart858c9f62007-06-17 19:56:39 -05001221static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001222lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1223 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001224{
Tony Jonesee959b02008-02-22 00:13:36 +01001225 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001226 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1227 struct lpfc_hba *phba = vport->phba;
1228 uint32_t cnt;
1229
1230 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1231 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1232 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1233}
1234
James Smarte59058c2008-08-24 21:49:00 -04001235/**
James Smart3621a712009-04-06 18:47:14 -04001236 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001237 * @dev: class device that is converted into a Scsi_host.
1238 * @attr: device attribute, not used.
1239 * @buf: on return contains the used vpi count in decimal or "Unknown".
1240 *
1241 * Description:
1242 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1243 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1244 * to "Unknown" and the buffer length is returned, therefore the caller
1245 * must check for "Unknown" in the buffer to detect a failure.
1246 *
1247 * Returns: size of formatted string.
1248 **/
James Smart858c9f62007-06-17 19:56:39 -05001249static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001250lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1251 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001252{
Tony Jonesee959b02008-02-22 00:13:36 +01001253 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1255 struct lpfc_hba *phba = vport->phba;
1256 uint32_t cnt, acnt;
1257
1258 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001259 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1260 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1261}
1262
James Smarte59058c2008-08-24 21:49:00 -04001263/**
James Smart3621a712009-04-06 18:47:14 -04001264 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001265 * @dev: class device that is converted into a Scsi_host.
1266 * @attr: device attribute, not used.
1267 * @buf: text that must be interpreted to determine if npiv is supported.
1268 *
1269 * Description:
1270 * Buffer will contain text indicating npiv is not suppoerted on the port,
1271 * the port is an NPIV physical port, or it is an npiv virtual port with
1272 * the id of the vport.
1273 *
1274 * Returns: size of formatted string.
1275 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001276static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001277lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1278 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001279{
Tony Jonesee959b02008-02-22 00:13:36 +01001280 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001281 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1282 struct lpfc_hba *phba = vport->phba;
1283
1284 if (!(phba->max_vpi))
1285 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1286 if (vport->port_type == LPFC_PHYSICAL_PORT)
1287 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1288 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1289}
1290
James Smarte59058c2008-08-24 21:49:00 -04001291/**
James Smart3621a712009-04-06 18:47:14 -04001292 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001293 * @dev: class device that is converted into a Scsi_host.
1294 * @attr: device attribute, not used.
1295 * @buf: on return contains the cfg_poll in hex.
1296 *
1297 * Notes:
1298 * cfg_poll should be a lpfc_polling_flags type.
1299 *
1300 * Returns: size of formatted string.
1301 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001302static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001303lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1304 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001305{
Tony Jonesee959b02008-02-22 00:13:36 +01001306 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001307 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1308 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001309
1310 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001315 * @dev: class device that is converted into a Scsi_host.
1316 * @attr: device attribute, not used.
1317 * @buf: one or more lpfc_polling_flags values.
1318 * @count: not used.
1319 *
1320 * Notes:
1321 * buf contents converted to integer and checked for a valid value.
1322 *
1323 * Returns:
1324 * -EINVAL if the buffer connot be converted or is out of range
1325 * length of the buf on success
1326 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001327static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001328lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1329 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001330{
Tony Jonesee959b02008-02-22 00:13:36 +01001331 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001332 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1333 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001334 uint32_t creg_val;
1335 uint32_t old_val;
1336 int val=0;
1337
1338 if (!isdigit(buf[0]))
1339 return -EINVAL;
1340
1341 if (sscanf(buf, "%i", &val) != 1)
1342 return -EINVAL;
1343
1344 if ((val & 0x3) != val)
1345 return -EINVAL;
1346
James Smart45ed1192009-10-02 15:17:02 -04001347 if (phba->sli_rev == LPFC_SLI_REV4)
1348 val = 0;
1349
James Smart88a2cfb2011-07-22 18:36:33 -04001350 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1351 "3051 lpfc_poll changed from %d to %d\n",
1352 phba->cfg_poll, val);
1353
James Smart2e0fef82007-06-17 19:56:36 -05001354 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001355
1356 old_val = phba->cfg_poll;
1357
1358 if (val & ENABLE_FCP_RING_POLLING) {
1359 if ((val & DISABLE_FCP_RING_INT) &&
1360 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001361 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1362 spin_unlock_irq(&phba->hbalock);
1363 return -EINVAL;
1364 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001365 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1366 writel(creg_val, phba->HCregaddr);
1367 readl(phba->HCregaddr); /* flush */
1368
1369 lpfc_poll_start_timer(phba);
1370 }
1371 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001372 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001373 return -EINVAL;
1374 }
1375
1376 if (!(val & DISABLE_FCP_RING_INT) &&
1377 (old_val & DISABLE_FCP_RING_INT))
1378 {
James Smart2e0fef82007-06-17 19:56:36 -05001379 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001380 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001381 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001382 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1383 spin_unlock_irq(&phba->hbalock);
1384 return -EINVAL;
1385 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001386 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1387 writel(creg_val, phba->HCregaddr);
1388 readl(phba->HCregaddr); /* flush */
1389 }
1390
1391 phba->cfg_poll = val;
1392
James Smart2e0fef82007-06-17 19:56:36 -05001393 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001394
1395 return strlen(buf);
1396}
dea31012005-04-17 16:05:31 -05001397
James Smarte59058c2008-08-24 21:49:00 -04001398/**
James Smartbc739052010-08-04 16:11:18 -04001399 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1400 * @dev: class unused variable.
1401 * @attr: device attribute, not used.
1402 * @buf: on return contains the module description text.
1403 *
1404 * Returns: size of formatted string.
1405 **/
1406static ssize_t
1407lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1408 char *buf)
1409{
1410 struct Scsi_Host *shost = class_to_shost(dev);
1411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1412 struct lpfc_hba *phba = vport->phba;
1413
1414 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1415}
1416
1417/**
1418 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1419 * @dev: class unused variable.
1420 * @attr: device attribute, not used.
1421 * @buf: on return contains the module description text.
1422 *
1423 * Returns: size of formatted string.
1424 **/
1425static ssize_t
1426lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1427 char *buf)
1428{
1429 struct Scsi_Host *shost = class_to_shost(dev);
1430 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1431 struct lpfc_hba *phba = vport->phba;
1432
1433 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1434}
1435
1436/**
James Smartab56dc22011-02-16 12:39:57 -05001437 * lpfc_dss_show - Return the current state of dss and the configured state
1438 * @dev: class converted to a Scsi_host structure.
1439 * @attr: device attribute, not used.
1440 * @buf: on return contains the formatted text.
1441 *
1442 * Returns: size of formatted string.
1443 **/
1444static ssize_t
1445lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1446 char *buf)
1447{
1448 struct Scsi_Host *shost = class_to_shost(dev);
1449 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1450 struct lpfc_hba *phba = vport->phba;
1451
1452 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1453 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1454 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1455 "" : "Not ");
1456}
1457
1458/**
James Smart912e3ac2011-05-24 11:42:11 -04001459 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1460 * @dev: class converted to a Scsi_host structure.
1461 * @attr: device attribute, not used.
1462 * @buf: on return contains the formatted support level.
1463 *
1464 * Description:
1465 * Returns the maximum number of virtual functions a physical function can
1466 * support, 0 will be returned if called on virtual function.
1467 *
1468 * Returns: size of formatted string.
1469 **/
1470static ssize_t
1471lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1472 struct device_attribute *attr,
1473 char *buf)
1474{
1475 struct Scsi_Host *shost = class_to_shost(dev);
1476 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1477 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001478 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001479
James Smart0a96e972011-07-22 18:37:28 -04001480 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1481 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001482}
1483
1484/**
James Smart3621a712009-04-06 18:47:14 -04001485 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001486 *
1487 * Description:
1488 * Macro that given an attr e.g. hba_queue_depth expands
1489 * into a function with the name lpfc_hba_queue_depth_show.
1490 *
1491 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1492 * @dev: class device that is converted into a Scsi_host.
1493 * @attr: device attribute, not used.
1494 * @buf: on return contains the attribute value in decimal.
1495 *
1496 * Returns: size of formatted string.
1497 **/
dea31012005-04-17 16:05:31 -05001498#define lpfc_param_show(attr) \
1499static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001500lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1501 char *buf) \
dea31012005-04-17 16:05:31 -05001502{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001503 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1505 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001506 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001507 val = phba->cfg_##attr;\
1508 return snprintf(buf, PAGE_SIZE, "%d\n",\
1509 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001510}
1511
James Smarte59058c2008-08-24 21:49:00 -04001512/**
James Smart3621a712009-04-06 18:47:14 -04001513 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001514 *
1515 * Description:
1516 * Macro that given an attr e.g. hba_queue_depth expands
1517 * into a function with the name lpfc_hba_queue_depth_show
1518 *
1519 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1520 * @dev: class device that is converted into a Scsi_host.
1521 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001522 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001523 *
1524 * Returns: size of formatted string.
1525 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001526#define lpfc_param_hex_show(attr) \
1527static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001528lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1529 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001530{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001531 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1533 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001534 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001535 val = phba->cfg_##attr;\
1536 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1537 phba->cfg_##attr);\
1538}
1539
James Smarte59058c2008-08-24 21:49:00 -04001540/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001541 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001542 *
1543 * Description:
1544 * Macro that given an attr e.g. hba_queue_depth expands
1545 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1546 * takes a default argument, a minimum and maximum argument.
1547 *
1548 * lpfc_##attr##_init: Initializes an attribute.
1549 * @phba: pointer the the adapter structure.
1550 * @val: integer attribute value.
1551 *
1552 * Validates the min and max values then sets the adapter config field
1553 * accordingly, or uses the default if out of range and prints an error message.
1554 *
1555 * Returns:
1556 * zero on success
1557 * -EINVAL if default used
1558 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001559#define lpfc_param_init(attr, default, minval, maxval) \
1560static int \
James Smart84d1b002010-02-12 14:42:33 -05001561lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001562{ \
1563 if (val >= minval && val <= maxval) {\
1564 phba->cfg_##attr = val;\
1565 return 0;\
1566 }\
1567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001568 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1569 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001570 phba->cfg_##attr = default;\
1571 return -EINVAL;\
1572}
1573
James Smarte59058c2008-08-24 21:49:00 -04001574/**
James Smart3621a712009-04-06 18:47:14 -04001575 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001576 *
1577 * Description:
1578 * Macro that given an attr e.g. hba_queue_depth expands
1579 * into a function with the name lpfc_hba_queue_depth_set
1580 *
1581 * lpfc_##attr##_set: Sets an attribute value.
1582 * @phba: pointer the the adapter structure.
1583 * @val: integer attribute value.
1584 *
1585 * Description:
1586 * Validates the min and max values then sets the
1587 * adapter config field if in the valid range. prints error message
1588 * and does not set the parameter if invalid.
1589 *
1590 * Returns:
1591 * zero on success
1592 * -EINVAL if val is invalid
1593 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001594#define lpfc_param_set(attr, default, minval, maxval) \
1595static int \
James Smart84d1b002010-02-12 14:42:33 -05001596lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001597{ \
1598 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1600 "3052 lpfc_" #attr " changed from %d to %d\n", \
1601 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001602 phba->cfg_##attr = val;\
1603 return 0;\
1604 }\
1605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001606 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1607 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001608 return -EINVAL;\
1609}
1610
James Smarte59058c2008-08-24 21:49:00 -04001611/**
James Smart3621a712009-04-06 18:47:14 -04001612 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001613 *
1614 * Description:
1615 * Macro that given an attr e.g. hba_queue_depth expands
1616 * into a function with the name lpfc_hba_queue_depth_store.
1617 *
1618 * lpfc_##attr##_store: Set an sttribute value.
1619 * @dev: class device that is converted into a Scsi_host.
1620 * @attr: device attribute, not used.
1621 * @buf: contains the attribute value in ascii.
1622 * @count: not used.
1623 *
1624 * Description:
1625 * Convert the ascii text number to an integer, then
1626 * use the lpfc_##attr##_set function to set the value.
1627 *
1628 * Returns:
1629 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1630 * length of buffer upon success.
1631 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001632#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001633static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001634lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1635 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001636{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001637 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1639 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001640 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001641 if (!isdigit(buf[0]))\
1642 return -EINVAL;\
1643 if (sscanf(buf, "%i", &val) != 1)\
1644 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001645 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001646 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001647 else \
1648 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001649}
1650
James Smarte59058c2008-08-24 21:49:00 -04001651/**
James Smart3621a712009-04-06 18:47:14 -04001652 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001653 *
1654 * Description:
1655 * Macro that given an attr e.g. hba_queue_depth expands
1656 * into a function with the name lpfc_hba_queue_depth_show
1657 *
1658 * lpfc_##attr##_show: prints the attribute value in decimal.
1659 * @dev: class device that is converted into a Scsi_host.
1660 * @attr: device attribute, not used.
1661 * @buf: on return contains the attribute value in decimal.
1662 *
1663 * Returns: length of formatted string.
1664 **/
James Smart3de2a652007-08-02 11:09:59 -04001665#define lpfc_vport_param_show(attr) \
1666static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001667lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1668 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001669{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001670 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001672 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001673 val = vport->cfg_##attr;\
1674 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1675}
1676
James Smarte59058c2008-08-24 21:49:00 -04001677/**
James Smart3621a712009-04-06 18:47:14 -04001678 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001679 *
1680 * Description:
1681 * Macro that given an attr e.g.
1682 * hba_queue_depth expands into a function with the name
1683 * lpfc_hba_queue_depth_show
1684 *
James Smart3621a712009-04-06 18:47:14 -04001685 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001686 * @dev: class device that is converted into a Scsi_host.
1687 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001688 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001689 *
1690 * Returns: length of formatted string.
1691 **/
James Smart3de2a652007-08-02 11:09:59 -04001692#define lpfc_vport_param_hex_show(attr) \
1693static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001694lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1695 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001696{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001697 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001699 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001700 val = vport->cfg_##attr;\
1701 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1702}
1703
James Smarte59058c2008-08-24 21:49:00 -04001704/**
James Smart3621a712009-04-06 18:47:14 -04001705 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001706 *
1707 * Description:
1708 * Macro that given an attr e.g. hba_queue_depth expands
1709 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1710 * takes a default argument, a minimum and maximum argument.
1711 *
1712 * lpfc_##attr##_init: validates the min and max values then sets the
1713 * adapter config field accordingly, or uses the default if out of range
1714 * and prints an error message.
1715 * @phba: pointer the the adapter structure.
1716 * @val: integer attribute value.
1717 *
1718 * Returns:
1719 * zero on success
1720 * -EINVAL if default used
1721 **/
James Smart3de2a652007-08-02 11:09:59 -04001722#define lpfc_vport_param_init(attr, default, minval, maxval) \
1723static int \
James Smart84d1b002010-02-12 14:42:33 -05001724lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001725{ \
1726 if (val >= minval && val <= maxval) {\
1727 vport->cfg_##attr = val;\
1728 return 0;\
1729 }\
James Smarte8b62012007-08-02 11:10:09 -04001730 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001731 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001732 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001733 vport->cfg_##attr = default;\
1734 return -EINVAL;\
1735}
1736
James Smarte59058c2008-08-24 21:49:00 -04001737/**
James Smart3621a712009-04-06 18:47:14 -04001738 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001739 *
1740 * Description:
1741 * Macro that given an attr e.g. hba_queue_depth expands
1742 * into a function with the name lpfc_hba_queue_depth_set
1743 *
1744 * lpfc_##attr##_set: validates the min and max values then sets the
1745 * adapter config field if in the valid range. prints error message
1746 * and does not set the parameter if invalid.
1747 * @phba: pointer the the adapter structure.
1748 * @val: integer attribute value.
1749 *
1750 * Returns:
1751 * zero on success
1752 * -EINVAL if val is invalid
1753 **/
James Smart3de2a652007-08-02 11:09:59 -04001754#define lpfc_vport_param_set(attr, default, minval, maxval) \
1755static int \
James Smart84d1b002010-02-12 14:42:33 -05001756lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001757{ \
1758 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001759 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1760 "3053 lpfc_" #attr " changed from %d to %d\n", \
1761 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001762 vport->cfg_##attr = val;\
1763 return 0;\
1764 }\
James Smarte8b62012007-08-02 11:10:09 -04001765 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001766 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001767 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001768 return -EINVAL;\
1769}
1770
James Smarte59058c2008-08-24 21:49:00 -04001771/**
James Smart3621a712009-04-06 18:47:14 -04001772 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001773 *
1774 * Description:
1775 * Macro that given an attr e.g. hba_queue_depth
1776 * expands into a function with the name lpfc_hba_queue_depth_store
1777 *
1778 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1779 * use the lpfc_##attr##_set function to set the value.
1780 * @cdev: class device that is converted into a Scsi_host.
1781 * @buf: contains the attribute value in decimal.
1782 * @count: not used.
1783 *
1784 * Returns:
1785 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1786 * length of buffer upon success.
1787 **/
James Smart3de2a652007-08-02 11:09:59 -04001788#define lpfc_vport_param_store(attr) \
1789static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001790lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1791 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001792{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001793 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001794 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001795 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001796 if (!isdigit(buf[0]))\
1797 return -EINVAL;\
1798 if (sscanf(buf, "%i", &val) != 1)\
1799 return -EINVAL;\
1800 if (lpfc_##attr##_set(vport, val) == 0) \
1801 return strlen(buf);\
1802 else \
1803 return -EINVAL;\
1804}
1805
1806
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001807#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001808static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001809module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001810MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001811lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001812
1813#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001814static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001815module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001816MODULE_PARM_DESC(lpfc_##name, desc);\
1817lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001818lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001819static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001820
1821#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001822static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001823module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001824MODULE_PARM_DESC(lpfc_##name, desc);\
1825lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001826lpfc_param_init(name, defval, minval, maxval)\
1827lpfc_param_set(name, defval, minval, maxval)\
1828lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001829static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1830 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001831
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001832#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001833static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001834module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001835MODULE_PARM_DESC(lpfc_##name, desc);\
1836lpfc_param_hex_show(name)\
1837lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001838static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001839
1840#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001841static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001842module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001843MODULE_PARM_DESC(lpfc_##name, desc);\
1844lpfc_param_hex_show(name)\
1845lpfc_param_init(name, defval, minval, maxval)\
1846lpfc_param_set(name, defval, minval, maxval)\
1847lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001848static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1849 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001850
James Smart3de2a652007-08-02 11:09:59 -04001851#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001852static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001853module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001854MODULE_PARM_DESC(lpfc_##name, desc);\
1855lpfc_vport_param_init(name, defval, minval, maxval)
1856
1857#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001858static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001859module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001860MODULE_PARM_DESC(lpfc_##name, desc);\
1861lpfc_vport_param_show(name)\
1862lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001863static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001864
1865#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001866static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001867module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001868MODULE_PARM_DESC(lpfc_##name, desc);\
1869lpfc_vport_param_show(name)\
1870lpfc_vport_param_init(name, defval, minval, maxval)\
1871lpfc_vport_param_set(name, defval, minval, maxval)\
1872lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001873static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1874 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001875
1876#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001877static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001878module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001879MODULE_PARM_DESC(lpfc_##name, desc);\
1880lpfc_vport_param_hex_show(name)\
1881lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001882static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001883
1884#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001885static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001886module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001887MODULE_PARM_DESC(lpfc_##name, desc);\
1888lpfc_vport_param_hex_show(name)\
1889lpfc_vport_param_init(name, defval, minval, maxval)\
1890lpfc_vport_param_set(name, defval, minval, maxval)\
1891lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001892static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1893 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001894
James Smart81301a92008-12-04 22:39:46 -05001895static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1896static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1897static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1898static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001899static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1900static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1901static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1902static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1903static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1904static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1905static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1906static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001907static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1908 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001909static DEVICE_ATTR(option_rom_version, S_IRUGO,
1910 lpfc_option_rom_version_show, NULL);
1911static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1912 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001913static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001914static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1915static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001916static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001917static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1918 lpfc_board_mode_show, lpfc_board_mode_store);
1919static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1920static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1921static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1922static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1923static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1924static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1925static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1926static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1927static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001928static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1929static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001930static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001931static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1932 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001933
James Smarta12e07b2006-12-02 13:35:30 -05001934static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001935
James Smarte59058c2008-08-24 21:49:00 -04001936/**
James Smart3621a712009-04-06 18:47:14 -04001937 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001938 * @dev: class device that is converted into a Scsi_host.
1939 * @attr: device attribute, not used.
1940 * @buf: containing the string lpfc_soft_wwn_key.
1941 * @count: must be size of lpfc_soft_wwn_key.
1942 *
1943 * Returns:
1944 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1945 * length of buf indicates success
1946 **/
James Smartc3f28af2006-08-18 17:47:18 -04001947static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001948lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1949 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001950{
Tony Jonesee959b02008-02-22 00:13:36 +01001951 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1953 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001954 unsigned int cnt = count;
1955
1956 /*
1957 * We're doing a simple sanity check for soft_wwpn setting.
1958 * We require that the user write a specific key to enable
1959 * the soft_wwpn attribute to be settable. Once the attribute
1960 * is written, the enable key resets. If further updates are
1961 * desired, the key must be written again to re-enable the
1962 * attribute.
1963 *
1964 * The "key" is not secret - it is a hardcoded string shown
1965 * here. The intent is to protect against the random user or
1966 * application that is just writing attributes.
1967 */
1968
1969 /* count may include a LF at end of string */
1970 if (buf[cnt-1] == '\n')
1971 cnt--;
1972
James Smarta12e07b2006-12-02 13:35:30 -05001973 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1974 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001975 return -EINVAL;
1976
James Smarta12e07b2006-12-02 13:35:30 -05001977 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001978 return count;
1979}
Tony Jonesee959b02008-02-22 00:13:36 +01001980static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1981 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001982
James Smarte59058c2008-08-24 21:49:00 -04001983/**
James Smart3621a712009-04-06 18:47:14 -04001984 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001985 * @dev: class device that is converted into a Scsi_host.
1986 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001987 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001988 *
1989 * Returns: size of formatted string.
1990 **/
James Smartc3f28af2006-08-18 17:47:18 -04001991static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001992lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1993 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001994{
Tony Jonesee959b02008-02-22 00:13:36 +01001995 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001996 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1997 struct lpfc_hba *phba = vport->phba;
1998
Randy Dunlapafc071e2006-10-23 21:47:13 -07001999 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2000 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002001}
2002
James Smarte59058c2008-08-24 21:49:00 -04002003/**
James Smart3621a712009-04-06 18:47:14 -04002004 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002005 * @dev class device that is converted into a Scsi_host.
2006 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002007 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002008 * @count: number of wwpn bytes in buf
2009 *
2010 * Returns:
2011 * -EACCES hba reset not enabled, adapter over temp
2012 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2013 * -EIO error taking adapter offline or online
2014 * value of count on success
2015 **/
James Smartc3f28af2006-08-18 17:47:18 -04002016static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002017lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2018 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002019{
Tony Jonesee959b02008-02-22 00:13:36 +01002020 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002021 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2022 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002023 struct completion online_compl;
2024 int stat1=0, stat2=0;
2025 unsigned int i, j, cnt=count;
2026 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002027 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002028
James Smart13815c82008-01-11 01:52:48 -05002029 if (!phba->cfg_enable_hba_reset)
2030 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002031 spin_lock_irq(&phba->hbalock);
2032 if (phba->over_temp_state == HBA_OVER_TEMP) {
2033 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002034 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002035 }
2036 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002037 /* count may include a LF at end of string */
2038 if (buf[cnt-1] == '\n')
2039 cnt--;
2040
James Smarta12e07b2006-12-02 13:35:30 -05002041 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002042 ((cnt == 17) && (*buf++ != 'x')) ||
2043 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2044 return -EINVAL;
2045
James Smarta12e07b2006-12-02 13:35:30 -05002046 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002047
2048 memset(wwpn, 0, sizeof(wwpn));
2049
2050 /* Validate and store the new name */
2051 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002052 int value;
2053
2054 value = hex_to_bin(*buf++);
2055 if (value >= 0)
2056 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002057 else
2058 return -EINVAL;
2059 if (i % 2) {
2060 wwpn[i/2] = j & 0xff;
2061 j = 0;
2062 }
2063 }
2064 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002065 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002066 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002067 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002068
2069 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2070 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2071
James Smart46fa3112007-04-25 09:51:45 -04002072 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002073 if (stat1)
2074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002075 "0463 lpfc_soft_wwpn attribute set failed to "
2076 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002077 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002078 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2079 LPFC_EVT_ONLINE);
2080 if (rc == 0)
2081 return -ENOMEM;
2082
James Smartc3f28af2006-08-18 17:47:18 -04002083 wait_for_completion(&online_compl);
2084 if (stat2)
2085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002086 "0464 lpfc_soft_wwpn attribute set failed to "
2087 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002088 return (stat1 || stat2) ? -EIO : count;
2089}
Tony Jonesee959b02008-02-22 00:13:36 +01002090static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2091 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002092
James Smarte59058c2008-08-24 21:49:00 -04002093/**
James Smart3621a712009-04-06 18:47:14 -04002094 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002095 * @dev: class device that is converted into a Scsi_host.
2096 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002097 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002098 *
2099 * Returns: size of formatted string.
2100 **/
James Smarta12e07b2006-12-02 13:35:30 -05002101static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002102lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2103 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002104{
Tony Jonesee959b02008-02-22 00:13:36 +01002105 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002106 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002107 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2108 (unsigned long long)phba->cfg_soft_wwnn);
2109}
2110
James Smarte59058c2008-08-24 21:49:00 -04002111/**
James Smart3621a712009-04-06 18:47:14 -04002112 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002113 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002114 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002115 * @count: number of wwnn bytes in buf.
2116 *
2117 * Returns:
2118 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2119 * value of count on success
2120 **/
James Smarta12e07b2006-12-02 13:35:30 -05002121static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002122lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2123 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002124{
Tony Jonesee959b02008-02-22 00:13:36 +01002125 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002126 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002127 unsigned int i, j, cnt=count;
2128 u8 wwnn[8];
2129
2130 /* count may include a LF at end of string */
2131 if (buf[cnt-1] == '\n')
2132 cnt--;
2133
2134 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2135 ((cnt == 17) && (*buf++ != 'x')) ||
2136 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2137 return -EINVAL;
2138
2139 /*
2140 * Allow wwnn to be set many times, as long as the enable is set.
2141 * However, once the wwpn is set, everything locks.
2142 */
2143
2144 memset(wwnn, 0, sizeof(wwnn));
2145
2146 /* Validate and store the new name */
2147 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002148 int value;
2149
2150 value = hex_to_bin(*buf++);
2151 if (value >= 0)
2152 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002153 else
2154 return -EINVAL;
2155 if (i % 2) {
2156 wwnn[i/2] = j & 0xff;
2157 j = 0;
2158 }
2159 }
2160 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2161
2162 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2163 "lpfc%d: soft_wwnn set. Value will take effect upon "
2164 "setting of the soft_wwpn\n", phba->brd_no);
2165
2166 return count;
2167}
Tony Jonesee959b02008-02-22 00:13:36 +01002168static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2169 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002170
James Smartc3f28af2006-08-18 17:47:18 -04002171
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002172static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002173module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002174MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2175 " 0 - none,"
2176 " 1 - poll with interrupts enabled"
2177 " 3 - poll and disable FCP ring interrupts");
2178
Tony Jonesee959b02008-02-22 00:13:36 +01002179static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2180 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002181
James Smart92d7f7b2007-06-17 19:56:38 -05002182int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002183module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002184MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2185 " 0 - auto (SLI-3 if supported),"
2186 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2187 " 3 - select SLI-3");
2188
James Smart15672312010-04-06 14:49:03 -04002189int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002190module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002191MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2192lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002193lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002194static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002195
James Smart7d791df2011-07-22 18:37:52 -04002196LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2197 "FCF Fast failover=1 Priority failover=2");
2198
James Smart19ca7602010-11-20 23:11:55 -05002199int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002200module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002201MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2202lpfc_param_show(enable_rrq);
2203lpfc_param_init(enable_rrq, 0, 0, 1);
2204static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2205
dea31012005-04-17 16:05:31 -05002206/*
James Smart84d1b002010-02-12 14:42:33 -05002207# lpfc_suppress_link_up: Bring link up at initialization
2208# 0x0 = bring link up (issue MBX_INIT_LINK)
2209# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2210# 0x2 = never bring up link
2211# Default value is 0.
2212*/
James Smarte40a02c2010-02-26 14:13:54 -05002213LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2214 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2215 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002216/*
2217# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2218# 1 - (1024)
2219# 2 - (2048)
2220# 3 - (3072)
2221# 4 - (4096)
2222# 5 - (5120)
2223*/
2224static ssize_t
2225lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2226{
2227 struct Scsi_Host *shost = class_to_shost(dev);
2228 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2229
2230 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2231}
2232
2233static DEVICE_ATTR(iocb_hw, S_IRUGO,
2234 lpfc_iocb_hw_show, NULL);
2235static ssize_t
2236lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2237{
2238 struct Scsi_Host *shost = class_to_shost(dev);
2239 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2240
2241 return snprintf(buf, PAGE_SIZE, "%d\n",
2242 phba->sli.ring[LPFC_ELS_RING].txq_max);
2243}
2244
2245static DEVICE_ATTR(txq_hw, S_IRUGO,
2246 lpfc_txq_hw_show, NULL);
2247static ssize_t
2248lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2249 char *buf)
2250{
2251 struct Scsi_Host *shost = class_to_shost(dev);
2252 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2253
2254 return snprintf(buf, PAGE_SIZE, "%d\n",
2255 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2256}
2257
2258static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2259 lpfc_txcmplq_hw_show, NULL);
2260
2261int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002262module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002263MODULE_PARM_DESC(lpfc_iocb_cnt,
2264 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2265lpfc_param_show(iocb_cnt);
2266lpfc_param_init(iocb_cnt, 2, 1, 5);
2267static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2268 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002269
2270/*
James Smartc01f3202006-08-18 17:47:08 -04002271# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2272# until the timer expires. Value range is [0,255]. Default value is 30.
2273*/
2274static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2275static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2276module_param(lpfc_nodev_tmo, int, 0);
2277MODULE_PARM_DESC(lpfc_nodev_tmo,
2278 "Seconds driver will hold I/O waiting "
2279 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002280
2281/**
James Smart3621a712009-04-06 18:47:14 -04002282 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002283 * @dev: class converted to a Scsi_host structure.
2284 * @attr: device attribute, not used.
2285 * @buf: on return contains the dev loss timeout in decimal.
2286 *
2287 * Returns: size of formatted string.
2288 **/
James Smartc01f3202006-08-18 17:47:08 -04002289static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002290lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2291 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002292{
Tony Jonesee959b02008-02-22 00:13:36 +01002293 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002294 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002295
James Smart3de2a652007-08-02 11:09:59 -04002296 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002297}
2298
James Smarte59058c2008-08-24 21:49:00 -04002299/**
James Smart3621a712009-04-06 18:47:14 -04002300 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002301 * @vport: lpfc vport structure pointer.
2302 * @val: contains the nodev timeout value.
2303 *
2304 * Description:
2305 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2306 * a kernel error message is printed and zero is returned.
2307 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2308 * Otherwise nodev tmo is set to the default value.
2309 *
2310 * Returns:
2311 * zero if already set or if val is in range
2312 * -EINVAL val out of range
2313 **/
James Smartc01f3202006-08-18 17:47:08 -04002314static int
James Smart3de2a652007-08-02 11:09:59 -04002315lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002316{
James Smart3de2a652007-08-02 11:09:59 -04002317 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2318 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2319 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002320 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002321 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002322 "parameter because devloss_tmo is "
2323 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002324 return 0;
2325 }
2326
2327 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002328 vport->cfg_nodev_tmo = val;
2329 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002330 return 0;
2331 }
James Smarte8b62012007-08-02 11:10:09 -04002332 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2333 "0400 lpfc_nodev_tmo attribute cannot be set to"
2334 " %d, allowed range is [%d, %d]\n",
2335 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002336 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002337 return -EINVAL;
2338}
2339
James Smarte59058c2008-08-24 21:49:00 -04002340/**
James Smart3621a712009-04-06 18:47:14 -04002341 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002342 * @vport: lpfc vport structure pointer.
2343 *
2344 * Description:
2345 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2346 **/
James Smart7054a602007-04-25 09:52:34 -04002347static void
James Smart3de2a652007-08-02 11:09:59 -04002348lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002349{
James Smart858c9f62007-06-17 19:56:39 -05002350 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002351 struct lpfc_nodelist *ndlp;
2352
James Smart51ef4c22007-08-02 11:10:31 -04002353 shost = lpfc_shost_from_vport(vport);
2354 spin_lock_irq(shost->host_lock);
2355 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002356 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002357 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2358 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002359}
2360
James Smarte59058c2008-08-24 21:49:00 -04002361/**
James Smart3621a712009-04-06 18:47:14 -04002362 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002363 * @vport: lpfc vport structure pointer.
2364 * @val: contains the tmo value.
2365 *
2366 * Description:
2367 * If the devloss tmo is already set or the vport dev loss tmo has changed
2368 * then a kernel error message is printed and zero is returned.
2369 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2370 * Otherwise nodev tmo is set to the default value.
2371 *
2372 * Returns:
2373 * zero if already set or if val is in range
2374 * -EINVAL val out of range
2375 **/
James Smartc01f3202006-08-18 17:47:08 -04002376static int
James Smart3de2a652007-08-02 11:09:59 -04002377lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002378{
James Smart3de2a652007-08-02 11:09:59 -04002379 if (vport->dev_loss_tmo_changed ||
2380 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002381 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2382 "0401 Ignoring change to nodev_tmo "
2383 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002384 return 0;
2385 }
James Smartc01f3202006-08-18 17:47:08 -04002386 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002387 vport->cfg_nodev_tmo = val;
2388 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002389 /*
2390 * For compat: set the fc_host dev loss so new rports
2391 * will get the value.
2392 */
2393 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002394 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002395 return 0;
2396 }
James Smarte8b62012007-08-02 11:10:09 -04002397 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2398 "0403 lpfc_nodev_tmo attribute cannot be set to"
2399 "%d, allowed range is [%d, %d]\n",
2400 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002401 return -EINVAL;
2402}
2403
James Smart3de2a652007-08-02 11:09:59 -04002404lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002405
Tony Jonesee959b02008-02-22 00:13:36 +01002406static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2407 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002408
2409/*
2410# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2411# disappear until the timer expires. Value range is [0,255]. Default
2412# value is 30.
2413*/
James Smartab56dc22011-02-16 12:39:57 -05002414module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002415MODULE_PARM_DESC(lpfc_devloss_tmo,
2416 "Seconds driver will hold I/O waiting "
2417 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002418lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2419 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2420lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002421
2422/**
James Smart3621a712009-04-06 18:47:14 -04002423 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002424 * @vport: lpfc vport structure pointer.
2425 * @val: contains the tmo value.
2426 *
2427 * Description:
2428 * If val is in a valid range then set the vport nodev tmo,
2429 * devloss tmo, also set the vport dev loss tmo changed flag.
2430 * Else a kernel error message is printed.
2431 *
2432 * Returns:
2433 * zero if val is in range
2434 * -EINVAL val out of range
2435 **/
James Smartc01f3202006-08-18 17:47:08 -04002436static int
James Smart3de2a652007-08-02 11:09:59 -04002437lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002438{
2439 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002440 vport->cfg_nodev_tmo = val;
2441 vport->cfg_devloss_tmo = val;
2442 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002443 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002444 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002445 return 0;
2446 }
2447
James Smarte8b62012007-08-02 11:10:09 -04002448 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2449 "0404 lpfc_devloss_tmo attribute cannot be set to"
2450 " %d, allowed range is [%d, %d]\n",
2451 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002452 return -EINVAL;
2453}
2454
James Smart3de2a652007-08-02 11:09:59 -04002455lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002456static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2457 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002458
2459/*
dea31012005-04-17 16:05:31 -05002460# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2461# deluged with LOTS of information.
2462# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002463# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002464*/
James Smartf4b4c682009-05-22 14:53:12 -04002465LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002466 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002467
2468/*
James Smart7ee5d432007-10-27 13:37:17 -04002469# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2470# objects that have been registered with the nameserver after login.
2471*/
2472LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2473 "Deregister nameserver objects before LOGO");
2474
2475/*
dea31012005-04-17 16:05:31 -05002476# lun_queue_depth: This parameter is used to limit the number of outstanding
2477# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2478*/
James Smart3de2a652007-08-02 11:09:59 -04002479LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2480 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002481
2482/*
James Smart7dc517d2010-07-14 15:32:10 -04002483# tgt_queue_depth: This parameter is used to limit the number of outstanding
2484# commands per target port. Value range is [10,65535]. Default value is 65535.
2485*/
2486LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2487 "Max number of FCP commands we can queue to a specific target port");
2488
2489/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002490# hba_queue_depth: This parameter is used to limit the number of outstanding
2491# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2492# value is greater than the maximum number of exchanges supported by the HBA,
2493# then maximum number of exchanges supported by the HBA is used to determine
2494# the hba_queue_depth.
2495*/
2496LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2497 "Max number of FCP commands we can queue to a lpfc HBA");
2498
2499/*
James Smart92d7f7b2007-06-17 19:56:38 -05002500# peer_port_login: This parameter allows/prevents logins
2501# between peer ports hosted on the same physical port.
2502# When this parameter is set 0 peer ports of same physical port
2503# are not allowed to login to each other.
2504# When this parameter is set 1 peer ports of same physical port
2505# are allowed to login to each other.
2506# Default value of this parameter is 0.
2507*/
James Smart3de2a652007-08-02 11:09:59 -04002508LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2509 "Allow peer ports on the same physical port to login to each "
2510 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002511
2512/*
James Smart3de2a652007-08-02 11:09:59 -04002513# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002514# between Virtual Ports and remote initiators.
2515# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2516# other initiators and will attempt to PLOGI all remote ports.
2517# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2518# remote ports and will not attempt to PLOGI to other initiators.
2519# This parameter does not restrict to the physical port.
2520# This parameter does not restrict logins to Fabric resident remote ports.
2521# Default value of this parameter is 1.
2522*/
James Smart3de2a652007-08-02 11:09:59 -04002523static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002524module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002525MODULE_PARM_DESC(lpfc_restrict_login,
2526 "Restrict virtual ports login to remote initiators.");
2527lpfc_vport_param_show(restrict_login);
2528
James Smarte59058c2008-08-24 21:49:00 -04002529/**
James Smart3621a712009-04-06 18:47:14 -04002530 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002531 * @vport: lpfc vport structure pointer.
2532 * @val: contains the restrict login value.
2533 *
2534 * Description:
2535 * If val is not in a valid range then log a kernel error message and set
2536 * the vport restrict login to one.
2537 * If the port type is physical clear the restrict login flag and return.
2538 * Else set the restrict login flag to val.
2539 *
2540 * Returns:
2541 * zero if val is in range
2542 * -EINVAL val out of range
2543 **/
James Smart3de2a652007-08-02 11:09:59 -04002544static int
2545lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2546{
2547 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002548 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002549 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002550 "be set to %d, allowed range is [0, 1]\n",
2551 val);
James Smart3de2a652007-08-02 11:09:59 -04002552 vport->cfg_restrict_login = 1;
2553 return -EINVAL;
2554 }
2555 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2556 vport->cfg_restrict_login = 0;
2557 return 0;
2558 }
2559 vport->cfg_restrict_login = val;
2560 return 0;
2561}
2562
James Smarte59058c2008-08-24 21:49:00 -04002563/**
James Smart3621a712009-04-06 18:47:14 -04002564 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002565 * @vport: lpfc vport structure pointer.
2566 * @val: contains the restrict login value.
2567 *
2568 * Description:
2569 * If val is not in a valid range then log a kernel error message and set
2570 * the vport restrict login to one.
2571 * If the port type is physical and the val is not zero log a kernel
2572 * error message, clear the restrict login flag and return zero.
2573 * Else set the restrict login flag to val.
2574 *
2575 * Returns:
2576 * zero if val is in range
2577 * -EINVAL val out of range
2578 **/
James Smart3de2a652007-08-02 11:09:59 -04002579static int
2580lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2581{
2582 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002583 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002584 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002585 "be set to %d, allowed range is [0, 1]\n",
2586 val);
James Smart3de2a652007-08-02 11:09:59 -04002587 vport->cfg_restrict_login = 1;
2588 return -EINVAL;
2589 }
2590 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002591 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2592 "0468 lpfc_restrict_login must be 0 for "
2593 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002594 vport->cfg_restrict_login = 0;
2595 return 0;
2596 }
2597 vport->cfg_restrict_login = val;
2598 return 0;
2599}
2600lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002601static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2602 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002603
2604/*
dea31012005-04-17 16:05:31 -05002605# Some disk devices have a "select ID" or "select Target" capability.
2606# From a protocol standpoint "select ID" usually means select the
2607# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2608# annex" which contains a table that maps a "select ID" (a number
2609# between 0 and 7F) to an ALPA. By default, for compatibility with
2610# older drivers, the lpfc driver scans this table from low ALPA to high
2611# ALPA.
2612#
2613# Turning on the scan-down variable (on = 1, off = 0) will
2614# cause the lpfc driver to use an inverted table, effectively
2615# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2616#
2617# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2618# and will not work across a fabric. Also this parameter will take
2619# effect only in the case when ALPA map is not available.)
2620*/
James Smart3de2a652007-08-02 11:09:59 -04002621LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2622 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002623
2624/*
dea31012005-04-17 16:05:31 -05002625# lpfc_topology: link topology for init link
2626# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002627# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002628# 0x02 = attempt point-to-point mode only
2629# 0x04 = attempt loop mode only
2630# 0x06 = attempt point-to-point mode then loop
2631# Set point-to-point mode if you want to run as an N_Port.
2632# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2633# Default value is 0.
2634*/
James Smarte59058c2008-08-24 21:49:00 -04002635
2636/**
James Smart3621a712009-04-06 18:47:14 -04002637 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002638 * @phba: lpfc_hba pointer.
2639 * @val: topology value.
2640 *
2641 * Description:
2642 * If val is in a valid range then set the adapter's topology field and
2643 * issue a lip; if the lip fails reset the topology to the old value.
2644 *
2645 * If the value is not in range log a kernel error message and return an error.
2646 *
2647 * Returns:
2648 * zero if val is in range and lip okay
2649 * non-zero return value from lpfc_issue_lip()
2650 * -EINVAL val out of range
2651 **/
James Smarta257bf92009-04-06 18:48:10 -04002652static ssize_t
2653lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2654 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002655{
James Smarta257bf92009-04-06 18:48:10 -04002656 struct Scsi_Host *shost = class_to_shost(dev);
2657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2658 struct lpfc_hba *phba = vport->phba;
2659 int val = 0;
2660 int nolip = 0;
2661 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002662 int err;
2663 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002664
2665 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2666 nolip = 1;
2667 val_buf = &buf[strlen("nolip ")];
2668 }
2669
2670 if (!isdigit(val_buf[0]))
2671 return -EINVAL;
2672 if (sscanf(val_buf, "%i", &val) != 1)
2673 return -EINVAL;
2674
James Smart83108bd2008-01-11 01:53:09 -05002675 if (val >= 0 && val <= 6) {
2676 prev_val = phba->cfg_topology;
2677 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002678 if (nolip)
2679 return strlen(buf);
2680
James Smart88a2cfb2011-07-22 18:36:33 -04002681 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2682 "3054 lpfc_topology changed from %d to %d\n",
2683 prev_val, val);
James Smart83108bd2008-01-11 01:53:09 -05002684 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002685 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002686 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002687 return -EINVAL;
2688 } else
2689 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002690 }
2691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2692 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2693 "allowed range is [0, 6]\n",
2694 phba->brd_no, val);
2695 return -EINVAL;
2696}
2697static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002698module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002699MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2700lpfc_param_show(topology)
2701lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002702static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002703 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002704
James Smart21e9a0a2009-05-22 14:53:21 -04002705/**
2706 * lpfc_static_vport_show: Read callback function for
2707 * lpfc_static_vport sysfs file.
2708 * @dev: Pointer to class device object.
2709 * @attr: device attribute structure.
2710 * @buf: Data buffer.
2711 *
2712 * This function is the read call back function for
2713 * lpfc_static_vport sysfs file. The lpfc_static_vport
2714 * sysfs file report the mageability of the vport.
2715 **/
2716static ssize_t
2717lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2718 char *buf)
2719{
2720 struct Scsi_Host *shost = class_to_shost(dev);
2721 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2722 if (vport->vport_flag & STATIC_VPORT)
2723 sprintf(buf, "1\n");
2724 else
2725 sprintf(buf, "0\n");
2726
2727 return strlen(buf);
2728}
2729
2730/*
2731 * Sysfs attribute to control the statistical data collection.
2732 */
2733static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2734 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002735
2736/**
James Smart3621a712009-04-06 18:47:14 -04002737 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002738 * @dev: Pointer to class device.
2739 * @buf: Data buffer.
2740 * @count: Size of the data buffer.
2741 *
2742 * This function get called when an user write to the lpfc_stat_data_ctrl
2743 * sysfs file. This function parse the command written to the sysfs file
2744 * and take appropriate action. These commands are used for controlling
2745 * driver statistical data collection.
2746 * Following are the command this function handles.
2747 *
2748 * setbucket <bucket_type> <base> <step>
2749 * = Set the latency buckets.
2750 * destroybucket = destroy all the buckets.
2751 * start = start data collection
2752 * stop = stop data collection
2753 * reset = reset the collected data
2754 **/
2755static ssize_t
2756lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2757 const char *buf, size_t count)
2758{
2759 struct Scsi_Host *shost = class_to_shost(dev);
2760 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2761 struct lpfc_hba *phba = vport->phba;
2762#define LPFC_MAX_DATA_CTRL_LEN 1024
2763 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2764 unsigned long i;
2765 char *str_ptr, *token;
2766 struct lpfc_vport **vports;
2767 struct Scsi_Host *v_shost;
2768 char *bucket_type_str, *base_str, *step_str;
2769 unsigned long base, step, bucket_type;
2770
2771 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002772 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002773 return -EINVAL;
2774
2775 strcpy(bucket_data, buf);
2776 str_ptr = &bucket_data[0];
2777 /* Ignore this token - this is command token */
2778 token = strsep(&str_ptr, "\t ");
2779 if (!token)
2780 return -EINVAL;
2781
2782 bucket_type_str = strsep(&str_ptr, "\t ");
2783 if (!bucket_type_str)
2784 return -EINVAL;
2785
2786 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2787 bucket_type = LPFC_LINEAR_BUCKET;
2788 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2789 bucket_type = LPFC_POWER2_BUCKET;
2790 else
2791 return -EINVAL;
2792
2793 base_str = strsep(&str_ptr, "\t ");
2794 if (!base_str)
2795 return -EINVAL;
2796 base = simple_strtoul(base_str, NULL, 0);
2797
2798 step_str = strsep(&str_ptr, "\t ");
2799 if (!step_str)
2800 return -EINVAL;
2801 step = simple_strtoul(step_str, NULL, 0);
2802 if (!step)
2803 return -EINVAL;
2804
2805 /* Block the data collection for every vport */
2806 vports = lpfc_create_vport_work_array(phba);
2807 if (vports == NULL)
2808 return -ENOMEM;
2809
James Smartf4b4c682009-05-22 14:53:12 -04002810 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002811 v_shost = lpfc_shost_from_vport(vports[i]);
2812 spin_lock_irq(v_shost->host_lock);
2813 /* Block and reset data collection */
2814 vports[i]->stat_data_blocked = 1;
2815 if (vports[i]->stat_data_enabled)
2816 lpfc_vport_reset_stat_data(vports[i]);
2817 spin_unlock_irq(v_shost->host_lock);
2818 }
2819
2820 /* Set the bucket attributes */
2821 phba->bucket_type = bucket_type;
2822 phba->bucket_base = base;
2823 phba->bucket_step = step;
2824
James Smartf4b4c682009-05-22 14:53:12 -04002825 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002826 v_shost = lpfc_shost_from_vport(vports[i]);
2827
2828 /* Unblock data collection */
2829 spin_lock_irq(v_shost->host_lock);
2830 vports[i]->stat_data_blocked = 0;
2831 spin_unlock_irq(v_shost->host_lock);
2832 }
2833 lpfc_destroy_vport_work_array(phba, vports);
2834 return strlen(buf);
2835 }
2836
2837 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2838 vports = lpfc_create_vport_work_array(phba);
2839 if (vports == NULL)
2840 return -ENOMEM;
2841
James Smartf4b4c682009-05-22 14:53:12 -04002842 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002843 v_shost = lpfc_shost_from_vport(vports[i]);
2844 spin_lock_irq(shost->host_lock);
2845 vports[i]->stat_data_blocked = 1;
2846 lpfc_free_bucket(vport);
2847 vport->stat_data_enabled = 0;
2848 vports[i]->stat_data_blocked = 0;
2849 spin_unlock_irq(shost->host_lock);
2850 }
2851 lpfc_destroy_vport_work_array(phba, vports);
2852 phba->bucket_type = LPFC_NO_BUCKET;
2853 phba->bucket_base = 0;
2854 phba->bucket_step = 0;
2855 return strlen(buf);
2856 }
2857
2858 if (!strncmp(buf, "start", strlen("start"))) {
2859 /* If no buckets configured return error */
2860 if (phba->bucket_type == LPFC_NO_BUCKET)
2861 return -EINVAL;
2862 spin_lock_irq(shost->host_lock);
2863 if (vport->stat_data_enabled) {
2864 spin_unlock_irq(shost->host_lock);
2865 return strlen(buf);
2866 }
2867 lpfc_alloc_bucket(vport);
2868 vport->stat_data_enabled = 1;
2869 spin_unlock_irq(shost->host_lock);
2870 return strlen(buf);
2871 }
2872
2873 if (!strncmp(buf, "stop", strlen("stop"))) {
2874 spin_lock_irq(shost->host_lock);
2875 if (vport->stat_data_enabled == 0) {
2876 spin_unlock_irq(shost->host_lock);
2877 return strlen(buf);
2878 }
2879 lpfc_free_bucket(vport);
2880 vport->stat_data_enabled = 0;
2881 spin_unlock_irq(shost->host_lock);
2882 return strlen(buf);
2883 }
2884
2885 if (!strncmp(buf, "reset", strlen("reset"))) {
2886 if ((phba->bucket_type == LPFC_NO_BUCKET)
2887 || !vport->stat_data_enabled)
2888 return strlen(buf);
2889 spin_lock_irq(shost->host_lock);
2890 vport->stat_data_blocked = 1;
2891 lpfc_vport_reset_stat_data(vport);
2892 vport->stat_data_blocked = 0;
2893 spin_unlock_irq(shost->host_lock);
2894 return strlen(buf);
2895 }
2896 return -EINVAL;
2897}
2898
2899
2900/**
James Smart3621a712009-04-06 18:47:14 -04002901 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002902 * @dev: Pointer to class device object.
2903 * @buf: Data buffer.
2904 *
2905 * This function is the read call back function for
2906 * lpfc_stat_data_ctrl sysfs file. This function report the
2907 * current statistical data collection state.
2908 **/
2909static ssize_t
2910lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2911 char *buf)
2912{
2913 struct Scsi_Host *shost = class_to_shost(dev);
2914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2915 struct lpfc_hba *phba = vport->phba;
2916 int index = 0;
2917 int i;
2918 char *bucket_type;
2919 unsigned long bucket_value;
2920
2921 switch (phba->bucket_type) {
2922 case LPFC_LINEAR_BUCKET:
2923 bucket_type = "linear";
2924 break;
2925 case LPFC_POWER2_BUCKET:
2926 bucket_type = "power2";
2927 break;
2928 default:
2929 bucket_type = "No Bucket";
2930 break;
2931 }
2932
2933 sprintf(&buf[index], "Statistical Data enabled :%d, "
2934 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2935 " Bucket step :%d\nLatency Ranges :",
2936 vport->stat_data_enabled, vport->stat_data_blocked,
2937 bucket_type, phba->bucket_base, phba->bucket_step);
2938 index = strlen(buf);
2939 if (phba->bucket_type != LPFC_NO_BUCKET) {
2940 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2941 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2942 bucket_value = phba->bucket_base +
2943 phba->bucket_step * i;
2944 else
2945 bucket_value = phba->bucket_base +
2946 (1 << i) * phba->bucket_step;
2947
2948 if (index + 10 > PAGE_SIZE)
2949 break;
2950 sprintf(&buf[index], "%08ld ", bucket_value);
2951 index = strlen(buf);
2952 }
2953 }
2954 sprintf(&buf[index], "\n");
2955 return strlen(buf);
2956}
2957
2958/*
2959 * Sysfs attribute to control the statistical data collection.
2960 */
2961static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2962 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2963
2964/*
2965 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2966 */
2967
2968/*
2969 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2970 * for each target.
2971 */
2972#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2973#define MAX_STAT_DATA_SIZE_PER_TARGET \
2974 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2975
2976
2977/**
James Smart3621a712009-04-06 18:47:14 -04002978 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002979 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002980 * @kobj: Pointer to the kernel object
2981 * @bin_attr: Attribute object
2982 * @buff: Buffer pointer
2983 * @off: File offset
2984 * @count: Buffer size
2985 *
2986 * This function is the read call back function for lpfc_drvr_stat_data
2987 * sysfs file. This function export the statistical data to user
2988 * applications.
2989 **/
2990static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002991sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2992 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002993 char *buf, loff_t off, size_t count)
2994{
2995 struct device *dev = container_of(kobj, struct device,
2996 kobj);
2997 struct Scsi_Host *shost = class_to_shost(dev);
2998 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2999 struct lpfc_hba *phba = vport->phba;
3000 int i = 0, index = 0;
3001 unsigned long nport_index;
3002 struct lpfc_nodelist *ndlp = NULL;
3003 nport_index = (unsigned long)off /
3004 MAX_STAT_DATA_SIZE_PER_TARGET;
3005
3006 if (!vport->stat_data_enabled || vport->stat_data_blocked
3007 || (phba->bucket_type == LPFC_NO_BUCKET))
3008 return 0;
3009
3010 spin_lock_irq(shost->host_lock);
3011 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3012 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3013 continue;
3014
3015 if (nport_index > 0) {
3016 nport_index--;
3017 continue;
3018 }
3019
3020 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3021 > count)
3022 break;
3023
3024 if (!ndlp->lat_data)
3025 continue;
3026
3027 /* Print the WWN */
3028 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3029 ndlp->nlp_portname.u.wwn[0],
3030 ndlp->nlp_portname.u.wwn[1],
3031 ndlp->nlp_portname.u.wwn[2],
3032 ndlp->nlp_portname.u.wwn[3],
3033 ndlp->nlp_portname.u.wwn[4],
3034 ndlp->nlp_portname.u.wwn[5],
3035 ndlp->nlp_portname.u.wwn[6],
3036 ndlp->nlp_portname.u.wwn[7]);
3037
3038 index = strlen(buf);
3039
3040 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3041 sprintf(&buf[index], "%010u,",
3042 ndlp->lat_data[i].cmd_count);
3043 index = strlen(buf);
3044 }
3045 sprintf(&buf[index], "\n");
3046 index = strlen(buf);
3047 }
3048 spin_unlock_irq(shost->host_lock);
3049 return index;
3050}
3051
3052static struct bin_attribute sysfs_drvr_stat_data_attr = {
3053 .attr = {
3054 .name = "lpfc_drvr_stat_data",
3055 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003056 },
3057 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3058 .read = sysfs_drvr_stat_data_read,
3059 .write = NULL,
3060};
3061
dea31012005-04-17 16:05:31 -05003062/*
3063# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3064# connection.
James Smart76a95d72010-11-20 23:11:48 -05003065# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003066*/
James Smarte59058c2008-08-24 21:49:00 -04003067/**
James Smart3621a712009-04-06 18:47:14 -04003068 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003069 * @phba: lpfc_hba pointer.
3070 * @val: link speed value.
3071 *
3072 * Description:
3073 * If val is in a valid range then set the adapter's link speed field and
3074 * issue a lip; if the lip fails reset the link speed to the old value.
3075 *
3076 * Notes:
3077 * If the value is not in range log a kernel error message and return an error.
3078 *
3079 * Returns:
3080 * zero if val is in range and lip okay.
3081 * non-zero return value from lpfc_issue_lip()
3082 * -EINVAL val out of range
3083 **/
James Smarta257bf92009-04-06 18:48:10 -04003084static ssize_t
3085lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3086 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003087{
James Smarta257bf92009-04-06 18:48:10 -04003088 struct Scsi_Host *shost = class_to_shost(dev);
3089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3090 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003091 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003092 int nolip = 0;
3093 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003094 int err;
3095 uint32_t prev_val;
3096
James Smarta257bf92009-04-06 18:48:10 -04003097 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3098 nolip = 1;
3099 val_buf = &buf[strlen("nolip ")];
3100 }
3101
3102 if (!isdigit(val_buf[0]))
3103 return -EINVAL;
3104 if (sscanf(val_buf, "%i", &val) != 1)
3105 return -EINVAL;
3106
James Smart88a2cfb2011-07-22 18:36:33 -04003107 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3108 "3055 lpfc_link_speed changed from %d to %d %s\n",
3109 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3110
James Smart76a95d72010-11-20 23:11:48 -05003111 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3112 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3113 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3114 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3115 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3116 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3117 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3118 "2879 lpfc_link_speed attribute cannot be set "
3119 "to %d. Speed is not supported by this port.\n",
3120 val);
James Smart83108bd2008-01-11 01:53:09 -05003121 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003122 }
3123 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3124 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003125 prev_val = phba->cfg_link_speed;
3126 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003127 if (nolip)
3128 return strlen(buf);
3129
James Smart83108bd2008-01-11 01:53:09 -05003130 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003131 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003132 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003133 return -EINVAL;
3134 } else
3135 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003136 }
James Smart83108bd2008-01-11 01:53:09 -05003137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003138 "0469 lpfc_link_speed attribute cannot be set to %d, "
3139 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003140 return -EINVAL;
3141}
3142
3143static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003144module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003145MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3146lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003147
3148/**
James Smart3621a712009-04-06 18:47:14 -04003149 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003150 * @phba: lpfc_hba pointer.
3151 * @val: link speed value.
3152 *
3153 * Description:
3154 * If val is in a valid range then set the adapter's link speed field.
3155 *
3156 * Notes:
3157 * If the value is not in range log a kernel error message, clear the link
3158 * speed and return an error.
3159 *
3160 * Returns:
3161 * zero if val saved.
3162 * -EINVAL val out of range
3163 **/
James Smart83108bd2008-01-11 01:53:09 -05003164static int
3165lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3166{
James Smart76a95d72010-11-20 23:11:48 -05003167 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3168 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003169 phba->cfg_link_speed = val;
3170 return 0;
3171 }
3172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003173 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003174 "be set to %d, allowed values are "
3175 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003176 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003177 return -EINVAL;
3178}
3179
Tony Jonesee959b02008-02-22 00:13:36 +01003180static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003181 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003182
3183/*
James Smart0d878412009-10-02 15:16:56 -04003184# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3185# 0 = aer disabled or not supported
3186# 1 = aer supported and enabled (default)
3187# Value range is [0,1]. Default value is 1.
3188*/
3189
3190/**
3191 * lpfc_aer_support_store - Set the adapter for aer support
3192 *
3193 * @dev: class device that is converted into a Scsi_host.
3194 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003195 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003196 * @count: unused variable.
3197 *
3198 * Description:
3199 * If the val is 1 and currently the device's AER capability was not
3200 * enabled, invoke the kernel's enable AER helper routine, trying to
3201 * enable the device's AER capability. If the helper routine enabling
3202 * AER returns success, update the device's cfg_aer_support flag to
3203 * indicate AER is supported by the device; otherwise, if the device
3204 * AER capability is already enabled to support AER, then do nothing.
3205 *
3206 * If the val is 0 and currently the device's AER support was enabled,
3207 * invoke the kernel's disable AER helper routine. After that, update
3208 * the device's cfg_aer_support flag to indicate AER is not supported
3209 * by the device; otherwise, if the device AER capability is already
3210 * disabled from supporting AER, then do nothing.
3211 *
3212 * Returns:
3213 * length of the buf on success if val is in range the intended mode
3214 * is supported.
3215 * -EINVAL if val out of range or intended mode is not supported.
3216 **/
3217static ssize_t
3218lpfc_aer_support_store(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 = 0, rc = -EINVAL;
3225
3226 if (!isdigit(buf[0]))
3227 return -EINVAL;
3228 if (sscanf(buf, "%i", &val) != 1)
3229 return -EINVAL;
3230
3231 switch (val) {
3232 case 0:
3233 if (phba->hba_flag & HBA_AER_ENABLED) {
3234 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3235 if (!rc) {
3236 spin_lock_irq(&phba->hbalock);
3237 phba->hba_flag &= ~HBA_AER_ENABLED;
3238 spin_unlock_irq(&phba->hbalock);
3239 phba->cfg_aer_support = 0;
3240 rc = strlen(buf);
3241 } else
James Smart891478a2009-11-18 15:40:23 -05003242 rc = -EPERM;
3243 } else {
James Smart0d878412009-10-02 15:16:56 -04003244 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003245 rc = strlen(buf);
3246 }
James Smart0d878412009-10-02 15:16:56 -04003247 break;
3248 case 1:
3249 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3250 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3251 if (!rc) {
3252 spin_lock_irq(&phba->hbalock);
3253 phba->hba_flag |= HBA_AER_ENABLED;
3254 spin_unlock_irq(&phba->hbalock);
3255 phba->cfg_aer_support = 1;
3256 rc = strlen(buf);
3257 } else
James Smart891478a2009-11-18 15:40:23 -05003258 rc = -EPERM;
3259 } else {
James Smart0d878412009-10-02 15:16:56 -04003260 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003261 rc = strlen(buf);
3262 }
James Smart0d878412009-10-02 15:16:56 -04003263 break;
3264 default:
3265 rc = -EINVAL;
3266 break;
3267 }
3268 return rc;
3269}
3270
3271static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003272module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003273MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3274lpfc_param_show(aer_support)
3275
3276/**
3277 * lpfc_aer_support_init - Set the initial adapters aer support flag
3278 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003279 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003280 *
3281 * Description:
3282 * If val is in a valid range [0,1], then set the adapter's initial
3283 * cfg_aer_support field. It will be up to the driver's probe_one
3284 * routine to determine whether the device's AER support can be set
3285 * or not.
3286 *
3287 * Notes:
3288 * If the value is not in range log a kernel error message, and
3289 * choose the default value of setting AER support and return.
3290 *
3291 * Returns:
3292 * zero if val saved.
3293 * -EINVAL val out of range
3294 **/
3295static int
3296lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3297{
3298 if (val == 0 || val == 1) {
3299 phba->cfg_aer_support = val;
3300 return 0;
3301 }
3302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3303 "2712 lpfc_aer_support attribute value %d out "
3304 "of range, allowed values are 0|1, setting it "
3305 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003306 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003307 phba->cfg_aer_support = 1;
3308 return -EINVAL;
3309}
3310
3311static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3312 lpfc_aer_support_show, lpfc_aer_support_store);
3313
3314/**
3315 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3316 * @dev: class device that is converted into a Scsi_host.
3317 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003318 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003319 * @count: unused variable.
3320 *
3321 * Description:
3322 * If the @buf contains 1 and the device currently has the AER support
3323 * enabled, then invokes the kernel AER helper routine
3324 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3325 * error status register.
3326 *
3327 * Notes:
3328 *
3329 * Returns:
3330 * -EINVAL if the buf does not contain the 1 or the device is not currently
3331 * enabled with the AER support.
3332 **/
3333static ssize_t
3334lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3335 const char *buf, size_t count)
3336{
3337 struct Scsi_Host *shost = class_to_shost(dev);
3338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3339 struct lpfc_hba *phba = vport->phba;
3340 int val, rc = -1;
3341
3342 if (!isdigit(buf[0]))
3343 return -EINVAL;
3344 if (sscanf(buf, "%i", &val) != 1)
3345 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003346 if (val != 1)
3347 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003348
James Smart891478a2009-11-18 15:40:23 -05003349 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003350 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3351
3352 if (rc == 0)
3353 return strlen(buf);
3354 else
James Smart891478a2009-11-18 15:40:23 -05003355 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003356}
3357
3358static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3359 lpfc_aer_cleanup_state);
3360
James Smart912e3ac2011-05-24 11:42:11 -04003361/**
3362 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3363 *
3364 * @dev: class device that is converted into a Scsi_host.
3365 * @attr: device attribute, not used.
3366 * @buf: containing the string the number of vfs to be enabled.
3367 * @count: unused variable.
3368 *
3369 * Description:
3370 * When this api is called either through user sysfs, the driver shall
3371 * try to enable or disable SR-IOV virtual functions according to the
3372 * following:
3373 *
3374 * If zero virtual function has been enabled to the physical function,
3375 * the driver shall invoke the pci enable virtual function api trying
3376 * to enable the virtual functions. If the nr_vfn provided is greater
3377 * than the maximum supported, the maximum virtual function number will
3378 * be used for invoking the api; otherwise, the nr_vfn provided shall
3379 * be used for invoking the api. If the api call returned success, the
3380 * actual number of virtual functions enabled will be set to the driver
3381 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3382 * cfg_sriov_nr_virtfn remains zero.
3383 *
3384 * If none-zero virtual functions have already been enabled to the
3385 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3386 * -EINVAL will be returned and the driver does nothing;
3387 *
3388 * If the nr_vfn provided is zero and none-zero virtual functions have
3389 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3390 * disabling virtual function api shall be invoded to disable all the
3391 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3392 * zero. Otherwise, if zero virtual function has been enabled, do
3393 * nothing.
3394 *
3395 * Returns:
3396 * length of the buf on success if val is in range the intended mode
3397 * is supported.
3398 * -EINVAL if val out of range or intended mode is not supported.
3399 **/
3400static ssize_t
3401lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3402 const char *buf, size_t count)
3403{
3404 struct Scsi_Host *shost = class_to_shost(dev);
3405 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3406 struct lpfc_hba *phba = vport->phba;
3407 struct pci_dev *pdev = phba->pcidev;
3408 int val = 0, rc = -EINVAL;
3409
3410 /* Sanity check on user data */
3411 if (!isdigit(buf[0]))
3412 return -EINVAL;
3413 if (sscanf(buf, "%i", &val) != 1)
3414 return -EINVAL;
3415 if (val < 0)
3416 return -EINVAL;
3417
3418 /* Request disabling virtual functions */
3419 if (val == 0) {
3420 if (phba->cfg_sriov_nr_virtfn > 0) {
3421 pci_disable_sriov(pdev);
3422 phba->cfg_sriov_nr_virtfn = 0;
3423 }
3424 return strlen(buf);
3425 }
3426
3427 /* Request enabling virtual functions */
3428 if (phba->cfg_sriov_nr_virtfn > 0) {
3429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3430 "3018 There are %d virtual functions "
3431 "enabled on physical function.\n",
3432 phba->cfg_sriov_nr_virtfn);
3433 return -EEXIST;
3434 }
3435
3436 if (val <= LPFC_MAX_VFN_PER_PFN)
3437 phba->cfg_sriov_nr_virtfn = val;
3438 else {
3439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3440 "3019 Enabling %d virtual functions is not "
3441 "allowed.\n", val);
3442 return -EINVAL;
3443 }
3444
3445 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3446 if (rc) {
3447 phba->cfg_sriov_nr_virtfn = 0;
3448 rc = -EPERM;
3449 } else
3450 rc = strlen(buf);
3451
3452 return rc;
3453}
3454
3455static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3456module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3457MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3458lpfc_param_show(sriov_nr_virtfn)
3459
3460/**
3461 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3462 * @phba: lpfc_hba pointer.
3463 * @val: link speed value.
3464 *
3465 * Description:
3466 * If val is in a valid range [0,255], then set the adapter's initial
3467 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3468 * number shall be used instead. It will be up to the driver's probe_one
3469 * routine to determine whether the device's SR-IOV is supported or not.
3470 *
3471 * Returns:
3472 * zero if val saved.
3473 * -EINVAL val out of range
3474 **/
3475static int
3476lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3477{
3478 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3479 phba->cfg_sriov_nr_virtfn = val;
3480 return 0;
3481 }
3482
3483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3484 "3017 Enabling %d virtual functions is not "
3485 "allowed.\n", val);
3486 return -EINVAL;
3487}
3488static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3489 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3490
James Smart0d878412009-10-02 15:16:56 -04003491/*
dea31012005-04-17 16:05:31 -05003492# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3493# Value range is [2,3]. Default value is 3.
3494*/
James Smart3de2a652007-08-02 11:09:59 -04003495LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3496 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003497
3498/*
3499# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3500# is [0,1]. Default value is 0.
3501*/
James Smart3de2a652007-08-02 11:09:59 -04003502LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3503 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003504
3505/*
James Smart977b5a02008-09-07 11:52:04 -04003506# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3507# depth. Default value is 0. When the value of this parameter is zero the
3508# SCSI command completion time is not used for controlling I/O queue depth. When
3509# the parameter is set to a non-zero value, the I/O queue depth is controlled
3510# to limit the I/O completion time to the parameter value.
3511# The value is set in milliseconds.
3512*/
3513static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003514module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003515MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3516 "Use command completion time to control queue depth");
3517lpfc_vport_param_show(max_scsicmpl_time);
3518lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3519static int
3520lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3521{
3522 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3523 struct lpfc_nodelist *ndlp, *next_ndlp;
3524
3525 if (val == vport->cfg_max_scsicmpl_time)
3526 return 0;
3527 if ((val < 0) || (val > 60000))
3528 return -EINVAL;
3529 vport->cfg_max_scsicmpl_time = val;
3530
3531 spin_lock_irq(shost->host_lock);
3532 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3533 if (!NLP_CHK_NODE_ACT(ndlp))
3534 continue;
3535 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3536 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003537 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003538 }
3539 spin_unlock_irq(shost->host_lock);
3540 return 0;
3541}
3542lpfc_vport_param_store(max_scsicmpl_time);
3543static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3544 lpfc_max_scsicmpl_time_show,
3545 lpfc_max_scsicmpl_time_store);
3546
3547/*
dea31012005-04-17 16:05:31 -05003548# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3549# range is [0,1]. Default value is 0.
3550*/
3551LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3552
3553/*
3554# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3555# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003556# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003557# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3558# cr_delay is set to 0.
3559*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003560LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003561 "interrupt response is generated");
3562
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003563LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003564 "interrupt response is generated");
3565
3566/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003567# lpfc_multi_ring_support: Determines how many rings to spread available
3568# cmd/rsp IOCB entries across.
3569# Value range is [1,2]. Default value is 1.
3570*/
3571LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3572 "SLI rings to spread IOCB entries across");
3573
3574/*
James Smarta4bc3372006-12-02 13:34:16 -05003575# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3576# identifies what rctl value to configure the additional ring for.
3577# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3578*/
James Smart6a9c52c2009-10-02 15:16:51 -04003579LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003580 255, "Identifies RCTL for additional ring configuration");
3581
3582/*
3583# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3584# identifies what type value to configure the additional ring for.
3585# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3586*/
James Smart6a9c52c2009-10-02 15:16:51 -04003587LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003588 255, "Identifies TYPE for additional ring configuration");
3589
3590/*
dea31012005-04-17 16:05:31 -05003591# lpfc_fdmi_on: controls FDMI support.
3592# 0 = no FDMI support
3593# 1 = support FDMI without attribute of hostname
3594# 2 = support FDMI with attribute of hostname
3595# Value range [0,2]. Default value is 0.
3596*/
James Smart3de2a652007-08-02 11:09:59 -04003597LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003598
3599/*
3600# Specifies the maximum number of ELS cmds we can have outstanding (for
3601# discovery). Value range is [1,64]. Default value = 32.
3602*/
James Smart3de2a652007-08-02 11:09:59 -04003603LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003604 "during discovery");
3605
3606/*
James Smart65a29c12006-07-06 15:50:50 -04003607# lpfc_max_luns: maximum allowed LUN.
3608# Value range is [0,65535]. Default value is 255.
3609# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003610*/
James Smart3de2a652007-08-02 11:09:59 -04003611LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003612
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003613/*
3614# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3615# Value range is [1,255], default value is 10.
3616*/
3617LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3618 "Milliseconds driver will wait between polling FCP ring");
3619
James Smart4ff43242006-12-02 13:34:56 -05003620/*
3621# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3622# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003623# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003624# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003625# 2 = MSI-X enabled (default)
3626# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003627*/
George Kadianakis8605c462010-01-17 21:19:31 +02003628LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003629 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003630
James Smart13815c82008-01-11 01:52:48 -05003631/*
James Smartda0436e2009-05-22 14:51:39 -04003632# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3633#
3634# Value range is [636,651042]. Default value is 10000.
3635*/
3636LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3637 "Set the maximum number of fast-path FCP interrupts per second");
3638
3639/*
3640# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3641#
3642# Value range is [1,31]. Default value is 4.
3643*/
3644LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3645 "Set the number of fast-path FCP work queues, if possible");
3646
3647/*
3648# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3649#
3650# Value range is [1,7]. Default value is 1.
3651*/
3652LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3653 "Set the number of fast-path FCP event queues, if possible");
3654
3655/*
James Smart13815c82008-01-11 01:52:48 -05003656# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3657# 0 = HBA resets disabled
3658# 1 = HBA resets enabled (default)
3659# Value range is [0,1]. Default value is 1.
3660*/
3661LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003662
James Smart13815c82008-01-11 01:52:48 -05003663/*
James Smarteb7a3392010-11-20 23:12:02 -05003664# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003665# 0 = HBA Heartbeat disabled
3666# 1 = HBA Heartbeat enabled (default)
3667# Value range is [0,1]. Default value is 1.
3668*/
James Smarteb7a3392010-11-20 23:12:02 -05003669LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003670
James Smart83108bd2008-01-11 01:53:09 -05003671/*
James Smart81301a92008-12-04 22:39:46 -05003672# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3673# 0 = BlockGuard disabled (default)
3674# 1 = BlockGuard enabled
3675# Value range is [0,1]. Default value is 0.
3676*/
3677LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3678
James Smart6fb120a2009-05-22 14:52:59 -04003679/*
James Smart81301a92008-12-04 22:39:46 -05003680# lpfc_prot_mask: i
3681# - Bit mask of host protection capabilities used to register with the
3682# SCSI mid-layer
3683# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3684# - Allows you to ultimately specify which profiles to use
3685# - Default will result in registering capabilities for all profiles.
3686#
3687*/
James Smart7c56b9f2011-07-22 18:36:25 -04003688unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3689 SHOST_DIX_TYPE0_PROTECTION |
3690 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003691
James Smartab56dc22011-02-16 12:39:57 -05003692module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003693MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3694
3695/*
3696# lpfc_prot_guard: i
3697# - Bit mask of protection guard types to register with the SCSI mid-layer
3698# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3699# - Allows you to ultimately specify which profiles to use
3700# - Default will result in registering capabilities for all guard types
3701#
3702*/
3703unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003704module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003705MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3706
James Smart92494142011-02-16 12:39:44 -05003707/*
3708 * Delay initial NPort discovery when Clean Address bit is cleared in
3709 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3710 * This parameter can have value 0 or 1.
3711 * When this parameter is set to 0, no delay is added to the initial
3712 * discovery.
3713 * When this parameter is set to non-zero value, initial Nport discovery is
3714 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3715 * accept and FCID/Fabric name/Fabric portname is changed.
3716 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3717 * when Clean Address bit is cleared in FLOGI/FDISC
3718 * accept and FCID/Fabric name/Fabric portname is changed.
3719 * Default value is 0.
3720 */
3721int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003722module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003723MODULE_PARM_DESC(lpfc_delay_discovery,
3724 "Delay NPort discovery when Clean Address bit is cleared. "
3725 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003726
3727/*
James Smart3621a712009-04-06 18:47:14 -04003728 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003729 * This value can be set to values between 64 and 256. The default value is
3730 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3731 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3732 */
3733LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3734 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3735
James Smart81301a92008-12-04 22:39:46 -05003736LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3737 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3738 "Max Protection Scatter Gather Segment Count");
3739
Tony Jonesee959b02008-02-22 00:13:36 +01003740struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003741 &dev_attr_bg_info,
3742 &dev_attr_bg_guard_err,
3743 &dev_attr_bg_apptag_err,
3744 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003745 &dev_attr_info,
3746 &dev_attr_serialnum,
3747 &dev_attr_modeldesc,
3748 &dev_attr_modelname,
3749 &dev_attr_programtype,
3750 &dev_attr_portnum,
3751 &dev_attr_fwrev,
3752 &dev_attr_hdw,
3753 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003754 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003755 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003756 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003757 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003758 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003759 &dev_attr_lpfc_temp_sensor,
3760 &dev_attr_lpfc_log_verbose,
3761 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003762 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003763 &dev_attr_lpfc_hba_queue_depth,
3764 &dev_attr_lpfc_peer_port_login,
3765 &dev_attr_lpfc_nodev_tmo,
3766 &dev_attr_lpfc_devloss_tmo,
3767 &dev_attr_lpfc_fcp_class,
3768 &dev_attr_lpfc_use_adisc,
3769 &dev_attr_lpfc_ack0,
3770 &dev_attr_lpfc_topology,
3771 &dev_attr_lpfc_scan_down,
3772 &dev_attr_lpfc_link_speed,
3773 &dev_attr_lpfc_cr_delay,
3774 &dev_attr_lpfc_cr_count,
3775 &dev_attr_lpfc_multi_ring_support,
3776 &dev_attr_lpfc_multi_ring_rctl,
3777 &dev_attr_lpfc_multi_ring_type,
3778 &dev_attr_lpfc_fdmi_on,
3779 &dev_attr_lpfc_max_luns,
3780 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04003781 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05003782 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003783 &dev_attr_nport_evt_cnt,
3784 &dev_attr_board_mode,
3785 &dev_attr_max_vpi,
3786 &dev_attr_used_vpi,
3787 &dev_attr_max_rpi,
3788 &dev_attr_used_rpi,
3789 &dev_attr_max_xri,
3790 &dev_attr_used_xri,
3791 &dev_attr_npiv_info,
3792 &dev_attr_issue_reset,
3793 &dev_attr_lpfc_poll,
3794 &dev_attr_lpfc_poll_tmo,
3795 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003796 &dev_attr_lpfc_fcp_imax,
3797 &dev_attr_lpfc_fcp_wq_count,
3798 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003799 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003800 &dev_attr_lpfc_soft_wwnn,
3801 &dev_attr_lpfc_soft_wwpn,
3802 &dev_attr_lpfc_soft_wwn_enable,
3803 &dev_attr_lpfc_enable_hba_reset,
3804 &dev_attr_lpfc_enable_hba_heartbeat,
3805 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003806 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003807 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003808 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003809 &dev_attr_lpfc_aer_support,
3810 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04003811 &dev_attr_lpfc_sriov_nr_virtfn,
James Smart84d1b002010-02-12 14:42:33 -05003812 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003813 &dev_attr_lpfc_iocb_cnt,
3814 &dev_attr_iocb_hw,
3815 &dev_attr_txq_hw,
3816 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003817 &dev_attr_lpfc_fips_level,
3818 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003819 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04003820 &dev_attr_lpfc_sriov_hw_max_virtfn,
dea31012005-04-17 16:05:31 -05003821 NULL,
3822};
3823
Tony Jonesee959b02008-02-22 00:13:36 +01003824struct device_attribute *lpfc_vport_attrs[] = {
3825 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003826 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003827 &dev_attr_num_discovered_ports,
3828 &dev_attr_lpfc_drvr_version,
3829 &dev_attr_lpfc_log_verbose,
3830 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003831 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003832 &dev_attr_lpfc_nodev_tmo,
3833 &dev_attr_lpfc_devloss_tmo,
3834 &dev_attr_lpfc_hba_queue_depth,
3835 &dev_attr_lpfc_peer_port_login,
3836 &dev_attr_lpfc_restrict_login,
3837 &dev_attr_lpfc_fcp_class,
3838 &dev_attr_lpfc_use_adisc,
3839 &dev_attr_lpfc_fdmi_on,
3840 &dev_attr_lpfc_max_luns,
3841 &dev_attr_nport_evt_cnt,
3842 &dev_attr_npiv_info,
3843 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003844 &dev_attr_lpfc_max_scsicmpl_time,
3845 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003846 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003847 &dev_attr_lpfc_fips_level,
3848 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003849 NULL,
3850};
3851
James Smarte59058c2008-08-24 21:49:00 -04003852/**
James Smart3621a712009-04-06 18:47:14 -04003853 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003854 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003855 * @kobj: kernel kobject that contains the kernel class device.
3856 * @bin_attr: kernel attributes passed to us.
3857 * @buf: contains the data to be written to the adapter IOREG space.
3858 * @off: offset into buffer to beginning of data.
3859 * @count: bytes to transfer.
3860 *
3861 * Description:
3862 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3863 * Uses the adapter io control registers to send buf contents to the adapter.
3864 *
3865 * Returns:
3866 * -ERANGE off and count combo out of range
3867 * -EINVAL off, count or buff address invalid
3868 * -EPERM adapter is offline
3869 * value of count, buf contents written
3870 **/
dea31012005-04-17 16:05:31 -05003871static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003872sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3873 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003874 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003875{
3876 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003877 struct device *dev = container_of(kobj, struct device, kobj);
3878 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003879 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3880 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003881
James Smartf1126682009-06-10 17:22:44 -04003882 if (phba->sli_rev >= LPFC_SLI_REV4)
3883 return -EPERM;
3884
dea31012005-04-17 16:05:31 -05003885 if ((off + count) > FF_REG_AREA_SIZE)
3886 return -ERANGE;
3887
3888 if (count == 0) return 0;
3889
3890 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3891 return -EINVAL;
3892
James Smart2e0fef82007-06-17 19:56:36 -05003893 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003894 return -EPERM;
3895 }
3896
James Smart2e0fef82007-06-17 19:56:36 -05003897 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003898 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3899 writel(*((uint32_t *)(buf + buf_off)),
3900 phba->ctrl_regs_memmap_p + off + buf_off);
3901
James Smart2e0fef82007-06-17 19:56:36 -05003902 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003903
3904 return count;
3905}
3906
James Smarte59058c2008-08-24 21:49:00 -04003907/**
James Smart3621a712009-04-06 18:47:14 -04003908 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003909 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003910 * @kobj: kernel kobject that contains the kernel class device.
3911 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003912 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003913 * @off: offset into buffer to beginning of data.
3914 * @count: bytes to transfer.
3915 *
3916 * Description:
3917 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3918 * Uses the adapter io control registers to read data into buf.
3919 *
3920 * Returns:
3921 * -ERANGE off and count combo out of range
3922 * -EINVAL off, count or buff address invalid
3923 * value of count, buf contents read
3924 **/
dea31012005-04-17 16:05:31 -05003925static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003926sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3927 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003928 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003929{
3930 size_t buf_off;
3931 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003932 struct device *dev = container_of(kobj, struct device, kobj);
3933 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003934 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3935 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003936
James Smartf1126682009-06-10 17:22:44 -04003937 if (phba->sli_rev >= LPFC_SLI_REV4)
3938 return -EPERM;
3939
dea31012005-04-17 16:05:31 -05003940 if (off > FF_REG_AREA_SIZE)
3941 return -ERANGE;
3942
3943 if ((off + count) > FF_REG_AREA_SIZE)
3944 count = FF_REG_AREA_SIZE - off;
3945
3946 if (count == 0) return 0;
3947
3948 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3949 return -EINVAL;
3950
James Smart2e0fef82007-06-17 19:56:36 -05003951 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003952
3953 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3954 tmp_ptr = (uint32_t *)(buf + buf_off);
3955 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3956 }
3957
James Smart2e0fef82007-06-17 19:56:36 -05003958 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003959
3960 return count;
3961}
3962
3963static struct bin_attribute sysfs_ctlreg_attr = {
3964 .attr = {
3965 .name = "ctlreg",
3966 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003967 },
3968 .size = 256,
3969 .read = sysfs_ctlreg_read,
3970 .write = sysfs_ctlreg_write,
3971};
3972
James Smarte59058c2008-08-24 21:49:00 -04003973/**
James Smart3621a712009-04-06 18:47:14 -04003974 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003975 * @phba: lpfc_hba pointer
3976 **/
dea31012005-04-17 16:05:31 -05003977static void
James Smart2e0fef82007-06-17 19:56:36 -05003978sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003979{
3980 phba->sysfs_mbox.state = SMBOX_IDLE;
3981 phba->sysfs_mbox.offset = 0;
3982
3983 if (phba->sysfs_mbox.mbox) {
3984 mempool_free(phba->sysfs_mbox.mbox,
3985 phba->mbox_mem_pool);
3986 phba->sysfs_mbox.mbox = NULL;
3987 }
3988}
3989
James Smarte59058c2008-08-24 21:49:00 -04003990/**
James Smart3621a712009-04-06 18:47:14 -04003991 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003992 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003993 * @kobj: kernel kobject that contains the kernel class device.
3994 * @bin_attr: kernel attributes passed to us.
3995 * @buf: contains the data to be written to sysfs mbox.
3996 * @off: offset into buffer to beginning of data.
3997 * @count: bytes to transfer.
3998 *
3999 * Description:
4000 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4001 * Uses the sysfs mbox to send buf contents to the adapter.
4002 *
4003 * Returns:
4004 * -ERANGE off and count combo out of range
4005 * -EINVAL off, count or buff address invalid
4006 * zero if count is zero
4007 * -EPERM adapter is offline
4008 * -ENOMEM failed to allocate memory for the mail box
4009 * -EAGAIN offset, state or mbox is NULL
4010 * count number of bytes transferred
4011 **/
dea31012005-04-17 16:05:31 -05004012static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004013sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4014 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004015 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004016{
Tony Jonesee959b02008-02-22 00:13:36 +01004017 struct device *dev = container_of(kobj, struct device, kobj);
4018 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004019 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4020 struct lpfc_hba *phba = vport->phba;
4021 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05004022
4023 if ((count + off) > MAILBOX_CMD_SIZE)
4024 return -ERANGE;
4025
4026 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4027 return -EINVAL;
4028
4029 if (count == 0)
4030 return 0;
4031
4032 if (off == 0) {
4033 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4034 if (!mbox)
4035 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05004036 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004037 }
4038
James Smart2e0fef82007-06-17 19:56:36 -05004039 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004040
4041 if (off == 0) {
4042 if (phba->sysfs_mbox.mbox)
4043 mempool_free(mbox, phba->mbox_mem_pool);
4044 else
4045 phba->sysfs_mbox.mbox = mbox;
4046 phba->sysfs_mbox.state = SMBOX_WRITING;
4047 } else {
4048 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4049 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05004050 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05004051 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004052 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004053 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004054 }
4055 }
4056
James Smart04c68492009-05-22 14:52:52 -04004057 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05004058 buf, count);
4059
4060 phba->sysfs_mbox.offset = off + count;
4061
James Smart2e0fef82007-06-17 19:56:36 -05004062 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004063
4064 return count;
4065}
4066
James Smarte59058c2008-08-24 21:49:00 -04004067/**
James Smart3621a712009-04-06 18:47:14 -04004068 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004069 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004070 * @kobj: kernel kobject that contains the kernel class device.
4071 * @bin_attr: kernel attributes passed to us.
4072 * @buf: contains the data to be read from sysfs mbox.
4073 * @off: offset into buffer to beginning of data.
4074 * @count: bytes to transfer.
4075 *
4076 * Description:
4077 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4078 * Uses the sysfs mbox to receive data from to the adapter.
4079 *
4080 * Returns:
4081 * -ERANGE off greater than mailbox command size
4082 * -EINVAL off, count or buff address invalid
4083 * zero if off and count are zero
4084 * -EACCES adapter over temp
4085 * -EPERM garbage can value to catch a multitude of errors
4086 * -EAGAIN management IO not permitted, state or off error
4087 * -ETIME mailbox timeout
4088 * -ENODEV mailbox error
4089 * count number of bytes transferred
4090 **/
dea31012005-04-17 16:05:31 -05004091static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004092sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4093 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004094 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004095{
Tony Jonesee959b02008-02-22 00:13:36 +01004096 struct device *dev = container_of(kobj, struct device, kobj);
4097 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004098 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4099 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004100 int rc;
James Smart04c68492009-05-22 14:52:52 -04004101 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05004102
James Smart1dcb58e2007-04-25 09:51:30 -04004103 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004104 return -ERANGE;
4105
James Smart1dcb58e2007-04-25 09:51:30 -04004106 if ((count + off) > MAILBOX_CMD_SIZE)
4107 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05004108
4109 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4110 return -EINVAL;
4111
4112 if (off && count == 0)
4113 return 0;
4114
James Smart2e0fef82007-06-17 19:56:36 -05004115 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004116
James Smart7af67052007-10-27 13:38:11 -04004117 if (phba->over_temp_state == HBA_OVER_TEMP) {
4118 sysfs_mbox_idle(phba);
4119 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05004120 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04004121 }
4122
dea31012005-04-17 16:05:31 -05004123 if (off == 0 &&
4124 phba->sysfs_mbox.state == SMBOX_WRITING &&
4125 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04004126 pmb = &phba->sysfs_mbox.mbox->u.mb;
4127 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05004128 /* Offline only */
dea31012005-04-17 16:05:31 -05004129 case MBX_INIT_LINK:
4130 case MBX_DOWN_LINK:
4131 case MBX_CONFIG_LINK:
4132 case MBX_CONFIG_RING:
4133 case MBX_RESET_RING:
4134 case MBX_UNREG_LOGIN:
4135 case MBX_CLEAR_LA:
4136 case MBX_DUMP_CONTEXT:
4137 case MBX_RUN_DIAGS:
4138 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05004139 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05004140 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05004141 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05004142 printk(KERN_WARNING "mbox_read:Command 0x%x "
4143 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04004144 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004145 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004146 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004147 return -EPERM;
4148 }
James Smarta8adb832007-10-27 13:37:53 -04004149 case MBX_WRITE_NV:
4150 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05004151 case MBX_LOAD_SM:
4152 case MBX_READ_NV:
4153 case MBX_READ_CONFIG:
4154 case MBX_READ_RCONFIG:
4155 case MBX_READ_STATUS:
4156 case MBX_READ_XRI:
4157 case MBX_READ_REV:
4158 case MBX_READ_LNK_STAT:
4159 case MBX_DUMP_MEMORY:
4160 case MBX_DOWN_LOAD:
4161 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004162 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05004163 case MBX_LOAD_AREA:
4164 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004165 case MBX_BEACON:
4166 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05004167 case MBX_SET_VARIABLE:
4168 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04004169 case MBX_PORT_CAPABILITIES:
4170 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05004171 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04004172 case MBX_SECURITY_MGMT:
4173 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04004174 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4175 printk(KERN_WARNING "mbox_read:Command 0x%x "
4176 "is not permitted\n", pmb->mbxCommand);
4177 sysfs_mbox_idle(phba);
4178 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04004179 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04004180 }
James Smartdcf2a4e2010-09-29 11:18:53 -04004181 break;
dea31012005-04-17 16:05:31 -05004182 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05004183 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05004184 case MBX_REG_LOGIN:
4185 case MBX_REG_LOGIN64:
4186 case MBX_CONFIG_PORT:
4187 case MBX_RUN_BIU_DIAG:
4188 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004189 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004190 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004191 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004192 return -EPERM;
4193 default:
4194 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004195 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004196 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004197 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004198 return -EPERM;
4199 }
4200
James Smart09372822008-01-11 01:52:54 -05004201 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05004202 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05004203 */
James Smartd7c255b2008-08-24 21:50:00 -04004204 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04004205 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4206 pmb->mbxCommand != MBX_RESTART &&
4207 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4208 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04004209 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4210 "1259 mbox: Issued mailbox cmd "
4211 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04004212 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05004213
James Smart92d7f7b2007-06-17 19:56:38 -05004214 phba->sysfs_mbox.mbox->vport = vport;
4215
James Smart58da1ff2008-04-07 10:15:56 -04004216 /* Don't allow mailbox commands to be sent when blocked
4217 * or when in the middle of discovery
4218 */
James Smart495a7142008-06-14 22:52:59 -04004219 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04004220 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004221 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04004222 return -EAGAIN;
4223 }
4224
James Smart2e0fef82007-06-17 19:56:36 -05004225 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004226 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05004227
James Smart2e0fef82007-06-17 19:56:36 -05004228 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004229 rc = lpfc_sli_issue_mbox (phba,
4230 phba->sysfs_mbox.mbox,
4231 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05004232 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004233
4234 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004235 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004236 rc = lpfc_sli_issue_mbox_wait (phba,
4237 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04004238 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05004239 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004240 }
4241
4242 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04004243 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04004244 phba->sysfs_mbox.mbox = NULL;
4245 }
dea31012005-04-17 16:05:31 -05004246 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004247 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004248 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05004249 }
4250 phba->sysfs_mbox.state = SMBOX_READING;
4251 }
4252 else if (phba->sysfs_mbox.offset != off ||
4253 phba->sysfs_mbox.state != SMBOX_READING) {
4254 printk(KERN_WARNING "mbox_read: Bad State\n");
4255 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004256 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004257 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004258 }
4259
James Smart04c68492009-05-22 14:52:52 -04004260 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05004261
4262 phba->sysfs_mbox.offset = off + count;
4263
James Smart1dcb58e2007-04-25 09:51:30 -04004264 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004265 sysfs_mbox_idle(phba);
4266
James Smart2e0fef82007-06-17 19:56:36 -05004267 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004268
4269 return count;
4270}
4271
4272static struct bin_attribute sysfs_mbox_attr = {
4273 .attr = {
4274 .name = "mbox",
4275 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004276 },
James Smartc0c11512011-05-24 11:41:34 -04004277 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004278 .read = sysfs_mbox_read,
4279 .write = sysfs_mbox_write,
4280};
4281
James Smarte59058c2008-08-24 21:49:00 -04004282/**
James Smart3621a712009-04-06 18:47:14 -04004283 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004284 * @vport: address of lpfc vport structure.
4285 *
4286 * Return codes:
4287 * zero on success
4288 * error return code from sysfs_create_bin_file()
4289 **/
dea31012005-04-17 16:05:31 -05004290int
James Smart2e0fef82007-06-17 19:56:36 -05004291lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004292{
James Smart2e0fef82007-06-17 19:56:36 -05004293 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004294 int error;
4295
Tony Jonesee959b02008-02-22 00:13:36 +01004296 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004297 &sysfs_drvr_stat_data_attr);
4298
4299 /* Virtual ports do not need ctrl_reg and mbox */
4300 if (error || vport->port_type == LPFC_NPIV_PORT)
4301 goto out;
4302
4303 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004304 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004305 if (error)
James Smarteada2722008-12-04 22:39:13 -05004306 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004307
Tony Jonesee959b02008-02-22 00:13:36 +01004308 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004309 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004310 if (error)
4311 goto out_remove_ctlreg_attr;
4312
4313 return 0;
4314out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004315 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004316out_remove_stat_attr:
4317 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4318 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004319out:
4320 return error;
4321}
4322
James Smarte59058c2008-08-24 21:49:00 -04004323/**
James Smart3621a712009-04-06 18:47:14 -04004324 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004325 * @vport: address of lpfc vport structure.
4326 **/
dea31012005-04-17 16:05:31 -05004327void
James Smart2e0fef82007-06-17 19:56:36 -05004328lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004329{
James Smart2e0fef82007-06-17 19:56:36 -05004330 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004331 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4332 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004333 /* Virtual ports do not need ctrl_reg and mbox */
4334 if (vport->port_type == LPFC_NPIV_PORT)
4335 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004336 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4337 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004338}
4339
4340
4341/*
4342 * Dynamic FC Host Attributes Support
4343 */
4344
James Smarte59058c2008-08-24 21:49:00 -04004345/**
James Smart3621a712009-04-06 18:47:14 -04004346 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004347 * @shost: kernel scsi host pointer.
4348 **/
dea31012005-04-17 16:05:31 -05004349static void
4350lpfc_get_host_port_id(struct Scsi_Host *shost)
4351{
James Smart2e0fef82007-06-17 19:56:36 -05004352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4353
dea31012005-04-17 16:05:31 -05004354 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004355 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004356}
4357
James Smarte59058c2008-08-24 21:49:00 -04004358/**
James Smart3621a712009-04-06 18:47:14 -04004359 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004360 * @shost: kernel scsi host pointer.
4361 **/
dea31012005-04-17 16:05:31 -05004362static void
4363lpfc_get_host_port_type(struct Scsi_Host *shost)
4364{
James Smart2e0fef82007-06-17 19:56:36 -05004365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4366 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004367
4368 spin_lock_irq(shost->host_lock);
4369
James Smart92d7f7b2007-06-17 19:56:38 -05004370 if (vport->port_type == LPFC_NPIV_PORT) {
4371 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4372 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004373 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004374 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004375 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4376 else
4377 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4378 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004379 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004380 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4381 else
4382 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4383 }
4384 } else
4385 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4386
4387 spin_unlock_irq(shost->host_lock);
4388}
4389
James Smarte59058c2008-08-24 21:49:00 -04004390/**
James Smart3621a712009-04-06 18:47:14 -04004391 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004392 * @shost: kernel scsi host pointer.
4393 **/
dea31012005-04-17 16:05:31 -05004394static void
4395lpfc_get_host_port_state(struct Scsi_Host *shost)
4396{
James Smart2e0fef82007-06-17 19:56:36 -05004397 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4398 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004399
4400 spin_lock_irq(shost->host_lock);
4401
James Smart2e0fef82007-06-17 19:56:36 -05004402 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004403 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4404 else {
James Smart2e0fef82007-06-17 19:56:36 -05004405 switch (phba->link_state) {
4406 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004407 case LPFC_LINK_DOWN:
4408 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4409 break;
4410 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004411 case LPFC_CLEAR_LA:
4412 case LPFC_HBA_READY:
4413 /* Links up, beyond this port_type reports state */
4414 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4415 break;
4416 case LPFC_HBA_ERROR:
4417 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4418 break;
4419 default:
4420 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4421 break;
4422 }
4423 }
4424
4425 spin_unlock_irq(shost->host_lock);
4426}
4427
James Smarte59058c2008-08-24 21:49:00 -04004428/**
James Smart3621a712009-04-06 18:47:14 -04004429 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004430 * @shost: kernel scsi host pointer.
4431 **/
dea31012005-04-17 16:05:31 -05004432static void
4433lpfc_get_host_speed(struct Scsi_Host *shost)
4434{
James Smart2e0fef82007-06-17 19:56:36 -05004435 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4436 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004437
4438 spin_lock_irq(shost->host_lock);
4439
James Smart2e0fef82007-06-17 19:56:36 -05004440 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004441 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004442 case LPFC_LINK_SPEED_1GHZ:
4443 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004444 break;
James Smart76a95d72010-11-20 23:11:48 -05004445 case LPFC_LINK_SPEED_2GHZ:
4446 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004447 break;
James Smart76a95d72010-11-20 23:11:48 -05004448 case LPFC_LINK_SPEED_4GHZ:
4449 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004450 break;
James Smart76a95d72010-11-20 23:11:48 -05004451 case LPFC_LINK_SPEED_8GHZ:
4452 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004453 break;
James Smart76a95d72010-11-20 23:11:48 -05004454 case LPFC_LINK_SPEED_10GHZ:
4455 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004456 break;
James Smart76a95d72010-11-20 23:11:48 -05004457 case LPFC_LINK_SPEED_16GHZ:
4458 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4459 break;
4460 default:
4461 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004462 break;
4463 }
James Smart09372822008-01-11 01:52:54 -05004464 } else
4465 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004466
4467 spin_unlock_irq(shost->host_lock);
4468}
4469
James Smarte59058c2008-08-24 21:49:00 -04004470/**
James Smart3621a712009-04-06 18:47:14 -04004471 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004472 * @shost: kernel scsi host pointer.
4473 **/
dea31012005-04-17 16:05:31 -05004474static void
4475lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4476{
James Smart2e0fef82007-06-17 19:56:36 -05004477 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4478 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004479 u64 node_name;
dea31012005-04-17 16:05:31 -05004480
4481 spin_lock_irq(shost->host_lock);
4482
James Smart2e0fef82007-06-17 19:56:36 -05004483 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004484 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004485 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004486 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004487 else
4488 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004489 node_name = 0;
dea31012005-04-17 16:05:31 -05004490
4491 spin_unlock_irq(shost->host_lock);
4492
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004493 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004494}
4495
James Smarte59058c2008-08-24 21:49:00 -04004496/**
James Smart3621a712009-04-06 18:47:14 -04004497 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004498 * @shost: kernel scsi host pointer.
4499 *
4500 * Notes:
4501 * NULL on error for link down, no mbox pool, sli2 active,
4502 * management not allowed, memory allocation error, or mbox error.
4503 *
4504 * Returns:
4505 * NULL for error
4506 * address of the adapter host statistics
4507 **/
dea31012005-04-17 16:05:31 -05004508static struct fc_host_statistics *
4509lpfc_get_stats(struct Scsi_Host *shost)
4510{
James Smart2e0fef82007-06-17 19:56:36 -05004511 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4512 struct lpfc_hba *phba = vport->phba;
4513 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004514 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004515 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004516 LPFC_MBOXQ_t *pmboxq;
4517 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004518 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004519 int rc = 0;
dea31012005-04-17 16:05:31 -05004520
James Smart92d7f7b2007-06-17 19:56:38 -05004521 /*
4522 * prevent udev from issuing mailbox commands until the port is
4523 * configured.
4524 */
James Smart2e0fef82007-06-17 19:56:36 -05004525 if (phba->link_state < LPFC_LINK_DOWN ||
4526 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004527 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004528 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004529
4530 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004531 return NULL;
4532
dea31012005-04-17 16:05:31 -05004533 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4534 if (!pmboxq)
4535 return NULL;
4536 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4537
James Smart04c68492009-05-22 14:52:52 -04004538 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004539 pmb->mbxCommand = MBX_READ_STATUS;
4540 pmb->mbxOwner = OWN_HOST;
4541 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004542 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004543
James Smart75baf692010-06-08 18:31:21 -04004544 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004545 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004546 else
dea31012005-04-17 16:05:31 -05004547 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4548
4549 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004550 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004551 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004552 return NULL;
4553 }
4554
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004555 memset(hs, 0, sizeof (struct fc_host_statistics));
4556
dea31012005-04-17 16:05:31 -05004557 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4558 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4559 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4560 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4561
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004562 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004563 pmb->mbxCommand = MBX_READ_LNK_STAT;
4564 pmb->mbxOwner = OWN_HOST;
4565 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004566 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004567
James Smart75baf692010-06-08 18:31:21 -04004568 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004569 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004570 else
dea31012005-04-17 16:05:31 -05004571 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4572
4573 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004574 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004575 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004576 return NULL;
4577 }
4578
4579 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4580 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4581 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4582 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4583 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4584 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4585 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4586
James Smart64ba8812006-08-02 15:24:34 -04004587 hs->link_failure_count -= lso->link_failure_count;
4588 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4589 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4590 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4591 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4592 hs->invalid_crc_count -= lso->invalid_crc_count;
4593 hs->error_frames -= lso->error_frames;
4594
James Smart76a95d72010-11-20 23:11:48 -05004595 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004596 hs->lip_count = -1;
4597 hs->nos_count = (phba->link_events >> 1);
4598 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004599 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004600 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004601 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004602 hs->nos_count = -1;
4603 } else {
4604 hs->lip_count = -1;
4605 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004606 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004607 }
4608
4609 hs->dumped_frames = -1;
4610
James Smart64ba8812006-08-02 15:24:34 -04004611 seconds = get_seconds();
4612 if (seconds < psli->stats_start)
4613 hs->seconds_since_last_reset = seconds +
4614 ((unsigned long)-1 - psli->stats_start);
4615 else
4616 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004617
James Smart1dcb58e2007-04-25 09:51:30 -04004618 mempool_free(pmboxq, phba->mbox_mem_pool);
4619
dea31012005-04-17 16:05:31 -05004620 return hs;
4621}
4622
James Smarte59058c2008-08-24 21:49:00 -04004623/**
James Smart3621a712009-04-06 18:47:14 -04004624 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004625 * @shost: kernel scsi host pointer.
4626 **/
James Smart64ba8812006-08-02 15:24:34 -04004627static void
4628lpfc_reset_stats(struct Scsi_Host *shost)
4629{
James Smart2e0fef82007-06-17 19:56:36 -05004630 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4631 struct lpfc_hba *phba = vport->phba;
4632 struct lpfc_sli *psli = &phba->sli;
4633 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004634 LPFC_MBOXQ_t *pmboxq;
4635 MAILBOX_t *pmb;
4636 int rc = 0;
4637
James Smart2e0fef82007-06-17 19:56:36 -05004638 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004639 return;
4640
James Smart64ba8812006-08-02 15:24:34 -04004641 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4642 if (!pmboxq)
4643 return;
4644 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4645
James Smart04c68492009-05-22 14:52:52 -04004646 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004647 pmb->mbxCommand = MBX_READ_STATUS;
4648 pmb->mbxOwner = OWN_HOST;
4649 pmb->un.varWords[0] = 0x1; /* reset request */
4650 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004651 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004652
James Smart2e0fef82007-06-17 19:56:36 -05004653 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004654 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004655 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4656 else
4657 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4658
4659 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004660 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004661 mempool_free(pmboxq, phba->mbox_mem_pool);
4662 return;
4663 }
4664
4665 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4666 pmb->mbxCommand = MBX_READ_LNK_STAT;
4667 pmb->mbxOwner = OWN_HOST;
4668 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004669 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004670
James Smart2e0fef82007-06-17 19:56:36 -05004671 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004672 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004673 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4674 else
4675 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4676
4677 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004678 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004679 mempool_free( pmboxq, phba->mbox_mem_pool);
4680 return;
4681 }
4682
4683 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4684 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4685 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4686 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4687 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4688 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4689 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004690 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004691 lso->link_events = (phba->link_events >> 1);
4692 else
4693 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004694
4695 psli->stats_start = get_seconds();
4696
James Smart1dcb58e2007-04-25 09:51:30 -04004697 mempool_free(pmboxq, phba->mbox_mem_pool);
4698
James Smart64ba8812006-08-02 15:24:34 -04004699 return;
4700}
dea31012005-04-17 16:05:31 -05004701
4702/*
4703 * The LPFC driver treats linkdown handling as target loss events so there
4704 * are no sysfs handlers for link_down_tmo.
4705 */
James Smart685f0bf2007-04-25 09:53:08 -04004706
James Smarte59058c2008-08-24 21:49:00 -04004707/**
James Smart3621a712009-04-06 18:47:14 -04004708 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004709 * @starget: kernel scsi target pointer.
4710 *
4711 * Returns:
4712 * address of the node list if found
4713 * NULL target not found
4714 **/
James Smart685f0bf2007-04-25 09:53:08 -04004715static struct lpfc_nodelist *
4716lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004717{
James Smart2e0fef82007-06-17 19:56:36 -05004718 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4719 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004720 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004721
4722 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004723 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004724 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004725 if (NLP_CHK_NODE_ACT(ndlp) &&
4726 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004727 starget->id == ndlp->nlp_sid) {
4728 spin_unlock_irq(shost->host_lock);
4729 return ndlp;
dea31012005-04-17 16:05:31 -05004730 }
4731 }
4732 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004733 return NULL;
4734}
dea31012005-04-17 16:05:31 -05004735
James Smarte59058c2008-08-24 21:49:00 -04004736/**
James Smart3621a712009-04-06 18:47:14 -04004737 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004738 * @starget: kernel scsi target pointer.
4739 **/
James Smart685f0bf2007-04-25 09:53:08 -04004740static void
4741lpfc_get_starget_port_id(struct scsi_target *starget)
4742{
4743 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4744
4745 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004746}
4747
James Smarte59058c2008-08-24 21:49:00 -04004748/**
James Smart3621a712009-04-06 18:47:14 -04004749 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004750 * @starget: kernel scsi target pointer.
4751 *
4752 * Description: Set the target node name to the ndlp node name wwn or zero.
4753 **/
dea31012005-04-17 16:05:31 -05004754static void
4755lpfc_get_starget_node_name(struct scsi_target *starget)
4756{
James Smart685f0bf2007-04-25 09:53:08 -04004757 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004758
James Smart685f0bf2007-04-25 09:53:08 -04004759 fc_starget_node_name(starget) =
4760 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004761}
4762
James Smarte59058c2008-08-24 21:49:00 -04004763/**
James Smart3621a712009-04-06 18:47:14 -04004764 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004765 * @starget: kernel scsi target pointer.
4766 *
4767 * Description: set the target port name to the ndlp port name wwn or zero.
4768 **/
dea31012005-04-17 16:05:31 -05004769static void
4770lpfc_get_starget_port_name(struct scsi_target *starget)
4771{
James Smart685f0bf2007-04-25 09:53:08 -04004772 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004773
James Smart685f0bf2007-04-25 09:53:08 -04004774 fc_starget_port_name(starget) =
4775 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004776}
4777
James Smarte59058c2008-08-24 21:49:00 -04004778/**
James Smart3621a712009-04-06 18:47:14 -04004779 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004780 * @rport: fc rport address.
4781 * @timeout: new value for dev loss tmo.
4782 *
4783 * Description:
4784 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4785 * dev_loss_tmo to one.
4786 **/
dea31012005-04-17 16:05:31 -05004787static void
dea31012005-04-17 16:05:31 -05004788lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4789{
dea31012005-04-17 16:05:31 -05004790 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004791 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004792 else
James Smartc01f3202006-08-18 17:47:08 -04004793 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004794}
4795
James Smarte59058c2008-08-24 21:49:00 -04004796/**
James Smart3621a712009-04-06 18:47:14 -04004797 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004798 *
4799 * Description:
4800 * Macro that uses field to generate a function with the name lpfc_show_rport_
4801 *
4802 * lpfc_show_rport_##field: returns the bytes formatted in buf
4803 * @cdev: class converted to an fc_rport.
4804 * @buf: on return contains the target_field or zero.
4805 *
4806 * Returns: size of formatted string.
4807 **/
dea31012005-04-17 16:05:31 -05004808#define lpfc_rport_show_function(field, format_string, sz, cast) \
4809static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004810lpfc_show_rport_##field (struct device *dev, \
4811 struct device_attribute *attr, \
4812 char *buf) \
dea31012005-04-17 16:05:31 -05004813{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004814 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004815 struct lpfc_rport_data *rdata = rport->hostdata; \
4816 return snprintf(buf, sz, format_string, \
4817 (rdata->target) ? cast rdata->target->field : 0); \
4818}
4819
4820#define lpfc_rport_rd_attr(field, format_string, sz) \
4821 lpfc_rport_show_function(field, format_string, sz, ) \
4822static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4823
James Smarteada2722008-12-04 22:39:13 -05004824/**
James Smart3621a712009-04-06 18:47:14 -04004825 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004826 * @fc_vport: The fc_vport who's symbolic name has been changed.
4827 *
4828 * Description:
4829 * This function is called by the transport after the @fc_vport's symbolic name
4830 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004831 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004832 **/
4833static void
4834lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4835{
4836 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4837
4838 if (vport->port_state == LPFC_VPORT_READY)
4839 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4840}
dea31012005-04-17 16:05:31 -05004841
James Smartf4b4c682009-05-22 14:53:12 -04004842/**
4843 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4844 * @phba: Pointer to lpfc_hba struct.
4845 *
4846 * This function is called by the lpfc_get_cfgparam() routine to set the
4847 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004848 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004849 * before hba port or vport created.
4850 **/
4851static void
4852lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4853{
4854 phba->cfg_log_verbose = verbose;
4855}
4856
dea31012005-04-17 16:05:31 -05004857struct fc_function_template lpfc_transport_functions = {
4858 /* fixed attributes the driver supports */
4859 .show_host_node_name = 1,
4860 .show_host_port_name = 1,
4861 .show_host_supported_classes = 1,
4862 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004863 .show_host_supported_speeds = 1,
4864 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004865 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004866
4867 /* dynamic attributes the driver supports */
4868 .get_host_port_id = lpfc_get_host_port_id,
4869 .show_host_port_id = 1,
4870
4871 .get_host_port_type = lpfc_get_host_port_type,
4872 .show_host_port_type = 1,
4873
4874 .get_host_port_state = lpfc_get_host_port_state,
4875 .show_host_port_state = 1,
4876
4877 /* active_fc4s is shown but doesn't change (thus no get function) */
4878 .show_host_active_fc4s = 1,
4879
4880 .get_host_speed = lpfc_get_host_speed,
4881 .show_host_speed = 1,
4882
4883 .get_host_fabric_name = lpfc_get_host_fabric_name,
4884 .show_host_fabric_name = 1,
4885
4886 /*
4887 * The LPFC driver treats linkdown handling as target loss events
4888 * so there are no sysfs handlers for link_down_tmo.
4889 */
4890
4891 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004892 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004893
4894 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4895 .show_rport_maxframe_size = 1,
4896 .show_rport_supported_classes = 1,
4897
dea31012005-04-17 16:05:31 -05004898 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4899 .show_rport_dev_loss_tmo = 1,
4900
4901 .get_starget_port_id = lpfc_get_starget_port_id,
4902 .show_starget_port_id = 1,
4903
4904 .get_starget_node_name = lpfc_get_starget_node_name,
4905 .show_starget_node_name = 1,
4906
4907 .get_starget_port_name = lpfc_get_starget_port_name,
4908 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004909
4910 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004911 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4912 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004913
James Smart92d7f7b2007-06-17 19:56:38 -05004914 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004915
4916 .vport_disable = lpfc_vport_disable,
4917
4918 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004919
4920 .bsg_request = lpfc_bsg_request,
4921 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004922};
4923
James Smart98c9ea52007-10-27 13:37:33 -04004924struct fc_function_template lpfc_vport_transport_functions = {
4925 /* fixed attributes the driver supports */
4926 .show_host_node_name = 1,
4927 .show_host_port_name = 1,
4928 .show_host_supported_classes = 1,
4929 .show_host_supported_fc4s = 1,
4930 .show_host_supported_speeds = 1,
4931 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004932 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004933
4934 /* dynamic attributes the driver supports */
4935 .get_host_port_id = lpfc_get_host_port_id,
4936 .show_host_port_id = 1,
4937
4938 .get_host_port_type = lpfc_get_host_port_type,
4939 .show_host_port_type = 1,
4940
4941 .get_host_port_state = lpfc_get_host_port_state,
4942 .show_host_port_state = 1,
4943
4944 /* active_fc4s is shown but doesn't change (thus no get function) */
4945 .show_host_active_fc4s = 1,
4946
4947 .get_host_speed = lpfc_get_host_speed,
4948 .show_host_speed = 1,
4949
4950 .get_host_fabric_name = lpfc_get_host_fabric_name,
4951 .show_host_fabric_name = 1,
4952
4953 /*
4954 * The LPFC driver treats linkdown handling as target loss events
4955 * so there are no sysfs handlers for link_down_tmo.
4956 */
4957
4958 .get_fc_host_stats = lpfc_get_stats,
4959 .reset_fc_host_stats = lpfc_reset_stats,
4960
4961 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4962 .show_rport_maxframe_size = 1,
4963 .show_rport_supported_classes = 1,
4964
4965 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4966 .show_rport_dev_loss_tmo = 1,
4967
4968 .get_starget_port_id = lpfc_get_starget_port_id,
4969 .show_starget_port_id = 1,
4970
4971 .get_starget_node_name = lpfc_get_starget_node_name,
4972 .show_starget_node_name = 1,
4973
4974 .get_starget_port_name = lpfc_get_starget_port_name,
4975 .show_starget_port_name = 1,
4976
4977 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4978 .terminate_rport_io = lpfc_terminate_rport_io,
4979
4980 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004981
4982 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004983};
4984
James Smarte59058c2008-08-24 21:49:00 -04004985/**
James Smart3621a712009-04-06 18:47:14 -04004986 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004987 * @phba: lpfc_hba pointer.
4988 **/
dea31012005-04-17 16:05:31 -05004989void
4990lpfc_get_cfgparam(struct lpfc_hba *phba)
4991{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004992 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4993 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004994 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004995 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4996 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004997 lpfc_ack0_init(phba, lpfc_ack0);
4998 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004999 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005000 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005001 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005002 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005003 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005004 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005005 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5006 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5007 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05005008 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5009 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005010 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005011 if (phba->sli_rev == LPFC_SLI_REV4)
5012 phba->cfg_poll = 0;
5013 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005014 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005015 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005016 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005017 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005018 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005019 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005020 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005021 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005022 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smart84d1b002010-02-12 14:42:33 -05005023 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005024 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005025 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005026 return;
5027}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005028
James Smarte59058c2008-08-24 21:49:00 -04005029/**
James Smart3621a712009-04-06 18:47:14 -04005030 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005031 * @vport: lpfc_vport pointer.
5032 **/
James Smart3de2a652007-08-02 11:09:59 -04005033void
5034lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5035{
James Smarte8b62012007-08-02 11:10:09 -04005036 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005037 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005038 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005039 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5040 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5041 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5042 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5043 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5044 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005045 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005046 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5047 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5048 lpfc_max_luns_init(vport, lpfc_max_luns);
5049 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005050 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005051 return;
5052}