blob: 6ecd6daffc15e8a5652f24205bd2af561bcfd4ae [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
James Smart0d878412009-10-02 15:16:56 -040026#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070028#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050029
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
33#include <scsi/scsi_tcq.h>
34#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040035#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050036
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_version.h"
47#include "lpfc_compat.h"
48#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050049#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050050
James Smartc01f3202006-08-18 17:47:08 -040051#define LPFC_DEF_DEVLOSS_TMO 30
52#define LPFC_MIN_DEVLOSS_TMO 1
53#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050054
James Smarte59058c2008-08-24 21:49:00 -040055/**
James Smart3621a712009-04-06 18:47:14 -040056 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040057 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
dea31012005-04-17 16:05:31 -050070static void
71lpfc_jedec_to_ascii(int incr, char hdw[])
72{
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84}
85
James Smarte59058c2008-08-24 21:49:00 -040086/**
James Smart3621a712009-04-06 18:47:14 -040087 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040088 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
dea31012005-04-17 16:05:31 -050094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010095lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
dea31012005-04-17 16:05:31 -050097{
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99}
100
James Smart45ed1192009-10-02 15:17:02 -0400101/**
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
106 *
107 * Returns: size of formatted string.
108 **/
109static ssize_t
110lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
111 char *buf)
112{
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
116
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
119 else
120 return snprintf(buf, PAGE_SIZE, "0\n");
121}
122
James Smart81301a92008-12-04 22:39:46 -0500123static ssize_t
124lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
126{
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
134 else
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
140}
141
142static ssize_t
143lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
149
James Smart87b5c322008-12-16 10:34:09 -0500150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500152}
153
154static ssize_t
155lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
156 char *buf)
157{
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
161
James Smart87b5c322008-12-16 10:34:09 -0500162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500164}
165
166static ssize_t
167lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
169{
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173
James Smart87b5c322008-12-16 10:34:09 -0500174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500176}
177
James Smarte59058c2008-08-24 21:49:00 -0400178/**
James Smart3621a712009-04-06 18:47:14 -0400179 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
183 *
184 * Returns: size of formatted string.
185 **/
dea31012005-04-17 16:05:31 -0500186static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100187lpfc_info_show(struct device *dev, struct device_attribute *attr,
188 char *buf)
dea31012005-04-17 16:05:31 -0500189{
Tony Jonesee959b02008-02-22 00:13:36 +0100190 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500191
dea31012005-04-17 16:05:31 -0500192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
193}
194
James Smarte59058c2008-08-24 21:49:00 -0400195/**
James Smart3621a712009-04-06 18:47:14 -0400196 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
200 *
201 * Returns: size of formatted string.
202 **/
dea31012005-04-17 16:05:31 -0500203static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100204lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
dea31012005-04-17 16:05:31 -0500206{
Tony Jonesee959b02008-02-22 00:13:36 +0100207 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
210
dea31012005-04-17 16:05:31 -0500211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
212}
213
James Smarte59058c2008-08-24 21:49:00 -0400214/**
James Smart3621a712009-04-06 18:47:14 -0400215 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
219 *
220 * Description:
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
223 *
224 * Returns: size of formatted string.
225 **/
dea31012005-04-17 16:05:31 -0500226static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100227lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
228 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400229{
Tony Jonesee959b02008-02-22 00:13:36 +0100230 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
234}
235
James Smarte59058c2008-08-24 21:49:00 -0400236/**
James Smart3621a712009-04-06 18:47:14 -0400237 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
241 *
242 * Returns: size of formatted string.
243 **/
James Smart57127f12007-10-27 13:37:05 -0400244static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100245lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
dea31012005-04-17 16:05:31 -0500247{
Tony Jonesee959b02008-02-22 00:13:36 +0100248 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
251
dea31012005-04-17 16:05:31 -0500252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
253}
254
James Smarte59058c2008-08-24 21:49:00 -0400255/**
James Smart3621a712009-04-06 18:47:14 -0400256 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
260 *
261 * Returns: size of formatted string.
262 **/
dea31012005-04-17 16:05:31 -0500263static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100264lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
265 char *buf)
dea31012005-04-17 16:05:31 -0500266{
Tony Jonesee959b02008-02-22 00:13:36 +0100267 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
270
dea31012005-04-17 16:05:31 -0500271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
272}
273
James Smarte59058c2008-08-24 21:49:00 -0400274/**
James Smart3621a712009-04-06 18:47:14 -0400275 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
279 *
280 * Returns: size of formatted string.
281 **/
dea31012005-04-17 16:05:31 -0500282static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100283lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
dea31012005-04-17 16:05:31 -0500285{
Tony Jonesee959b02008-02-22 00:13:36 +0100286 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
289
dea31012005-04-17 16:05:31 -0500290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
291}
292
James Smarte59058c2008-08-24 21:49:00 -0400293/**
James Smart3621a712009-04-06 18:47:14 -0400294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
298 *
299 * Returns: size of formatted string.
300 **/
301static ssize_t
302lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
303{
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
307
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
310}
311
312/**
James Smart3621a712009-04-06 18:47:14 -0400313 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
317 *
318 * Returns: size of formatted string.
319 **/
dea31012005-04-17 16:05:31 -0500320static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100321lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
322 char *buf)
dea31012005-04-17 16:05:31 -0500323{
Tony Jonesee959b02008-02-22 00:13:36 +0100324 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
327
dea31012005-04-17 16:05:31 -0500328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
329}
330
James Smarte59058c2008-08-24 21:49:00 -0400331/**
James Smart3621a712009-04-06 18:47:14 -0400332 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
336 *
337 * Returns: size of formatted string.
338 **/
dea31012005-04-17 16:05:31 -0500339static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100340lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
341 char *buf)
dea31012005-04-17 16:05:31 -0500342{
Tony Jonesee959b02008-02-22 00:13:36 +0100343 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500346 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500347
dea31012005-04-17 16:05:31 -0500348 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500350}
351
James Smarte59058c2008-08-24 21:49:00 -0400352/**
James Smart3621a712009-04-06 18:47:14 -0400353 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
357 *
358 * Returns: size of formatted string.
359 **/
dea31012005-04-17 16:05:31 -0500360static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100361lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500362{
363 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100364 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500367 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500368
dea31012005-04-17 16:05:31 -0500369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
371}
James Smarte59058c2008-08-24 21:49:00 -0400372
373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
dea31012005-04-17 16:05:31 -0500384{
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
dea31012005-04-17 16:05:31 -0500389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
390}
James Smarte59058c2008-08-24 21:49:00 -0400391
392/**
James Smart3621a712009-04-06 18:47:14 -0400393 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
397 *
398 * Notes:
399 * The switch statement has no default so zero will be returned.
400 *
401 * Returns: size of formatted string.
402 **/
dea31012005-04-17 16:05:31 -0500403static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100404lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
dea31012005-04-17 16:05:31 -0500406{
Tony Jonesee959b02008-02-22 00:13:36 +0100407 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
410 int len = 0;
411
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500414 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
417 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500418 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
422 else
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down\n");
dea31012005-04-17 16:05:31 -0500425 break;
426 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500427 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500428 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500430
431 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500434 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500435 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500436 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500437 case LPFC_FLOGI:
438 case LPFC_FABRIC_CFG_LINK:
439 case LPFC_NS_REG:
440 case LPFC_NS_QRY:
441 case LPFC_BUILD_DISC_LIST:
442 case LPFC_DISC_AUTH:
443 len += snprintf(buf + len, PAGE_SIZE - len,
444 "Discovery\n");
445 break;
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
448 break;
449
James Smart92d7f7b2007-06-17 19:56:38 -0500450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
452 break;
453
454 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500455 len += snprintf(buf + len, PAGE_SIZE - len,
456 "Unknown\n");
457 break;
458 }
James Smart84774a42008-08-24 21:50:06 -0400459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500463 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500464 len += snprintf(buf + len, PAGE_SIZE-len,
465 " Public Loop\n");
466 else
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Private Loop\n");
469 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500470 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Fabric\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Point-2-Point\n");
476 }
477 }
James Smart2e0fef82007-06-17 19:56:36 -0500478
dea31012005-04-17 16:05:31 -0500479 return len;
480}
481
James Smarte59058c2008-08-24 21:49:00 -0400482/**
James Smart84d1b002010-02-12 14:42:33 -0500483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
487 * @count: not used.
488 *
489 * Returns:
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
493 **/
494static ssize_t
495lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
497{
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
501
502 int status = -EINVAL;
503
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500510
511 if (status == 0)
512 return strlen(buf);
513 else
514 return status;
515}
516
517/**
James Smart3621a712009-04-06 18:47:14 -0400518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
522 *
523 * Description:
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
525 * vport counts.
526 *
527 * Returns: size of formatted string.
528 **/
dea31012005-04-17 16:05:31 -0500529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100530lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500532{
Tony Jonesee959b02008-02-22 00:13:36 +0100533 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500538}
539
James Smarte59058c2008-08-24 21:49:00 -0400540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400542 * @shost: Scsi_Host pointer.
543 *
544 * Description:
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
547 *
548 * Returns:
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
552 * zero for success
553 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700554static int
James Smart2e0fef82007-06-17 19:56:36 -0500555lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500556{
James Smart2e0fef82007-06-17 19:56:36 -0500557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
561
James Smart2e0fef82007-06-17 19:56:36 -0500562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500564 return -EPERM;
565
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
567
568 if (!pmboxq)
569 return -ENOMEM;
570
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400574
James Smart33ccf8d2006-08-17 11:57:58 -0400575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500576
James Smart04c68492009-05-22 14:52:52 -0400577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
584 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400590 }
591
James Smart5b8bd0c2007-04-25 09:52:49 -0400592 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500593 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400594 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500595
596 if (mbxstatus == MBXERR_ERROR)
597 return -EIO;
598
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700599 return 0;
dea31012005-04-17 16:05:31 -0500600}
601
James Smarte59058c2008-08-24 21:49:00 -0400602/**
James Smart3621a712009-04-06 18:47:14 -0400603 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
606 *
607 * Notes:
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400612 *
613 * Returns:
614 * -EIO error posting the event
615 * zero for success
616 **/
James Smart40496f02006-07-06 15:50:22 -0400617static int
James Smart46fa3112007-04-25 09:51:45 -0400618lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
619{
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
623 int status = 0;
624 int cnt = 0;
625 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500626 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400627
628 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400630 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500631 if (rc == 0)
632 return -ENOMEM;
633
James Smart46fa3112007-04-25 09:51:45 -0400634 wait_for_completion(&online_compl);
635
636 if (status != 0)
637 return -EIO;
638
639 psli = &phba->sli;
640
James Smart09372822008-01-11 01:52:54 -0500641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
643 */
James Smart46fa3112007-04-25 09:51:45 -0400644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400646 while (pring->txcmplq_cnt) {
647 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500648 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400653 break;
654 }
655 }
656 }
657
658 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
662
James Smart46fa3112007-04-25 09:51:45 -0400663 wait_for_completion(&online_compl);
664
665 if (status != 0)
666 return -EIO;
667
668 return 0;
669}
670
James Smarte59058c2008-08-24 21:49:00 -0400671/**
James Smart3621a712009-04-06 18:47:14 -0400672 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400673 * @phba: lpfc_hba pointer.
674 *
675 * Description:
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
678 *
679 * Notes:
680 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500681 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400682 *
683 * Returns:
684 * lpfc_do_offline() return code if not zero
685 * -EIO reset not configured or error posting the event
686 * zero for success
687 **/
James Smart7f860592011-03-11 16:05:52 -0500688int
James Smart40496f02006-07-06 15:50:22 -0400689lpfc_selective_reset(struct lpfc_hba *phba)
690{
691 struct completion online_compl;
692 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500693 int rc;
James Smart40496f02006-07-06 15:50:22 -0400694
James Smart13815c82008-01-11 01:52:48 -0500695 if (!phba->cfg_enable_hba_reset)
696 return -EIO;
697
James Smart46fa3112007-04-25 09:51:45 -0400698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400699
700 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400701 return status;
James Smart40496f02006-07-06 15:50:22 -0400702
703 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400705 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500706 if (rc == 0)
707 return -ENOMEM;
708
James Smart40496f02006-07-06 15:50:22 -0400709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 return 0;
715}
716
James Smarte59058c2008-08-24 21:49:00 -0400717/**
James Smart3621a712009-04-06 18:47:14 -0400718 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400719 * @dev: class device that is converted into a Scsi_host.
720 * @attr: device attribute, not used.
721 * @buf: containing the string "selective".
722 * @count: unused variable.
723 *
724 * Description:
725 * If the buf contains the string "selective" then lpfc_selective_reset()
726 * is called to perform the reset.
727 *
728 * Notes:
729 * Assumes any error from lpfc_selective_reset() will be negative.
730 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200731 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400732 *
733 * Returns:
734 * -EINVAL if the buffer does not contain the string "selective"
735 * length of buf if lpfc-selective_reset() if the call succeeds
736 * return value of lpfc_selective_reset() if the call fails
737**/
James Smart40496f02006-07-06 15:50:22 -0400738static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100739lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
740 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400741{
Tony Jonesee959b02008-02-22 00:13:36 +0100742 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
744 struct lpfc_hba *phba = vport->phba;
745
James Smart40496f02006-07-06 15:50:22 -0400746 int status = -EINVAL;
747
748 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500749 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400750
751 if (status == 0)
752 return strlen(buf);
753 else
754 return status;
755}
756
James Smarte59058c2008-08-24 21:49:00 -0400757/**
James Smartc0c11512011-05-24 11:41:34 -0400758 * lpfc_sli4_fw_dump_request - Request firmware to perform a firmware dump
759 * @phba: lpfc_hba pointer.
760 *
761 * Description:
762 * Request SLI4 interface type-2 device to perform a dump of firmware dump
763 * object into it's /dbg directory of the flash file system.
764 *
765 * Returns:
766 * zero for success
767 **/
768static ssize_t
769lpfc_sli4_fw_dump_request(struct lpfc_hba *phba)
770{
771 struct completion online_compl;
772 uint32_t reg_val;
773 int status = 0;
774 int rc;
775
776 if (!phba->cfg_enable_hba_reset)
777 return -EIO;
778
779 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
780
781 if (status != 0)
782 return status;
783
784 /* wait for the device to be quiesced before firmware reset */
785 msleep(100);
786
787 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
788 LPFC_CTL_PDEV_CTL_OFFSET);
789 reg_val |= LPFC_FW_DUMP_REQUEST;
790 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
791 LPFC_CTL_PDEV_CTL_OFFSET);
792 /* flush */
793 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
794
795 /* delay driver action following IF_TYPE_2 reset */
796 msleep(100);
797
798 init_completion(&online_compl);
799 rc = lpfc_workq_post_event(phba, &status, &online_compl,
800 LPFC_EVT_ONLINE);
801 if (rc == 0)
802 return -ENOMEM;
803
804 wait_for_completion(&online_compl);
805
806 if (status != 0)
807 return -EIO;
808
809 return 0;
810}
811
812/**
James Smart3621a712009-04-06 18:47:14 -0400813 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400814 * @dev: class device that is converted into a Scsi_host.
815 * @attr: device attribute, not used.
816 * @buf: on return contains the ascii number of nport events.
817 *
818 * Returns: size of formatted string.
819 **/
dea31012005-04-17 16:05:31 -0500820static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100821lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
822 char *buf)
dea31012005-04-17 16:05:31 -0500823{
Tony Jonesee959b02008-02-22 00:13:36 +0100824 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500825 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
826 struct lpfc_hba *phba = vport->phba;
827
dea31012005-04-17 16:05:31 -0500828 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
829}
830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart3621a712009-04-06 18:47:14 -0400832 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400833 * @dev: class device that is converted into a Scsi_host.
834 * @attr: device attribute, not used.
835 * @buf: on return contains the state of the adapter.
836 *
837 * Returns: size of formatted string.
838 **/
dea31012005-04-17 16:05:31 -0500839static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100840lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
841 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500842{
Tony Jonesee959b02008-02-22 00:13:36 +0100843 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500844 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
845 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500846 char * state;
847
James Smart2e0fef82007-06-17 19:56:36 -0500848 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500849 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500850 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500851 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500852 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500853 state = "offline";
854 else
855 state = "online";
856
857 return snprintf(buf, PAGE_SIZE, "%s\n", state);
858}
859
James Smarte59058c2008-08-24 21:49:00 -0400860/**
James Smart3621a712009-04-06 18:47:14 -0400861 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400862 * @dev: class device that is converted into a Scsi_host.
863 * @attr: device attribute, not used.
864 * @buf: containing one of the strings "online", "offline", "warm" or "error".
865 * @count: unused variable.
866 *
867 * Returns:
868 * -EACCES if enable hba reset not enabled
869 * -EINVAL if the buffer does not contain a valid string (see above)
870 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
871 * buf length greater than zero indicates success
872 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500873static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100874lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
875 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500876{
Tony Jonesee959b02008-02-22 00:13:36 +0100877 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500878 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
879 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500880 struct completion online_compl;
881 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500882 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500883
James Smart13815c82008-01-11 01:52:48 -0500884 if (!phba->cfg_enable_hba_reset)
885 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500886 init_completion(&online_compl);
887
James Smart46fa3112007-04-25 09:51:45 -0400888 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500889 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500890 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500891 if (rc == 0)
892 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400893 wait_for_completion(&online_compl);
894 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
895 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500896 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400897 if (phba->sli_rev == LPFC_SLI_REV4)
898 return -EINVAL;
899 else
900 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400901 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400902 if (phba->sli_rev == LPFC_SLI_REV4)
903 return -EINVAL;
904 else
905 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -0400906 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
907 if ((phba->sli_rev < LPFC_SLI_REV4) ||
908 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
909 LPFC_SLI_INTF_IF_TYPE_2))
910 return -EPERM;
911 else
912 status = lpfc_sli4_fw_dump_request(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500913 else
914 return -EINVAL;
915
Jamie Wellnitz41415862006-02-28 19:25:27 -0500916 if (!status)
917 return strlen(buf);
918 else
919 return -EIO;
920}
921
James Smarte59058c2008-08-24 21:49:00 -0400922/**
James Smart3621a712009-04-06 18:47:14 -0400923 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400924 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400925 * @mxri: max xri count.
926 * @axri: available xri count.
927 * @mrpi: max rpi count.
928 * @arpi: available rpi count.
929 * @mvpi: max vpi count.
930 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400931 *
932 * Description:
933 * If an integer pointer for an count is not null then the value for the
934 * count is returned.
935 *
936 * Returns:
937 * zero on error
938 * one for success
939 **/
James Smart311464e2007-08-02 11:10:37 -0400940static int
James Smart858c9f62007-06-17 19:56:39 -0500941lpfc_get_hba_info(struct lpfc_hba *phba,
942 uint32_t *mxri, uint32_t *axri,
943 uint32_t *mrpi, uint32_t *arpi,
944 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500945{
James Smart04c68492009-05-22 14:52:52 -0400946 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500947 LPFC_MBOXQ_t *pmboxq;
948 MAILBOX_t *pmb;
949 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400950 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500951
952 /*
953 * prevent udev from issuing mailbox commands until the port is
954 * configured.
955 */
956 if (phba->link_state < LPFC_LINK_DOWN ||
957 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400958 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500959 return 0;
960
961 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
962 return 0;
963
964 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
965 if (!pmboxq)
966 return 0;
967 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
968
James Smart04c68492009-05-22 14:52:52 -0400969 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500970 pmb->mbxCommand = MBX_READ_CONFIG;
971 pmb->mbxOwner = OWN_HOST;
972 pmboxq->context1 = NULL;
973
James Smart75baf692010-06-08 18:31:21 -0400974 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500975 rc = MBX_NOT_FINISHED;
976 else
977 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
978
979 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500980 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500981 mempool_free(pmboxq, phba->mbox_mem_pool);
982 return 0;
983 }
984
James Smartda0436e2009-05-22 14:51:39 -0400985 if (phba->sli_rev == LPFC_SLI_REV4) {
986 rd_config = &pmboxq->u.mqe.un.rd_config;
987 if (mrpi)
988 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
989 if (arpi)
990 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
991 phba->sli4_hba.max_cfg_param.rpi_used;
992 if (mxri)
993 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
994 if (axri)
995 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
996 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400997
998 /* Account for differences with SLI-3. Get vpi count from
999 * mailbox data and subtract one for max vpi value.
1000 */
1001 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1002 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1003
James Smartda0436e2009-05-22 14:51:39 -04001004 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001005 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001006 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001007 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001008 } else {
1009 if (mrpi)
1010 *mrpi = pmb->un.varRdConfig.max_rpi;
1011 if (arpi)
1012 *arpi = pmb->un.varRdConfig.avail_rpi;
1013 if (mxri)
1014 *mxri = pmb->un.varRdConfig.max_xri;
1015 if (axri)
1016 *axri = pmb->un.varRdConfig.avail_xri;
1017 if (mvpi)
1018 *mvpi = pmb->un.varRdConfig.max_vpi;
1019 if (avpi)
1020 *avpi = pmb->un.varRdConfig.avail_vpi;
1021 }
James Smart92d7f7b2007-06-17 19:56:38 -05001022
1023 mempool_free(pmboxq, phba->mbox_mem_pool);
1024 return 1;
1025}
1026
James Smarte59058c2008-08-24 21:49:00 -04001027/**
James Smart3621a712009-04-06 18:47:14 -04001028 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001029 * @dev: class device that is converted into a Scsi_host.
1030 * @attr: device attribute, not used.
1031 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1032 *
1033 * Description:
1034 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1035 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1036 * to "Unknown" and the buffer length is returned, therefore the caller
1037 * must check for "Unknown" in the buffer to detect a failure.
1038 *
1039 * Returns: size of formatted string.
1040 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001041static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001042lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1043 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001044{
Tony Jonesee959b02008-02-22 00:13:36 +01001045 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001046 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1047 struct lpfc_hba *phba = vport->phba;
1048 uint32_t cnt;
1049
James Smart858c9f62007-06-17 19:56:39 -05001050 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001051 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1052 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1053}
1054
James Smarte59058c2008-08-24 21:49:00 -04001055/**
James Smart3621a712009-04-06 18:47:14 -04001056 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001057 * @dev: class device that is converted into a Scsi_host.
1058 * @attr: device attribute, not used.
1059 * @buf: containing the used rpi count in decimal or "Unknown".
1060 *
1061 * Description:
1062 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1063 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1064 * to "Unknown" and the buffer length is returned, therefore the caller
1065 * must check for "Unknown" in the buffer to detect a failure.
1066 *
1067 * Returns: size of formatted string.
1068 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001069static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001070lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1071 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001072{
Tony Jonesee959b02008-02-22 00:13:36 +01001073 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001074 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1075 struct lpfc_hba *phba = vport->phba;
1076 uint32_t cnt, acnt;
1077
James Smart858c9f62007-06-17 19:56:39 -05001078 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001079 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1080 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1081}
1082
James Smarte59058c2008-08-24 21:49:00 -04001083/**
James Smart3621a712009-04-06 18:47:14 -04001084 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001085 * @dev: class device that is converted into a Scsi_host.
1086 * @attr: device attribute, not used.
1087 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1088 *
1089 * Description:
1090 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1091 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1092 * to "Unknown" and the buffer length is returned, therefore the caller
1093 * must check for "Unknown" in the buffer to detect a failure.
1094 *
1095 * Returns: size of formatted string.
1096 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001097static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001098lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1099 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001100{
Tony Jonesee959b02008-02-22 00:13:36 +01001101 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1103 struct lpfc_hba *phba = vport->phba;
1104 uint32_t cnt;
1105
James Smart858c9f62007-06-17 19:56:39 -05001106 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001107 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1108 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1109}
1110
James Smarte59058c2008-08-24 21:49:00 -04001111/**
James Smart3621a712009-04-06 18:47:14 -04001112 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001113 * @dev: class device that is converted into a Scsi_host.
1114 * @attr: device attribute, not used.
1115 * @buf: on return contains the used xri count in decimal or "Unknown".
1116 *
1117 * Description:
1118 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1119 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1120 * to "Unknown" and the buffer length is returned, therefore the caller
1121 * must check for "Unknown" in the buffer to detect a failure.
1122 *
1123 * Returns: size of formatted string.
1124 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001125static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001126lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1127 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001128{
Tony Jonesee959b02008-02-22 00:13:36 +01001129 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1131 struct lpfc_hba *phba = vport->phba;
1132 uint32_t cnt, acnt;
1133
James Smart858c9f62007-06-17 19:56:39 -05001134 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1135 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1136 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1137}
1138
James Smarte59058c2008-08-24 21:49:00 -04001139/**
James Smart3621a712009-04-06 18:47:14 -04001140 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001141 * @dev: class device that is converted into a Scsi_host.
1142 * @attr: device attribute, not used.
1143 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1144 *
1145 * Description:
1146 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1147 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1148 * to "Unknown" and the buffer length is returned, therefore the caller
1149 * must check for "Unknown" in the buffer to detect a failure.
1150 *
1151 * Returns: size of formatted string.
1152 **/
James Smart858c9f62007-06-17 19:56:39 -05001153static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001154lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1155 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001156{
Tony Jonesee959b02008-02-22 00:13:36 +01001157 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1159 struct lpfc_hba *phba = vport->phba;
1160 uint32_t cnt;
1161
1162 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1163 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1164 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1165}
1166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
James Smart3621a712009-04-06 18:47:14 -04001168 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001169 * @dev: class device that is converted into a Scsi_host.
1170 * @attr: device attribute, not used.
1171 * @buf: on return contains the used vpi count in decimal or "Unknown".
1172 *
1173 * Description:
1174 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1175 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1176 * to "Unknown" and the buffer length is returned, therefore the caller
1177 * must check for "Unknown" in the buffer to detect a failure.
1178 *
1179 * Returns: size of formatted string.
1180 **/
James Smart858c9f62007-06-17 19:56:39 -05001181static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001182lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1183 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001184{
Tony Jonesee959b02008-02-22 00:13:36 +01001185 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1187 struct lpfc_hba *phba = vport->phba;
1188 uint32_t cnt, acnt;
1189
1190 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001191 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1192 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1193}
1194
James Smarte59058c2008-08-24 21:49:00 -04001195/**
James Smart3621a712009-04-06 18:47:14 -04001196 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001197 * @dev: class device that is converted into a Scsi_host.
1198 * @attr: device attribute, not used.
1199 * @buf: text that must be interpreted to determine if npiv is supported.
1200 *
1201 * Description:
1202 * Buffer will contain text indicating npiv is not suppoerted on the port,
1203 * the port is an NPIV physical port, or it is an npiv virtual port with
1204 * the id of the vport.
1205 *
1206 * Returns: size of formatted string.
1207 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001208static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001209lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1210 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001211{
Tony Jonesee959b02008-02-22 00:13:36 +01001212 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001213 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1214 struct lpfc_hba *phba = vport->phba;
1215
1216 if (!(phba->max_vpi))
1217 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1218 if (vport->port_type == LPFC_PHYSICAL_PORT)
1219 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1220 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1221}
1222
James Smarte59058c2008-08-24 21:49:00 -04001223/**
James Smart3621a712009-04-06 18:47:14 -04001224 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001225 * @dev: class device that is converted into a Scsi_host.
1226 * @attr: device attribute, not used.
1227 * @buf: on return contains the cfg_poll in hex.
1228 *
1229 * Notes:
1230 * cfg_poll should be a lpfc_polling_flags type.
1231 *
1232 * Returns: size of formatted string.
1233 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001234static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001235lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1236 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001237{
Tony Jonesee959b02008-02-22 00:13:36 +01001238 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1240 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001241
1242 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1243}
1244
James Smarte59058c2008-08-24 21:49:00 -04001245/**
James Smart3621a712009-04-06 18:47:14 -04001246 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001247 * @dev: class device that is converted into a Scsi_host.
1248 * @attr: device attribute, not used.
1249 * @buf: one or more lpfc_polling_flags values.
1250 * @count: not used.
1251 *
1252 * Notes:
1253 * buf contents converted to integer and checked for a valid value.
1254 *
1255 * Returns:
1256 * -EINVAL if the buffer connot be converted or is out of range
1257 * length of the buf on success
1258 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001259static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001260lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1261 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001262{
Tony Jonesee959b02008-02-22 00:13:36 +01001263 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001264 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1265 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001266 uint32_t creg_val;
1267 uint32_t old_val;
1268 int val=0;
1269
1270 if (!isdigit(buf[0]))
1271 return -EINVAL;
1272
1273 if (sscanf(buf, "%i", &val) != 1)
1274 return -EINVAL;
1275
1276 if ((val & 0x3) != val)
1277 return -EINVAL;
1278
James Smart45ed1192009-10-02 15:17:02 -04001279 if (phba->sli_rev == LPFC_SLI_REV4)
1280 val = 0;
1281
James Smart2e0fef82007-06-17 19:56:36 -05001282 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001283
1284 old_val = phba->cfg_poll;
1285
1286 if (val & ENABLE_FCP_RING_POLLING) {
1287 if ((val & DISABLE_FCP_RING_INT) &&
1288 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001289 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1290 spin_unlock_irq(&phba->hbalock);
1291 return -EINVAL;
1292 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001293 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1294 writel(creg_val, phba->HCregaddr);
1295 readl(phba->HCregaddr); /* flush */
1296
1297 lpfc_poll_start_timer(phba);
1298 }
1299 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001300 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001301 return -EINVAL;
1302 }
1303
1304 if (!(val & DISABLE_FCP_RING_INT) &&
1305 (old_val & DISABLE_FCP_RING_INT))
1306 {
James Smart2e0fef82007-06-17 19:56:36 -05001307 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001308 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001309 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001310 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1311 spin_unlock_irq(&phba->hbalock);
1312 return -EINVAL;
1313 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001314 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1315 writel(creg_val, phba->HCregaddr);
1316 readl(phba->HCregaddr); /* flush */
1317 }
1318
1319 phba->cfg_poll = val;
1320
James Smart2e0fef82007-06-17 19:56:36 -05001321 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001322
1323 return strlen(buf);
1324}
dea31012005-04-17 16:05:31 -05001325
James Smarte59058c2008-08-24 21:49:00 -04001326/**
James Smartbc739052010-08-04 16:11:18 -04001327 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1328 * @dev: class unused variable.
1329 * @attr: device attribute, not used.
1330 * @buf: on return contains the module description text.
1331 *
1332 * Returns: size of formatted string.
1333 **/
1334static ssize_t
1335lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1336 char *buf)
1337{
1338 struct Scsi_Host *shost = class_to_shost(dev);
1339 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1340 struct lpfc_hba *phba = vport->phba;
1341
1342 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1343}
1344
1345/**
1346 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1347 * @dev: class unused variable.
1348 * @attr: device attribute, not used.
1349 * @buf: on return contains the module description text.
1350 *
1351 * Returns: size of formatted string.
1352 **/
1353static ssize_t
1354lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1355 char *buf)
1356{
1357 struct Scsi_Host *shost = class_to_shost(dev);
1358 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1359 struct lpfc_hba *phba = vport->phba;
1360
1361 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1362}
1363
1364/**
James Smartab56dc22011-02-16 12:39:57 -05001365 * lpfc_dss_show - Return the current state of dss and the configured state
1366 * @dev: class converted to a Scsi_host structure.
1367 * @attr: device attribute, not used.
1368 * @buf: on return contains the formatted text.
1369 *
1370 * Returns: size of formatted string.
1371 **/
1372static ssize_t
1373lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1374 char *buf)
1375{
1376 struct Scsi_Host *shost = class_to_shost(dev);
1377 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1378 struct lpfc_hba *phba = vport->phba;
1379
1380 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1381 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1382 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1383 "" : "Not ");
1384}
1385
1386/**
James Smart912e3ac2011-05-24 11:42:11 -04001387 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1388 * @dev: class converted to a Scsi_host structure.
1389 * @attr: device attribute, not used.
1390 * @buf: on return contains the formatted support level.
1391 *
1392 * Description:
1393 * Returns the maximum number of virtual functions a physical function can
1394 * support, 0 will be returned if called on virtual function.
1395 *
1396 * Returns: size of formatted string.
1397 **/
1398static ssize_t
1399lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1400 struct device_attribute *attr,
1401 char *buf)
1402{
1403 struct Scsi_Host *shost = class_to_shost(dev);
1404 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1405 struct lpfc_hba *phba = vport->phba;
1406 struct pci_dev *pdev = phba->pcidev;
1407 union lpfc_sli4_cfg_shdr *shdr;
1408 uint32_t shdr_status, shdr_add_status;
1409 LPFC_MBOXQ_t *mboxq;
1410 struct lpfc_mbx_get_prof_cfg *get_prof_cfg;
1411 struct lpfc_rsrc_desc_pcie *desc;
1412 uint32_t max_nr_virtfn;
1413 uint32_t desc_count;
1414 int length, rc, i;
1415
1416 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1417 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1418 LPFC_SLI_INTF_IF_TYPE_2))
1419 return -EPERM;
1420
1421 if (!pdev->is_physfn)
1422 return snprintf(buf, PAGE_SIZE, "%d\n", 0);
1423
1424 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1425 if (!mboxq)
1426 return -ENOMEM;
1427
1428 /* get the maximum number of virtfn support by physfn */
1429 length = (sizeof(struct lpfc_mbx_get_prof_cfg) -
1430 sizeof(struct lpfc_sli4_cfg_mhdr));
1431 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
1432 LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG,
1433 length, LPFC_SLI4_MBX_EMBED);
1434 shdr = (union lpfc_sli4_cfg_shdr *)
1435 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
1436 bf_set(lpfc_mbox_hdr_pf_num, &shdr->request,
1437 phba->sli4_hba.iov.pf_number + 1);
1438
1439 get_prof_cfg = &mboxq->u.mqe.un.get_prof_cfg;
1440 bf_set(lpfc_mbx_get_prof_cfg_prof_tp, &get_prof_cfg->u.request,
1441 LPFC_CFG_TYPE_CURRENT_ACTIVE);
1442
1443 rc = lpfc_sli_issue_mbox_wait(phba, mboxq,
1444 lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG));
1445
1446 if (rc != MBX_TIMEOUT) {
1447 /* check return status */
1448 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1449 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
1450 &shdr->response);
1451 if (shdr_status || shdr_add_status || rc)
1452 goto error_out;
1453
1454 } else
1455 goto error_out;
1456
1457 desc_count = get_prof_cfg->u.response.prof_cfg.rsrc_desc_count;
1458
1459 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
1460 desc = (struct lpfc_rsrc_desc_pcie *)
1461 &get_prof_cfg->u.response.prof_cfg.desc[i];
1462 if (LPFC_RSRC_DESC_TYPE_PCIE ==
1463 bf_get(lpfc_rsrc_desc_pcie_type, desc)) {
1464 max_nr_virtfn = bf_get(lpfc_rsrc_desc_pcie_nr_virtfn,
1465 desc);
1466 break;
1467 }
1468 }
1469
1470 if (i < LPFC_RSRC_DESC_MAX_NUM) {
1471 if (rc != MBX_TIMEOUT)
1472 mempool_free(mboxq, phba->mbox_mem_pool);
1473 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1474 }
1475
1476error_out:
1477 if (rc != MBX_TIMEOUT)
1478 mempool_free(mboxq, phba->mbox_mem_pool);
1479 return -EIO;
1480}
1481
1482/**
James Smart3621a712009-04-06 18:47:14 -04001483 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001484 *
1485 * Description:
1486 * Macro that given an attr e.g. hba_queue_depth expands
1487 * into a function with the name lpfc_hba_queue_depth_show.
1488 *
1489 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1490 * @dev: class device that is converted into a Scsi_host.
1491 * @attr: device attribute, not used.
1492 * @buf: on return contains the attribute value in decimal.
1493 *
1494 * Returns: size of formatted string.
1495 **/
dea31012005-04-17 16:05:31 -05001496#define lpfc_param_show(attr) \
1497static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001498lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1499 char *buf) \
dea31012005-04-17 16:05:31 -05001500{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001501 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1503 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001504 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001505 val = phba->cfg_##attr;\
1506 return snprintf(buf, PAGE_SIZE, "%d\n",\
1507 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001508}
1509
James Smarte59058c2008-08-24 21:49:00 -04001510/**
James Smart3621a712009-04-06 18:47:14 -04001511 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001512 *
1513 * Description:
1514 * Macro that given an attr e.g. hba_queue_depth expands
1515 * into a function with the name lpfc_hba_queue_depth_show
1516 *
1517 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1518 * @dev: class device that is converted into a Scsi_host.
1519 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001520 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001521 *
1522 * Returns: size of formatted string.
1523 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001524#define lpfc_param_hex_show(attr) \
1525static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001526lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1527 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001528{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001529 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001530 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1531 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001532 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001533 val = phba->cfg_##attr;\
1534 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1535 phba->cfg_##attr);\
1536}
1537
James Smarte59058c2008-08-24 21:49:00 -04001538/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001539 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001540 *
1541 * Description:
1542 * Macro that given an attr e.g. hba_queue_depth expands
1543 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1544 * takes a default argument, a minimum and maximum argument.
1545 *
1546 * lpfc_##attr##_init: Initializes an attribute.
1547 * @phba: pointer the the adapter structure.
1548 * @val: integer attribute value.
1549 *
1550 * Validates the min and max values then sets the adapter config field
1551 * accordingly, or uses the default if out of range and prints an error message.
1552 *
1553 * Returns:
1554 * zero on success
1555 * -EINVAL if default used
1556 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001557#define lpfc_param_init(attr, default, minval, maxval) \
1558static int \
James Smart84d1b002010-02-12 14:42:33 -05001559lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001560{ \
1561 if (val >= minval && val <= maxval) {\
1562 phba->cfg_##attr = val;\
1563 return 0;\
1564 }\
1565 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001566 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1567 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001568 phba->cfg_##attr = default;\
1569 return -EINVAL;\
1570}
1571
James Smarte59058c2008-08-24 21:49:00 -04001572/**
James Smart3621a712009-04-06 18:47:14 -04001573 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001574 *
1575 * Description:
1576 * Macro that given an attr e.g. hba_queue_depth expands
1577 * into a function with the name lpfc_hba_queue_depth_set
1578 *
1579 * lpfc_##attr##_set: Sets an attribute value.
1580 * @phba: pointer the the adapter structure.
1581 * @val: integer attribute value.
1582 *
1583 * Description:
1584 * Validates the min and max values then sets the
1585 * adapter config field if in the valid range. prints error message
1586 * and does not set the parameter if invalid.
1587 *
1588 * Returns:
1589 * zero on success
1590 * -EINVAL if val is invalid
1591 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001592#define lpfc_param_set(attr, default, minval, maxval) \
1593static int \
James Smart84d1b002010-02-12 14:42:33 -05001594lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001595{ \
1596 if (val >= minval && val <= maxval) {\
1597 phba->cfg_##attr = val;\
1598 return 0;\
1599 }\
1600 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001601 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1602 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001603 return -EINVAL;\
1604}
1605
James Smarte59058c2008-08-24 21:49:00 -04001606/**
James Smart3621a712009-04-06 18:47:14 -04001607 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001608 *
1609 * Description:
1610 * Macro that given an attr e.g. hba_queue_depth expands
1611 * into a function with the name lpfc_hba_queue_depth_store.
1612 *
1613 * lpfc_##attr##_store: Set an sttribute value.
1614 * @dev: class device that is converted into a Scsi_host.
1615 * @attr: device attribute, not used.
1616 * @buf: contains the attribute value in ascii.
1617 * @count: not used.
1618 *
1619 * Description:
1620 * Convert the ascii text number to an integer, then
1621 * use the lpfc_##attr##_set function to set the value.
1622 *
1623 * Returns:
1624 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1625 * length of buffer upon success.
1626 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001627#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001628static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001629lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1630 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001631{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001632 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001633 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1634 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001635 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001636 if (!isdigit(buf[0]))\
1637 return -EINVAL;\
1638 if (sscanf(buf, "%i", &val) != 1)\
1639 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001640 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001641 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001642 else \
1643 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001644}
1645
James Smarte59058c2008-08-24 21:49:00 -04001646/**
James Smart3621a712009-04-06 18:47:14 -04001647 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001648 *
1649 * Description:
1650 * Macro that given an attr e.g. hba_queue_depth expands
1651 * into a function with the name lpfc_hba_queue_depth_show
1652 *
1653 * lpfc_##attr##_show: prints the attribute value in decimal.
1654 * @dev: class device that is converted into a Scsi_host.
1655 * @attr: device attribute, not used.
1656 * @buf: on return contains the attribute value in decimal.
1657 *
1658 * Returns: length of formatted string.
1659 **/
James Smart3de2a652007-08-02 11:09:59 -04001660#define lpfc_vport_param_show(attr) \
1661static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001662lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1663 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001664{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001665 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001667 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001668 val = vport->cfg_##attr;\
1669 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1670}
1671
James Smarte59058c2008-08-24 21:49:00 -04001672/**
James Smart3621a712009-04-06 18:47:14 -04001673 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001674 *
1675 * Description:
1676 * Macro that given an attr e.g.
1677 * hba_queue_depth expands into a function with the name
1678 * lpfc_hba_queue_depth_show
1679 *
James Smart3621a712009-04-06 18:47:14 -04001680 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001681 * @dev: class device that is converted into a Scsi_host.
1682 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001683 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001684 *
1685 * Returns: length of formatted string.
1686 **/
James Smart3de2a652007-08-02 11:09:59 -04001687#define lpfc_vport_param_hex_show(attr) \
1688static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001689lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1690 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001691{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001692 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001693 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001694 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001695 val = vport->cfg_##attr;\
1696 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1697}
1698
James Smarte59058c2008-08-24 21:49:00 -04001699/**
James Smart3621a712009-04-06 18:47:14 -04001700 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001701 *
1702 * Description:
1703 * Macro that given an attr e.g. hba_queue_depth expands
1704 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1705 * takes a default argument, a minimum and maximum argument.
1706 *
1707 * lpfc_##attr##_init: validates the min and max values then sets the
1708 * adapter config field accordingly, or uses the default if out of range
1709 * and prints an error message.
1710 * @phba: pointer the the adapter structure.
1711 * @val: integer attribute value.
1712 *
1713 * Returns:
1714 * zero on success
1715 * -EINVAL if default used
1716 **/
James Smart3de2a652007-08-02 11:09:59 -04001717#define lpfc_vport_param_init(attr, default, minval, maxval) \
1718static int \
James Smart84d1b002010-02-12 14:42:33 -05001719lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001720{ \
1721 if (val >= minval && val <= maxval) {\
1722 vport->cfg_##attr = val;\
1723 return 0;\
1724 }\
James Smarte8b62012007-08-02 11:10:09 -04001725 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001726 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001727 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001728 vport->cfg_##attr = default;\
1729 return -EINVAL;\
1730}
1731
James Smarte59058c2008-08-24 21:49:00 -04001732/**
James Smart3621a712009-04-06 18:47:14 -04001733 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001734 *
1735 * Description:
1736 * Macro that given an attr e.g. hba_queue_depth expands
1737 * into a function with the name lpfc_hba_queue_depth_set
1738 *
1739 * lpfc_##attr##_set: validates the min and max values then sets the
1740 * adapter config field if in the valid range. prints error message
1741 * and does not set the parameter if invalid.
1742 * @phba: pointer the the adapter structure.
1743 * @val: integer attribute value.
1744 *
1745 * Returns:
1746 * zero on success
1747 * -EINVAL if val is invalid
1748 **/
James Smart3de2a652007-08-02 11:09:59 -04001749#define lpfc_vport_param_set(attr, default, minval, maxval) \
1750static int \
James Smart84d1b002010-02-12 14:42:33 -05001751lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001752{ \
1753 if (val >= minval && val <= maxval) {\
1754 vport->cfg_##attr = val;\
1755 return 0;\
1756 }\
James Smarte8b62012007-08-02 11:10:09 -04001757 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001758 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001759 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001760 return -EINVAL;\
1761}
1762
James Smarte59058c2008-08-24 21:49:00 -04001763/**
James Smart3621a712009-04-06 18:47:14 -04001764 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001765 *
1766 * Description:
1767 * Macro that given an attr e.g. hba_queue_depth
1768 * expands into a function with the name lpfc_hba_queue_depth_store
1769 *
1770 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1771 * use the lpfc_##attr##_set function to set the value.
1772 * @cdev: class device that is converted into a Scsi_host.
1773 * @buf: contains the attribute value in decimal.
1774 * @count: not used.
1775 *
1776 * Returns:
1777 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1778 * length of buffer upon success.
1779 **/
James Smart3de2a652007-08-02 11:09:59 -04001780#define lpfc_vport_param_store(attr) \
1781static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001782lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1783 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001784{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001785 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001786 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001787 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001788 if (!isdigit(buf[0]))\
1789 return -EINVAL;\
1790 if (sscanf(buf, "%i", &val) != 1)\
1791 return -EINVAL;\
1792 if (lpfc_##attr##_set(vport, val) == 0) \
1793 return strlen(buf);\
1794 else \
1795 return -EINVAL;\
1796}
1797
1798
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001799#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001800static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001801module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001802MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001803lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001804
1805#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001806static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001807module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001808MODULE_PARM_DESC(lpfc_##name, desc);\
1809lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001810lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001811static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001812
1813#define LPFC_ATTR_RW(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)\
1819lpfc_param_set(name, defval, minval, maxval)\
1820lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001821static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1822 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001823
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001824#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001825static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001826module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001827MODULE_PARM_DESC(lpfc_##name, desc);\
1828lpfc_param_hex_show(name)\
1829lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001830static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001831
1832#define LPFC_ATTR_HEX_RW(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)\
1838lpfc_param_set(name, defval, minval, maxval)\
1839lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001840static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1841 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001842
James Smart3de2a652007-08-02 11:09:59 -04001843#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001844static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001845module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001846MODULE_PARM_DESC(lpfc_##name, desc);\
1847lpfc_vport_param_init(name, defval, minval, maxval)
1848
1849#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001850static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001851module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001852MODULE_PARM_DESC(lpfc_##name, desc);\
1853lpfc_vport_param_show(name)\
1854lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001855static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001856
1857#define LPFC_VPORT_ATTR_RW(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)\
1863lpfc_vport_param_set(name, defval, minval, maxval)\
1864lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001865static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1866 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001867
1868#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001869static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001870module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001871MODULE_PARM_DESC(lpfc_##name, desc);\
1872lpfc_vport_param_hex_show(name)\
1873lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001874static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001875
1876#define LPFC_VPORT_ATTR_HEX_RW(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)\
1882lpfc_vport_param_set(name, defval, minval, maxval)\
1883lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001884static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1885 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001886
James Smart81301a92008-12-04 22:39:46 -05001887static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1888static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1889static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1890static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001891static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1892static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1893static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1894static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1895static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1896static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1897static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1898static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001899static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1900 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001901static DEVICE_ATTR(option_rom_version, S_IRUGO,
1902 lpfc_option_rom_version_show, NULL);
1903static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1904 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001905static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001906static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1907static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001908static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001909static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1910 lpfc_board_mode_show, lpfc_board_mode_store);
1911static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1912static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1913static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1914static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1915static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1916static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1917static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1918static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1919static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001920static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1921static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001922static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001923static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1924 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001925
James Smarta12e07b2006-12-02 13:35:30 -05001926static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001927
James Smarte59058c2008-08-24 21:49:00 -04001928/**
James Smart3621a712009-04-06 18:47:14 -04001929 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001930 * @dev: class device that is converted into a Scsi_host.
1931 * @attr: device attribute, not used.
1932 * @buf: containing the string lpfc_soft_wwn_key.
1933 * @count: must be size of lpfc_soft_wwn_key.
1934 *
1935 * Returns:
1936 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1937 * length of buf indicates success
1938 **/
James Smartc3f28af2006-08-18 17:47:18 -04001939static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001940lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1941 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001942{
Tony Jonesee959b02008-02-22 00:13:36 +01001943 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001944 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1945 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001946 unsigned int cnt = count;
1947
1948 /*
1949 * We're doing a simple sanity check for soft_wwpn setting.
1950 * We require that the user write a specific key to enable
1951 * the soft_wwpn attribute to be settable. Once the attribute
1952 * is written, the enable key resets. If further updates are
1953 * desired, the key must be written again to re-enable the
1954 * attribute.
1955 *
1956 * The "key" is not secret - it is a hardcoded string shown
1957 * here. The intent is to protect against the random user or
1958 * application that is just writing attributes.
1959 */
1960
1961 /* count may include a LF at end of string */
1962 if (buf[cnt-1] == '\n')
1963 cnt--;
1964
James Smarta12e07b2006-12-02 13:35:30 -05001965 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1966 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001967 return -EINVAL;
1968
James Smarta12e07b2006-12-02 13:35:30 -05001969 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001970 return count;
1971}
Tony Jonesee959b02008-02-22 00:13:36 +01001972static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1973 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001974
James Smarte59058c2008-08-24 21:49:00 -04001975/**
James Smart3621a712009-04-06 18:47:14 -04001976 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001977 * @dev: class device that is converted into a Scsi_host.
1978 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001979 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001980 *
1981 * Returns: size of formatted string.
1982 **/
James Smartc3f28af2006-08-18 17:47:18 -04001983static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001984lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1985 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001986{
Tony Jonesee959b02008-02-22 00:13:36 +01001987 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001988 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1989 struct lpfc_hba *phba = vport->phba;
1990
Randy Dunlapafc071e2006-10-23 21:47:13 -07001991 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1992 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001993}
1994
James Smarte59058c2008-08-24 21:49:00 -04001995/**
James Smart3621a712009-04-06 18:47:14 -04001996 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001997 * @dev class device that is converted into a Scsi_host.
1998 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001999 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002000 * @count: number of wwpn bytes in buf
2001 *
2002 * Returns:
2003 * -EACCES hba reset not enabled, adapter over temp
2004 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2005 * -EIO error taking adapter offline or online
2006 * value of count on success
2007 **/
James Smartc3f28af2006-08-18 17:47:18 -04002008static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002009lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2010 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002011{
Tony Jonesee959b02008-02-22 00:13:36 +01002012 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002013 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2014 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002015 struct completion online_compl;
2016 int stat1=0, stat2=0;
2017 unsigned int i, j, cnt=count;
2018 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002019 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002020
James Smart13815c82008-01-11 01:52:48 -05002021 if (!phba->cfg_enable_hba_reset)
2022 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002023 spin_lock_irq(&phba->hbalock);
2024 if (phba->over_temp_state == HBA_OVER_TEMP) {
2025 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002026 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002027 }
2028 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002029 /* count may include a LF at end of string */
2030 if (buf[cnt-1] == '\n')
2031 cnt--;
2032
James Smarta12e07b2006-12-02 13:35:30 -05002033 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002034 ((cnt == 17) && (*buf++ != 'x')) ||
2035 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2036 return -EINVAL;
2037
James Smarta12e07b2006-12-02 13:35:30 -05002038 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002039
2040 memset(wwpn, 0, sizeof(wwpn));
2041
2042 /* Validate and store the new name */
2043 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002044 int value;
2045
2046 value = hex_to_bin(*buf++);
2047 if (value >= 0)
2048 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002049 else
2050 return -EINVAL;
2051 if (i % 2) {
2052 wwpn[i/2] = j & 0xff;
2053 j = 0;
2054 }
2055 }
2056 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002057 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002058 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002059 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002060
2061 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2062 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2063
James Smart46fa3112007-04-25 09:51:45 -04002064 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002065 if (stat1)
2066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002067 "0463 lpfc_soft_wwpn attribute set failed to "
2068 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002069 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002070 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2071 LPFC_EVT_ONLINE);
2072 if (rc == 0)
2073 return -ENOMEM;
2074
James Smartc3f28af2006-08-18 17:47:18 -04002075 wait_for_completion(&online_compl);
2076 if (stat2)
2077 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002078 "0464 lpfc_soft_wwpn attribute set failed to "
2079 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002080 return (stat1 || stat2) ? -EIO : count;
2081}
Tony Jonesee959b02008-02-22 00:13:36 +01002082static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2083 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002084
James Smarte59058c2008-08-24 21:49:00 -04002085/**
James Smart3621a712009-04-06 18:47:14 -04002086 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002087 * @dev: class device that is converted into a Scsi_host.
2088 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002089 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002090 *
2091 * Returns: size of formatted string.
2092 **/
James Smarta12e07b2006-12-02 13:35:30 -05002093static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002094lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2095 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002096{
Tony Jonesee959b02008-02-22 00:13:36 +01002097 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002098 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002099 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2100 (unsigned long long)phba->cfg_soft_wwnn);
2101}
2102
James Smarte59058c2008-08-24 21:49:00 -04002103/**
James Smart3621a712009-04-06 18:47:14 -04002104 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002105 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002106 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002107 * @count: number of wwnn bytes in buf.
2108 *
2109 * Returns:
2110 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2111 * value of count on success
2112 **/
James Smarta12e07b2006-12-02 13:35:30 -05002113static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002114lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2115 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002116{
Tony Jonesee959b02008-02-22 00:13:36 +01002117 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002118 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002119 unsigned int i, j, cnt=count;
2120 u8 wwnn[8];
2121
2122 /* count may include a LF at end of string */
2123 if (buf[cnt-1] == '\n')
2124 cnt--;
2125
2126 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2127 ((cnt == 17) && (*buf++ != 'x')) ||
2128 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2129 return -EINVAL;
2130
2131 /*
2132 * Allow wwnn to be set many times, as long as the enable is set.
2133 * However, once the wwpn is set, everything locks.
2134 */
2135
2136 memset(wwnn, 0, sizeof(wwnn));
2137
2138 /* Validate and store the new name */
2139 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002140 int value;
2141
2142 value = hex_to_bin(*buf++);
2143 if (value >= 0)
2144 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002145 else
2146 return -EINVAL;
2147 if (i % 2) {
2148 wwnn[i/2] = j & 0xff;
2149 j = 0;
2150 }
2151 }
2152 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2153
2154 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2155 "lpfc%d: soft_wwnn set. Value will take effect upon "
2156 "setting of the soft_wwpn\n", phba->brd_no);
2157
2158 return count;
2159}
Tony Jonesee959b02008-02-22 00:13:36 +01002160static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2161 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002162
James Smartc3f28af2006-08-18 17:47:18 -04002163
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002164static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002165module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002166MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2167 " 0 - none,"
2168 " 1 - poll with interrupts enabled"
2169 " 3 - poll and disable FCP ring interrupts");
2170
Tony Jonesee959b02008-02-22 00:13:36 +01002171static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2172 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002173
James Smart92d7f7b2007-06-17 19:56:38 -05002174int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002175module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002176MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2177 " 0 - auto (SLI-3 if supported),"
2178 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2179 " 3 - select SLI-3");
2180
James Smart15672312010-04-06 14:49:03 -04002181int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002182module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002183MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2184lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002185lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002186static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002187
James Smart19ca7602010-11-20 23:11:55 -05002188int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002189module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002190MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2191lpfc_param_show(enable_rrq);
2192lpfc_param_init(enable_rrq, 0, 0, 1);
2193static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2194
dea31012005-04-17 16:05:31 -05002195/*
James Smart84d1b002010-02-12 14:42:33 -05002196# lpfc_suppress_link_up: Bring link up at initialization
2197# 0x0 = bring link up (issue MBX_INIT_LINK)
2198# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2199# 0x2 = never bring up link
2200# Default value is 0.
2201*/
James Smarte40a02c2010-02-26 14:13:54 -05002202LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2203 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2204 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002205/*
2206# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2207# 1 - (1024)
2208# 2 - (2048)
2209# 3 - (3072)
2210# 4 - (4096)
2211# 5 - (5120)
2212*/
2213static ssize_t
2214lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2215{
2216 struct Scsi_Host *shost = class_to_shost(dev);
2217 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2218
2219 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2220}
2221
2222static DEVICE_ATTR(iocb_hw, S_IRUGO,
2223 lpfc_iocb_hw_show, NULL);
2224static ssize_t
2225lpfc_txq_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",
2231 phba->sli.ring[LPFC_ELS_RING].txq_max);
2232}
2233
2234static DEVICE_ATTR(txq_hw, S_IRUGO,
2235 lpfc_txq_hw_show, NULL);
2236static ssize_t
2237lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2238 char *buf)
2239{
2240 struct Scsi_Host *shost = class_to_shost(dev);
2241 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2242
2243 return snprintf(buf, PAGE_SIZE, "%d\n",
2244 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2245}
2246
2247static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2248 lpfc_txcmplq_hw_show, NULL);
2249
2250int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002251module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002252MODULE_PARM_DESC(lpfc_iocb_cnt,
2253 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2254lpfc_param_show(iocb_cnt);
2255lpfc_param_init(iocb_cnt, 2, 1, 5);
2256static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2257 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002258
2259/*
James Smartc01f3202006-08-18 17:47:08 -04002260# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2261# until the timer expires. Value range is [0,255]. Default value is 30.
2262*/
2263static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2264static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2265module_param(lpfc_nodev_tmo, int, 0);
2266MODULE_PARM_DESC(lpfc_nodev_tmo,
2267 "Seconds driver will hold I/O waiting "
2268 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002269
2270/**
James Smart3621a712009-04-06 18:47:14 -04002271 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002272 * @dev: class converted to a Scsi_host structure.
2273 * @attr: device attribute, not used.
2274 * @buf: on return contains the dev loss timeout in decimal.
2275 *
2276 * Returns: size of formatted string.
2277 **/
James Smartc01f3202006-08-18 17:47:08 -04002278static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002279lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2280 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002281{
Tony Jonesee959b02008-02-22 00:13:36 +01002282 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002284
James Smart3de2a652007-08-02 11:09:59 -04002285 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002286}
2287
James Smarte59058c2008-08-24 21:49:00 -04002288/**
James Smart3621a712009-04-06 18:47:14 -04002289 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002290 * @vport: lpfc vport structure pointer.
2291 * @val: contains the nodev timeout value.
2292 *
2293 * Description:
2294 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2295 * a kernel error message is printed and zero is returned.
2296 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2297 * Otherwise nodev tmo is set to the default value.
2298 *
2299 * Returns:
2300 * zero if already set or if val is in range
2301 * -EINVAL val out of range
2302 **/
James Smartc01f3202006-08-18 17:47:08 -04002303static int
James Smart3de2a652007-08-02 11:09:59 -04002304lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002305{
James Smart3de2a652007-08-02 11:09:59 -04002306 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2307 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2308 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002309 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002310 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002311 "parameter because devloss_tmo is "
2312 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002313 return 0;
2314 }
2315
2316 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002317 vport->cfg_nodev_tmo = val;
2318 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002319 return 0;
2320 }
James Smarte8b62012007-08-02 11:10:09 -04002321 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2322 "0400 lpfc_nodev_tmo attribute cannot be set to"
2323 " %d, allowed range is [%d, %d]\n",
2324 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002325 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002326 return -EINVAL;
2327}
2328
James Smarte59058c2008-08-24 21:49:00 -04002329/**
James Smart3621a712009-04-06 18:47:14 -04002330 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002331 * @vport: lpfc vport structure pointer.
2332 *
2333 * Description:
2334 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2335 **/
James Smart7054a602007-04-25 09:52:34 -04002336static void
James Smart3de2a652007-08-02 11:09:59 -04002337lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002338{
James Smart858c9f62007-06-17 19:56:39 -05002339 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002340 struct lpfc_nodelist *ndlp;
2341
James Smart51ef4c22007-08-02 11:10:31 -04002342 shost = lpfc_shost_from_vport(vport);
2343 spin_lock_irq(shost->host_lock);
2344 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002345 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002346 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2347 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002348}
2349
James Smarte59058c2008-08-24 21:49:00 -04002350/**
James Smart3621a712009-04-06 18:47:14 -04002351 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002352 * @vport: lpfc vport structure pointer.
2353 * @val: contains the tmo value.
2354 *
2355 * Description:
2356 * If the devloss tmo is already set or the vport dev loss tmo has changed
2357 * then a kernel error message is printed and zero is returned.
2358 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2359 * Otherwise nodev tmo is set to the default value.
2360 *
2361 * Returns:
2362 * zero if already set or if val is in range
2363 * -EINVAL val out of range
2364 **/
James Smartc01f3202006-08-18 17:47:08 -04002365static int
James Smart3de2a652007-08-02 11:09:59 -04002366lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002367{
James Smart3de2a652007-08-02 11:09:59 -04002368 if (vport->dev_loss_tmo_changed ||
2369 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002370 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2371 "0401 Ignoring change to nodev_tmo "
2372 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002373 return 0;
2374 }
James Smartc01f3202006-08-18 17:47:08 -04002375 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002376 vport->cfg_nodev_tmo = val;
2377 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002378 /*
2379 * For compat: set the fc_host dev loss so new rports
2380 * will get the value.
2381 */
2382 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002383 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002384 return 0;
2385 }
James Smarte8b62012007-08-02 11:10:09 -04002386 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2387 "0403 lpfc_nodev_tmo attribute cannot be set to"
2388 "%d, allowed range is [%d, %d]\n",
2389 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002390 return -EINVAL;
2391}
2392
James Smart3de2a652007-08-02 11:09:59 -04002393lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002394
Tony Jonesee959b02008-02-22 00:13:36 +01002395static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2396 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002397
2398/*
2399# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2400# disappear until the timer expires. Value range is [0,255]. Default
2401# value is 30.
2402*/
James Smartab56dc22011-02-16 12:39:57 -05002403module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002404MODULE_PARM_DESC(lpfc_devloss_tmo,
2405 "Seconds driver will hold I/O waiting "
2406 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002407lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2408 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2409lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002410
2411/**
James Smart3621a712009-04-06 18:47:14 -04002412 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002413 * @vport: lpfc vport structure pointer.
2414 * @val: contains the tmo value.
2415 *
2416 * Description:
2417 * If val is in a valid range then set the vport nodev tmo,
2418 * devloss tmo, also set the vport dev loss tmo changed flag.
2419 * Else a kernel error message is printed.
2420 *
2421 * Returns:
2422 * zero if val is in range
2423 * -EINVAL val out of range
2424 **/
James Smartc01f3202006-08-18 17:47:08 -04002425static int
James Smart3de2a652007-08-02 11:09:59 -04002426lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002427{
2428 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002429 vport->cfg_nodev_tmo = val;
2430 vport->cfg_devloss_tmo = val;
2431 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002432 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002433 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002434 return 0;
2435 }
2436
James Smarte8b62012007-08-02 11:10:09 -04002437 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2438 "0404 lpfc_devloss_tmo attribute cannot be set to"
2439 " %d, allowed range is [%d, %d]\n",
2440 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002441 return -EINVAL;
2442}
2443
James Smart3de2a652007-08-02 11:09:59 -04002444lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002445static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2446 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002447
2448/*
dea31012005-04-17 16:05:31 -05002449# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2450# deluged with LOTS of information.
2451# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002452# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002453*/
James Smartf4b4c682009-05-22 14:53:12 -04002454LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002455 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002456
2457/*
James Smart7ee5d432007-10-27 13:37:17 -04002458# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2459# objects that have been registered with the nameserver after login.
2460*/
2461LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2462 "Deregister nameserver objects before LOGO");
2463
2464/*
dea31012005-04-17 16:05:31 -05002465# lun_queue_depth: This parameter is used to limit the number of outstanding
2466# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2467*/
James Smart3de2a652007-08-02 11:09:59 -04002468LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2469 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002470
2471/*
James Smart7dc517d2010-07-14 15:32:10 -04002472# tgt_queue_depth: This parameter is used to limit the number of outstanding
2473# commands per target port. Value range is [10,65535]. Default value is 65535.
2474*/
2475LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2476 "Max number of FCP commands we can queue to a specific target port");
2477
2478/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002479# hba_queue_depth: This parameter is used to limit the number of outstanding
2480# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2481# value is greater than the maximum number of exchanges supported by the HBA,
2482# then maximum number of exchanges supported by the HBA is used to determine
2483# the hba_queue_depth.
2484*/
2485LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2486 "Max number of FCP commands we can queue to a lpfc HBA");
2487
2488/*
James Smart92d7f7b2007-06-17 19:56:38 -05002489# peer_port_login: This parameter allows/prevents logins
2490# between peer ports hosted on the same physical port.
2491# When this parameter is set 0 peer ports of same physical port
2492# are not allowed to login to each other.
2493# When this parameter is set 1 peer ports of same physical port
2494# are allowed to login to each other.
2495# Default value of this parameter is 0.
2496*/
James Smart3de2a652007-08-02 11:09:59 -04002497LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2498 "Allow peer ports on the same physical port to login to each "
2499 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002500
2501/*
James Smart3de2a652007-08-02 11:09:59 -04002502# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002503# between Virtual Ports and remote initiators.
2504# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2505# other initiators and will attempt to PLOGI all remote ports.
2506# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2507# remote ports and will not attempt to PLOGI to other initiators.
2508# This parameter does not restrict to the physical port.
2509# This parameter does not restrict logins to Fabric resident remote ports.
2510# Default value of this parameter is 1.
2511*/
James Smart3de2a652007-08-02 11:09:59 -04002512static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002513module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002514MODULE_PARM_DESC(lpfc_restrict_login,
2515 "Restrict virtual ports login to remote initiators.");
2516lpfc_vport_param_show(restrict_login);
2517
James Smarte59058c2008-08-24 21:49:00 -04002518/**
James Smart3621a712009-04-06 18:47:14 -04002519 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002520 * @vport: lpfc vport structure pointer.
2521 * @val: contains the restrict login value.
2522 *
2523 * Description:
2524 * If val is not in a valid range then log a kernel error message and set
2525 * the vport restrict login to one.
2526 * If the port type is physical clear the restrict login flag and return.
2527 * Else set the restrict login flag to val.
2528 *
2529 * Returns:
2530 * zero if val is in range
2531 * -EINVAL val out of range
2532 **/
James Smart3de2a652007-08-02 11:09:59 -04002533static int
2534lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2535{
2536 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002537 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002538 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002539 "be set to %d, allowed range is [0, 1]\n",
2540 val);
James Smart3de2a652007-08-02 11:09:59 -04002541 vport->cfg_restrict_login = 1;
2542 return -EINVAL;
2543 }
2544 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2545 vport->cfg_restrict_login = 0;
2546 return 0;
2547 }
2548 vport->cfg_restrict_login = val;
2549 return 0;
2550}
2551
James Smarte59058c2008-08-24 21:49:00 -04002552/**
James Smart3621a712009-04-06 18:47:14 -04002553 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002554 * @vport: lpfc vport structure pointer.
2555 * @val: contains the restrict login value.
2556 *
2557 * Description:
2558 * If val is not in a valid range then log a kernel error message and set
2559 * the vport restrict login to one.
2560 * If the port type is physical and the val is not zero log a kernel
2561 * error message, clear the restrict login flag and return zero.
2562 * Else set the restrict login flag to val.
2563 *
2564 * Returns:
2565 * zero if val is in range
2566 * -EINVAL val out of range
2567 **/
James Smart3de2a652007-08-02 11:09:59 -04002568static int
2569lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2570{
2571 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002572 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002573 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002574 "be set to %d, allowed range is [0, 1]\n",
2575 val);
James Smart3de2a652007-08-02 11:09:59 -04002576 vport->cfg_restrict_login = 1;
2577 return -EINVAL;
2578 }
2579 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002580 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2581 "0468 lpfc_restrict_login must be 0 for "
2582 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002583 vport->cfg_restrict_login = 0;
2584 return 0;
2585 }
2586 vport->cfg_restrict_login = val;
2587 return 0;
2588}
2589lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002590static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2591 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002592
2593/*
dea31012005-04-17 16:05:31 -05002594# Some disk devices have a "select ID" or "select Target" capability.
2595# From a protocol standpoint "select ID" usually means select the
2596# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2597# annex" which contains a table that maps a "select ID" (a number
2598# between 0 and 7F) to an ALPA. By default, for compatibility with
2599# older drivers, the lpfc driver scans this table from low ALPA to high
2600# ALPA.
2601#
2602# Turning on the scan-down variable (on = 1, off = 0) will
2603# cause the lpfc driver to use an inverted table, effectively
2604# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2605#
2606# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2607# and will not work across a fabric. Also this parameter will take
2608# effect only in the case when ALPA map is not available.)
2609*/
James Smart3de2a652007-08-02 11:09:59 -04002610LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2611 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002612
2613/*
dea31012005-04-17 16:05:31 -05002614# lpfc_topology: link topology for init link
2615# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002616# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002617# 0x02 = attempt point-to-point mode only
2618# 0x04 = attempt loop mode only
2619# 0x06 = attempt point-to-point mode then loop
2620# Set point-to-point mode if you want to run as an N_Port.
2621# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2622# Default value is 0.
2623*/
James Smarte59058c2008-08-24 21:49:00 -04002624
2625/**
James Smart3621a712009-04-06 18:47:14 -04002626 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002627 * @phba: lpfc_hba pointer.
2628 * @val: topology value.
2629 *
2630 * Description:
2631 * If val is in a valid range then set the adapter's topology field and
2632 * issue a lip; if the lip fails reset the topology to the old value.
2633 *
2634 * If the value is not in range log a kernel error message and return an error.
2635 *
2636 * Returns:
2637 * zero if val is in range and lip okay
2638 * non-zero return value from lpfc_issue_lip()
2639 * -EINVAL val out of range
2640 **/
James Smarta257bf92009-04-06 18:48:10 -04002641static ssize_t
2642lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2643 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002644{
James Smarta257bf92009-04-06 18:48:10 -04002645 struct Scsi_Host *shost = class_to_shost(dev);
2646 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2647 struct lpfc_hba *phba = vport->phba;
2648 int val = 0;
2649 int nolip = 0;
2650 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002651 int err;
2652 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002653
2654 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2655 nolip = 1;
2656 val_buf = &buf[strlen("nolip ")];
2657 }
2658
2659 if (!isdigit(val_buf[0]))
2660 return -EINVAL;
2661 if (sscanf(val_buf, "%i", &val) != 1)
2662 return -EINVAL;
2663
James Smart83108bd2008-01-11 01:53:09 -05002664 if (val >= 0 && val <= 6) {
2665 prev_val = phba->cfg_topology;
2666 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002667 if (nolip)
2668 return strlen(buf);
2669
James Smart83108bd2008-01-11 01:53:09 -05002670 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002671 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002672 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002673 return -EINVAL;
2674 } else
2675 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002676 }
2677 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2678 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2679 "allowed range is [0, 6]\n",
2680 phba->brd_no, val);
2681 return -EINVAL;
2682}
2683static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002684module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002685MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2686lpfc_param_show(topology)
2687lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002688static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002689 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002690
James Smart21e9a0a2009-05-22 14:53:21 -04002691/**
2692 * lpfc_static_vport_show: Read callback function for
2693 * lpfc_static_vport sysfs file.
2694 * @dev: Pointer to class device object.
2695 * @attr: device attribute structure.
2696 * @buf: Data buffer.
2697 *
2698 * This function is the read call back function for
2699 * lpfc_static_vport sysfs file. The lpfc_static_vport
2700 * sysfs file report the mageability of the vport.
2701 **/
2702static ssize_t
2703lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2704 char *buf)
2705{
2706 struct Scsi_Host *shost = class_to_shost(dev);
2707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2708 if (vport->vport_flag & STATIC_VPORT)
2709 sprintf(buf, "1\n");
2710 else
2711 sprintf(buf, "0\n");
2712
2713 return strlen(buf);
2714}
2715
2716/*
2717 * Sysfs attribute to control the statistical data collection.
2718 */
2719static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2720 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002721
2722/**
James Smart3621a712009-04-06 18:47:14 -04002723 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002724 * @dev: Pointer to class device.
2725 * @buf: Data buffer.
2726 * @count: Size of the data buffer.
2727 *
2728 * This function get called when an user write to the lpfc_stat_data_ctrl
2729 * sysfs file. This function parse the command written to the sysfs file
2730 * and take appropriate action. These commands are used for controlling
2731 * driver statistical data collection.
2732 * Following are the command this function handles.
2733 *
2734 * setbucket <bucket_type> <base> <step>
2735 * = Set the latency buckets.
2736 * destroybucket = destroy all the buckets.
2737 * start = start data collection
2738 * stop = stop data collection
2739 * reset = reset the collected data
2740 **/
2741static ssize_t
2742lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2743 const char *buf, size_t count)
2744{
2745 struct Scsi_Host *shost = class_to_shost(dev);
2746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2747 struct lpfc_hba *phba = vport->phba;
2748#define LPFC_MAX_DATA_CTRL_LEN 1024
2749 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2750 unsigned long i;
2751 char *str_ptr, *token;
2752 struct lpfc_vport **vports;
2753 struct Scsi_Host *v_shost;
2754 char *bucket_type_str, *base_str, *step_str;
2755 unsigned long base, step, bucket_type;
2756
2757 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002758 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002759 return -EINVAL;
2760
2761 strcpy(bucket_data, buf);
2762 str_ptr = &bucket_data[0];
2763 /* Ignore this token - this is command token */
2764 token = strsep(&str_ptr, "\t ");
2765 if (!token)
2766 return -EINVAL;
2767
2768 bucket_type_str = strsep(&str_ptr, "\t ");
2769 if (!bucket_type_str)
2770 return -EINVAL;
2771
2772 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2773 bucket_type = LPFC_LINEAR_BUCKET;
2774 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2775 bucket_type = LPFC_POWER2_BUCKET;
2776 else
2777 return -EINVAL;
2778
2779 base_str = strsep(&str_ptr, "\t ");
2780 if (!base_str)
2781 return -EINVAL;
2782 base = simple_strtoul(base_str, NULL, 0);
2783
2784 step_str = strsep(&str_ptr, "\t ");
2785 if (!step_str)
2786 return -EINVAL;
2787 step = simple_strtoul(step_str, NULL, 0);
2788 if (!step)
2789 return -EINVAL;
2790
2791 /* Block the data collection for every vport */
2792 vports = lpfc_create_vport_work_array(phba);
2793 if (vports == NULL)
2794 return -ENOMEM;
2795
James Smartf4b4c682009-05-22 14:53:12 -04002796 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002797 v_shost = lpfc_shost_from_vport(vports[i]);
2798 spin_lock_irq(v_shost->host_lock);
2799 /* Block and reset data collection */
2800 vports[i]->stat_data_blocked = 1;
2801 if (vports[i]->stat_data_enabled)
2802 lpfc_vport_reset_stat_data(vports[i]);
2803 spin_unlock_irq(v_shost->host_lock);
2804 }
2805
2806 /* Set the bucket attributes */
2807 phba->bucket_type = bucket_type;
2808 phba->bucket_base = base;
2809 phba->bucket_step = step;
2810
James Smartf4b4c682009-05-22 14:53:12 -04002811 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002812 v_shost = lpfc_shost_from_vport(vports[i]);
2813
2814 /* Unblock data collection */
2815 spin_lock_irq(v_shost->host_lock);
2816 vports[i]->stat_data_blocked = 0;
2817 spin_unlock_irq(v_shost->host_lock);
2818 }
2819 lpfc_destroy_vport_work_array(phba, vports);
2820 return strlen(buf);
2821 }
2822
2823 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2824 vports = lpfc_create_vport_work_array(phba);
2825 if (vports == NULL)
2826 return -ENOMEM;
2827
James Smartf4b4c682009-05-22 14:53:12 -04002828 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002829 v_shost = lpfc_shost_from_vport(vports[i]);
2830 spin_lock_irq(shost->host_lock);
2831 vports[i]->stat_data_blocked = 1;
2832 lpfc_free_bucket(vport);
2833 vport->stat_data_enabled = 0;
2834 vports[i]->stat_data_blocked = 0;
2835 spin_unlock_irq(shost->host_lock);
2836 }
2837 lpfc_destroy_vport_work_array(phba, vports);
2838 phba->bucket_type = LPFC_NO_BUCKET;
2839 phba->bucket_base = 0;
2840 phba->bucket_step = 0;
2841 return strlen(buf);
2842 }
2843
2844 if (!strncmp(buf, "start", strlen("start"))) {
2845 /* If no buckets configured return error */
2846 if (phba->bucket_type == LPFC_NO_BUCKET)
2847 return -EINVAL;
2848 spin_lock_irq(shost->host_lock);
2849 if (vport->stat_data_enabled) {
2850 spin_unlock_irq(shost->host_lock);
2851 return strlen(buf);
2852 }
2853 lpfc_alloc_bucket(vport);
2854 vport->stat_data_enabled = 1;
2855 spin_unlock_irq(shost->host_lock);
2856 return strlen(buf);
2857 }
2858
2859 if (!strncmp(buf, "stop", strlen("stop"))) {
2860 spin_lock_irq(shost->host_lock);
2861 if (vport->stat_data_enabled == 0) {
2862 spin_unlock_irq(shost->host_lock);
2863 return strlen(buf);
2864 }
2865 lpfc_free_bucket(vport);
2866 vport->stat_data_enabled = 0;
2867 spin_unlock_irq(shost->host_lock);
2868 return strlen(buf);
2869 }
2870
2871 if (!strncmp(buf, "reset", strlen("reset"))) {
2872 if ((phba->bucket_type == LPFC_NO_BUCKET)
2873 || !vport->stat_data_enabled)
2874 return strlen(buf);
2875 spin_lock_irq(shost->host_lock);
2876 vport->stat_data_blocked = 1;
2877 lpfc_vport_reset_stat_data(vport);
2878 vport->stat_data_blocked = 0;
2879 spin_unlock_irq(shost->host_lock);
2880 return strlen(buf);
2881 }
2882 return -EINVAL;
2883}
2884
2885
2886/**
James Smart3621a712009-04-06 18:47:14 -04002887 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002888 * @dev: Pointer to class device object.
2889 * @buf: Data buffer.
2890 *
2891 * This function is the read call back function for
2892 * lpfc_stat_data_ctrl sysfs file. This function report the
2893 * current statistical data collection state.
2894 **/
2895static ssize_t
2896lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2897 char *buf)
2898{
2899 struct Scsi_Host *shost = class_to_shost(dev);
2900 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2901 struct lpfc_hba *phba = vport->phba;
2902 int index = 0;
2903 int i;
2904 char *bucket_type;
2905 unsigned long bucket_value;
2906
2907 switch (phba->bucket_type) {
2908 case LPFC_LINEAR_BUCKET:
2909 bucket_type = "linear";
2910 break;
2911 case LPFC_POWER2_BUCKET:
2912 bucket_type = "power2";
2913 break;
2914 default:
2915 bucket_type = "No Bucket";
2916 break;
2917 }
2918
2919 sprintf(&buf[index], "Statistical Data enabled :%d, "
2920 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2921 " Bucket step :%d\nLatency Ranges :",
2922 vport->stat_data_enabled, vport->stat_data_blocked,
2923 bucket_type, phba->bucket_base, phba->bucket_step);
2924 index = strlen(buf);
2925 if (phba->bucket_type != LPFC_NO_BUCKET) {
2926 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2927 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2928 bucket_value = phba->bucket_base +
2929 phba->bucket_step * i;
2930 else
2931 bucket_value = phba->bucket_base +
2932 (1 << i) * phba->bucket_step;
2933
2934 if (index + 10 > PAGE_SIZE)
2935 break;
2936 sprintf(&buf[index], "%08ld ", bucket_value);
2937 index = strlen(buf);
2938 }
2939 }
2940 sprintf(&buf[index], "\n");
2941 return strlen(buf);
2942}
2943
2944/*
2945 * Sysfs attribute to control the statistical data collection.
2946 */
2947static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2948 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2949
2950/*
2951 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2952 */
2953
2954/*
2955 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2956 * for each target.
2957 */
2958#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2959#define MAX_STAT_DATA_SIZE_PER_TARGET \
2960 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2961
2962
2963/**
James Smart3621a712009-04-06 18:47:14 -04002964 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002965 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002966 * @kobj: Pointer to the kernel object
2967 * @bin_attr: Attribute object
2968 * @buff: Buffer pointer
2969 * @off: File offset
2970 * @count: Buffer size
2971 *
2972 * This function is the read call back function for lpfc_drvr_stat_data
2973 * sysfs file. This function export the statistical data to user
2974 * applications.
2975 **/
2976static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002977sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2978 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002979 char *buf, loff_t off, size_t count)
2980{
2981 struct device *dev = container_of(kobj, struct device,
2982 kobj);
2983 struct Scsi_Host *shost = class_to_shost(dev);
2984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2985 struct lpfc_hba *phba = vport->phba;
2986 int i = 0, index = 0;
2987 unsigned long nport_index;
2988 struct lpfc_nodelist *ndlp = NULL;
2989 nport_index = (unsigned long)off /
2990 MAX_STAT_DATA_SIZE_PER_TARGET;
2991
2992 if (!vport->stat_data_enabled || vport->stat_data_blocked
2993 || (phba->bucket_type == LPFC_NO_BUCKET))
2994 return 0;
2995
2996 spin_lock_irq(shost->host_lock);
2997 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2998 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2999 continue;
3000
3001 if (nport_index > 0) {
3002 nport_index--;
3003 continue;
3004 }
3005
3006 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3007 > count)
3008 break;
3009
3010 if (!ndlp->lat_data)
3011 continue;
3012
3013 /* Print the WWN */
3014 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3015 ndlp->nlp_portname.u.wwn[0],
3016 ndlp->nlp_portname.u.wwn[1],
3017 ndlp->nlp_portname.u.wwn[2],
3018 ndlp->nlp_portname.u.wwn[3],
3019 ndlp->nlp_portname.u.wwn[4],
3020 ndlp->nlp_portname.u.wwn[5],
3021 ndlp->nlp_portname.u.wwn[6],
3022 ndlp->nlp_portname.u.wwn[7]);
3023
3024 index = strlen(buf);
3025
3026 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3027 sprintf(&buf[index], "%010u,",
3028 ndlp->lat_data[i].cmd_count);
3029 index = strlen(buf);
3030 }
3031 sprintf(&buf[index], "\n");
3032 index = strlen(buf);
3033 }
3034 spin_unlock_irq(shost->host_lock);
3035 return index;
3036}
3037
3038static struct bin_attribute sysfs_drvr_stat_data_attr = {
3039 .attr = {
3040 .name = "lpfc_drvr_stat_data",
3041 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003042 },
3043 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3044 .read = sysfs_drvr_stat_data_read,
3045 .write = NULL,
3046};
3047
dea31012005-04-17 16:05:31 -05003048/*
3049# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3050# connection.
James Smart76a95d72010-11-20 23:11:48 -05003051# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003052*/
James Smarte59058c2008-08-24 21:49:00 -04003053/**
James Smart3621a712009-04-06 18:47:14 -04003054 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003055 * @phba: lpfc_hba pointer.
3056 * @val: link speed value.
3057 *
3058 * Description:
3059 * If val is in a valid range then set the adapter's link speed field and
3060 * issue a lip; if the lip fails reset the link speed to the old value.
3061 *
3062 * Notes:
3063 * If the value is not in range log a kernel error message and return an error.
3064 *
3065 * Returns:
3066 * zero if val is in range and lip okay.
3067 * non-zero return value from lpfc_issue_lip()
3068 * -EINVAL val out of range
3069 **/
James Smarta257bf92009-04-06 18:48:10 -04003070static ssize_t
3071lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3072 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003073{
James Smarta257bf92009-04-06 18:48:10 -04003074 struct Scsi_Host *shost = class_to_shost(dev);
3075 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3076 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003077 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003078 int nolip = 0;
3079 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003080 int err;
3081 uint32_t prev_val;
3082
James Smarta257bf92009-04-06 18:48:10 -04003083 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3084 nolip = 1;
3085 val_buf = &buf[strlen("nolip ")];
3086 }
3087
3088 if (!isdigit(val_buf[0]))
3089 return -EINVAL;
3090 if (sscanf(val_buf, "%i", &val) != 1)
3091 return -EINVAL;
3092
James Smart76a95d72010-11-20 23:11:48 -05003093 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3094 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3095 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3096 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3097 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3098 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3100 "2879 lpfc_link_speed attribute cannot be set "
3101 "to %d. Speed is not supported by this port.\n",
3102 val);
James Smart83108bd2008-01-11 01:53:09 -05003103 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003104 }
3105 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3106 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003107 prev_val = phba->cfg_link_speed;
3108 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003109 if (nolip)
3110 return strlen(buf);
3111
James Smart83108bd2008-01-11 01:53:09 -05003112 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003113 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003114 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003115 return -EINVAL;
3116 } else
3117 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003118 }
James Smart83108bd2008-01-11 01:53:09 -05003119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003120 "0469 lpfc_link_speed attribute cannot be set to %d, "
3121 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003122 return -EINVAL;
3123}
3124
3125static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003126module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003127MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3128lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003129
3130/**
James Smart3621a712009-04-06 18:47:14 -04003131 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003132 * @phba: lpfc_hba pointer.
3133 * @val: link speed value.
3134 *
3135 * Description:
3136 * If val is in a valid range then set the adapter's link speed field.
3137 *
3138 * Notes:
3139 * If the value is not in range log a kernel error message, clear the link
3140 * speed and return an error.
3141 *
3142 * Returns:
3143 * zero if val saved.
3144 * -EINVAL val out of range
3145 **/
James Smart83108bd2008-01-11 01:53:09 -05003146static int
3147lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3148{
James Smart76a95d72010-11-20 23:11:48 -05003149 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3150 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003151 phba->cfg_link_speed = val;
3152 return 0;
3153 }
3154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003155 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003156 "be set to %d, allowed values are "
3157 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003158 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003159 return -EINVAL;
3160}
3161
Tony Jonesee959b02008-02-22 00:13:36 +01003162static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003163 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003164
3165/*
James Smart0d878412009-10-02 15:16:56 -04003166# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3167# 0 = aer disabled or not supported
3168# 1 = aer supported and enabled (default)
3169# Value range is [0,1]. Default value is 1.
3170*/
3171
3172/**
3173 * lpfc_aer_support_store - Set the adapter for aer support
3174 *
3175 * @dev: class device that is converted into a Scsi_host.
3176 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003177 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003178 * @count: unused variable.
3179 *
3180 * Description:
3181 * If the val is 1 and currently the device's AER capability was not
3182 * enabled, invoke the kernel's enable AER helper routine, trying to
3183 * enable the device's AER capability. If the helper routine enabling
3184 * AER returns success, update the device's cfg_aer_support flag to
3185 * indicate AER is supported by the device; otherwise, if the device
3186 * AER capability is already enabled to support AER, then do nothing.
3187 *
3188 * If the val is 0 and currently the device's AER support was enabled,
3189 * invoke the kernel's disable AER helper routine. After that, update
3190 * the device's cfg_aer_support flag to indicate AER is not supported
3191 * by the device; otherwise, if the device AER capability is already
3192 * disabled from supporting AER, then do nothing.
3193 *
3194 * Returns:
3195 * length of the buf on success if val is in range the intended mode
3196 * is supported.
3197 * -EINVAL if val out of range or intended mode is not supported.
3198 **/
3199static ssize_t
3200lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3201 const char *buf, size_t count)
3202{
3203 struct Scsi_Host *shost = class_to_shost(dev);
3204 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3205 struct lpfc_hba *phba = vport->phba;
3206 int val = 0, rc = -EINVAL;
3207
3208 if (!isdigit(buf[0]))
3209 return -EINVAL;
3210 if (sscanf(buf, "%i", &val) != 1)
3211 return -EINVAL;
3212
3213 switch (val) {
3214 case 0:
3215 if (phba->hba_flag & HBA_AER_ENABLED) {
3216 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3217 if (!rc) {
3218 spin_lock_irq(&phba->hbalock);
3219 phba->hba_flag &= ~HBA_AER_ENABLED;
3220 spin_unlock_irq(&phba->hbalock);
3221 phba->cfg_aer_support = 0;
3222 rc = strlen(buf);
3223 } else
James Smart891478a2009-11-18 15:40:23 -05003224 rc = -EPERM;
3225 } else {
James Smart0d878412009-10-02 15:16:56 -04003226 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003227 rc = strlen(buf);
3228 }
James Smart0d878412009-10-02 15:16:56 -04003229 break;
3230 case 1:
3231 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3232 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3233 if (!rc) {
3234 spin_lock_irq(&phba->hbalock);
3235 phba->hba_flag |= HBA_AER_ENABLED;
3236 spin_unlock_irq(&phba->hbalock);
3237 phba->cfg_aer_support = 1;
3238 rc = strlen(buf);
3239 } else
James Smart891478a2009-11-18 15:40:23 -05003240 rc = -EPERM;
3241 } else {
James Smart0d878412009-10-02 15:16:56 -04003242 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003243 rc = strlen(buf);
3244 }
James Smart0d878412009-10-02 15:16:56 -04003245 break;
3246 default:
3247 rc = -EINVAL;
3248 break;
3249 }
3250 return rc;
3251}
3252
3253static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003254module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003255MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3256lpfc_param_show(aer_support)
3257
3258/**
3259 * lpfc_aer_support_init - Set the initial adapters aer support flag
3260 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003261 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003262 *
3263 * Description:
3264 * If val is in a valid range [0,1], then set the adapter's initial
3265 * cfg_aer_support field. It will be up to the driver's probe_one
3266 * routine to determine whether the device's AER support can be set
3267 * or not.
3268 *
3269 * Notes:
3270 * If the value is not in range log a kernel error message, and
3271 * choose the default value of setting AER support and return.
3272 *
3273 * Returns:
3274 * zero if val saved.
3275 * -EINVAL val out of range
3276 **/
3277static int
3278lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3279{
3280 if (val == 0 || val == 1) {
3281 phba->cfg_aer_support = val;
3282 return 0;
3283 }
3284 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3285 "2712 lpfc_aer_support attribute value %d out "
3286 "of range, allowed values are 0|1, setting it "
3287 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003288 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003289 phba->cfg_aer_support = 1;
3290 return -EINVAL;
3291}
3292
3293static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3294 lpfc_aer_support_show, lpfc_aer_support_store);
3295
3296/**
3297 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3298 * @dev: class device that is converted into a Scsi_host.
3299 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003300 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003301 * @count: unused variable.
3302 *
3303 * Description:
3304 * If the @buf contains 1 and the device currently has the AER support
3305 * enabled, then invokes the kernel AER helper routine
3306 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3307 * error status register.
3308 *
3309 * Notes:
3310 *
3311 * Returns:
3312 * -EINVAL if the buf does not contain the 1 or the device is not currently
3313 * enabled with the AER support.
3314 **/
3315static ssize_t
3316lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3317 const char *buf, size_t count)
3318{
3319 struct Scsi_Host *shost = class_to_shost(dev);
3320 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3321 struct lpfc_hba *phba = vport->phba;
3322 int val, rc = -1;
3323
3324 if (!isdigit(buf[0]))
3325 return -EINVAL;
3326 if (sscanf(buf, "%i", &val) != 1)
3327 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003328 if (val != 1)
3329 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003330
James Smart891478a2009-11-18 15:40:23 -05003331 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003332 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3333
3334 if (rc == 0)
3335 return strlen(buf);
3336 else
James Smart891478a2009-11-18 15:40:23 -05003337 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003338}
3339
3340static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3341 lpfc_aer_cleanup_state);
3342
James Smart912e3ac2011-05-24 11:42:11 -04003343/**
3344 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3345 *
3346 * @dev: class device that is converted into a Scsi_host.
3347 * @attr: device attribute, not used.
3348 * @buf: containing the string the number of vfs to be enabled.
3349 * @count: unused variable.
3350 *
3351 * Description:
3352 * When this api is called either through user sysfs, the driver shall
3353 * try to enable or disable SR-IOV virtual functions according to the
3354 * following:
3355 *
3356 * If zero virtual function has been enabled to the physical function,
3357 * the driver shall invoke the pci enable virtual function api trying
3358 * to enable the virtual functions. If the nr_vfn provided is greater
3359 * than the maximum supported, the maximum virtual function number will
3360 * be used for invoking the api; otherwise, the nr_vfn provided shall
3361 * be used for invoking the api. If the api call returned success, the
3362 * actual number of virtual functions enabled will be set to the driver
3363 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3364 * cfg_sriov_nr_virtfn remains zero.
3365 *
3366 * If none-zero virtual functions have already been enabled to the
3367 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3368 * -EINVAL will be returned and the driver does nothing;
3369 *
3370 * If the nr_vfn provided is zero and none-zero virtual functions have
3371 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3372 * disabling virtual function api shall be invoded to disable all the
3373 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3374 * zero. Otherwise, if zero virtual function has been enabled, do
3375 * nothing.
3376 *
3377 * Returns:
3378 * length of the buf on success if val is in range the intended mode
3379 * is supported.
3380 * -EINVAL if val out of range or intended mode is not supported.
3381 **/
3382static ssize_t
3383lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3384 const char *buf, size_t count)
3385{
3386 struct Scsi_Host *shost = class_to_shost(dev);
3387 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3388 struct lpfc_hba *phba = vport->phba;
3389 struct pci_dev *pdev = phba->pcidev;
3390 int val = 0, rc = -EINVAL;
3391
3392 /* Sanity check on user data */
3393 if (!isdigit(buf[0]))
3394 return -EINVAL;
3395 if (sscanf(buf, "%i", &val) != 1)
3396 return -EINVAL;
3397 if (val < 0)
3398 return -EINVAL;
3399
3400 /* Request disabling virtual functions */
3401 if (val == 0) {
3402 if (phba->cfg_sriov_nr_virtfn > 0) {
3403 pci_disable_sriov(pdev);
3404 phba->cfg_sriov_nr_virtfn = 0;
3405 }
3406 return strlen(buf);
3407 }
3408
3409 /* Request enabling virtual functions */
3410 if (phba->cfg_sriov_nr_virtfn > 0) {
3411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3412 "3018 There are %d virtual functions "
3413 "enabled on physical function.\n",
3414 phba->cfg_sriov_nr_virtfn);
3415 return -EEXIST;
3416 }
3417
3418 if (val <= LPFC_MAX_VFN_PER_PFN)
3419 phba->cfg_sriov_nr_virtfn = val;
3420 else {
3421 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3422 "3019 Enabling %d virtual functions is not "
3423 "allowed.\n", val);
3424 return -EINVAL;
3425 }
3426
3427 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3428 if (rc) {
3429 phba->cfg_sriov_nr_virtfn = 0;
3430 rc = -EPERM;
3431 } else
3432 rc = strlen(buf);
3433
3434 return rc;
3435}
3436
3437static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3438module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3439MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3440lpfc_param_show(sriov_nr_virtfn)
3441
3442/**
3443 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3444 * @phba: lpfc_hba pointer.
3445 * @val: link speed value.
3446 *
3447 * Description:
3448 * If val is in a valid range [0,255], then set the adapter's initial
3449 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3450 * number shall be used instead. It will be up to the driver's probe_one
3451 * routine to determine whether the device's SR-IOV is supported or not.
3452 *
3453 * Returns:
3454 * zero if val saved.
3455 * -EINVAL val out of range
3456 **/
3457static int
3458lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3459{
3460 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3461 phba->cfg_sriov_nr_virtfn = val;
3462 return 0;
3463 }
3464
3465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3466 "3017 Enabling %d virtual functions is not "
3467 "allowed.\n", val);
3468 return -EINVAL;
3469}
3470static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3471 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3472
James Smart0d878412009-10-02 15:16:56 -04003473/*
dea31012005-04-17 16:05:31 -05003474# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3475# Value range is [2,3]. Default value is 3.
3476*/
James Smart3de2a652007-08-02 11:09:59 -04003477LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3478 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003479
3480/*
3481# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3482# is [0,1]. Default value is 0.
3483*/
James Smart3de2a652007-08-02 11:09:59 -04003484LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3485 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003486
3487/*
James Smart977b5a02008-09-07 11:52:04 -04003488# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3489# depth. Default value is 0. When the value of this parameter is zero the
3490# SCSI command completion time is not used for controlling I/O queue depth. When
3491# the parameter is set to a non-zero value, the I/O queue depth is controlled
3492# to limit the I/O completion time to the parameter value.
3493# The value is set in milliseconds.
3494*/
3495static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003496module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003497MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3498 "Use command completion time to control queue depth");
3499lpfc_vport_param_show(max_scsicmpl_time);
3500lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3501static int
3502lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3503{
3504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3505 struct lpfc_nodelist *ndlp, *next_ndlp;
3506
3507 if (val == vport->cfg_max_scsicmpl_time)
3508 return 0;
3509 if ((val < 0) || (val > 60000))
3510 return -EINVAL;
3511 vport->cfg_max_scsicmpl_time = val;
3512
3513 spin_lock_irq(shost->host_lock);
3514 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3515 if (!NLP_CHK_NODE_ACT(ndlp))
3516 continue;
3517 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3518 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003519 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003520 }
3521 spin_unlock_irq(shost->host_lock);
3522 return 0;
3523}
3524lpfc_vport_param_store(max_scsicmpl_time);
3525static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3526 lpfc_max_scsicmpl_time_show,
3527 lpfc_max_scsicmpl_time_store);
3528
3529/*
dea31012005-04-17 16:05:31 -05003530# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3531# range is [0,1]. Default value is 0.
3532*/
3533LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3534
3535/*
3536# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3537# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003538# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003539# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3540# cr_delay is set to 0.
3541*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003542LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003543 "interrupt response is generated");
3544
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003545LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003546 "interrupt response is generated");
3547
3548/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003549# lpfc_multi_ring_support: Determines how many rings to spread available
3550# cmd/rsp IOCB entries across.
3551# Value range is [1,2]. Default value is 1.
3552*/
3553LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3554 "SLI rings to spread IOCB entries across");
3555
3556/*
James Smarta4bc3372006-12-02 13:34:16 -05003557# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3558# identifies what rctl value to configure the additional ring for.
3559# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3560*/
James Smart6a9c52c2009-10-02 15:16:51 -04003561LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003562 255, "Identifies RCTL for additional ring configuration");
3563
3564/*
3565# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3566# identifies what type value to configure the additional ring for.
3567# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3568*/
James Smart6a9c52c2009-10-02 15:16:51 -04003569LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003570 255, "Identifies TYPE for additional ring configuration");
3571
3572/*
dea31012005-04-17 16:05:31 -05003573# lpfc_fdmi_on: controls FDMI support.
3574# 0 = no FDMI support
3575# 1 = support FDMI without attribute of hostname
3576# 2 = support FDMI with attribute of hostname
3577# Value range [0,2]. Default value is 0.
3578*/
James Smart3de2a652007-08-02 11:09:59 -04003579LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003580
3581/*
3582# Specifies the maximum number of ELS cmds we can have outstanding (for
3583# discovery). Value range is [1,64]. Default value = 32.
3584*/
James Smart3de2a652007-08-02 11:09:59 -04003585LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003586 "during discovery");
3587
3588/*
James Smart65a29c12006-07-06 15:50:50 -04003589# lpfc_max_luns: maximum allowed LUN.
3590# Value range is [0,65535]. Default value is 255.
3591# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003592*/
James Smart3de2a652007-08-02 11:09:59 -04003593LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003594
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003595/*
3596# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3597# Value range is [1,255], default value is 10.
3598*/
3599LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3600 "Milliseconds driver will wait between polling FCP ring");
3601
James Smart4ff43242006-12-02 13:34:56 -05003602/*
3603# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3604# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003605# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003606# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003607# 2 = MSI-X enabled (default)
3608# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003609*/
George Kadianakis8605c462010-01-17 21:19:31 +02003610LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003611 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003612
James Smart13815c82008-01-11 01:52:48 -05003613/*
James Smartda0436e2009-05-22 14:51:39 -04003614# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3615#
3616# Value range is [636,651042]. Default value is 10000.
3617*/
3618LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3619 "Set the maximum number of fast-path FCP interrupts per second");
3620
3621/*
3622# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3623#
3624# Value range is [1,31]. Default value is 4.
3625*/
3626LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3627 "Set the number of fast-path FCP work queues, if possible");
3628
3629/*
3630# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3631#
3632# Value range is [1,7]. Default value is 1.
3633*/
3634LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3635 "Set the number of fast-path FCP event queues, if possible");
3636
3637/*
James Smart13815c82008-01-11 01:52:48 -05003638# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3639# 0 = HBA resets disabled
3640# 1 = HBA resets enabled (default)
3641# Value range is [0,1]. Default value is 1.
3642*/
3643LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003644
James Smart13815c82008-01-11 01:52:48 -05003645/*
James Smarteb7a3392010-11-20 23:12:02 -05003646# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003647# 0 = HBA Heartbeat disabled
3648# 1 = HBA Heartbeat enabled (default)
3649# Value range is [0,1]. Default value is 1.
3650*/
James Smarteb7a3392010-11-20 23:12:02 -05003651LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003652
James Smart83108bd2008-01-11 01:53:09 -05003653/*
James Smart81301a92008-12-04 22:39:46 -05003654# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3655# 0 = BlockGuard disabled (default)
3656# 1 = BlockGuard enabled
3657# Value range is [0,1]. Default value is 0.
3658*/
3659LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3660
James Smart6fb120a2009-05-22 14:52:59 -04003661/*
James Smart81301a92008-12-04 22:39:46 -05003662# lpfc_prot_mask: i
3663# - Bit mask of host protection capabilities used to register with the
3664# SCSI mid-layer
3665# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3666# - Allows you to ultimately specify which profiles to use
3667# - Default will result in registering capabilities for all profiles.
3668#
3669*/
James Smartbc739052010-08-04 16:11:18 -04003670unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003671
James Smartab56dc22011-02-16 12:39:57 -05003672module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003673MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3674
3675/*
3676# lpfc_prot_guard: i
3677# - Bit mask of protection guard types to register with the SCSI mid-layer
3678# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3679# - Allows you to ultimately specify which profiles to use
3680# - Default will result in registering capabilities for all guard types
3681#
3682*/
3683unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003684module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003685MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3686
James Smart92494142011-02-16 12:39:44 -05003687/*
3688 * Delay initial NPort discovery when Clean Address bit is cleared in
3689 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3690 * This parameter can have value 0 or 1.
3691 * When this parameter is set to 0, no delay is added to the initial
3692 * discovery.
3693 * When this parameter is set to non-zero value, initial Nport discovery is
3694 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3695 * accept and FCID/Fabric name/Fabric portname is changed.
3696 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3697 * when Clean Address bit is cleared in FLOGI/FDISC
3698 * accept and FCID/Fabric name/Fabric portname is changed.
3699 * Default value is 0.
3700 */
3701int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003702module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003703MODULE_PARM_DESC(lpfc_delay_discovery,
3704 "Delay NPort discovery when Clean Address bit is cleared. "
3705 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003706
3707/*
James Smart3621a712009-04-06 18:47:14 -04003708 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003709 * This value can be set to values between 64 and 256. The default value is
3710 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3711 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3712 */
3713LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3714 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3715
James Smart81301a92008-12-04 22:39:46 -05003716LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3717 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3718 "Max Protection Scatter Gather Segment Count");
3719
Tony Jonesee959b02008-02-22 00:13:36 +01003720struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003721 &dev_attr_bg_info,
3722 &dev_attr_bg_guard_err,
3723 &dev_attr_bg_apptag_err,
3724 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003725 &dev_attr_info,
3726 &dev_attr_serialnum,
3727 &dev_attr_modeldesc,
3728 &dev_attr_modelname,
3729 &dev_attr_programtype,
3730 &dev_attr_portnum,
3731 &dev_attr_fwrev,
3732 &dev_attr_hdw,
3733 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003734 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003735 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003736 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003737 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003738 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003739 &dev_attr_lpfc_temp_sensor,
3740 &dev_attr_lpfc_log_verbose,
3741 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003742 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003743 &dev_attr_lpfc_hba_queue_depth,
3744 &dev_attr_lpfc_peer_port_login,
3745 &dev_attr_lpfc_nodev_tmo,
3746 &dev_attr_lpfc_devloss_tmo,
3747 &dev_attr_lpfc_fcp_class,
3748 &dev_attr_lpfc_use_adisc,
3749 &dev_attr_lpfc_ack0,
3750 &dev_attr_lpfc_topology,
3751 &dev_attr_lpfc_scan_down,
3752 &dev_attr_lpfc_link_speed,
3753 &dev_attr_lpfc_cr_delay,
3754 &dev_attr_lpfc_cr_count,
3755 &dev_attr_lpfc_multi_ring_support,
3756 &dev_attr_lpfc_multi_ring_rctl,
3757 &dev_attr_lpfc_multi_ring_type,
3758 &dev_attr_lpfc_fdmi_on,
3759 &dev_attr_lpfc_max_luns,
3760 &dev_attr_lpfc_enable_npiv,
James Smart19ca7602010-11-20 23:11:55 -05003761 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003762 &dev_attr_nport_evt_cnt,
3763 &dev_attr_board_mode,
3764 &dev_attr_max_vpi,
3765 &dev_attr_used_vpi,
3766 &dev_attr_max_rpi,
3767 &dev_attr_used_rpi,
3768 &dev_attr_max_xri,
3769 &dev_attr_used_xri,
3770 &dev_attr_npiv_info,
3771 &dev_attr_issue_reset,
3772 &dev_attr_lpfc_poll,
3773 &dev_attr_lpfc_poll_tmo,
3774 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003775 &dev_attr_lpfc_fcp_imax,
3776 &dev_attr_lpfc_fcp_wq_count,
3777 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003778 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003779 &dev_attr_lpfc_soft_wwnn,
3780 &dev_attr_lpfc_soft_wwpn,
3781 &dev_attr_lpfc_soft_wwn_enable,
3782 &dev_attr_lpfc_enable_hba_reset,
3783 &dev_attr_lpfc_enable_hba_heartbeat,
3784 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003785 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003786 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003787 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003788 &dev_attr_lpfc_aer_support,
3789 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04003790 &dev_attr_lpfc_sriov_nr_virtfn,
James Smart84d1b002010-02-12 14:42:33 -05003791 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003792 &dev_attr_lpfc_iocb_cnt,
3793 &dev_attr_iocb_hw,
3794 &dev_attr_txq_hw,
3795 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003796 &dev_attr_lpfc_fips_level,
3797 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003798 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04003799 &dev_attr_lpfc_sriov_hw_max_virtfn,
dea31012005-04-17 16:05:31 -05003800 NULL,
3801};
3802
Tony Jonesee959b02008-02-22 00:13:36 +01003803struct device_attribute *lpfc_vport_attrs[] = {
3804 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003805 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003806 &dev_attr_num_discovered_ports,
3807 &dev_attr_lpfc_drvr_version,
3808 &dev_attr_lpfc_log_verbose,
3809 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003810 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003811 &dev_attr_lpfc_nodev_tmo,
3812 &dev_attr_lpfc_devloss_tmo,
3813 &dev_attr_lpfc_hba_queue_depth,
3814 &dev_attr_lpfc_peer_port_login,
3815 &dev_attr_lpfc_restrict_login,
3816 &dev_attr_lpfc_fcp_class,
3817 &dev_attr_lpfc_use_adisc,
3818 &dev_attr_lpfc_fdmi_on,
3819 &dev_attr_lpfc_max_luns,
3820 &dev_attr_nport_evt_cnt,
3821 &dev_attr_npiv_info,
3822 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003823 &dev_attr_lpfc_max_scsicmpl_time,
3824 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003825 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003826 &dev_attr_lpfc_fips_level,
3827 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003828 NULL,
3829};
3830
James Smarte59058c2008-08-24 21:49:00 -04003831/**
James Smart3621a712009-04-06 18:47:14 -04003832 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003833 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003834 * @kobj: kernel kobject that contains the kernel class device.
3835 * @bin_attr: kernel attributes passed to us.
3836 * @buf: contains the data to be written to the adapter IOREG space.
3837 * @off: offset into buffer to beginning of data.
3838 * @count: bytes to transfer.
3839 *
3840 * Description:
3841 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3842 * Uses the adapter io control registers to send buf contents to the adapter.
3843 *
3844 * Returns:
3845 * -ERANGE off and count combo out of range
3846 * -EINVAL off, count or buff address invalid
3847 * -EPERM adapter is offline
3848 * value of count, buf contents written
3849 **/
dea31012005-04-17 16:05:31 -05003850static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003851sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3852 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003853 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003854{
3855 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003856 struct device *dev = container_of(kobj, struct device, kobj);
3857 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003858 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3859 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003860
James Smartf1126682009-06-10 17:22:44 -04003861 if (phba->sli_rev >= LPFC_SLI_REV4)
3862 return -EPERM;
3863
dea31012005-04-17 16:05:31 -05003864 if ((off + count) > FF_REG_AREA_SIZE)
3865 return -ERANGE;
3866
3867 if (count == 0) return 0;
3868
3869 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3870 return -EINVAL;
3871
James Smart2e0fef82007-06-17 19:56:36 -05003872 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003873 return -EPERM;
3874 }
3875
James Smart2e0fef82007-06-17 19:56:36 -05003876 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003877 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3878 writel(*((uint32_t *)(buf + buf_off)),
3879 phba->ctrl_regs_memmap_p + off + buf_off);
3880
James Smart2e0fef82007-06-17 19:56:36 -05003881 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003882
3883 return count;
3884}
3885
James Smarte59058c2008-08-24 21:49:00 -04003886/**
James Smart3621a712009-04-06 18:47:14 -04003887 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003888 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003889 * @kobj: kernel kobject that contains the kernel class device.
3890 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003891 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003892 * @off: offset into buffer to beginning of data.
3893 * @count: bytes to transfer.
3894 *
3895 * Description:
3896 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3897 * Uses the adapter io control registers to read data into buf.
3898 *
3899 * Returns:
3900 * -ERANGE off and count combo out of range
3901 * -EINVAL off, count or buff address invalid
3902 * value of count, buf contents read
3903 **/
dea31012005-04-17 16:05:31 -05003904static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003905sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3906 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003907 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003908{
3909 size_t buf_off;
3910 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003911 struct device *dev = container_of(kobj, struct device, kobj);
3912 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003913 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3914 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003915
James Smartf1126682009-06-10 17:22:44 -04003916 if (phba->sli_rev >= LPFC_SLI_REV4)
3917 return -EPERM;
3918
dea31012005-04-17 16:05:31 -05003919 if (off > FF_REG_AREA_SIZE)
3920 return -ERANGE;
3921
3922 if ((off + count) > FF_REG_AREA_SIZE)
3923 count = FF_REG_AREA_SIZE - off;
3924
3925 if (count == 0) return 0;
3926
3927 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3928 return -EINVAL;
3929
James Smart2e0fef82007-06-17 19:56:36 -05003930 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003931
3932 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3933 tmp_ptr = (uint32_t *)(buf + buf_off);
3934 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3935 }
3936
James Smart2e0fef82007-06-17 19:56:36 -05003937 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003938
3939 return count;
3940}
3941
3942static struct bin_attribute sysfs_ctlreg_attr = {
3943 .attr = {
3944 .name = "ctlreg",
3945 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003946 },
3947 .size = 256,
3948 .read = sysfs_ctlreg_read,
3949 .write = sysfs_ctlreg_write,
3950};
3951
James Smarte59058c2008-08-24 21:49:00 -04003952/**
James Smart3621a712009-04-06 18:47:14 -04003953 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003954 * @phba: lpfc_hba pointer
3955 **/
dea31012005-04-17 16:05:31 -05003956static void
James Smart2e0fef82007-06-17 19:56:36 -05003957sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003958{
3959 phba->sysfs_mbox.state = SMBOX_IDLE;
3960 phba->sysfs_mbox.offset = 0;
3961
3962 if (phba->sysfs_mbox.mbox) {
3963 mempool_free(phba->sysfs_mbox.mbox,
3964 phba->mbox_mem_pool);
3965 phba->sysfs_mbox.mbox = NULL;
3966 }
3967}
3968
James Smarte59058c2008-08-24 21:49:00 -04003969/**
James Smart3621a712009-04-06 18:47:14 -04003970 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003971 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003972 * @kobj: kernel kobject that contains the kernel class device.
3973 * @bin_attr: kernel attributes passed to us.
3974 * @buf: contains the data to be written to sysfs mbox.
3975 * @off: offset into buffer to beginning of data.
3976 * @count: bytes to transfer.
3977 *
3978 * Description:
3979 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3980 * Uses the sysfs mbox to send buf contents to the adapter.
3981 *
3982 * Returns:
3983 * -ERANGE off and count combo out of range
3984 * -EINVAL off, count or buff address invalid
3985 * zero if count is zero
3986 * -EPERM adapter is offline
3987 * -ENOMEM failed to allocate memory for the mail box
3988 * -EAGAIN offset, state or mbox is NULL
3989 * count number of bytes transferred
3990 **/
dea31012005-04-17 16:05:31 -05003991static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003992sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3993 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003994 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003995{
Tony Jonesee959b02008-02-22 00:13:36 +01003996 struct device *dev = container_of(kobj, struct device, kobj);
3997 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003998 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3999 struct lpfc_hba *phba = vport->phba;
4000 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05004001
4002 if ((count + off) > MAILBOX_CMD_SIZE)
4003 return -ERANGE;
4004
4005 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4006 return -EINVAL;
4007
4008 if (count == 0)
4009 return 0;
4010
4011 if (off == 0) {
4012 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4013 if (!mbox)
4014 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05004015 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004016 }
4017
James Smart2e0fef82007-06-17 19:56:36 -05004018 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004019
4020 if (off == 0) {
4021 if (phba->sysfs_mbox.mbox)
4022 mempool_free(mbox, phba->mbox_mem_pool);
4023 else
4024 phba->sysfs_mbox.mbox = mbox;
4025 phba->sysfs_mbox.state = SMBOX_WRITING;
4026 } else {
4027 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4028 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05004029 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05004030 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004031 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004032 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004033 }
4034 }
4035
James Smart04c68492009-05-22 14:52:52 -04004036 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05004037 buf, count);
4038
4039 phba->sysfs_mbox.offset = off + count;
4040
James Smart2e0fef82007-06-17 19:56:36 -05004041 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004042
4043 return count;
4044}
4045
James Smarte59058c2008-08-24 21:49:00 -04004046/**
James Smart3621a712009-04-06 18:47:14 -04004047 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004048 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004049 * @kobj: kernel kobject that contains the kernel class device.
4050 * @bin_attr: kernel attributes passed to us.
4051 * @buf: contains the data to be read from sysfs mbox.
4052 * @off: offset into buffer to beginning of data.
4053 * @count: bytes to transfer.
4054 *
4055 * Description:
4056 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4057 * Uses the sysfs mbox to receive data from to the adapter.
4058 *
4059 * Returns:
4060 * -ERANGE off greater than mailbox command size
4061 * -EINVAL off, count or buff address invalid
4062 * zero if off and count are zero
4063 * -EACCES adapter over temp
4064 * -EPERM garbage can value to catch a multitude of errors
4065 * -EAGAIN management IO not permitted, state or off error
4066 * -ETIME mailbox timeout
4067 * -ENODEV mailbox error
4068 * count number of bytes transferred
4069 **/
dea31012005-04-17 16:05:31 -05004070static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004071sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4072 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004073 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004074{
Tony Jonesee959b02008-02-22 00:13:36 +01004075 struct device *dev = container_of(kobj, struct device, kobj);
4076 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004077 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4078 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004079 int rc;
James Smart04c68492009-05-22 14:52:52 -04004080 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05004081
James Smart1dcb58e2007-04-25 09:51:30 -04004082 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004083 return -ERANGE;
4084
James Smart1dcb58e2007-04-25 09:51:30 -04004085 if ((count + off) > MAILBOX_CMD_SIZE)
4086 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05004087
4088 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4089 return -EINVAL;
4090
4091 if (off && count == 0)
4092 return 0;
4093
James Smart2e0fef82007-06-17 19:56:36 -05004094 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004095
James Smart7af67052007-10-27 13:38:11 -04004096 if (phba->over_temp_state == HBA_OVER_TEMP) {
4097 sysfs_mbox_idle(phba);
4098 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05004099 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04004100 }
4101
dea31012005-04-17 16:05:31 -05004102 if (off == 0 &&
4103 phba->sysfs_mbox.state == SMBOX_WRITING &&
4104 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04004105 pmb = &phba->sysfs_mbox.mbox->u.mb;
4106 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05004107 /* Offline only */
dea31012005-04-17 16:05:31 -05004108 case MBX_INIT_LINK:
4109 case MBX_DOWN_LINK:
4110 case MBX_CONFIG_LINK:
4111 case MBX_CONFIG_RING:
4112 case MBX_RESET_RING:
4113 case MBX_UNREG_LOGIN:
4114 case MBX_CLEAR_LA:
4115 case MBX_DUMP_CONTEXT:
4116 case MBX_RUN_DIAGS:
4117 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05004118 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05004119 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05004120 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05004121 printk(KERN_WARNING "mbox_read:Command 0x%x "
4122 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04004123 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004124 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004125 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004126 return -EPERM;
4127 }
James Smarta8adb832007-10-27 13:37:53 -04004128 case MBX_WRITE_NV:
4129 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05004130 case MBX_LOAD_SM:
4131 case MBX_READ_NV:
4132 case MBX_READ_CONFIG:
4133 case MBX_READ_RCONFIG:
4134 case MBX_READ_STATUS:
4135 case MBX_READ_XRI:
4136 case MBX_READ_REV:
4137 case MBX_READ_LNK_STAT:
4138 case MBX_DUMP_MEMORY:
4139 case MBX_DOWN_LOAD:
4140 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004141 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05004142 case MBX_LOAD_AREA:
4143 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004144 case MBX_BEACON:
4145 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05004146 case MBX_SET_VARIABLE:
4147 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04004148 case MBX_PORT_CAPABILITIES:
4149 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05004150 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04004151 case MBX_SECURITY_MGMT:
4152 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04004153 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4154 printk(KERN_WARNING "mbox_read:Command 0x%x "
4155 "is not permitted\n", pmb->mbxCommand);
4156 sysfs_mbox_idle(phba);
4157 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04004158 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04004159 }
James Smartdcf2a4e2010-09-29 11:18:53 -04004160 break;
dea31012005-04-17 16:05:31 -05004161 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05004162 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05004163 case MBX_REG_LOGIN:
4164 case MBX_REG_LOGIN64:
4165 case MBX_CONFIG_PORT:
4166 case MBX_RUN_BIU_DIAG:
4167 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004168 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004169 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004170 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004171 return -EPERM;
4172 default:
4173 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004174 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004175 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004176 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004177 return -EPERM;
4178 }
4179
James Smart09372822008-01-11 01:52:54 -05004180 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05004181 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05004182 */
James Smartd7c255b2008-08-24 21:50:00 -04004183 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04004184 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4185 pmb->mbxCommand != MBX_RESTART &&
4186 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4187 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04004188 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4189 "1259 mbox: Issued mailbox cmd "
4190 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04004191 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05004192
James Smart92d7f7b2007-06-17 19:56:38 -05004193 phba->sysfs_mbox.mbox->vport = vport;
4194
James Smart58da1ff2008-04-07 10:15:56 -04004195 /* Don't allow mailbox commands to be sent when blocked
4196 * or when in the middle of discovery
4197 */
James Smart495a7142008-06-14 22:52:59 -04004198 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04004199 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004200 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04004201 return -EAGAIN;
4202 }
4203
James Smart2e0fef82007-06-17 19:56:36 -05004204 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004205 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05004206
James Smart2e0fef82007-06-17 19:56:36 -05004207 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004208 rc = lpfc_sli_issue_mbox (phba,
4209 phba->sysfs_mbox.mbox,
4210 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05004211 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004212
4213 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004214 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004215 rc = lpfc_sli_issue_mbox_wait (phba,
4216 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04004217 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05004218 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004219 }
4220
4221 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04004222 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04004223 phba->sysfs_mbox.mbox = NULL;
4224 }
dea31012005-04-17 16:05:31 -05004225 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004226 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004227 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05004228 }
4229 phba->sysfs_mbox.state = SMBOX_READING;
4230 }
4231 else if (phba->sysfs_mbox.offset != off ||
4232 phba->sysfs_mbox.state != SMBOX_READING) {
4233 printk(KERN_WARNING "mbox_read: Bad State\n");
4234 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004235 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004236 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004237 }
4238
James Smart04c68492009-05-22 14:52:52 -04004239 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05004240
4241 phba->sysfs_mbox.offset = off + count;
4242
James Smart1dcb58e2007-04-25 09:51:30 -04004243 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004244 sysfs_mbox_idle(phba);
4245
James Smart2e0fef82007-06-17 19:56:36 -05004246 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004247
4248 return count;
4249}
4250
4251static struct bin_attribute sysfs_mbox_attr = {
4252 .attr = {
4253 .name = "mbox",
4254 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004255 },
James Smartc0c11512011-05-24 11:41:34 -04004256 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004257 .read = sysfs_mbox_read,
4258 .write = sysfs_mbox_write,
4259};
4260
James Smarte59058c2008-08-24 21:49:00 -04004261/**
James Smart3621a712009-04-06 18:47:14 -04004262 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004263 * @vport: address of lpfc vport structure.
4264 *
4265 * Return codes:
4266 * zero on success
4267 * error return code from sysfs_create_bin_file()
4268 **/
dea31012005-04-17 16:05:31 -05004269int
James Smart2e0fef82007-06-17 19:56:36 -05004270lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004271{
James Smart2e0fef82007-06-17 19:56:36 -05004272 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004273 int error;
4274
Tony Jonesee959b02008-02-22 00:13:36 +01004275 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004276 &sysfs_drvr_stat_data_attr);
4277
4278 /* Virtual ports do not need ctrl_reg and mbox */
4279 if (error || vport->port_type == LPFC_NPIV_PORT)
4280 goto out;
4281
4282 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004283 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004284 if (error)
James Smarteada2722008-12-04 22:39:13 -05004285 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004286
Tony Jonesee959b02008-02-22 00:13:36 +01004287 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004288 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004289 if (error)
4290 goto out_remove_ctlreg_attr;
4291
4292 return 0;
4293out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004294 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004295out_remove_stat_attr:
4296 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4297 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004298out:
4299 return error;
4300}
4301
James Smarte59058c2008-08-24 21:49:00 -04004302/**
James Smart3621a712009-04-06 18:47:14 -04004303 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004304 * @vport: address of lpfc vport structure.
4305 **/
dea31012005-04-17 16:05:31 -05004306void
James Smart2e0fef82007-06-17 19:56:36 -05004307lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004308{
James Smart2e0fef82007-06-17 19:56:36 -05004309 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004310 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4311 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004312 /* Virtual ports do not need ctrl_reg and mbox */
4313 if (vport->port_type == LPFC_NPIV_PORT)
4314 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004315 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4316 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004317}
4318
4319
4320/*
4321 * Dynamic FC Host Attributes Support
4322 */
4323
James Smarte59058c2008-08-24 21:49:00 -04004324/**
James Smart3621a712009-04-06 18:47:14 -04004325 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004326 * @shost: kernel scsi host pointer.
4327 **/
dea31012005-04-17 16:05:31 -05004328static void
4329lpfc_get_host_port_id(struct Scsi_Host *shost)
4330{
James Smart2e0fef82007-06-17 19:56:36 -05004331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4332
dea31012005-04-17 16:05:31 -05004333 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004334 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004335}
4336
James Smarte59058c2008-08-24 21:49:00 -04004337/**
James Smart3621a712009-04-06 18:47:14 -04004338 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004339 * @shost: kernel scsi host pointer.
4340 **/
dea31012005-04-17 16:05:31 -05004341static void
4342lpfc_get_host_port_type(struct Scsi_Host *shost)
4343{
James Smart2e0fef82007-06-17 19:56:36 -05004344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004346
4347 spin_lock_irq(shost->host_lock);
4348
James Smart92d7f7b2007-06-17 19:56:38 -05004349 if (vport->port_type == LPFC_NPIV_PORT) {
4350 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4351 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004352 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004353 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004354 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4355 else
4356 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4357 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004358 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004359 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4360 else
4361 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4362 }
4363 } else
4364 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4365
4366 spin_unlock_irq(shost->host_lock);
4367}
4368
James Smarte59058c2008-08-24 21:49:00 -04004369/**
James Smart3621a712009-04-06 18:47:14 -04004370 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004371 * @shost: kernel scsi host pointer.
4372 **/
dea31012005-04-17 16:05:31 -05004373static void
4374lpfc_get_host_port_state(struct Scsi_Host *shost)
4375{
James Smart2e0fef82007-06-17 19:56:36 -05004376 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4377 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004378
4379 spin_lock_irq(shost->host_lock);
4380
James Smart2e0fef82007-06-17 19:56:36 -05004381 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004382 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4383 else {
James Smart2e0fef82007-06-17 19:56:36 -05004384 switch (phba->link_state) {
4385 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004386 case LPFC_LINK_DOWN:
4387 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4388 break;
4389 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004390 case LPFC_CLEAR_LA:
4391 case LPFC_HBA_READY:
4392 /* Links up, beyond this port_type reports state */
4393 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4394 break;
4395 case LPFC_HBA_ERROR:
4396 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4397 break;
4398 default:
4399 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4400 break;
4401 }
4402 }
4403
4404 spin_unlock_irq(shost->host_lock);
4405}
4406
James Smarte59058c2008-08-24 21:49:00 -04004407/**
James Smart3621a712009-04-06 18:47:14 -04004408 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004409 * @shost: kernel scsi host pointer.
4410 **/
dea31012005-04-17 16:05:31 -05004411static void
4412lpfc_get_host_speed(struct Scsi_Host *shost)
4413{
James Smart2e0fef82007-06-17 19:56:36 -05004414 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4415 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004416
4417 spin_lock_irq(shost->host_lock);
4418
James Smart2e0fef82007-06-17 19:56:36 -05004419 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004420 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004421 case LPFC_LINK_SPEED_1GHZ:
4422 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004423 break;
James Smart76a95d72010-11-20 23:11:48 -05004424 case LPFC_LINK_SPEED_2GHZ:
4425 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004426 break;
James Smart76a95d72010-11-20 23:11:48 -05004427 case LPFC_LINK_SPEED_4GHZ:
4428 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004429 break;
James Smart76a95d72010-11-20 23:11:48 -05004430 case LPFC_LINK_SPEED_8GHZ:
4431 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004432 break;
James Smart76a95d72010-11-20 23:11:48 -05004433 case LPFC_LINK_SPEED_10GHZ:
4434 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004435 break;
James Smart76a95d72010-11-20 23:11:48 -05004436 case LPFC_LINK_SPEED_16GHZ:
4437 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4438 break;
4439 default:
4440 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004441 break;
4442 }
James Smart09372822008-01-11 01:52:54 -05004443 } else
4444 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004445
4446 spin_unlock_irq(shost->host_lock);
4447}
4448
James Smarte59058c2008-08-24 21:49:00 -04004449/**
James Smart3621a712009-04-06 18:47:14 -04004450 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004451 * @shost: kernel scsi host pointer.
4452 **/
dea31012005-04-17 16:05:31 -05004453static void
4454lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4455{
James Smart2e0fef82007-06-17 19:56:36 -05004456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4457 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004458 u64 node_name;
dea31012005-04-17 16:05:31 -05004459
4460 spin_lock_irq(shost->host_lock);
4461
James Smart2e0fef82007-06-17 19:56:36 -05004462 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004463 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004464 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004465 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004466 else
4467 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004468 node_name = 0;
dea31012005-04-17 16:05:31 -05004469
4470 spin_unlock_irq(shost->host_lock);
4471
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004472 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004473}
4474
James Smarte59058c2008-08-24 21:49:00 -04004475/**
James Smart3621a712009-04-06 18:47:14 -04004476 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004477 * @shost: kernel scsi host pointer.
4478 *
4479 * Notes:
4480 * NULL on error for link down, no mbox pool, sli2 active,
4481 * management not allowed, memory allocation error, or mbox error.
4482 *
4483 * Returns:
4484 * NULL for error
4485 * address of the adapter host statistics
4486 **/
dea31012005-04-17 16:05:31 -05004487static struct fc_host_statistics *
4488lpfc_get_stats(struct Scsi_Host *shost)
4489{
James Smart2e0fef82007-06-17 19:56:36 -05004490 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4491 struct lpfc_hba *phba = vport->phba;
4492 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004493 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004494 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004495 LPFC_MBOXQ_t *pmboxq;
4496 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004497 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004498 int rc = 0;
dea31012005-04-17 16:05:31 -05004499
James Smart92d7f7b2007-06-17 19:56:38 -05004500 /*
4501 * prevent udev from issuing mailbox commands until the port is
4502 * configured.
4503 */
James Smart2e0fef82007-06-17 19:56:36 -05004504 if (phba->link_state < LPFC_LINK_DOWN ||
4505 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004506 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004507 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004508
4509 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004510 return NULL;
4511
dea31012005-04-17 16:05:31 -05004512 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4513 if (!pmboxq)
4514 return NULL;
4515 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4516
James Smart04c68492009-05-22 14:52:52 -04004517 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004518 pmb->mbxCommand = MBX_READ_STATUS;
4519 pmb->mbxOwner = OWN_HOST;
4520 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004521 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004522
James Smart75baf692010-06-08 18:31:21 -04004523 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004524 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004525 else
dea31012005-04-17 16:05:31 -05004526 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4527
4528 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004529 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004530 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004531 return NULL;
4532 }
4533
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004534 memset(hs, 0, sizeof (struct fc_host_statistics));
4535
dea31012005-04-17 16:05:31 -05004536 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4537 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4538 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4539 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4540
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004541 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004542 pmb->mbxCommand = MBX_READ_LNK_STAT;
4543 pmb->mbxOwner = OWN_HOST;
4544 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004545 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004546
James Smart75baf692010-06-08 18:31:21 -04004547 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004548 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004549 else
dea31012005-04-17 16:05:31 -05004550 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4551
4552 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004553 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004554 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004555 return NULL;
4556 }
4557
4558 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4559 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4560 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4561 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4562 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4563 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4564 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4565
James Smart64ba8812006-08-02 15:24:34 -04004566 hs->link_failure_count -= lso->link_failure_count;
4567 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4568 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4569 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4570 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4571 hs->invalid_crc_count -= lso->invalid_crc_count;
4572 hs->error_frames -= lso->error_frames;
4573
James Smart76a95d72010-11-20 23:11:48 -05004574 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004575 hs->lip_count = -1;
4576 hs->nos_count = (phba->link_events >> 1);
4577 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004578 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004579 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004580 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004581 hs->nos_count = -1;
4582 } else {
4583 hs->lip_count = -1;
4584 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004585 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004586 }
4587
4588 hs->dumped_frames = -1;
4589
James Smart64ba8812006-08-02 15:24:34 -04004590 seconds = get_seconds();
4591 if (seconds < psli->stats_start)
4592 hs->seconds_since_last_reset = seconds +
4593 ((unsigned long)-1 - psli->stats_start);
4594 else
4595 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004596
James Smart1dcb58e2007-04-25 09:51:30 -04004597 mempool_free(pmboxq, phba->mbox_mem_pool);
4598
dea31012005-04-17 16:05:31 -05004599 return hs;
4600}
4601
James Smarte59058c2008-08-24 21:49:00 -04004602/**
James Smart3621a712009-04-06 18:47:14 -04004603 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004604 * @shost: kernel scsi host pointer.
4605 **/
James Smart64ba8812006-08-02 15:24:34 -04004606static void
4607lpfc_reset_stats(struct Scsi_Host *shost)
4608{
James Smart2e0fef82007-06-17 19:56:36 -05004609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4610 struct lpfc_hba *phba = vport->phba;
4611 struct lpfc_sli *psli = &phba->sli;
4612 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004613 LPFC_MBOXQ_t *pmboxq;
4614 MAILBOX_t *pmb;
4615 int rc = 0;
4616
James Smart2e0fef82007-06-17 19:56:36 -05004617 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004618 return;
4619
James Smart64ba8812006-08-02 15:24:34 -04004620 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4621 if (!pmboxq)
4622 return;
4623 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4624
James Smart04c68492009-05-22 14:52:52 -04004625 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004626 pmb->mbxCommand = MBX_READ_STATUS;
4627 pmb->mbxOwner = OWN_HOST;
4628 pmb->un.varWords[0] = 0x1; /* reset request */
4629 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004630 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004631
James Smart2e0fef82007-06-17 19:56:36 -05004632 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004633 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004634 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4635 else
4636 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4637
4638 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004639 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004640 mempool_free(pmboxq, phba->mbox_mem_pool);
4641 return;
4642 }
4643
4644 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4645 pmb->mbxCommand = MBX_READ_LNK_STAT;
4646 pmb->mbxOwner = OWN_HOST;
4647 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004648 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004649
James Smart2e0fef82007-06-17 19:56:36 -05004650 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004651 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004652 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4653 else
4654 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4655
4656 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004657 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004658 mempool_free( pmboxq, phba->mbox_mem_pool);
4659 return;
4660 }
4661
4662 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4663 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4664 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4665 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4666 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4667 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4668 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004669 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004670 lso->link_events = (phba->link_events >> 1);
4671 else
4672 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004673
4674 psli->stats_start = get_seconds();
4675
James Smart1dcb58e2007-04-25 09:51:30 -04004676 mempool_free(pmboxq, phba->mbox_mem_pool);
4677
James Smart64ba8812006-08-02 15:24:34 -04004678 return;
4679}
dea31012005-04-17 16:05:31 -05004680
4681/*
4682 * The LPFC driver treats linkdown handling as target loss events so there
4683 * are no sysfs handlers for link_down_tmo.
4684 */
James Smart685f0bf2007-04-25 09:53:08 -04004685
James Smarte59058c2008-08-24 21:49:00 -04004686/**
James Smart3621a712009-04-06 18:47:14 -04004687 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004688 * @starget: kernel scsi target pointer.
4689 *
4690 * Returns:
4691 * address of the node list if found
4692 * NULL target not found
4693 **/
James Smart685f0bf2007-04-25 09:53:08 -04004694static struct lpfc_nodelist *
4695lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004696{
James Smart2e0fef82007-06-17 19:56:36 -05004697 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004699 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004700
4701 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004702 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004703 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004704 if (NLP_CHK_NODE_ACT(ndlp) &&
4705 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004706 starget->id == ndlp->nlp_sid) {
4707 spin_unlock_irq(shost->host_lock);
4708 return ndlp;
dea31012005-04-17 16:05:31 -05004709 }
4710 }
4711 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004712 return NULL;
4713}
dea31012005-04-17 16:05:31 -05004714
James Smarte59058c2008-08-24 21:49:00 -04004715/**
James Smart3621a712009-04-06 18:47:14 -04004716 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004717 * @starget: kernel scsi target pointer.
4718 **/
James Smart685f0bf2007-04-25 09:53:08 -04004719static void
4720lpfc_get_starget_port_id(struct scsi_target *starget)
4721{
4722 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4723
4724 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004725}
4726
James Smarte59058c2008-08-24 21:49:00 -04004727/**
James Smart3621a712009-04-06 18:47:14 -04004728 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004729 * @starget: kernel scsi target pointer.
4730 *
4731 * Description: Set the target node name to the ndlp node name wwn or zero.
4732 **/
dea31012005-04-17 16:05:31 -05004733static void
4734lpfc_get_starget_node_name(struct scsi_target *starget)
4735{
James Smart685f0bf2007-04-25 09:53:08 -04004736 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004737
James Smart685f0bf2007-04-25 09:53:08 -04004738 fc_starget_node_name(starget) =
4739 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004740}
4741
James Smarte59058c2008-08-24 21:49:00 -04004742/**
James Smart3621a712009-04-06 18:47:14 -04004743 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004744 * @starget: kernel scsi target pointer.
4745 *
4746 * Description: set the target port name to the ndlp port name wwn or zero.
4747 **/
dea31012005-04-17 16:05:31 -05004748static void
4749lpfc_get_starget_port_name(struct scsi_target *starget)
4750{
James Smart685f0bf2007-04-25 09:53:08 -04004751 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004752
James Smart685f0bf2007-04-25 09:53:08 -04004753 fc_starget_port_name(starget) =
4754 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004755}
4756
James Smarte59058c2008-08-24 21:49:00 -04004757/**
James Smart3621a712009-04-06 18:47:14 -04004758 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004759 * @rport: fc rport address.
4760 * @timeout: new value for dev loss tmo.
4761 *
4762 * Description:
4763 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4764 * dev_loss_tmo to one.
4765 **/
dea31012005-04-17 16:05:31 -05004766static void
dea31012005-04-17 16:05:31 -05004767lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4768{
dea31012005-04-17 16:05:31 -05004769 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004770 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004771 else
James Smartc01f3202006-08-18 17:47:08 -04004772 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004773}
4774
James Smarte59058c2008-08-24 21:49:00 -04004775/**
James Smart3621a712009-04-06 18:47:14 -04004776 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004777 *
4778 * Description:
4779 * Macro that uses field to generate a function with the name lpfc_show_rport_
4780 *
4781 * lpfc_show_rport_##field: returns the bytes formatted in buf
4782 * @cdev: class converted to an fc_rport.
4783 * @buf: on return contains the target_field or zero.
4784 *
4785 * Returns: size of formatted string.
4786 **/
dea31012005-04-17 16:05:31 -05004787#define lpfc_rport_show_function(field, format_string, sz, cast) \
4788static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004789lpfc_show_rport_##field (struct device *dev, \
4790 struct device_attribute *attr, \
4791 char *buf) \
dea31012005-04-17 16:05:31 -05004792{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004793 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004794 struct lpfc_rport_data *rdata = rport->hostdata; \
4795 return snprintf(buf, sz, format_string, \
4796 (rdata->target) ? cast rdata->target->field : 0); \
4797}
4798
4799#define lpfc_rport_rd_attr(field, format_string, sz) \
4800 lpfc_rport_show_function(field, format_string, sz, ) \
4801static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4802
James Smarteada2722008-12-04 22:39:13 -05004803/**
James Smart3621a712009-04-06 18:47:14 -04004804 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004805 * @fc_vport: The fc_vport who's symbolic name has been changed.
4806 *
4807 * Description:
4808 * This function is called by the transport after the @fc_vport's symbolic name
4809 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004810 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004811 **/
4812static void
4813lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4814{
4815 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4816
4817 if (vport->port_state == LPFC_VPORT_READY)
4818 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4819}
dea31012005-04-17 16:05:31 -05004820
James Smartf4b4c682009-05-22 14:53:12 -04004821/**
4822 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4823 * @phba: Pointer to lpfc_hba struct.
4824 *
4825 * This function is called by the lpfc_get_cfgparam() routine to set the
4826 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004827 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004828 * before hba port or vport created.
4829 **/
4830static void
4831lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4832{
4833 phba->cfg_log_verbose = verbose;
4834}
4835
dea31012005-04-17 16:05:31 -05004836struct fc_function_template lpfc_transport_functions = {
4837 /* fixed attributes the driver supports */
4838 .show_host_node_name = 1,
4839 .show_host_port_name = 1,
4840 .show_host_supported_classes = 1,
4841 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004842 .show_host_supported_speeds = 1,
4843 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004844 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004845
4846 /* dynamic attributes the driver supports */
4847 .get_host_port_id = lpfc_get_host_port_id,
4848 .show_host_port_id = 1,
4849
4850 .get_host_port_type = lpfc_get_host_port_type,
4851 .show_host_port_type = 1,
4852
4853 .get_host_port_state = lpfc_get_host_port_state,
4854 .show_host_port_state = 1,
4855
4856 /* active_fc4s is shown but doesn't change (thus no get function) */
4857 .show_host_active_fc4s = 1,
4858
4859 .get_host_speed = lpfc_get_host_speed,
4860 .show_host_speed = 1,
4861
4862 .get_host_fabric_name = lpfc_get_host_fabric_name,
4863 .show_host_fabric_name = 1,
4864
4865 /*
4866 * The LPFC driver treats linkdown handling as target loss events
4867 * so there are no sysfs handlers for link_down_tmo.
4868 */
4869
4870 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004871 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004872
4873 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4874 .show_rport_maxframe_size = 1,
4875 .show_rport_supported_classes = 1,
4876
dea31012005-04-17 16:05:31 -05004877 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4878 .show_rport_dev_loss_tmo = 1,
4879
4880 .get_starget_port_id = lpfc_get_starget_port_id,
4881 .show_starget_port_id = 1,
4882
4883 .get_starget_node_name = lpfc_get_starget_node_name,
4884 .show_starget_node_name = 1,
4885
4886 .get_starget_port_name = lpfc_get_starget_port_name,
4887 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004888
4889 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004890 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4891 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004892
James Smart92d7f7b2007-06-17 19:56:38 -05004893 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004894
4895 .vport_disable = lpfc_vport_disable,
4896
4897 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004898
4899 .bsg_request = lpfc_bsg_request,
4900 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004901};
4902
James Smart98c9ea52007-10-27 13:37:33 -04004903struct fc_function_template lpfc_vport_transport_functions = {
4904 /* fixed attributes the driver supports */
4905 .show_host_node_name = 1,
4906 .show_host_port_name = 1,
4907 .show_host_supported_classes = 1,
4908 .show_host_supported_fc4s = 1,
4909 .show_host_supported_speeds = 1,
4910 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004911 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004912
4913 /* dynamic attributes the driver supports */
4914 .get_host_port_id = lpfc_get_host_port_id,
4915 .show_host_port_id = 1,
4916
4917 .get_host_port_type = lpfc_get_host_port_type,
4918 .show_host_port_type = 1,
4919
4920 .get_host_port_state = lpfc_get_host_port_state,
4921 .show_host_port_state = 1,
4922
4923 /* active_fc4s is shown but doesn't change (thus no get function) */
4924 .show_host_active_fc4s = 1,
4925
4926 .get_host_speed = lpfc_get_host_speed,
4927 .show_host_speed = 1,
4928
4929 .get_host_fabric_name = lpfc_get_host_fabric_name,
4930 .show_host_fabric_name = 1,
4931
4932 /*
4933 * The LPFC driver treats linkdown handling as target loss events
4934 * so there are no sysfs handlers for link_down_tmo.
4935 */
4936
4937 .get_fc_host_stats = lpfc_get_stats,
4938 .reset_fc_host_stats = lpfc_reset_stats,
4939
4940 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4941 .show_rport_maxframe_size = 1,
4942 .show_rport_supported_classes = 1,
4943
4944 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4945 .show_rport_dev_loss_tmo = 1,
4946
4947 .get_starget_port_id = lpfc_get_starget_port_id,
4948 .show_starget_port_id = 1,
4949
4950 .get_starget_node_name = lpfc_get_starget_node_name,
4951 .show_starget_node_name = 1,
4952
4953 .get_starget_port_name = lpfc_get_starget_port_name,
4954 .show_starget_port_name = 1,
4955
4956 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4957 .terminate_rport_io = lpfc_terminate_rport_io,
4958
4959 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004960
4961 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004962};
4963
James Smarte59058c2008-08-24 21:49:00 -04004964/**
James Smart3621a712009-04-06 18:47:14 -04004965 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004966 * @phba: lpfc_hba pointer.
4967 **/
dea31012005-04-17 16:05:31 -05004968void
4969lpfc_get_cfgparam(struct lpfc_hba *phba)
4970{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004971 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4972 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004973 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004974 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4975 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004976 lpfc_ack0_init(phba, lpfc_ack0);
4977 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004978 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004979 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004980 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart19ca7602010-11-20 23:11:55 -05004981 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05004982 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004983 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4984 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4985 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004986 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4987 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004988 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004989 if (phba->sli_rev == LPFC_SLI_REV4)
4990 phba->cfg_poll = 0;
4991 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004992 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004993 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004994 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004995 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004996 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004997 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004998 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004999 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005000 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smart84d1b002010-02-12 14:42:33 -05005001 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005002 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005003 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005004 return;
5005}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005006
James Smarte59058c2008-08-24 21:49:00 -04005007/**
James Smart3621a712009-04-06 18:47:14 -04005008 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005009 * @vport: lpfc_vport pointer.
5010 **/
James Smart3de2a652007-08-02 11:09:59 -04005011void
5012lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5013{
James Smarte8b62012007-08-02 11:10:09 -04005014 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005015 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005016 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005017 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5018 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5019 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5020 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5021 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5022 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005023 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005024 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5025 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5026 lpfc_max_luns_init(vport, lpfc_max_luns);
5027 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005028 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005029 return;
5030}