blob: bffd86f204dd72688c3b5a85fa768747a862c205 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
James Smart0d878412009-10-02 15:16:56 -040026#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070028#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050029
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
33#include <scsi/scsi_tcq.h>
34#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040035#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050036
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_version.h"
47#include "lpfc_compat.h"
48#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050049#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050050
James Smartc01f3202006-08-18 17:47:08 -040051#define LPFC_DEF_DEVLOSS_TMO 30
52#define LPFC_MIN_DEVLOSS_TMO 1
53#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050054
James Smarte59058c2008-08-24 21:49:00 -040055/**
James Smart3621a712009-04-06 18:47:14 -040056 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040057 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
dea31012005-04-17 16:05:31 -050070static void
71lpfc_jedec_to_ascii(int incr, char hdw[])
72{
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84}
85
James Smarte59058c2008-08-24 21:49:00 -040086/**
James Smart3621a712009-04-06 18:47:14 -040087 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040088 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
dea31012005-04-17 16:05:31 -050094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010095lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
dea31012005-04-17 16:05:31 -050097{
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99}
100
James Smart45ed1192009-10-02 15:17:02 -0400101/**
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
106 *
107 * Returns: size of formatted string.
108 **/
109static ssize_t
110lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
111 char *buf)
112{
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
116
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
119 else
120 return snprintf(buf, PAGE_SIZE, "0\n");
121}
122
James Smart81301a92008-12-04 22:39:46 -0500123static ssize_t
124lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
126{
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
134 else
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
140}
141
142static ssize_t
143lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
149
James Smart87b5c322008-12-16 10:34:09 -0500150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500152}
153
154static ssize_t
155lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
156 char *buf)
157{
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
161
James Smart87b5c322008-12-16 10:34:09 -0500162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500164}
165
166static ssize_t
167lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
169{
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173
James Smart87b5c322008-12-16 10:34:09 -0500174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500176}
177
James Smarte59058c2008-08-24 21:49:00 -0400178/**
James Smart3621a712009-04-06 18:47:14 -0400179 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
183 *
184 * Returns: size of formatted string.
185 **/
dea31012005-04-17 16:05:31 -0500186static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100187lpfc_info_show(struct device *dev, struct device_attribute *attr,
188 char *buf)
dea31012005-04-17 16:05:31 -0500189{
Tony Jonesee959b02008-02-22 00:13:36 +0100190 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500191
dea31012005-04-17 16:05:31 -0500192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
193}
194
James Smarte59058c2008-08-24 21:49:00 -0400195/**
James Smart3621a712009-04-06 18:47:14 -0400196 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
200 *
201 * Returns: size of formatted string.
202 **/
dea31012005-04-17 16:05:31 -0500203static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100204lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
dea31012005-04-17 16:05:31 -0500206{
Tony Jonesee959b02008-02-22 00:13:36 +0100207 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
210
dea31012005-04-17 16:05:31 -0500211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
212}
213
James Smarte59058c2008-08-24 21:49:00 -0400214/**
James Smart3621a712009-04-06 18:47:14 -0400215 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
219 *
220 * Description:
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
223 *
224 * Returns: size of formatted string.
225 **/
dea31012005-04-17 16:05:31 -0500226static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100227lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
228 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400229{
Tony Jonesee959b02008-02-22 00:13:36 +0100230 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
234}
235
James Smarte59058c2008-08-24 21:49:00 -0400236/**
James Smart3621a712009-04-06 18:47:14 -0400237 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
241 *
242 * Returns: size of formatted string.
243 **/
James Smart57127f12007-10-27 13:37:05 -0400244static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100245lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
dea31012005-04-17 16:05:31 -0500247{
Tony Jonesee959b02008-02-22 00:13:36 +0100248 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
251
dea31012005-04-17 16:05:31 -0500252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
253}
254
James Smarte59058c2008-08-24 21:49:00 -0400255/**
James Smart3621a712009-04-06 18:47:14 -0400256 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
260 *
261 * Returns: size of formatted string.
262 **/
dea31012005-04-17 16:05:31 -0500263static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100264lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
265 char *buf)
dea31012005-04-17 16:05:31 -0500266{
Tony Jonesee959b02008-02-22 00:13:36 +0100267 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
270
dea31012005-04-17 16:05:31 -0500271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
272}
273
James Smarte59058c2008-08-24 21:49:00 -0400274/**
James Smart3621a712009-04-06 18:47:14 -0400275 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
279 *
280 * Returns: size of formatted string.
281 **/
dea31012005-04-17 16:05:31 -0500282static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100283lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
dea31012005-04-17 16:05:31 -0500285{
Tony Jonesee959b02008-02-22 00:13:36 +0100286 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
289
dea31012005-04-17 16:05:31 -0500290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
291}
292
James Smarte59058c2008-08-24 21:49:00 -0400293/**
James Smart3621a712009-04-06 18:47:14 -0400294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
298 *
299 * Returns: size of formatted string.
300 **/
301static ssize_t
302lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
303{
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
307
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
310}
311
312/**
James Smart3621a712009-04-06 18:47:14 -0400313 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
317 *
318 * Returns: size of formatted string.
319 **/
dea31012005-04-17 16:05:31 -0500320static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100321lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
322 char *buf)
dea31012005-04-17 16:05:31 -0500323{
Tony Jonesee959b02008-02-22 00:13:36 +0100324 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
327
dea31012005-04-17 16:05:31 -0500328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
329}
330
James Smarte59058c2008-08-24 21:49:00 -0400331/**
James Smart3621a712009-04-06 18:47:14 -0400332 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
336 *
337 * Returns: size of formatted string.
338 **/
dea31012005-04-17 16:05:31 -0500339static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100340lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
341 char *buf)
dea31012005-04-17 16:05:31 -0500342{
Tony Jonesee959b02008-02-22 00:13:36 +0100343 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500346 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500347
dea31012005-04-17 16:05:31 -0500348 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500350}
351
James Smarte59058c2008-08-24 21:49:00 -0400352/**
James Smart3621a712009-04-06 18:47:14 -0400353 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
357 *
358 * Returns: size of formatted string.
359 **/
dea31012005-04-17 16:05:31 -0500360static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100361lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500362{
363 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100364 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500367 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500368
dea31012005-04-17 16:05:31 -0500369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
371}
James Smarte59058c2008-08-24 21:49:00 -0400372
373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
dea31012005-04-17 16:05:31 -0500384{
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
dea31012005-04-17 16:05:31 -0500389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
390}
James Smarte59058c2008-08-24 21:49:00 -0400391
392/**
James Smart3621a712009-04-06 18:47:14 -0400393 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
397 *
398 * Notes:
399 * The switch statement has no default so zero will be returned.
400 *
401 * Returns: size of formatted string.
402 **/
dea31012005-04-17 16:05:31 -0500403static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100404lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
dea31012005-04-17 16:05:31 -0500406{
Tony Jonesee959b02008-02-22 00:13:36 +0100407 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
410 int len = 0;
411
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500414 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
417 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500418 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
422 else
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down\n");
dea31012005-04-17 16:05:31 -0500425 break;
426 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500427 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500428 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500430
431 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500434 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500435 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500436 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500437 case LPFC_FLOGI:
438 case LPFC_FABRIC_CFG_LINK:
439 case LPFC_NS_REG:
440 case LPFC_NS_QRY:
441 case LPFC_BUILD_DISC_LIST:
442 case LPFC_DISC_AUTH:
443 len += snprintf(buf + len, PAGE_SIZE - len,
444 "Discovery\n");
445 break;
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
448 break;
449
James Smart92d7f7b2007-06-17 19:56:38 -0500450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
452 break;
453
454 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500455 len += snprintf(buf + len, PAGE_SIZE - len,
456 "Unknown\n");
457 break;
458 }
James Smart84774a42008-08-24 21:50:06 -0400459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500463 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500464 len += snprintf(buf + len, PAGE_SIZE-len,
465 " Public Loop\n");
466 else
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Private Loop\n");
469 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500470 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Fabric\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Point-2-Point\n");
476 }
477 }
James Smart2e0fef82007-06-17 19:56:36 -0500478
dea31012005-04-17 16:05:31 -0500479 return len;
480}
481
James Smarte59058c2008-08-24 21:49:00 -0400482/**
James Smart84d1b002010-02-12 14:42:33 -0500483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
487 * @count: not used.
488 *
489 * Returns:
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
493 **/
494static ssize_t
495lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
497{
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
501
502 int status = -EINVAL;
503
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500510
511 if (status == 0)
512 return strlen(buf);
513 else
514 return status;
515}
516
517/**
James Smart3621a712009-04-06 18:47:14 -0400518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
522 *
523 * Description:
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
525 * vport counts.
526 *
527 * Returns: size of formatted string.
528 **/
dea31012005-04-17 16:05:31 -0500529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100530lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500532{
Tony Jonesee959b02008-02-22 00:13:36 +0100533 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500538}
539
James Smarte59058c2008-08-24 21:49:00 -0400540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400542 * @shost: Scsi_Host pointer.
543 *
544 * Description:
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
547 *
548 * Returns:
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
552 * zero for success
553 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700554static int
James Smart2e0fef82007-06-17 19:56:36 -0500555lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500556{
James Smart2e0fef82007-06-17 19:56:36 -0500557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
561
James Smart2e0fef82007-06-17 19:56:36 -0500562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500564 return -EPERM;
565
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
567
568 if (!pmboxq)
569 return -ENOMEM;
570
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400574
James Smart33ccf8d2006-08-17 11:57:58 -0400575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500576
James Smart04c68492009-05-22 14:52:52 -0400577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
584 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400590 }
591
James Smart5b8bd0c2007-04-25 09:52:49 -0400592 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500593 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400594 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500595
596 if (mbxstatus == MBXERR_ERROR)
597 return -EIO;
598
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700599 return 0;
dea31012005-04-17 16:05:31 -0500600}
601
James Smarte59058c2008-08-24 21:49:00 -0400602/**
James Smart3621a712009-04-06 18:47:14 -0400603 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
606 *
607 * Notes:
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400612 *
613 * Returns:
614 * -EIO error posting the event
615 * zero for success
616 **/
James Smart40496f02006-07-06 15:50:22 -0400617static int
James Smart46fa3112007-04-25 09:51:45 -0400618lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
619{
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
623 int status = 0;
624 int cnt = 0;
625 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500626 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400627
628 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400630 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500631 if (rc == 0)
632 return -ENOMEM;
633
James Smart46fa3112007-04-25 09:51:45 -0400634 wait_for_completion(&online_compl);
635
636 if (status != 0)
637 return -EIO;
638
639 psli = &phba->sli;
640
James Smart09372822008-01-11 01:52:54 -0500641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
643 */
James Smart46fa3112007-04-25 09:51:45 -0400644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400646 while (pring->txcmplq_cnt) {
647 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500648 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400653 break;
654 }
655 }
656 }
657
658 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
662
James Smart46fa3112007-04-25 09:51:45 -0400663 wait_for_completion(&online_compl);
664
665 if (status != 0)
666 return -EIO;
667
668 return 0;
669}
670
James Smarte59058c2008-08-24 21:49:00 -0400671/**
James Smart3621a712009-04-06 18:47:14 -0400672 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400673 * @phba: lpfc_hba pointer.
674 *
675 * Description:
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
678 *
679 * Notes:
680 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500681 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400682 *
683 * Returns:
684 * lpfc_do_offline() return code if not zero
685 * -EIO reset not configured or error posting the event
686 * zero for success
687 **/
James Smart7f860592011-03-11 16:05:52 -0500688int
James Smart40496f02006-07-06 15:50:22 -0400689lpfc_selective_reset(struct lpfc_hba *phba)
690{
691 struct completion online_compl;
692 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500693 int rc;
James Smart40496f02006-07-06 15:50:22 -0400694
James Smart13815c82008-01-11 01:52:48 -0500695 if (!phba->cfg_enable_hba_reset)
696 return -EIO;
697
James Smart46fa3112007-04-25 09:51:45 -0400698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400699
700 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400701 return status;
James Smart40496f02006-07-06 15:50:22 -0400702
703 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400705 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500706 if (rc == 0)
707 return -ENOMEM;
708
James Smart40496f02006-07-06 15:50:22 -0400709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 return 0;
715}
716
James Smarte59058c2008-08-24 21:49:00 -0400717/**
James Smart3621a712009-04-06 18:47:14 -0400718 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400719 * @dev: class device that is converted into a Scsi_host.
720 * @attr: device attribute, not used.
721 * @buf: containing the string "selective".
722 * @count: unused variable.
723 *
724 * Description:
725 * If the buf contains the string "selective" then lpfc_selective_reset()
726 * is called to perform the reset.
727 *
728 * Notes:
729 * Assumes any error from lpfc_selective_reset() will be negative.
730 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200731 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400732 *
733 * Returns:
734 * -EINVAL if the buffer does not contain the string "selective"
735 * length of buf if lpfc-selective_reset() if the call succeeds
736 * return value of lpfc_selective_reset() if the call fails
737**/
James Smart40496f02006-07-06 15:50:22 -0400738static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100739lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
740 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400741{
Tony Jonesee959b02008-02-22 00:13:36 +0100742 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
744 struct lpfc_hba *phba = vport->phba;
745
James Smart40496f02006-07-06 15:50:22 -0400746 int status = -EINVAL;
747
748 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500749 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400750
751 if (status == 0)
752 return strlen(buf);
753 else
754 return status;
755}
756
James Smarte59058c2008-08-24 21:49:00 -0400757/**
James Smart88a2cfb2011-07-22 18:36:33 -0400758 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
759 * @phba: lpfc_hba pointer.
760 *
761 * Description:
762 * SLI4 interface type-2 device to wait on the sliport status register for
763 * the readyness after performing a firmware reset.
764 *
765 * Returns:
766 * zero for success
767 **/
768static int
769lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
770{
771 struct lpfc_register portstat_reg;
772 int i;
773
774
775 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
776 &portstat_reg.word0);
777
778 /* wait for the SLI port firmware ready after firmware reset */
779 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
780 msleep(10);
781 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
782 &portstat_reg.word0);
783 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
784 continue;
785 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
786 continue;
787 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
788 continue;
789 break;
790 }
791
792 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
793 return 0;
794 else
795 return -EIO;
796}
797
798/**
James Smart52d52442011-05-24 11:42:45 -0400799 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400800 * @phba: lpfc_hba pointer.
801 *
802 * Description:
James Smart52d52442011-05-24 11:42:45 -0400803 * Request SLI4 interface type-2 device to perform a physical register set
804 * access.
James Smartc0c11512011-05-24 11:41:34 -0400805 *
806 * Returns:
807 * zero for success
808 **/
809static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400810lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400811{
812 struct completion online_compl;
813 uint32_t reg_val;
814 int status = 0;
815 int rc;
816
817 if (!phba->cfg_enable_hba_reset)
818 return -EIO;
819
James Smart52d52442011-05-24 11:42:45 -0400820 if ((phba->sli_rev < LPFC_SLI_REV4) ||
821 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
822 LPFC_SLI_INTF_IF_TYPE_2))
823 return -EPERM;
824
James Smartc0c11512011-05-24 11:41:34 -0400825 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
826
827 if (status != 0)
828 return status;
829
830 /* wait for the device to be quiesced before firmware reset */
831 msleep(100);
832
833 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
834 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400835
836 if (opcode == LPFC_FW_DUMP)
837 reg_val |= LPFC_FW_DUMP_REQUEST;
838 else if (opcode == LPFC_FW_RESET)
839 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
840 else if (opcode == LPFC_DV_RESET)
841 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
842
James Smartc0c11512011-05-24 11:41:34 -0400843 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
844 LPFC_CTL_PDEV_CTL_OFFSET);
845 /* flush */
846 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
847
848 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400849 rc = lpfc_sli4_pdev_status_reg_wait(phba);
850
851 if (rc)
852 return -EIO;
James Smartc0c11512011-05-24 11:41:34 -0400853
854 init_completion(&online_compl);
855 rc = lpfc_workq_post_event(phba, &status, &online_compl,
856 LPFC_EVT_ONLINE);
857 if (rc == 0)
858 return -ENOMEM;
859
860 wait_for_completion(&online_compl);
861
862 if (status != 0)
863 return -EIO;
864
865 return 0;
866}
867
868/**
James Smart3621a712009-04-06 18:47:14 -0400869 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400870 * @dev: class device that is converted into a Scsi_host.
871 * @attr: device attribute, not used.
872 * @buf: on return contains the ascii number of nport events.
873 *
874 * Returns: size of formatted string.
875 **/
dea31012005-04-17 16:05:31 -0500876static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100877lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
878 char *buf)
dea31012005-04-17 16:05:31 -0500879{
Tony Jonesee959b02008-02-22 00:13:36 +0100880 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
882 struct lpfc_hba *phba = vport->phba;
883
dea31012005-04-17 16:05:31 -0500884 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
885}
886
James Smarte59058c2008-08-24 21:49:00 -0400887/**
James Smart3621a712009-04-06 18:47:14 -0400888 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400889 * @dev: class device that is converted into a Scsi_host.
890 * @attr: device attribute, not used.
891 * @buf: on return contains the state of the adapter.
892 *
893 * Returns: size of formatted string.
894 **/
dea31012005-04-17 16:05:31 -0500895static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100896lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
897 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500898{
Tony Jonesee959b02008-02-22 00:13:36 +0100899 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500900 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
901 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500902 char * state;
903
James Smart2e0fef82007-06-17 19:56:36 -0500904 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500905 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500906 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500907 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500908 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500909 state = "offline";
910 else
911 state = "online";
912
913 return snprintf(buf, PAGE_SIZE, "%s\n", state);
914}
915
James Smarte59058c2008-08-24 21:49:00 -0400916/**
James Smart3621a712009-04-06 18:47:14 -0400917 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400918 * @dev: class device that is converted into a Scsi_host.
919 * @attr: device attribute, not used.
920 * @buf: containing one of the strings "online", "offline", "warm" or "error".
921 * @count: unused variable.
922 *
923 * Returns:
924 * -EACCES if enable hba reset not enabled
925 * -EINVAL if the buffer does not contain a valid string (see above)
926 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
927 * buf length greater than zero indicates success
928 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500929static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100930lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
931 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500932{
Tony Jonesee959b02008-02-22 00:13:36 +0100933 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500934 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
935 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500936 struct completion online_compl;
937 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500938 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500939
James Smart13815c82008-01-11 01:52:48 -0500940 if (!phba->cfg_enable_hba_reset)
941 return -EACCES;
James Smart88a2cfb2011-07-22 18:36:33 -0400942
943 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
944 "3050 lpfc_board_mode set to %s\n", buf);
945
Jamie Wellnitz41415862006-02-28 19:25:27 -0500946 init_completion(&online_compl);
947
James Smart46fa3112007-04-25 09:51:45 -0400948 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500949 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500950 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500951 if (rc == 0)
952 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400953 wait_for_completion(&online_compl);
954 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
955 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500956 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400957 if (phba->sli_rev == LPFC_SLI_REV4)
958 return -EINVAL;
959 else
960 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400961 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400962 if (phba->sli_rev == LPFC_SLI_REV4)
963 return -EINVAL;
964 else
965 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -0400966 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -0400967 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
968 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
969 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
970 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
971 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500972 else
973 return -EINVAL;
974
Jamie Wellnitz41415862006-02-28 19:25:27 -0500975 if (!status)
976 return strlen(buf);
977 else
978 return -EIO;
979}
980
James Smarte59058c2008-08-24 21:49:00 -0400981/**
James Smart3621a712009-04-06 18:47:14 -0400982 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400983 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400984 * @mxri: max xri count.
985 * @axri: available xri count.
986 * @mrpi: max rpi count.
987 * @arpi: available rpi count.
988 * @mvpi: max vpi count.
989 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400990 *
991 * Description:
992 * If an integer pointer for an count is not null then the value for the
993 * count is returned.
994 *
995 * Returns:
996 * zero on error
997 * one for success
998 **/
James Smart311464e2007-08-02 11:10:37 -0400999static int
James Smart858c9f62007-06-17 19:56:39 -05001000lpfc_get_hba_info(struct lpfc_hba *phba,
1001 uint32_t *mxri, uint32_t *axri,
1002 uint32_t *mrpi, uint32_t *arpi,
1003 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001004{
James Smart04c68492009-05-22 14:52:52 -04001005 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001006 LPFC_MBOXQ_t *pmboxq;
1007 MAILBOX_t *pmb;
1008 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001009 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001010
1011 /*
1012 * prevent udev from issuing mailbox commands until the port is
1013 * configured.
1014 */
1015 if (phba->link_state < LPFC_LINK_DOWN ||
1016 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001017 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001018 return 0;
1019
1020 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1021 return 0;
1022
1023 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1024 if (!pmboxq)
1025 return 0;
1026 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1027
James Smart04c68492009-05-22 14:52:52 -04001028 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001029 pmb->mbxCommand = MBX_READ_CONFIG;
1030 pmb->mbxOwner = OWN_HOST;
1031 pmboxq->context1 = NULL;
1032
James Smart75baf692010-06-08 18:31:21 -04001033 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001034 rc = MBX_NOT_FINISHED;
1035 else
1036 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1037
1038 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001039 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001040 mempool_free(pmboxq, phba->mbox_mem_pool);
1041 return 0;
1042 }
1043
James Smartda0436e2009-05-22 14:51:39 -04001044 if (phba->sli_rev == LPFC_SLI_REV4) {
1045 rd_config = &pmboxq->u.mqe.un.rd_config;
1046 if (mrpi)
1047 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1048 if (arpi)
1049 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1050 phba->sli4_hba.max_cfg_param.rpi_used;
1051 if (mxri)
1052 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1053 if (axri)
1054 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1055 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001056
1057 /* Account for differences with SLI-3. Get vpi count from
1058 * mailbox data and subtract one for max vpi value.
1059 */
1060 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1061 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1062
James Smartda0436e2009-05-22 14:51:39 -04001063 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001064 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001065 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001066 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001067 } else {
1068 if (mrpi)
1069 *mrpi = pmb->un.varRdConfig.max_rpi;
1070 if (arpi)
1071 *arpi = pmb->un.varRdConfig.avail_rpi;
1072 if (mxri)
1073 *mxri = pmb->un.varRdConfig.max_xri;
1074 if (axri)
1075 *axri = pmb->un.varRdConfig.avail_xri;
1076 if (mvpi)
1077 *mvpi = pmb->un.varRdConfig.max_vpi;
1078 if (avpi)
1079 *avpi = pmb->un.varRdConfig.avail_vpi;
1080 }
James Smart92d7f7b2007-06-17 19:56:38 -05001081
1082 mempool_free(pmboxq, phba->mbox_mem_pool);
1083 return 1;
1084}
1085
James Smarte59058c2008-08-24 21:49:00 -04001086/**
James Smart3621a712009-04-06 18:47:14 -04001087 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001088 * @dev: class device that is converted into a Scsi_host.
1089 * @attr: device attribute, not used.
1090 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1091 *
1092 * Description:
1093 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1094 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1095 * to "Unknown" and the buffer length is returned, therefore the caller
1096 * must check for "Unknown" in the buffer to detect a failure.
1097 *
1098 * Returns: size of formatted string.
1099 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001100static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001101lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1102 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001103{
Tony Jonesee959b02008-02-22 00:13:36 +01001104 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001105 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1106 struct lpfc_hba *phba = vport->phba;
1107 uint32_t cnt;
1108
James Smart858c9f62007-06-17 19:56:39 -05001109 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001110 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1111 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1112}
1113
James Smarte59058c2008-08-24 21:49:00 -04001114/**
James Smart3621a712009-04-06 18:47:14 -04001115 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001116 * @dev: class device that is converted into a Scsi_host.
1117 * @attr: device attribute, not used.
1118 * @buf: containing the used rpi count in decimal or "Unknown".
1119 *
1120 * Description:
1121 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1122 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1123 * to "Unknown" and the buffer length is returned, therefore the caller
1124 * must check for "Unknown" in the buffer to detect a failure.
1125 *
1126 * Returns: size of formatted string.
1127 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001128static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001129lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1130 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001131{
Tony Jonesee959b02008-02-22 00:13:36 +01001132 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1134 struct lpfc_hba *phba = vport->phba;
1135 uint32_t cnt, acnt;
1136
James Smart858c9f62007-06-17 19:56:39 -05001137 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001138 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1139 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1140}
1141
James Smarte59058c2008-08-24 21:49:00 -04001142/**
James Smart3621a712009-04-06 18:47:14 -04001143 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001144 * @dev: class device that is converted into a Scsi_host.
1145 * @attr: device attribute, not used.
1146 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1147 *
1148 * Description:
1149 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1150 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1151 * to "Unknown" and the buffer length is returned, therefore the caller
1152 * must check for "Unknown" in the buffer to detect a failure.
1153 *
1154 * Returns: size of formatted string.
1155 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001156static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001157lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1158 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001159{
Tony Jonesee959b02008-02-22 00:13:36 +01001160 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1162 struct lpfc_hba *phba = vport->phba;
1163 uint32_t cnt;
1164
James Smart858c9f62007-06-17 19:56:39 -05001165 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001166 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1167 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1168}
1169
James Smarte59058c2008-08-24 21:49:00 -04001170/**
James Smart3621a712009-04-06 18:47:14 -04001171 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001172 * @dev: class device that is converted into a Scsi_host.
1173 * @attr: device attribute, not used.
1174 * @buf: on return contains the used xri count in decimal or "Unknown".
1175 *
1176 * Description:
1177 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1178 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1179 * to "Unknown" and the buffer length is returned, therefore the caller
1180 * must check for "Unknown" in the buffer to detect a failure.
1181 *
1182 * Returns: size of formatted string.
1183 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001184static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001185lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1186 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001187{
Tony Jonesee959b02008-02-22 00:13:36 +01001188 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001189 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1190 struct lpfc_hba *phba = vport->phba;
1191 uint32_t cnt, acnt;
1192
James Smart858c9f62007-06-17 19:56:39 -05001193 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1194 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1195 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1196}
1197
James Smarte59058c2008-08-24 21:49:00 -04001198/**
James Smart3621a712009-04-06 18:47:14 -04001199 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001200 * @dev: class device that is converted into a Scsi_host.
1201 * @attr: device attribute, not used.
1202 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1203 *
1204 * Description:
1205 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1206 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1207 * to "Unknown" and the buffer length is returned, therefore the caller
1208 * must check for "Unknown" in the buffer to detect a failure.
1209 *
1210 * Returns: size of formatted string.
1211 **/
James Smart858c9f62007-06-17 19:56:39 -05001212static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001213lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1214 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001215{
Tony Jonesee959b02008-02-22 00:13:36 +01001216 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001217 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1218 struct lpfc_hba *phba = vport->phba;
1219 uint32_t cnt;
1220
1221 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1222 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1223 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1224}
1225
James Smarte59058c2008-08-24 21:49:00 -04001226/**
James Smart3621a712009-04-06 18:47:14 -04001227 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001228 * @dev: class device that is converted into a Scsi_host.
1229 * @attr: device attribute, not used.
1230 * @buf: on return contains the used vpi count in decimal or "Unknown".
1231 *
1232 * Description:
1233 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1234 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1235 * to "Unknown" and the buffer length is returned, therefore the caller
1236 * must check for "Unknown" in the buffer to detect a failure.
1237 *
1238 * Returns: size of formatted string.
1239 **/
James Smart858c9f62007-06-17 19:56:39 -05001240static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001241lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1242 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001243{
Tony Jonesee959b02008-02-22 00:13:36 +01001244 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1246 struct lpfc_hba *phba = vport->phba;
1247 uint32_t cnt, acnt;
1248
1249 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001250 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1251 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1252}
1253
James Smarte59058c2008-08-24 21:49:00 -04001254/**
James Smart3621a712009-04-06 18:47:14 -04001255 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001256 * @dev: class device that is converted into a Scsi_host.
1257 * @attr: device attribute, not used.
1258 * @buf: text that must be interpreted to determine if npiv is supported.
1259 *
1260 * Description:
1261 * Buffer will contain text indicating npiv is not suppoerted on the port,
1262 * the port is an NPIV physical port, or it is an npiv virtual port with
1263 * the id of the vport.
1264 *
1265 * Returns: size of formatted string.
1266 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001267static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001268lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1269 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001270{
Tony Jonesee959b02008-02-22 00:13:36 +01001271 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1273 struct lpfc_hba *phba = vport->phba;
1274
1275 if (!(phba->max_vpi))
1276 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1277 if (vport->port_type == LPFC_PHYSICAL_PORT)
1278 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1279 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1280}
1281
James Smarte59058c2008-08-24 21:49:00 -04001282/**
James Smart3621a712009-04-06 18:47:14 -04001283 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001284 * @dev: class device that is converted into a Scsi_host.
1285 * @attr: device attribute, not used.
1286 * @buf: on return contains the cfg_poll in hex.
1287 *
1288 * Notes:
1289 * cfg_poll should be a lpfc_polling_flags type.
1290 *
1291 * Returns: size of formatted string.
1292 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001293static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001294lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1295 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001296{
Tony Jonesee959b02008-02-22 00:13:36 +01001297 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001298 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1299 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001300
1301 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1302}
1303
James Smarte59058c2008-08-24 21:49:00 -04001304/**
James Smart3621a712009-04-06 18:47:14 -04001305 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001306 * @dev: class device that is converted into a Scsi_host.
1307 * @attr: device attribute, not used.
1308 * @buf: one or more lpfc_polling_flags values.
1309 * @count: not used.
1310 *
1311 * Notes:
1312 * buf contents converted to integer and checked for a valid value.
1313 *
1314 * Returns:
1315 * -EINVAL if the buffer connot be converted or is out of range
1316 * length of the buf on success
1317 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001318static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001319lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1320 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001321{
Tony Jonesee959b02008-02-22 00:13:36 +01001322 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1324 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001325 uint32_t creg_val;
1326 uint32_t old_val;
1327 int val=0;
1328
1329 if (!isdigit(buf[0]))
1330 return -EINVAL;
1331
1332 if (sscanf(buf, "%i", &val) != 1)
1333 return -EINVAL;
1334
1335 if ((val & 0x3) != val)
1336 return -EINVAL;
1337
James Smart45ed1192009-10-02 15:17:02 -04001338 if (phba->sli_rev == LPFC_SLI_REV4)
1339 val = 0;
1340
James Smart88a2cfb2011-07-22 18:36:33 -04001341 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1342 "3051 lpfc_poll changed from %d to %d\n",
1343 phba->cfg_poll, val);
1344
James Smart2e0fef82007-06-17 19:56:36 -05001345 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001346
1347 old_val = phba->cfg_poll;
1348
1349 if (val & ENABLE_FCP_RING_POLLING) {
1350 if ((val & DISABLE_FCP_RING_INT) &&
1351 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001352 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1353 spin_unlock_irq(&phba->hbalock);
1354 return -EINVAL;
1355 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001356 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1357 writel(creg_val, phba->HCregaddr);
1358 readl(phba->HCregaddr); /* flush */
1359
1360 lpfc_poll_start_timer(phba);
1361 }
1362 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001363 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001364 return -EINVAL;
1365 }
1366
1367 if (!(val & DISABLE_FCP_RING_INT) &&
1368 (old_val & DISABLE_FCP_RING_INT))
1369 {
James Smart2e0fef82007-06-17 19:56:36 -05001370 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001371 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001372 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001373 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1374 spin_unlock_irq(&phba->hbalock);
1375 return -EINVAL;
1376 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001377 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1378 writel(creg_val, phba->HCregaddr);
1379 readl(phba->HCregaddr); /* flush */
1380 }
1381
1382 phba->cfg_poll = val;
1383
James Smart2e0fef82007-06-17 19:56:36 -05001384 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001385
1386 return strlen(buf);
1387}
dea31012005-04-17 16:05:31 -05001388
James Smarte59058c2008-08-24 21:49:00 -04001389/**
James Smartbc739052010-08-04 16:11:18 -04001390 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1391 * @dev: class unused variable.
1392 * @attr: device attribute, not used.
1393 * @buf: on return contains the module description text.
1394 *
1395 * Returns: size of formatted string.
1396 **/
1397static ssize_t
1398lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1399 char *buf)
1400{
1401 struct Scsi_Host *shost = class_to_shost(dev);
1402 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1403 struct lpfc_hba *phba = vport->phba;
1404
1405 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1406}
1407
1408/**
1409 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1410 * @dev: class unused variable.
1411 * @attr: device attribute, not used.
1412 * @buf: on return contains the module description text.
1413 *
1414 * Returns: size of formatted string.
1415 **/
1416static ssize_t
1417lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1418 char *buf)
1419{
1420 struct Scsi_Host *shost = class_to_shost(dev);
1421 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1422 struct lpfc_hba *phba = vport->phba;
1423
1424 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1425}
1426
1427/**
James Smartab56dc22011-02-16 12:39:57 -05001428 * lpfc_dss_show - Return the current state of dss and the configured state
1429 * @dev: class converted to a Scsi_host structure.
1430 * @attr: device attribute, not used.
1431 * @buf: on return contains the formatted text.
1432 *
1433 * Returns: size of formatted string.
1434 **/
1435static ssize_t
1436lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1437 char *buf)
1438{
1439 struct Scsi_Host *shost = class_to_shost(dev);
1440 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1441 struct lpfc_hba *phba = vport->phba;
1442
1443 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1444 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1445 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1446 "" : "Not ");
1447}
1448
1449/**
James Smart912e3ac2011-05-24 11:42:11 -04001450 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1451 * @dev: class converted to a Scsi_host structure.
1452 * @attr: device attribute, not used.
1453 * @buf: on return contains the formatted support level.
1454 *
1455 * Description:
1456 * Returns the maximum number of virtual functions a physical function can
1457 * support, 0 will be returned if called on virtual function.
1458 *
1459 * Returns: size of formatted string.
1460 **/
1461static ssize_t
1462lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1463 struct device_attribute *attr,
1464 char *buf)
1465{
1466 struct Scsi_Host *shost = class_to_shost(dev);
1467 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1468 struct lpfc_hba *phba = vport->phba;
1469 struct pci_dev *pdev = phba->pcidev;
1470 union lpfc_sli4_cfg_shdr *shdr;
1471 uint32_t shdr_status, shdr_add_status;
1472 LPFC_MBOXQ_t *mboxq;
1473 struct lpfc_mbx_get_prof_cfg *get_prof_cfg;
1474 struct lpfc_rsrc_desc_pcie *desc;
1475 uint32_t max_nr_virtfn;
1476 uint32_t desc_count;
1477 int length, rc, i;
1478
1479 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1480 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1481 LPFC_SLI_INTF_IF_TYPE_2))
1482 return -EPERM;
1483
1484 if (!pdev->is_physfn)
1485 return snprintf(buf, PAGE_SIZE, "%d\n", 0);
1486
1487 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1488 if (!mboxq)
1489 return -ENOMEM;
1490
1491 /* get the maximum number of virtfn support by physfn */
1492 length = (sizeof(struct lpfc_mbx_get_prof_cfg) -
1493 sizeof(struct lpfc_sli4_cfg_mhdr));
1494 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
1495 LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG,
1496 length, LPFC_SLI4_MBX_EMBED);
1497 shdr = (union lpfc_sli4_cfg_shdr *)
1498 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
1499 bf_set(lpfc_mbox_hdr_pf_num, &shdr->request,
1500 phba->sli4_hba.iov.pf_number + 1);
1501
1502 get_prof_cfg = &mboxq->u.mqe.un.get_prof_cfg;
1503 bf_set(lpfc_mbx_get_prof_cfg_prof_tp, &get_prof_cfg->u.request,
1504 LPFC_CFG_TYPE_CURRENT_ACTIVE);
1505
1506 rc = lpfc_sli_issue_mbox_wait(phba, mboxq,
1507 lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG));
1508
1509 if (rc != MBX_TIMEOUT) {
1510 /* check return status */
1511 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1512 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
1513 &shdr->response);
1514 if (shdr_status || shdr_add_status || rc)
1515 goto error_out;
1516
1517 } else
1518 goto error_out;
1519
1520 desc_count = get_prof_cfg->u.response.prof_cfg.rsrc_desc_count;
1521
1522 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
1523 desc = (struct lpfc_rsrc_desc_pcie *)
1524 &get_prof_cfg->u.response.prof_cfg.desc[i];
1525 if (LPFC_RSRC_DESC_TYPE_PCIE ==
1526 bf_get(lpfc_rsrc_desc_pcie_type, desc)) {
1527 max_nr_virtfn = bf_get(lpfc_rsrc_desc_pcie_nr_virtfn,
1528 desc);
1529 break;
1530 }
1531 }
1532
1533 if (i < LPFC_RSRC_DESC_MAX_NUM) {
1534 if (rc != MBX_TIMEOUT)
1535 mempool_free(mboxq, phba->mbox_mem_pool);
1536 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1537 }
1538
1539error_out:
1540 if (rc != MBX_TIMEOUT)
1541 mempool_free(mboxq, phba->mbox_mem_pool);
1542 return -EIO;
1543}
1544
1545/**
James Smart3621a712009-04-06 18:47:14 -04001546 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001547 *
1548 * Description:
1549 * Macro that given an attr e.g. hba_queue_depth expands
1550 * into a function with the name lpfc_hba_queue_depth_show.
1551 *
1552 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1553 * @dev: class device that is converted into a Scsi_host.
1554 * @attr: device attribute, not used.
1555 * @buf: on return contains the attribute value in decimal.
1556 *
1557 * Returns: size of formatted string.
1558 **/
dea31012005-04-17 16:05:31 -05001559#define lpfc_param_show(attr) \
1560static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001561lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1562 char *buf) \
dea31012005-04-17 16:05:31 -05001563{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001564 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1566 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001567 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001568 val = phba->cfg_##attr;\
1569 return snprintf(buf, PAGE_SIZE, "%d\n",\
1570 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001571}
1572
James Smarte59058c2008-08-24 21:49:00 -04001573/**
James Smart3621a712009-04-06 18:47:14 -04001574 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001575 *
1576 * Description:
1577 * Macro that given an attr e.g. hba_queue_depth expands
1578 * into a function with the name lpfc_hba_queue_depth_show
1579 *
1580 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1581 * @dev: class device that is converted into a Scsi_host.
1582 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001583 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001584 *
1585 * Returns: size of formatted string.
1586 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001587#define lpfc_param_hex_show(attr) \
1588static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001589lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1590 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001591{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001592 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001593 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1594 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001595 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001596 val = phba->cfg_##attr;\
1597 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1598 phba->cfg_##attr);\
1599}
1600
James Smarte59058c2008-08-24 21:49:00 -04001601/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001602 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001603 *
1604 * Description:
1605 * Macro that given an attr e.g. hba_queue_depth expands
1606 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1607 * takes a default argument, a minimum and maximum argument.
1608 *
1609 * lpfc_##attr##_init: Initializes an attribute.
1610 * @phba: pointer the the adapter structure.
1611 * @val: integer attribute value.
1612 *
1613 * Validates the min and max values then sets the adapter config field
1614 * accordingly, or uses the default if out of range and prints an error message.
1615 *
1616 * Returns:
1617 * zero on success
1618 * -EINVAL if default used
1619 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001620#define lpfc_param_init(attr, default, minval, maxval) \
1621static int \
James Smart84d1b002010-02-12 14:42:33 -05001622lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001623{ \
1624 if (val >= minval && val <= maxval) {\
1625 phba->cfg_##attr = val;\
1626 return 0;\
1627 }\
1628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001629 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1630 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001631 phba->cfg_##attr = default;\
1632 return -EINVAL;\
1633}
1634
James Smarte59058c2008-08-24 21:49:00 -04001635/**
James Smart3621a712009-04-06 18:47:14 -04001636 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001637 *
1638 * Description:
1639 * Macro that given an attr e.g. hba_queue_depth expands
1640 * into a function with the name lpfc_hba_queue_depth_set
1641 *
1642 * lpfc_##attr##_set: Sets an attribute value.
1643 * @phba: pointer the the adapter structure.
1644 * @val: integer attribute value.
1645 *
1646 * Description:
1647 * Validates the min and max values then sets the
1648 * adapter config field if in the valid range. prints error message
1649 * and does not set the parameter if invalid.
1650 *
1651 * Returns:
1652 * zero on success
1653 * -EINVAL if val is invalid
1654 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001655#define lpfc_param_set(attr, default, minval, maxval) \
1656static int \
James Smart84d1b002010-02-12 14:42:33 -05001657lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001658{ \
1659 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1661 "3052 lpfc_" #attr " changed from %d to %d\n", \
1662 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001663 phba->cfg_##attr = val;\
1664 return 0;\
1665 }\
1666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001667 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1668 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001669 return -EINVAL;\
1670}
1671
James Smarte59058c2008-08-24 21:49:00 -04001672/**
James Smart3621a712009-04-06 18:47:14 -04001673 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001674 *
1675 * Description:
1676 * Macro that given an attr e.g. hba_queue_depth expands
1677 * into a function with the name lpfc_hba_queue_depth_store.
1678 *
1679 * lpfc_##attr##_store: Set an sttribute value.
1680 * @dev: class device that is converted into a Scsi_host.
1681 * @attr: device attribute, not used.
1682 * @buf: contains the attribute value in ascii.
1683 * @count: not used.
1684 *
1685 * Description:
1686 * Convert the ascii text number to an integer, then
1687 * use the lpfc_##attr##_set function to set the value.
1688 *
1689 * Returns:
1690 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1691 * length of buffer upon success.
1692 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001693#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001694static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001695lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1696 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001697{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001698 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1700 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001701 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001702 if (!isdigit(buf[0]))\
1703 return -EINVAL;\
1704 if (sscanf(buf, "%i", &val) != 1)\
1705 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001706 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001707 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001708 else \
1709 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001710}
1711
James Smarte59058c2008-08-24 21:49:00 -04001712/**
James Smart3621a712009-04-06 18:47:14 -04001713 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001714 *
1715 * Description:
1716 * Macro that given an attr e.g. hba_queue_depth expands
1717 * into a function with the name lpfc_hba_queue_depth_show
1718 *
1719 * lpfc_##attr##_show: prints the attribute value in decimal.
1720 * @dev: class device that is converted into a Scsi_host.
1721 * @attr: device attribute, not used.
1722 * @buf: on return contains the attribute value in decimal.
1723 *
1724 * Returns: length of formatted string.
1725 **/
James Smart3de2a652007-08-02 11:09:59 -04001726#define lpfc_vport_param_show(attr) \
1727static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001728lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1729 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001730{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001731 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001733 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001734 val = vport->cfg_##attr;\
1735 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1736}
1737
James Smarte59058c2008-08-24 21:49:00 -04001738/**
James Smart3621a712009-04-06 18:47:14 -04001739 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001740 *
1741 * Description:
1742 * Macro that given an attr e.g.
1743 * hba_queue_depth expands into a function with the name
1744 * lpfc_hba_queue_depth_show
1745 *
James Smart3621a712009-04-06 18:47:14 -04001746 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001747 * @dev: class device that is converted into a Scsi_host.
1748 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001749 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001750 *
1751 * Returns: length of formatted string.
1752 **/
James Smart3de2a652007-08-02 11:09:59 -04001753#define lpfc_vport_param_hex_show(attr) \
1754static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001755lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1756 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001757{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001758 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001759 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001760 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001761 val = vport->cfg_##attr;\
1762 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1763}
1764
James Smarte59058c2008-08-24 21:49:00 -04001765/**
James Smart3621a712009-04-06 18:47:14 -04001766 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001767 *
1768 * Description:
1769 * Macro that given an attr e.g. hba_queue_depth expands
1770 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1771 * takes a default argument, a minimum and maximum argument.
1772 *
1773 * lpfc_##attr##_init: validates the min and max values then sets the
1774 * adapter config field accordingly, or uses the default if out of range
1775 * and prints an error message.
1776 * @phba: pointer the the adapter structure.
1777 * @val: integer attribute value.
1778 *
1779 * Returns:
1780 * zero on success
1781 * -EINVAL if default used
1782 **/
James Smart3de2a652007-08-02 11:09:59 -04001783#define lpfc_vport_param_init(attr, default, minval, maxval) \
1784static int \
James Smart84d1b002010-02-12 14:42:33 -05001785lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001786{ \
1787 if (val >= minval && val <= maxval) {\
1788 vport->cfg_##attr = val;\
1789 return 0;\
1790 }\
James Smarte8b62012007-08-02 11:10:09 -04001791 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001792 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001793 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001794 vport->cfg_##attr = default;\
1795 return -EINVAL;\
1796}
1797
James Smarte59058c2008-08-24 21:49:00 -04001798/**
James Smart3621a712009-04-06 18:47:14 -04001799 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001800 *
1801 * Description:
1802 * Macro that given an attr e.g. hba_queue_depth expands
1803 * into a function with the name lpfc_hba_queue_depth_set
1804 *
1805 * lpfc_##attr##_set: validates the min and max values then sets the
1806 * adapter config field if in the valid range. prints error message
1807 * and does not set the parameter if invalid.
1808 * @phba: pointer the the adapter structure.
1809 * @val: integer attribute value.
1810 *
1811 * Returns:
1812 * zero on success
1813 * -EINVAL if val is invalid
1814 **/
James Smart3de2a652007-08-02 11:09:59 -04001815#define lpfc_vport_param_set(attr, default, minval, maxval) \
1816static int \
James Smart84d1b002010-02-12 14:42:33 -05001817lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001818{ \
1819 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001820 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1821 "3053 lpfc_" #attr " changed from %d to %d\n", \
1822 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001823 vport->cfg_##attr = val;\
1824 return 0;\
1825 }\
James Smarte8b62012007-08-02 11:10:09 -04001826 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001827 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001828 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001829 return -EINVAL;\
1830}
1831
James Smarte59058c2008-08-24 21:49:00 -04001832/**
James Smart3621a712009-04-06 18:47:14 -04001833 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001834 *
1835 * Description:
1836 * Macro that given an attr e.g. hba_queue_depth
1837 * expands into a function with the name lpfc_hba_queue_depth_store
1838 *
1839 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1840 * use the lpfc_##attr##_set function to set the value.
1841 * @cdev: class device that is converted into a Scsi_host.
1842 * @buf: contains the attribute value in decimal.
1843 * @count: not used.
1844 *
1845 * Returns:
1846 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1847 * length of buffer upon success.
1848 **/
James Smart3de2a652007-08-02 11:09:59 -04001849#define lpfc_vport_param_store(attr) \
1850static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001851lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1852 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001853{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001854 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001855 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001856 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001857 if (!isdigit(buf[0]))\
1858 return -EINVAL;\
1859 if (sscanf(buf, "%i", &val) != 1)\
1860 return -EINVAL;\
1861 if (lpfc_##attr##_set(vport, val) == 0) \
1862 return strlen(buf);\
1863 else \
1864 return -EINVAL;\
1865}
1866
1867
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001868#define LPFC_ATTR(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);\
dea31012005-04-17 16:05:31 -05001871MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001872lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001873
1874#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001875static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001876module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001877MODULE_PARM_DESC(lpfc_##name, desc);\
1878lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001879lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001880static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001881
1882#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001883static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001884module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001885MODULE_PARM_DESC(lpfc_##name, desc);\
1886lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001887lpfc_param_init(name, defval, minval, maxval)\
1888lpfc_param_set(name, defval, minval, maxval)\
1889lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001890static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1891 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001892
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001893#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001894static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001895module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001896MODULE_PARM_DESC(lpfc_##name, desc);\
1897lpfc_param_hex_show(name)\
1898lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001899static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001900
1901#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001902static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001903module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001904MODULE_PARM_DESC(lpfc_##name, desc);\
1905lpfc_param_hex_show(name)\
1906lpfc_param_init(name, defval, minval, maxval)\
1907lpfc_param_set(name, defval, minval, maxval)\
1908lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001909static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1910 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001911
James Smart3de2a652007-08-02 11:09:59 -04001912#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001913static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001914module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001915MODULE_PARM_DESC(lpfc_##name, desc);\
1916lpfc_vport_param_init(name, defval, minval, maxval)
1917
1918#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001919static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001920module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001921MODULE_PARM_DESC(lpfc_##name, desc);\
1922lpfc_vport_param_show(name)\
1923lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001924static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001925
1926#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001927static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001928module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001929MODULE_PARM_DESC(lpfc_##name, desc);\
1930lpfc_vport_param_show(name)\
1931lpfc_vport_param_init(name, defval, minval, maxval)\
1932lpfc_vport_param_set(name, defval, minval, maxval)\
1933lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001934static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1935 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001936
1937#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001938static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001939module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001940MODULE_PARM_DESC(lpfc_##name, desc);\
1941lpfc_vport_param_hex_show(name)\
1942lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001943static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001944
1945#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001946static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001947module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001948MODULE_PARM_DESC(lpfc_##name, desc);\
1949lpfc_vport_param_hex_show(name)\
1950lpfc_vport_param_init(name, defval, minval, maxval)\
1951lpfc_vport_param_set(name, defval, minval, maxval)\
1952lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001953static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1954 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001955
James Smart81301a92008-12-04 22:39:46 -05001956static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1957static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1958static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1959static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001960static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1961static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1962static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1963static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1964static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1965static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1966static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1967static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001968static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1969 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001970static DEVICE_ATTR(option_rom_version, S_IRUGO,
1971 lpfc_option_rom_version_show, NULL);
1972static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1973 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001974static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001975static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1976static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001977static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001978static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1979 lpfc_board_mode_show, lpfc_board_mode_store);
1980static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1981static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1982static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1983static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1984static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1985static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1986static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1987static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1988static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001989static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1990static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001991static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001992static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1993 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001994
James Smarta12e07b2006-12-02 13:35:30 -05001995static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001996
James Smarte59058c2008-08-24 21:49:00 -04001997/**
James Smart3621a712009-04-06 18:47:14 -04001998 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001999 * @dev: class device that is converted into a Scsi_host.
2000 * @attr: device attribute, not used.
2001 * @buf: containing the string lpfc_soft_wwn_key.
2002 * @count: must be size of lpfc_soft_wwn_key.
2003 *
2004 * Returns:
2005 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2006 * length of buf indicates success
2007 **/
James Smartc3f28af2006-08-18 17:47:18 -04002008static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002009lpfc_soft_wwn_enable_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 unsigned int cnt = count;
2016
2017 /*
2018 * We're doing a simple sanity check for soft_wwpn setting.
2019 * We require that the user write a specific key to enable
2020 * the soft_wwpn attribute to be settable. Once the attribute
2021 * is written, the enable key resets. If further updates are
2022 * desired, the key must be written again to re-enable the
2023 * attribute.
2024 *
2025 * The "key" is not secret - it is a hardcoded string shown
2026 * here. The intent is to protect against the random user or
2027 * application that is just writing attributes.
2028 */
2029
2030 /* count may include a LF at end of string */
2031 if (buf[cnt-1] == '\n')
2032 cnt--;
2033
James Smarta12e07b2006-12-02 13:35:30 -05002034 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2035 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002036 return -EINVAL;
2037
James Smarta12e07b2006-12-02 13:35:30 -05002038 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002039 return count;
2040}
Tony Jonesee959b02008-02-22 00:13:36 +01002041static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2042 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002043
James Smarte59058c2008-08-24 21:49:00 -04002044/**
James Smart3621a712009-04-06 18:47:14 -04002045 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002046 * @dev: class device that is converted into a Scsi_host.
2047 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002048 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002049 *
2050 * Returns: size of formatted string.
2051 **/
James Smartc3f28af2006-08-18 17:47:18 -04002052static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002053lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2054 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002055{
Tony Jonesee959b02008-02-22 00:13:36 +01002056 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002057 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2058 struct lpfc_hba *phba = vport->phba;
2059
Randy Dunlapafc071e2006-10-23 21:47:13 -07002060 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2061 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002062}
2063
James Smarte59058c2008-08-24 21:49:00 -04002064/**
James Smart3621a712009-04-06 18:47:14 -04002065 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002066 * @dev class device that is converted into a Scsi_host.
2067 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002068 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002069 * @count: number of wwpn bytes in buf
2070 *
2071 * Returns:
2072 * -EACCES hba reset not enabled, adapter over temp
2073 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2074 * -EIO error taking adapter offline or online
2075 * value of count on success
2076 **/
James Smartc3f28af2006-08-18 17:47:18 -04002077static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002078lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2079 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002080{
Tony Jonesee959b02008-02-22 00:13:36 +01002081 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002082 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2083 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002084 struct completion online_compl;
2085 int stat1=0, stat2=0;
2086 unsigned int i, j, cnt=count;
2087 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002088 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002089
James Smart13815c82008-01-11 01:52:48 -05002090 if (!phba->cfg_enable_hba_reset)
2091 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002092 spin_lock_irq(&phba->hbalock);
2093 if (phba->over_temp_state == HBA_OVER_TEMP) {
2094 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002095 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002096 }
2097 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002098 /* count may include a LF at end of string */
2099 if (buf[cnt-1] == '\n')
2100 cnt--;
2101
James Smarta12e07b2006-12-02 13:35:30 -05002102 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002103 ((cnt == 17) && (*buf++ != 'x')) ||
2104 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2105 return -EINVAL;
2106
James Smarta12e07b2006-12-02 13:35:30 -05002107 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002108
2109 memset(wwpn, 0, sizeof(wwpn));
2110
2111 /* Validate and store the new name */
2112 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002113 int value;
2114
2115 value = hex_to_bin(*buf++);
2116 if (value >= 0)
2117 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002118 else
2119 return -EINVAL;
2120 if (i % 2) {
2121 wwpn[i/2] = j & 0xff;
2122 j = 0;
2123 }
2124 }
2125 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002126 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002127 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002128 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002129
2130 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2131 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2132
James Smart46fa3112007-04-25 09:51:45 -04002133 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002134 if (stat1)
2135 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002136 "0463 lpfc_soft_wwpn attribute set failed to "
2137 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002138 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002139 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2140 LPFC_EVT_ONLINE);
2141 if (rc == 0)
2142 return -ENOMEM;
2143
James Smartc3f28af2006-08-18 17:47:18 -04002144 wait_for_completion(&online_compl);
2145 if (stat2)
2146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002147 "0464 lpfc_soft_wwpn attribute set failed to "
2148 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002149 return (stat1 || stat2) ? -EIO : count;
2150}
Tony Jonesee959b02008-02-22 00:13:36 +01002151static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2152 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002153
James Smarte59058c2008-08-24 21:49:00 -04002154/**
James Smart3621a712009-04-06 18:47:14 -04002155 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002156 * @dev: class device that is converted into a Scsi_host.
2157 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002158 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002159 *
2160 * Returns: size of formatted string.
2161 **/
James Smarta12e07b2006-12-02 13:35:30 -05002162static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002163lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2164 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002165{
Tony Jonesee959b02008-02-22 00:13:36 +01002166 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002167 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002168 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2169 (unsigned long long)phba->cfg_soft_wwnn);
2170}
2171
James Smarte59058c2008-08-24 21:49:00 -04002172/**
James Smart3621a712009-04-06 18:47:14 -04002173 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002174 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002175 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002176 * @count: number of wwnn bytes in buf.
2177 *
2178 * Returns:
2179 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2180 * value of count on success
2181 **/
James Smarta12e07b2006-12-02 13:35:30 -05002182static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002183lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2184 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002185{
Tony Jonesee959b02008-02-22 00:13:36 +01002186 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002187 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002188 unsigned int i, j, cnt=count;
2189 u8 wwnn[8];
2190
2191 /* count may include a LF at end of string */
2192 if (buf[cnt-1] == '\n')
2193 cnt--;
2194
2195 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2196 ((cnt == 17) && (*buf++ != 'x')) ||
2197 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2198 return -EINVAL;
2199
2200 /*
2201 * Allow wwnn to be set many times, as long as the enable is set.
2202 * However, once the wwpn is set, everything locks.
2203 */
2204
2205 memset(wwnn, 0, sizeof(wwnn));
2206
2207 /* Validate and store the new name */
2208 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002209 int value;
2210
2211 value = hex_to_bin(*buf++);
2212 if (value >= 0)
2213 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002214 else
2215 return -EINVAL;
2216 if (i % 2) {
2217 wwnn[i/2] = j & 0xff;
2218 j = 0;
2219 }
2220 }
2221 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2222
2223 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2224 "lpfc%d: soft_wwnn set. Value will take effect upon "
2225 "setting of the soft_wwpn\n", phba->brd_no);
2226
2227 return count;
2228}
Tony Jonesee959b02008-02-22 00:13:36 +01002229static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2230 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002231
James Smartc3f28af2006-08-18 17:47:18 -04002232
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002233static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002234module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002235MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2236 " 0 - none,"
2237 " 1 - poll with interrupts enabled"
2238 " 3 - poll and disable FCP ring interrupts");
2239
Tony Jonesee959b02008-02-22 00:13:36 +01002240static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2241 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002242
James Smart92d7f7b2007-06-17 19:56:38 -05002243int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002244module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002245MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2246 " 0 - auto (SLI-3 if supported),"
2247 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2248 " 3 - select SLI-3");
2249
James Smart15672312010-04-06 14:49:03 -04002250int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002251module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002252MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2253lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002254lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002255static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002256
James Smart19ca7602010-11-20 23:11:55 -05002257int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002258module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002259MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2260lpfc_param_show(enable_rrq);
2261lpfc_param_init(enable_rrq, 0, 0, 1);
2262static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2263
dea31012005-04-17 16:05:31 -05002264/*
James Smart84d1b002010-02-12 14:42:33 -05002265# lpfc_suppress_link_up: Bring link up at initialization
2266# 0x0 = bring link up (issue MBX_INIT_LINK)
2267# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2268# 0x2 = never bring up link
2269# Default value is 0.
2270*/
James Smarte40a02c2010-02-26 14:13:54 -05002271LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2272 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2273 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002274/*
2275# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2276# 1 - (1024)
2277# 2 - (2048)
2278# 3 - (3072)
2279# 4 - (4096)
2280# 5 - (5120)
2281*/
2282static ssize_t
2283lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2284{
2285 struct Scsi_Host *shost = class_to_shost(dev);
2286 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2287
2288 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2289}
2290
2291static DEVICE_ATTR(iocb_hw, S_IRUGO,
2292 lpfc_iocb_hw_show, NULL);
2293static ssize_t
2294lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2295{
2296 struct Scsi_Host *shost = class_to_shost(dev);
2297 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2298
2299 return snprintf(buf, PAGE_SIZE, "%d\n",
2300 phba->sli.ring[LPFC_ELS_RING].txq_max);
2301}
2302
2303static DEVICE_ATTR(txq_hw, S_IRUGO,
2304 lpfc_txq_hw_show, NULL);
2305static ssize_t
2306lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2307 char *buf)
2308{
2309 struct Scsi_Host *shost = class_to_shost(dev);
2310 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2311
2312 return snprintf(buf, PAGE_SIZE, "%d\n",
2313 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2314}
2315
2316static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2317 lpfc_txcmplq_hw_show, NULL);
2318
2319int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002320module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002321MODULE_PARM_DESC(lpfc_iocb_cnt,
2322 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2323lpfc_param_show(iocb_cnt);
2324lpfc_param_init(iocb_cnt, 2, 1, 5);
2325static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2326 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002327
2328/*
James Smartc01f3202006-08-18 17:47:08 -04002329# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2330# until the timer expires. Value range is [0,255]. Default value is 30.
2331*/
2332static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2333static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2334module_param(lpfc_nodev_tmo, int, 0);
2335MODULE_PARM_DESC(lpfc_nodev_tmo,
2336 "Seconds driver will hold I/O waiting "
2337 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002338
2339/**
James Smart3621a712009-04-06 18:47:14 -04002340 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002341 * @dev: class converted to a Scsi_host structure.
2342 * @attr: device attribute, not used.
2343 * @buf: on return contains the dev loss timeout in decimal.
2344 *
2345 * Returns: size of formatted string.
2346 **/
James Smartc01f3202006-08-18 17:47:08 -04002347static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002348lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2349 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002350{
Tony Jonesee959b02008-02-22 00:13:36 +01002351 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002353
James Smart3de2a652007-08-02 11:09:59 -04002354 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002355}
2356
James Smarte59058c2008-08-24 21:49:00 -04002357/**
James Smart3621a712009-04-06 18:47:14 -04002358 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002359 * @vport: lpfc vport structure pointer.
2360 * @val: contains the nodev timeout value.
2361 *
2362 * Description:
2363 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2364 * a kernel error message is printed and zero is returned.
2365 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2366 * Otherwise nodev tmo is set to the default value.
2367 *
2368 * Returns:
2369 * zero if already set or if val is in range
2370 * -EINVAL val out of range
2371 **/
James Smartc01f3202006-08-18 17:47:08 -04002372static int
James Smart3de2a652007-08-02 11:09:59 -04002373lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002374{
James Smart3de2a652007-08-02 11:09:59 -04002375 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2376 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2377 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002378 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002379 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002380 "parameter because devloss_tmo is "
2381 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002382 return 0;
2383 }
2384
2385 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002386 vport->cfg_nodev_tmo = val;
2387 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002388 return 0;
2389 }
James Smarte8b62012007-08-02 11:10:09 -04002390 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2391 "0400 lpfc_nodev_tmo attribute cannot be set to"
2392 " %d, allowed range is [%d, %d]\n",
2393 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002394 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002395 return -EINVAL;
2396}
2397
James Smarte59058c2008-08-24 21:49:00 -04002398/**
James Smart3621a712009-04-06 18:47:14 -04002399 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002400 * @vport: lpfc vport structure pointer.
2401 *
2402 * Description:
2403 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2404 **/
James Smart7054a602007-04-25 09:52:34 -04002405static void
James Smart3de2a652007-08-02 11:09:59 -04002406lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002407{
James Smart858c9f62007-06-17 19:56:39 -05002408 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002409 struct lpfc_nodelist *ndlp;
2410
James Smart51ef4c22007-08-02 11:10:31 -04002411 shost = lpfc_shost_from_vport(vport);
2412 spin_lock_irq(shost->host_lock);
2413 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002414 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002415 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2416 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002417}
2418
James Smarte59058c2008-08-24 21:49:00 -04002419/**
James Smart3621a712009-04-06 18:47:14 -04002420 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002421 * @vport: lpfc vport structure pointer.
2422 * @val: contains the tmo value.
2423 *
2424 * Description:
2425 * If the devloss tmo is already set or the vport dev loss tmo has changed
2426 * then a kernel error message is printed and zero is returned.
2427 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2428 * Otherwise nodev tmo is set to the default value.
2429 *
2430 * Returns:
2431 * zero if already set or if val is in range
2432 * -EINVAL val out of range
2433 **/
James Smartc01f3202006-08-18 17:47:08 -04002434static int
James Smart3de2a652007-08-02 11:09:59 -04002435lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002436{
James Smart3de2a652007-08-02 11:09:59 -04002437 if (vport->dev_loss_tmo_changed ||
2438 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002439 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2440 "0401 Ignoring change to nodev_tmo "
2441 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002442 return 0;
2443 }
James Smartc01f3202006-08-18 17:47:08 -04002444 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002445 vport->cfg_nodev_tmo = val;
2446 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002447 /*
2448 * For compat: set the fc_host dev loss so new rports
2449 * will get the value.
2450 */
2451 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002452 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002453 return 0;
2454 }
James Smarte8b62012007-08-02 11:10:09 -04002455 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2456 "0403 lpfc_nodev_tmo attribute cannot be set to"
2457 "%d, allowed range is [%d, %d]\n",
2458 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002459 return -EINVAL;
2460}
2461
James Smart3de2a652007-08-02 11:09:59 -04002462lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002463
Tony Jonesee959b02008-02-22 00:13:36 +01002464static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2465 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002466
2467/*
2468# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2469# disappear until the timer expires. Value range is [0,255]. Default
2470# value is 30.
2471*/
James Smartab56dc22011-02-16 12:39:57 -05002472module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002473MODULE_PARM_DESC(lpfc_devloss_tmo,
2474 "Seconds driver will hold I/O waiting "
2475 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002476lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2477 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2478lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002479
2480/**
James Smart3621a712009-04-06 18:47:14 -04002481 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002482 * @vport: lpfc vport structure pointer.
2483 * @val: contains the tmo value.
2484 *
2485 * Description:
2486 * If val is in a valid range then set the vport nodev tmo,
2487 * devloss tmo, also set the vport dev loss tmo changed flag.
2488 * Else a kernel error message is printed.
2489 *
2490 * Returns:
2491 * zero if val is in range
2492 * -EINVAL val out of range
2493 **/
James Smartc01f3202006-08-18 17:47:08 -04002494static int
James Smart3de2a652007-08-02 11:09:59 -04002495lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002496{
2497 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002498 vport->cfg_nodev_tmo = val;
2499 vport->cfg_devloss_tmo = val;
2500 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002501 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002502 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002503 return 0;
2504 }
2505
James Smarte8b62012007-08-02 11:10:09 -04002506 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2507 "0404 lpfc_devloss_tmo attribute cannot be set to"
2508 " %d, allowed range is [%d, %d]\n",
2509 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002510 return -EINVAL;
2511}
2512
James Smart3de2a652007-08-02 11:09:59 -04002513lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002514static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2515 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002516
2517/*
dea31012005-04-17 16:05:31 -05002518# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2519# deluged with LOTS of information.
2520# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002521# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002522*/
James Smartf4b4c682009-05-22 14:53:12 -04002523LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002524 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002525
2526/*
James Smart7ee5d432007-10-27 13:37:17 -04002527# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2528# objects that have been registered with the nameserver after login.
2529*/
2530LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2531 "Deregister nameserver objects before LOGO");
2532
2533/*
dea31012005-04-17 16:05:31 -05002534# lun_queue_depth: This parameter is used to limit the number of outstanding
2535# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2536*/
James Smart3de2a652007-08-02 11:09:59 -04002537LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2538 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002539
2540/*
James Smart7dc517d2010-07-14 15:32:10 -04002541# tgt_queue_depth: This parameter is used to limit the number of outstanding
2542# commands per target port. Value range is [10,65535]. Default value is 65535.
2543*/
2544LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2545 "Max number of FCP commands we can queue to a specific target port");
2546
2547/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002548# hba_queue_depth: This parameter is used to limit the number of outstanding
2549# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2550# value is greater than the maximum number of exchanges supported by the HBA,
2551# then maximum number of exchanges supported by the HBA is used to determine
2552# the hba_queue_depth.
2553*/
2554LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2555 "Max number of FCP commands we can queue to a lpfc HBA");
2556
2557/*
James Smart92d7f7b2007-06-17 19:56:38 -05002558# peer_port_login: This parameter allows/prevents logins
2559# between peer ports hosted on the same physical port.
2560# When this parameter is set 0 peer ports of same physical port
2561# are not allowed to login to each other.
2562# When this parameter is set 1 peer ports of same physical port
2563# are allowed to login to each other.
2564# Default value of this parameter is 0.
2565*/
James Smart3de2a652007-08-02 11:09:59 -04002566LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2567 "Allow peer ports on the same physical port to login to each "
2568 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002569
2570/*
James Smart3de2a652007-08-02 11:09:59 -04002571# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002572# between Virtual Ports and remote initiators.
2573# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2574# other initiators and will attempt to PLOGI all remote ports.
2575# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2576# remote ports and will not attempt to PLOGI to other initiators.
2577# This parameter does not restrict to the physical port.
2578# This parameter does not restrict logins to Fabric resident remote ports.
2579# Default value of this parameter is 1.
2580*/
James Smart3de2a652007-08-02 11:09:59 -04002581static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002582module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002583MODULE_PARM_DESC(lpfc_restrict_login,
2584 "Restrict virtual ports login to remote initiators.");
2585lpfc_vport_param_show(restrict_login);
2586
James Smarte59058c2008-08-24 21:49:00 -04002587/**
James Smart3621a712009-04-06 18:47:14 -04002588 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002589 * @vport: lpfc vport structure pointer.
2590 * @val: contains the restrict login value.
2591 *
2592 * Description:
2593 * If val is not in a valid range then log a kernel error message and set
2594 * the vport restrict login to one.
2595 * If the port type is physical clear the restrict login flag and return.
2596 * Else set the restrict login flag to val.
2597 *
2598 * Returns:
2599 * zero if val is in range
2600 * -EINVAL val out of range
2601 **/
James Smart3de2a652007-08-02 11:09:59 -04002602static int
2603lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2604{
2605 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002606 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002607 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002608 "be set to %d, allowed range is [0, 1]\n",
2609 val);
James Smart3de2a652007-08-02 11:09:59 -04002610 vport->cfg_restrict_login = 1;
2611 return -EINVAL;
2612 }
2613 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2614 vport->cfg_restrict_login = 0;
2615 return 0;
2616 }
2617 vport->cfg_restrict_login = val;
2618 return 0;
2619}
2620
James Smarte59058c2008-08-24 21:49:00 -04002621/**
James Smart3621a712009-04-06 18:47:14 -04002622 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002623 * @vport: lpfc vport structure pointer.
2624 * @val: contains the restrict login value.
2625 *
2626 * Description:
2627 * If val is not in a valid range then log a kernel error message and set
2628 * the vport restrict login to one.
2629 * If the port type is physical and the val is not zero log a kernel
2630 * error message, clear the restrict login flag and return zero.
2631 * Else set the restrict login flag to val.
2632 *
2633 * Returns:
2634 * zero if val is in range
2635 * -EINVAL val out of range
2636 **/
James Smart3de2a652007-08-02 11:09:59 -04002637static int
2638lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2639{
2640 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002641 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002642 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002643 "be set to %d, allowed range is [0, 1]\n",
2644 val);
James Smart3de2a652007-08-02 11:09:59 -04002645 vport->cfg_restrict_login = 1;
2646 return -EINVAL;
2647 }
2648 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002649 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2650 "0468 lpfc_restrict_login must be 0 for "
2651 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002652 vport->cfg_restrict_login = 0;
2653 return 0;
2654 }
2655 vport->cfg_restrict_login = val;
2656 return 0;
2657}
2658lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002659static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2660 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002661
2662/*
dea31012005-04-17 16:05:31 -05002663# Some disk devices have a "select ID" or "select Target" capability.
2664# From a protocol standpoint "select ID" usually means select the
2665# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2666# annex" which contains a table that maps a "select ID" (a number
2667# between 0 and 7F) to an ALPA. By default, for compatibility with
2668# older drivers, the lpfc driver scans this table from low ALPA to high
2669# ALPA.
2670#
2671# Turning on the scan-down variable (on = 1, off = 0) will
2672# cause the lpfc driver to use an inverted table, effectively
2673# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2674#
2675# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2676# and will not work across a fabric. Also this parameter will take
2677# effect only in the case when ALPA map is not available.)
2678*/
James Smart3de2a652007-08-02 11:09:59 -04002679LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2680 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002681
2682/*
dea31012005-04-17 16:05:31 -05002683# lpfc_topology: link topology for init link
2684# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002685# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002686# 0x02 = attempt point-to-point mode only
2687# 0x04 = attempt loop mode only
2688# 0x06 = attempt point-to-point mode then loop
2689# Set point-to-point mode if you want to run as an N_Port.
2690# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2691# Default value is 0.
2692*/
James Smarte59058c2008-08-24 21:49:00 -04002693
2694/**
James Smart3621a712009-04-06 18:47:14 -04002695 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002696 * @phba: lpfc_hba pointer.
2697 * @val: topology value.
2698 *
2699 * Description:
2700 * If val is in a valid range then set the adapter's topology field and
2701 * issue a lip; if the lip fails reset the topology to the old value.
2702 *
2703 * If the value is not in range log a kernel error message and return an error.
2704 *
2705 * Returns:
2706 * zero if val is in range and lip okay
2707 * non-zero return value from lpfc_issue_lip()
2708 * -EINVAL val out of range
2709 **/
James Smarta257bf92009-04-06 18:48:10 -04002710static ssize_t
2711lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2712 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002713{
James Smarta257bf92009-04-06 18:48:10 -04002714 struct Scsi_Host *shost = class_to_shost(dev);
2715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2716 struct lpfc_hba *phba = vport->phba;
2717 int val = 0;
2718 int nolip = 0;
2719 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002720 int err;
2721 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002722
2723 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2724 nolip = 1;
2725 val_buf = &buf[strlen("nolip ")];
2726 }
2727
2728 if (!isdigit(val_buf[0]))
2729 return -EINVAL;
2730 if (sscanf(val_buf, "%i", &val) != 1)
2731 return -EINVAL;
2732
James Smart83108bd2008-01-11 01:53:09 -05002733 if (val >= 0 && val <= 6) {
2734 prev_val = phba->cfg_topology;
2735 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002736 if (nolip)
2737 return strlen(buf);
2738
James Smart88a2cfb2011-07-22 18:36:33 -04002739 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2740 "3054 lpfc_topology changed from %d to %d\n",
2741 prev_val, val);
James Smart83108bd2008-01-11 01:53:09 -05002742 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002743 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002744 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002745 return -EINVAL;
2746 } else
2747 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002748 }
2749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2750 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2751 "allowed range is [0, 6]\n",
2752 phba->brd_no, val);
2753 return -EINVAL;
2754}
2755static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002756module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002757MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2758lpfc_param_show(topology)
2759lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002760static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002761 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002762
James Smart21e9a0a2009-05-22 14:53:21 -04002763/**
2764 * lpfc_static_vport_show: Read callback function for
2765 * lpfc_static_vport sysfs file.
2766 * @dev: Pointer to class device object.
2767 * @attr: device attribute structure.
2768 * @buf: Data buffer.
2769 *
2770 * This function is the read call back function for
2771 * lpfc_static_vport sysfs file. The lpfc_static_vport
2772 * sysfs file report the mageability of the vport.
2773 **/
2774static ssize_t
2775lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2776 char *buf)
2777{
2778 struct Scsi_Host *shost = class_to_shost(dev);
2779 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2780 if (vport->vport_flag & STATIC_VPORT)
2781 sprintf(buf, "1\n");
2782 else
2783 sprintf(buf, "0\n");
2784
2785 return strlen(buf);
2786}
2787
2788/*
2789 * Sysfs attribute to control the statistical data collection.
2790 */
2791static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2792 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002793
2794/**
James Smart3621a712009-04-06 18:47:14 -04002795 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002796 * @dev: Pointer to class device.
2797 * @buf: Data buffer.
2798 * @count: Size of the data buffer.
2799 *
2800 * This function get called when an user write to the lpfc_stat_data_ctrl
2801 * sysfs file. This function parse the command written to the sysfs file
2802 * and take appropriate action. These commands are used for controlling
2803 * driver statistical data collection.
2804 * Following are the command this function handles.
2805 *
2806 * setbucket <bucket_type> <base> <step>
2807 * = Set the latency buckets.
2808 * destroybucket = destroy all the buckets.
2809 * start = start data collection
2810 * stop = stop data collection
2811 * reset = reset the collected data
2812 **/
2813static ssize_t
2814lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2815 const char *buf, size_t count)
2816{
2817 struct Scsi_Host *shost = class_to_shost(dev);
2818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2819 struct lpfc_hba *phba = vport->phba;
2820#define LPFC_MAX_DATA_CTRL_LEN 1024
2821 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2822 unsigned long i;
2823 char *str_ptr, *token;
2824 struct lpfc_vport **vports;
2825 struct Scsi_Host *v_shost;
2826 char *bucket_type_str, *base_str, *step_str;
2827 unsigned long base, step, bucket_type;
2828
2829 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002830 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002831 return -EINVAL;
2832
2833 strcpy(bucket_data, buf);
2834 str_ptr = &bucket_data[0];
2835 /* Ignore this token - this is command token */
2836 token = strsep(&str_ptr, "\t ");
2837 if (!token)
2838 return -EINVAL;
2839
2840 bucket_type_str = strsep(&str_ptr, "\t ");
2841 if (!bucket_type_str)
2842 return -EINVAL;
2843
2844 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2845 bucket_type = LPFC_LINEAR_BUCKET;
2846 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2847 bucket_type = LPFC_POWER2_BUCKET;
2848 else
2849 return -EINVAL;
2850
2851 base_str = strsep(&str_ptr, "\t ");
2852 if (!base_str)
2853 return -EINVAL;
2854 base = simple_strtoul(base_str, NULL, 0);
2855
2856 step_str = strsep(&str_ptr, "\t ");
2857 if (!step_str)
2858 return -EINVAL;
2859 step = simple_strtoul(step_str, NULL, 0);
2860 if (!step)
2861 return -EINVAL;
2862
2863 /* Block the data collection for every vport */
2864 vports = lpfc_create_vport_work_array(phba);
2865 if (vports == NULL)
2866 return -ENOMEM;
2867
James Smartf4b4c682009-05-22 14:53:12 -04002868 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002869 v_shost = lpfc_shost_from_vport(vports[i]);
2870 spin_lock_irq(v_shost->host_lock);
2871 /* Block and reset data collection */
2872 vports[i]->stat_data_blocked = 1;
2873 if (vports[i]->stat_data_enabled)
2874 lpfc_vport_reset_stat_data(vports[i]);
2875 spin_unlock_irq(v_shost->host_lock);
2876 }
2877
2878 /* Set the bucket attributes */
2879 phba->bucket_type = bucket_type;
2880 phba->bucket_base = base;
2881 phba->bucket_step = step;
2882
James Smartf4b4c682009-05-22 14:53:12 -04002883 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002884 v_shost = lpfc_shost_from_vport(vports[i]);
2885
2886 /* Unblock data collection */
2887 spin_lock_irq(v_shost->host_lock);
2888 vports[i]->stat_data_blocked = 0;
2889 spin_unlock_irq(v_shost->host_lock);
2890 }
2891 lpfc_destroy_vport_work_array(phba, vports);
2892 return strlen(buf);
2893 }
2894
2895 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2896 vports = lpfc_create_vport_work_array(phba);
2897 if (vports == NULL)
2898 return -ENOMEM;
2899
James Smartf4b4c682009-05-22 14:53:12 -04002900 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002901 v_shost = lpfc_shost_from_vport(vports[i]);
2902 spin_lock_irq(shost->host_lock);
2903 vports[i]->stat_data_blocked = 1;
2904 lpfc_free_bucket(vport);
2905 vport->stat_data_enabled = 0;
2906 vports[i]->stat_data_blocked = 0;
2907 spin_unlock_irq(shost->host_lock);
2908 }
2909 lpfc_destroy_vport_work_array(phba, vports);
2910 phba->bucket_type = LPFC_NO_BUCKET;
2911 phba->bucket_base = 0;
2912 phba->bucket_step = 0;
2913 return strlen(buf);
2914 }
2915
2916 if (!strncmp(buf, "start", strlen("start"))) {
2917 /* If no buckets configured return error */
2918 if (phba->bucket_type == LPFC_NO_BUCKET)
2919 return -EINVAL;
2920 spin_lock_irq(shost->host_lock);
2921 if (vport->stat_data_enabled) {
2922 spin_unlock_irq(shost->host_lock);
2923 return strlen(buf);
2924 }
2925 lpfc_alloc_bucket(vport);
2926 vport->stat_data_enabled = 1;
2927 spin_unlock_irq(shost->host_lock);
2928 return strlen(buf);
2929 }
2930
2931 if (!strncmp(buf, "stop", strlen("stop"))) {
2932 spin_lock_irq(shost->host_lock);
2933 if (vport->stat_data_enabled == 0) {
2934 spin_unlock_irq(shost->host_lock);
2935 return strlen(buf);
2936 }
2937 lpfc_free_bucket(vport);
2938 vport->stat_data_enabled = 0;
2939 spin_unlock_irq(shost->host_lock);
2940 return strlen(buf);
2941 }
2942
2943 if (!strncmp(buf, "reset", strlen("reset"))) {
2944 if ((phba->bucket_type == LPFC_NO_BUCKET)
2945 || !vport->stat_data_enabled)
2946 return strlen(buf);
2947 spin_lock_irq(shost->host_lock);
2948 vport->stat_data_blocked = 1;
2949 lpfc_vport_reset_stat_data(vport);
2950 vport->stat_data_blocked = 0;
2951 spin_unlock_irq(shost->host_lock);
2952 return strlen(buf);
2953 }
2954 return -EINVAL;
2955}
2956
2957
2958/**
James Smart3621a712009-04-06 18:47:14 -04002959 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002960 * @dev: Pointer to class device object.
2961 * @buf: Data buffer.
2962 *
2963 * This function is the read call back function for
2964 * lpfc_stat_data_ctrl sysfs file. This function report the
2965 * current statistical data collection state.
2966 **/
2967static ssize_t
2968lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2969 char *buf)
2970{
2971 struct Scsi_Host *shost = class_to_shost(dev);
2972 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2973 struct lpfc_hba *phba = vport->phba;
2974 int index = 0;
2975 int i;
2976 char *bucket_type;
2977 unsigned long bucket_value;
2978
2979 switch (phba->bucket_type) {
2980 case LPFC_LINEAR_BUCKET:
2981 bucket_type = "linear";
2982 break;
2983 case LPFC_POWER2_BUCKET:
2984 bucket_type = "power2";
2985 break;
2986 default:
2987 bucket_type = "No Bucket";
2988 break;
2989 }
2990
2991 sprintf(&buf[index], "Statistical Data enabled :%d, "
2992 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2993 " Bucket step :%d\nLatency Ranges :",
2994 vport->stat_data_enabled, vport->stat_data_blocked,
2995 bucket_type, phba->bucket_base, phba->bucket_step);
2996 index = strlen(buf);
2997 if (phba->bucket_type != LPFC_NO_BUCKET) {
2998 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2999 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3000 bucket_value = phba->bucket_base +
3001 phba->bucket_step * i;
3002 else
3003 bucket_value = phba->bucket_base +
3004 (1 << i) * phba->bucket_step;
3005
3006 if (index + 10 > PAGE_SIZE)
3007 break;
3008 sprintf(&buf[index], "%08ld ", bucket_value);
3009 index = strlen(buf);
3010 }
3011 }
3012 sprintf(&buf[index], "\n");
3013 return strlen(buf);
3014}
3015
3016/*
3017 * Sysfs attribute to control the statistical data collection.
3018 */
3019static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3020 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3021
3022/*
3023 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3024 */
3025
3026/*
3027 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3028 * for each target.
3029 */
3030#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3031#define MAX_STAT_DATA_SIZE_PER_TARGET \
3032 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3033
3034
3035/**
James Smart3621a712009-04-06 18:47:14 -04003036 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003037 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003038 * @kobj: Pointer to the kernel object
3039 * @bin_attr: Attribute object
3040 * @buff: Buffer pointer
3041 * @off: File offset
3042 * @count: Buffer size
3043 *
3044 * This function is the read call back function for lpfc_drvr_stat_data
3045 * sysfs file. This function export the statistical data to user
3046 * applications.
3047 **/
3048static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003049sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3050 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003051 char *buf, loff_t off, size_t count)
3052{
3053 struct device *dev = container_of(kobj, struct device,
3054 kobj);
3055 struct Scsi_Host *shost = class_to_shost(dev);
3056 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3057 struct lpfc_hba *phba = vport->phba;
3058 int i = 0, index = 0;
3059 unsigned long nport_index;
3060 struct lpfc_nodelist *ndlp = NULL;
3061 nport_index = (unsigned long)off /
3062 MAX_STAT_DATA_SIZE_PER_TARGET;
3063
3064 if (!vport->stat_data_enabled || vport->stat_data_blocked
3065 || (phba->bucket_type == LPFC_NO_BUCKET))
3066 return 0;
3067
3068 spin_lock_irq(shost->host_lock);
3069 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3070 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3071 continue;
3072
3073 if (nport_index > 0) {
3074 nport_index--;
3075 continue;
3076 }
3077
3078 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3079 > count)
3080 break;
3081
3082 if (!ndlp->lat_data)
3083 continue;
3084
3085 /* Print the WWN */
3086 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3087 ndlp->nlp_portname.u.wwn[0],
3088 ndlp->nlp_portname.u.wwn[1],
3089 ndlp->nlp_portname.u.wwn[2],
3090 ndlp->nlp_portname.u.wwn[3],
3091 ndlp->nlp_portname.u.wwn[4],
3092 ndlp->nlp_portname.u.wwn[5],
3093 ndlp->nlp_portname.u.wwn[6],
3094 ndlp->nlp_portname.u.wwn[7]);
3095
3096 index = strlen(buf);
3097
3098 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3099 sprintf(&buf[index], "%010u,",
3100 ndlp->lat_data[i].cmd_count);
3101 index = strlen(buf);
3102 }
3103 sprintf(&buf[index], "\n");
3104 index = strlen(buf);
3105 }
3106 spin_unlock_irq(shost->host_lock);
3107 return index;
3108}
3109
3110static struct bin_attribute sysfs_drvr_stat_data_attr = {
3111 .attr = {
3112 .name = "lpfc_drvr_stat_data",
3113 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003114 },
3115 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3116 .read = sysfs_drvr_stat_data_read,
3117 .write = NULL,
3118};
3119
dea31012005-04-17 16:05:31 -05003120/*
3121# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3122# connection.
James Smart76a95d72010-11-20 23:11:48 -05003123# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003124*/
James Smarte59058c2008-08-24 21:49:00 -04003125/**
James Smart3621a712009-04-06 18:47:14 -04003126 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003127 * @phba: lpfc_hba pointer.
3128 * @val: link speed value.
3129 *
3130 * Description:
3131 * If val is in a valid range then set the adapter's link speed field and
3132 * issue a lip; if the lip fails reset the link speed to the old value.
3133 *
3134 * Notes:
3135 * If the value is not in range log a kernel error message and return an error.
3136 *
3137 * Returns:
3138 * zero if val is in range and lip okay.
3139 * non-zero return value from lpfc_issue_lip()
3140 * -EINVAL val out of range
3141 **/
James Smarta257bf92009-04-06 18:48:10 -04003142static ssize_t
3143lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3144 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003145{
James Smarta257bf92009-04-06 18:48:10 -04003146 struct Scsi_Host *shost = class_to_shost(dev);
3147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3148 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003149 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003150 int nolip = 0;
3151 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003152 int err;
3153 uint32_t prev_val;
3154
James Smarta257bf92009-04-06 18:48:10 -04003155 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3156 nolip = 1;
3157 val_buf = &buf[strlen("nolip ")];
3158 }
3159
3160 if (!isdigit(val_buf[0]))
3161 return -EINVAL;
3162 if (sscanf(val_buf, "%i", &val) != 1)
3163 return -EINVAL;
3164
James Smart88a2cfb2011-07-22 18:36:33 -04003165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3166 "3055 lpfc_link_speed changed from %d to %d %s\n",
3167 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3168
James Smart76a95d72010-11-20 23:11:48 -05003169 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3170 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3171 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3172 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3173 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3174 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3175 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3176 "2879 lpfc_link_speed attribute cannot be set "
3177 "to %d. Speed is not supported by this port.\n",
3178 val);
James Smart83108bd2008-01-11 01:53:09 -05003179 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003180 }
3181 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3182 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003183 prev_val = phba->cfg_link_speed;
3184 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003185 if (nolip)
3186 return strlen(buf);
3187
James Smart83108bd2008-01-11 01:53:09 -05003188 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003189 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003190 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003191 return -EINVAL;
3192 } else
3193 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003194 }
James Smart83108bd2008-01-11 01:53:09 -05003195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003196 "0469 lpfc_link_speed attribute cannot be set to %d, "
3197 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003198 return -EINVAL;
3199}
3200
3201static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003202module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003203MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3204lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003205
3206/**
James Smart3621a712009-04-06 18:47:14 -04003207 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003208 * @phba: lpfc_hba pointer.
3209 * @val: link speed value.
3210 *
3211 * Description:
3212 * If val is in a valid range then set the adapter's link speed field.
3213 *
3214 * Notes:
3215 * If the value is not in range log a kernel error message, clear the link
3216 * speed and return an error.
3217 *
3218 * Returns:
3219 * zero if val saved.
3220 * -EINVAL val out of range
3221 **/
James Smart83108bd2008-01-11 01:53:09 -05003222static int
3223lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3224{
James Smart76a95d72010-11-20 23:11:48 -05003225 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3226 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003227 phba->cfg_link_speed = val;
3228 return 0;
3229 }
3230 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003231 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003232 "be set to %d, allowed values are "
3233 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003234 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003235 return -EINVAL;
3236}
3237
Tony Jonesee959b02008-02-22 00:13:36 +01003238static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003239 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003240
3241/*
James Smart0d878412009-10-02 15:16:56 -04003242# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3243# 0 = aer disabled or not supported
3244# 1 = aer supported and enabled (default)
3245# Value range is [0,1]. Default value is 1.
3246*/
3247
3248/**
3249 * lpfc_aer_support_store - Set the adapter for aer support
3250 *
3251 * @dev: class device that is converted into a Scsi_host.
3252 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003253 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003254 * @count: unused variable.
3255 *
3256 * Description:
3257 * If the val is 1 and currently the device's AER capability was not
3258 * enabled, invoke the kernel's enable AER helper routine, trying to
3259 * enable the device's AER capability. If the helper routine enabling
3260 * AER returns success, update the device's cfg_aer_support flag to
3261 * indicate AER is supported by the device; otherwise, if the device
3262 * AER capability is already enabled to support AER, then do nothing.
3263 *
3264 * If the val is 0 and currently the device's AER support was enabled,
3265 * invoke the kernel's disable AER helper routine. After that, update
3266 * the device's cfg_aer_support flag to indicate AER is not supported
3267 * by the device; otherwise, if the device AER capability is already
3268 * disabled from supporting AER, then do nothing.
3269 *
3270 * Returns:
3271 * length of the buf on success if val is in range the intended mode
3272 * is supported.
3273 * -EINVAL if val out of range or intended mode is not supported.
3274 **/
3275static ssize_t
3276lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3277 const char *buf, size_t count)
3278{
3279 struct Scsi_Host *shost = class_to_shost(dev);
3280 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3281 struct lpfc_hba *phba = vport->phba;
3282 int val = 0, rc = -EINVAL;
3283
3284 if (!isdigit(buf[0]))
3285 return -EINVAL;
3286 if (sscanf(buf, "%i", &val) != 1)
3287 return -EINVAL;
3288
3289 switch (val) {
3290 case 0:
3291 if (phba->hba_flag & HBA_AER_ENABLED) {
3292 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3293 if (!rc) {
3294 spin_lock_irq(&phba->hbalock);
3295 phba->hba_flag &= ~HBA_AER_ENABLED;
3296 spin_unlock_irq(&phba->hbalock);
3297 phba->cfg_aer_support = 0;
3298 rc = strlen(buf);
3299 } else
James Smart891478a2009-11-18 15:40:23 -05003300 rc = -EPERM;
3301 } else {
James Smart0d878412009-10-02 15:16:56 -04003302 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003303 rc = strlen(buf);
3304 }
James Smart0d878412009-10-02 15:16:56 -04003305 break;
3306 case 1:
3307 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3308 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3309 if (!rc) {
3310 spin_lock_irq(&phba->hbalock);
3311 phba->hba_flag |= HBA_AER_ENABLED;
3312 spin_unlock_irq(&phba->hbalock);
3313 phba->cfg_aer_support = 1;
3314 rc = strlen(buf);
3315 } else
James Smart891478a2009-11-18 15:40:23 -05003316 rc = -EPERM;
3317 } else {
James Smart0d878412009-10-02 15:16:56 -04003318 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003319 rc = strlen(buf);
3320 }
James Smart0d878412009-10-02 15:16:56 -04003321 break;
3322 default:
3323 rc = -EINVAL;
3324 break;
3325 }
3326 return rc;
3327}
3328
3329static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003330module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003331MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3332lpfc_param_show(aer_support)
3333
3334/**
3335 * lpfc_aer_support_init - Set the initial adapters aer support flag
3336 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003337 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003338 *
3339 * Description:
3340 * If val is in a valid range [0,1], then set the adapter's initial
3341 * cfg_aer_support field. It will be up to the driver's probe_one
3342 * routine to determine whether the device's AER support can be set
3343 * or not.
3344 *
3345 * Notes:
3346 * If the value is not in range log a kernel error message, and
3347 * choose the default value of setting AER support and return.
3348 *
3349 * Returns:
3350 * zero if val saved.
3351 * -EINVAL val out of range
3352 **/
3353static int
3354lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3355{
3356 if (val == 0 || val == 1) {
3357 phba->cfg_aer_support = val;
3358 return 0;
3359 }
3360 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3361 "2712 lpfc_aer_support attribute value %d out "
3362 "of range, allowed values are 0|1, setting it "
3363 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003364 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003365 phba->cfg_aer_support = 1;
3366 return -EINVAL;
3367}
3368
3369static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3370 lpfc_aer_support_show, lpfc_aer_support_store);
3371
3372/**
3373 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3374 * @dev: class device that is converted into a Scsi_host.
3375 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003376 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003377 * @count: unused variable.
3378 *
3379 * Description:
3380 * If the @buf contains 1 and the device currently has the AER support
3381 * enabled, then invokes the kernel AER helper routine
3382 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3383 * error status register.
3384 *
3385 * Notes:
3386 *
3387 * Returns:
3388 * -EINVAL if the buf does not contain the 1 or the device is not currently
3389 * enabled with the AER support.
3390 **/
3391static ssize_t
3392lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3393 const char *buf, size_t count)
3394{
3395 struct Scsi_Host *shost = class_to_shost(dev);
3396 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3397 struct lpfc_hba *phba = vport->phba;
3398 int val, rc = -1;
3399
3400 if (!isdigit(buf[0]))
3401 return -EINVAL;
3402 if (sscanf(buf, "%i", &val) != 1)
3403 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003404 if (val != 1)
3405 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003406
James Smart891478a2009-11-18 15:40:23 -05003407 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003408 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3409
3410 if (rc == 0)
3411 return strlen(buf);
3412 else
James Smart891478a2009-11-18 15:40:23 -05003413 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003414}
3415
3416static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3417 lpfc_aer_cleanup_state);
3418
James Smart912e3ac2011-05-24 11:42:11 -04003419/**
3420 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3421 *
3422 * @dev: class device that is converted into a Scsi_host.
3423 * @attr: device attribute, not used.
3424 * @buf: containing the string the number of vfs to be enabled.
3425 * @count: unused variable.
3426 *
3427 * Description:
3428 * When this api is called either through user sysfs, the driver shall
3429 * try to enable or disable SR-IOV virtual functions according to the
3430 * following:
3431 *
3432 * If zero virtual function has been enabled to the physical function,
3433 * the driver shall invoke the pci enable virtual function api trying
3434 * to enable the virtual functions. If the nr_vfn provided is greater
3435 * than the maximum supported, the maximum virtual function number will
3436 * be used for invoking the api; otherwise, the nr_vfn provided shall
3437 * be used for invoking the api. If the api call returned success, the
3438 * actual number of virtual functions enabled will be set to the driver
3439 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3440 * cfg_sriov_nr_virtfn remains zero.
3441 *
3442 * If none-zero virtual functions have already been enabled to the
3443 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3444 * -EINVAL will be returned and the driver does nothing;
3445 *
3446 * If the nr_vfn provided is zero and none-zero virtual functions have
3447 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3448 * disabling virtual function api shall be invoded to disable all the
3449 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3450 * zero. Otherwise, if zero virtual function has been enabled, do
3451 * nothing.
3452 *
3453 * Returns:
3454 * length of the buf on success if val is in range the intended mode
3455 * is supported.
3456 * -EINVAL if val out of range or intended mode is not supported.
3457 **/
3458static ssize_t
3459lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3460 const char *buf, size_t count)
3461{
3462 struct Scsi_Host *shost = class_to_shost(dev);
3463 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3464 struct lpfc_hba *phba = vport->phba;
3465 struct pci_dev *pdev = phba->pcidev;
3466 int val = 0, rc = -EINVAL;
3467
3468 /* Sanity check on user data */
3469 if (!isdigit(buf[0]))
3470 return -EINVAL;
3471 if (sscanf(buf, "%i", &val) != 1)
3472 return -EINVAL;
3473 if (val < 0)
3474 return -EINVAL;
3475
3476 /* Request disabling virtual functions */
3477 if (val == 0) {
3478 if (phba->cfg_sriov_nr_virtfn > 0) {
3479 pci_disable_sriov(pdev);
3480 phba->cfg_sriov_nr_virtfn = 0;
3481 }
3482 return strlen(buf);
3483 }
3484
3485 /* Request enabling virtual functions */
3486 if (phba->cfg_sriov_nr_virtfn > 0) {
3487 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3488 "3018 There are %d virtual functions "
3489 "enabled on physical function.\n",
3490 phba->cfg_sriov_nr_virtfn);
3491 return -EEXIST;
3492 }
3493
3494 if (val <= LPFC_MAX_VFN_PER_PFN)
3495 phba->cfg_sriov_nr_virtfn = val;
3496 else {
3497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3498 "3019 Enabling %d virtual functions is not "
3499 "allowed.\n", val);
3500 return -EINVAL;
3501 }
3502
3503 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3504 if (rc) {
3505 phba->cfg_sriov_nr_virtfn = 0;
3506 rc = -EPERM;
3507 } else
3508 rc = strlen(buf);
3509
3510 return rc;
3511}
3512
3513static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3514module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3515MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3516lpfc_param_show(sriov_nr_virtfn)
3517
3518/**
3519 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3520 * @phba: lpfc_hba pointer.
3521 * @val: link speed value.
3522 *
3523 * Description:
3524 * If val is in a valid range [0,255], then set the adapter's initial
3525 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3526 * number shall be used instead. It will be up to the driver's probe_one
3527 * routine to determine whether the device's SR-IOV is supported or not.
3528 *
3529 * Returns:
3530 * zero if val saved.
3531 * -EINVAL val out of range
3532 **/
3533static int
3534lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3535{
3536 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3537 phba->cfg_sriov_nr_virtfn = val;
3538 return 0;
3539 }
3540
3541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3542 "3017 Enabling %d virtual functions is not "
3543 "allowed.\n", val);
3544 return -EINVAL;
3545}
3546static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3547 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3548
James Smart0d878412009-10-02 15:16:56 -04003549/*
dea31012005-04-17 16:05:31 -05003550# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3551# Value range is [2,3]. Default value is 3.
3552*/
James Smart3de2a652007-08-02 11:09:59 -04003553LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3554 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003555
3556/*
3557# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3558# is [0,1]. Default value is 0.
3559*/
James Smart3de2a652007-08-02 11:09:59 -04003560LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3561 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003562
3563/*
James Smart977b5a02008-09-07 11:52:04 -04003564# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3565# depth. Default value is 0. When the value of this parameter is zero the
3566# SCSI command completion time is not used for controlling I/O queue depth. When
3567# the parameter is set to a non-zero value, the I/O queue depth is controlled
3568# to limit the I/O completion time to the parameter value.
3569# The value is set in milliseconds.
3570*/
3571static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003572module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003573MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3574 "Use command completion time to control queue depth");
3575lpfc_vport_param_show(max_scsicmpl_time);
3576lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3577static int
3578lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3579{
3580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3581 struct lpfc_nodelist *ndlp, *next_ndlp;
3582
3583 if (val == vport->cfg_max_scsicmpl_time)
3584 return 0;
3585 if ((val < 0) || (val > 60000))
3586 return -EINVAL;
3587 vport->cfg_max_scsicmpl_time = val;
3588
3589 spin_lock_irq(shost->host_lock);
3590 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3591 if (!NLP_CHK_NODE_ACT(ndlp))
3592 continue;
3593 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3594 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003595 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003596 }
3597 spin_unlock_irq(shost->host_lock);
3598 return 0;
3599}
3600lpfc_vport_param_store(max_scsicmpl_time);
3601static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3602 lpfc_max_scsicmpl_time_show,
3603 lpfc_max_scsicmpl_time_store);
3604
3605/*
dea31012005-04-17 16:05:31 -05003606# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3607# range is [0,1]. Default value is 0.
3608*/
3609LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3610
3611/*
3612# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3613# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003614# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003615# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3616# cr_delay is set to 0.
3617*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003618LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003619 "interrupt response is generated");
3620
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003621LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003622 "interrupt response is generated");
3623
3624/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003625# lpfc_multi_ring_support: Determines how many rings to spread available
3626# cmd/rsp IOCB entries across.
3627# Value range is [1,2]. Default value is 1.
3628*/
3629LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3630 "SLI rings to spread IOCB entries across");
3631
3632/*
James Smarta4bc3372006-12-02 13:34:16 -05003633# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3634# identifies what rctl value to configure the additional ring for.
3635# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3636*/
James Smart6a9c52c2009-10-02 15:16:51 -04003637LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003638 255, "Identifies RCTL for additional ring configuration");
3639
3640/*
3641# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3642# identifies what type value to configure the additional ring for.
3643# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3644*/
James Smart6a9c52c2009-10-02 15:16:51 -04003645LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003646 255, "Identifies TYPE for additional ring configuration");
3647
3648/*
dea31012005-04-17 16:05:31 -05003649# lpfc_fdmi_on: controls FDMI support.
3650# 0 = no FDMI support
3651# 1 = support FDMI without attribute of hostname
3652# 2 = support FDMI with attribute of hostname
3653# Value range [0,2]. Default value is 0.
3654*/
James Smart3de2a652007-08-02 11:09:59 -04003655LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003656
3657/*
3658# Specifies the maximum number of ELS cmds we can have outstanding (for
3659# discovery). Value range is [1,64]. Default value = 32.
3660*/
James Smart3de2a652007-08-02 11:09:59 -04003661LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003662 "during discovery");
3663
3664/*
James Smart65a29c12006-07-06 15:50:50 -04003665# lpfc_max_luns: maximum allowed LUN.
3666# Value range is [0,65535]. Default value is 255.
3667# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003668*/
James Smart3de2a652007-08-02 11:09:59 -04003669LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003670
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003671/*
3672# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3673# Value range is [1,255], default value is 10.
3674*/
3675LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3676 "Milliseconds driver will wait between polling FCP ring");
3677
James Smart4ff43242006-12-02 13:34:56 -05003678/*
3679# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3680# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003681# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003682# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003683# 2 = MSI-X enabled (default)
3684# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003685*/
George Kadianakis8605c462010-01-17 21:19:31 +02003686LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003687 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003688
James Smart13815c82008-01-11 01:52:48 -05003689/*
James Smartda0436e2009-05-22 14:51:39 -04003690# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3691#
3692# Value range is [636,651042]. Default value is 10000.
3693*/
3694LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3695 "Set the maximum number of fast-path FCP interrupts per second");
3696
3697/*
3698# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3699#
3700# Value range is [1,31]. Default value is 4.
3701*/
3702LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3703 "Set the number of fast-path FCP work queues, if possible");
3704
3705/*
3706# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3707#
3708# Value range is [1,7]. Default value is 1.
3709*/
3710LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3711 "Set the number of fast-path FCP event queues, if possible");
3712
3713/*
James Smart13815c82008-01-11 01:52:48 -05003714# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3715# 0 = HBA resets disabled
3716# 1 = HBA resets enabled (default)
3717# Value range is [0,1]. Default value is 1.
3718*/
3719LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003720
James Smart13815c82008-01-11 01:52:48 -05003721/*
James Smarteb7a3392010-11-20 23:12:02 -05003722# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003723# 0 = HBA Heartbeat disabled
3724# 1 = HBA Heartbeat enabled (default)
3725# Value range is [0,1]. Default value is 1.
3726*/
James Smarteb7a3392010-11-20 23:12:02 -05003727LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003728
James Smart83108bd2008-01-11 01:53:09 -05003729/*
James Smart81301a92008-12-04 22:39:46 -05003730# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3731# 0 = BlockGuard disabled (default)
3732# 1 = BlockGuard enabled
3733# Value range is [0,1]. Default value is 0.
3734*/
3735LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3736
James Smart6fb120a2009-05-22 14:52:59 -04003737/*
James Smart81301a92008-12-04 22:39:46 -05003738# lpfc_prot_mask: i
3739# - Bit mask of host protection capabilities used to register with the
3740# SCSI mid-layer
3741# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3742# - Allows you to ultimately specify which profiles to use
3743# - Default will result in registering capabilities for all profiles.
3744#
3745*/
James Smart7c56b9f2011-07-22 18:36:25 -04003746unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3747 SHOST_DIX_TYPE0_PROTECTION |
3748 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003749
James Smartab56dc22011-02-16 12:39:57 -05003750module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003751MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3752
3753/*
3754# lpfc_prot_guard: i
3755# - Bit mask of protection guard types to register with the SCSI mid-layer
3756# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3757# - Allows you to ultimately specify which profiles to use
3758# - Default will result in registering capabilities for all guard types
3759#
3760*/
3761unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003762module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003763MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3764
James Smart92494142011-02-16 12:39:44 -05003765/*
3766 * Delay initial NPort discovery when Clean Address bit is cleared in
3767 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3768 * This parameter can have value 0 or 1.
3769 * When this parameter is set to 0, no delay is added to the initial
3770 * discovery.
3771 * When this parameter is set to non-zero value, initial Nport discovery is
3772 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3773 * accept and FCID/Fabric name/Fabric portname is changed.
3774 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3775 * when Clean Address bit is cleared in FLOGI/FDISC
3776 * accept and FCID/Fabric name/Fabric portname is changed.
3777 * Default value is 0.
3778 */
3779int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003780module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003781MODULE_PARM_DESC(lpfc_delay_discovery,
3782 "Delay NPort discovery when Clean Address bit is cleared. "
3783 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003784
3785/*
James Smart3621a712009-04-06 18:47:14 -04003786 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003787 * This value can be set to values between 64 and 256. The default value is
3788 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3789 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3790 */
3791LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3792 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3793
James Smart81301a92008-12-04 22:39:46 -05003794LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3795 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3796 "Max Protection Scatter Gather Segment Count");
3797
Tony Jonesee959b02008-02-22 00:13:36 +01003798struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003799 &dev_attr_bg_info,
3800 &dev_attr_bg_guard_err,
3801 &dev_attr_bg_apptag_err,
3802 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003803 &dev_attr_info,
3804 &dev_attr_serialnum,
3805 &dev_attr_modeldesc,
3806 &dev_attr_modelname,
3807 &dev_attr_programtype,
3808 &dev_attr_portnum,
3809 &dev_attr_fwrev,
3810 &dev_attr_hdw,
3811 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003812 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003813 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003814 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003815 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003816 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003817 &dev_attr_lpfc_temp_sensor,
3818 &dev_attr_lpfc_log_verbose,
3819 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003820 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003821 &dev_attr_lpfc_hba_queue_depth,
3822 &dev_attr_lpfc_peer_port_login,
3823 &dev_attr_lpfc_nodev_tmo,
3824 &dev_attr_lpfc_devloss_tmo,
3825 &dev_attr_lpfc_fcp_class,
3826 &dev_attr_lpfc_use_adisc,
3827 &dev_attr_lpfc_ack0,
3828 &dev_attr_lpfc_topology,
3829 &dev_attr_lpfc_scan_down,
3830 &dev_attr_lpfc_link_speed,
3831 &dev_attr_lpfc_cr_delay,
3832 &dev_attr_lpfc_cr_count,
3833 &dev_attr_lpfc_multi_ring_support,
3834 &dev_attr_lpfc_multi_ring_rctl,
3835 &dev_attr_lpfc_multi_ring_type,
3836 &dev_attr_lpfc_fdmi_on,
3837 &dev_attr_lpfc_max_luns,
3838 &dev_attr_lpfc_enable_npiv,
James Smart19ca7602010-11-20 23:11:55 -05003839 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003840 &dev_attr_nport_evt_cnt,
3841 &dev_attr_board_mode,
3842 &dev_attr_max_vpi,
3843 &dev_attr_used_vpi,
3844 &dev_attr_max_rpi,
3845 &dev_attr_used_rpi,
3846 &dev_attr_max_xri,
3847 &dev_attr_used_xri,
3848 &dev_attr_npiv_info,
3849 &dev_attr_issue_reset,
3850 &dev_attr_lpfc_poll,
3851 &dev_attr_lpfc_poll_tmo,
3852 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003853 &dev_attr_lpfc_fcp_imax,
3854 &dev_attr_lpfc_fcp_wq_count,
3855 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003856 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003857 &dev_attr_lpfc_soft_wwnn,
3858 &dev_attr_lpfc_soft_wwpn,
3859 &dev_attr_lpfc_soft_wwn_enable,
3860 &dev_attr_lpfc_enable_hba_reset,
3861 &dev_attr_lpfc_enable_hba_heartbeat,
3862 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003863 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003864 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003865 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003866 &dev_attr_lpfc_aer_support,
3867 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04003868 &dev_attr_lpfc_sriov_nr_virtfn,
James Smart84d1b002010-02-12 14:42:33 -05003869 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003870 &dev_attr_lpfc_iocb_cnt,
3871 &dev_attr_iocb_hw,
3872 &dev_attr_txq_hw,
3873 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003874 &dev_attr_lpfc_fips_level,
3875 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003876 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04003877 &dev_attr_lpfc_sriov_hw_max_virtfn,
dea31012005-04-17 16:05:31 -05003878 NULL,
3879};
3880
Tony Jonesee959b02008-02-22 00:13:36 +01003881struct device_attribute *lpfc_vport_attrs[] = {
3882 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003883 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003884 &dev_attr_num_discovered_ports,
3885 &dev_attr_lpfc_drvr_version,
3886 &dev_attr_lpfc_log_verbose,
3887 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003888 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003889 &dev_attr_lpfc_nodev_tmo,
3890 &dev_attr_lpfc_devloss_tmo,
3891 &dev_attr_lpfc_hba_queue_depth,
3892 &dev_attr_lpfc_peer_port_login,
3893 &dev_attr_lpfc_restrict_login,
3894 &dev_attr_lpfc_fcp_class,
3895 &dev_attr_lpfc_use_adisc,
3896 &dev_attr_lpfc_fdmi_on,
3897 &dev_attr_lpfc_max_luns,
3898 &dev_attr_nport_evt_cnt,
3899 &dev_attr_npiv_info,
3900 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003901 &dev_attr_lpfc_max_scsicmpl_time,
3902 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003903 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003904 &dev_attr_lpfc_fips_level,
3905 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003906 NULL,
3907};
3908
James Smarte59058c2008-08-24 21:49:00 -04003909/**
James Smart3621a712009-04-06 18:47:14 -04003910 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003911 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003912 * @kobj: kernel kobject that contains the kernel class device.
3913 * @bin_attr: kernel attributes passed to us.
3914 * @buf: contains the data to be written to the adapter IOREG space.
3915 * @off: offset into buffer to beginning of data.
3916 * @count: bytes to transfer.
3917 *
3918 * Description:
3919 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3920 * Uses the adapter io control registers to send buf contents to the adapter.
3921 *
3922 * Returns:
3923 * -ERANGE off and count combo out of range
3924 * -EINVAL off, count or buff address invalid
3925 * -EPERM adapter is offline
3926 * value of count, buf contents written
3927 **/
dea31012005-04-17 16:05:31 -05003928static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003929sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3930 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003931 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003932{
3933 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003934 struct device *dev = container_of(kobj, struct device, kobj);
3935 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003936 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3937 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003938
James Smartf1126682009-06-10 17:22:44 -04003939 if (phba->sli_rev >= LPFC_SLI_REV4)
3940 return -EPERM;
3941
dea31012005-04-17 16:05:31 -05003942 if ((off + count) > FF_REG_AREA_SIZE)
3943 return -ERANGE;
3944
3945 if (count == 0) return 0;
3946
3947 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3948 return -EINVAL;
3949
James Smart2e0fef82007-06-17 19:56:36 -05003950 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003951 return -EPERM;
3952 }
3953
James Smart2e0fef82007-06-17 19:56:36 -05003954 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003955 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3956 writel(*((uint32_t *)(buf + buf_off)),
3957 phba->ctrl_regs_memmap_p + off + buf_off);
3958
James Smart2e0fef82007-06-17 19:56:36 -05003959 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003960
3961 return count;
3962}
3963
James Smarte59058c2008-08-24 21:49:00 -04003964/**
James Smart3621a712009-04-06 18:47:14 -04003965 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003966 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003967 * @kobj: kernel kobject that contains the kernel class device.
3968 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003969 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003970 * @off: offset into buffer to beginning of data.
3971 * @count: bytes to transfer.
3972 *
3973 * Description:
3974 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3975 * Uses the adapter io control registers to read data into buf.
3976 *
3977 * Returns:
3978 * -ERANGE off and count combo out of range
3979 * -EINVAL off, count or buff address invalid
3980 * value of count, buf contents read
3981 **/
dea31012005-04-17 16:05:31 -05003982static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003983sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3984 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003985 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003986{
3987 size_t buf_off;
3988 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003989 struct device *dev = container_of(kobj, struct device, kobj);
3990 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3992 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003993
James Smartf1126682009-06-10 17:22:44 -04003994 if (phba->sli_rev >= LPFC_SLI_REV4)
3995 return -EPERM;
3996
dea31012005-04-17 16:05:31 -05003997 if (off > FF_REG_AREA_SIZE)
3998 return -ERANGE;
3999
4000 if ((off + count) > FF_REG_AREA_SIZE)
4001 count = FF_REG_AREA_SIZE - off;
4002
4003 if (count == 0) return 0;
4004
4005 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4006 return -EINVAL;
4007
James Smart2e0fef82007-06-17 19:56:36 -05004008 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004009
4010 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4011 tmp_ptr = (uint32_t *)(buf + buf_off);
4012 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4013 }
4014
James Smart2e0fef82007-06-17 19:56:36 -05004015 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004016
4017 return count;
4018}
4019
4020static struct bin_attribute sysfs_ctlreg_attr = {
4021 .attr = {
4022 .name = "ctlreg",
4023 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004024 },
4025 .size = 256,
4026 .read = sysfs_ctlreg_read,
4027 .write = sysfs_ctlreg_write,
4028};
4029
James Smarte59058c2008-08-24 21:49:00 -04004030/**
James Smart3621a712009-04-06 18:47:14 -04004031 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04004032 * @phba: lpfc_hba pointer
4033 **/
dea31012005-04-17 16:05:31 -05004034static void
James Smart2e0fef82007-06-17 19:56:36 -05004035sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004036{
4037 phba->sysfs_mbox.state = SMBOX_IDLE;
4038 phba->sysfs_mbox.offset = 0;
4039
4040 if (phba->sysfs_mbox.mbox) {
4041 mempool_free(phba->sysfs_mbox.mbox,
4042 phba->mbox_mem_pool);
4043 phba->sysfs_mbox.mbox = NULL;
4044 }
4045}
4046
James Smarte59058c2008-08-24 21:49:00 -04004047/**
James Smart3621a712009-04-06 18:47:14 -04004048 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004049 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004050 * @kobj: kernel kobject that contains the kernel class device.
4051 * @bin_attr: kernel attributes passed to us.
4052 * @buf: contains the data to be written to sysfs mbox.
4053 * @off: offset into buffer to beginning of data.
4054 * @count: bytes to transfer.
4055 *
4056 * Description:
4057 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4058 * Uses the sysfs mbox to send buf contents to the adapter.
4059 *
4060 * Returns:
4061 * -ERANGE off and count combo out of range
4062 * -EINVAL off, count or buff address invalid
4063 * zero if count is zero
4064 * -EPERM adapter is offline
4065 * -ENOMEM failed to allocate memory for the mail box
4066 * -EAGAIN offset, state or mbox is NULL
4067 * count number of bytes transferred
4068 **/
dea31012005-04-17 16:05:31 -05004069static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004070sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4071 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004072 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004073{
Tony Jonesee959b02008-02-22 00:13:36 +01004074 struct device *dev = container_of(kobj, struct device, kobj);
4075 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004076 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4077 struct lpfc_hba *phba = vport->phba;
4078 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05004079
4080 if ((count + off) > MAILBOX_CMD_SIZE)
4081 return -ERANGE;
4082
4083 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4084 return -EINVAL;
4085
4086 if (count == 0)
4087 return 0;
4088
4089 if (off == 0) {
4090 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4091 if (!mbox)
4092 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05004093 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004094 }
4095
James Smart2e0fef82007-06-17 19:56:36 -05004096 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004097
4098 if (off == 0) {
4099 if (phba->sysfs_mbox.mbox)
4100 mempool_free(mbox, phba->mbox_mem_pool);
4101 else
4102 phba->sysfs_mbox.mbox = mbox;
4103 phba->sysfs_mbox.state = SMBOX_WRITING;
4104 } else {
4105 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4106 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05004107 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05004108 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004109 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004110 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004111 }
4112 }
4113
James Smart04c68492009-05-22 14:52:52 -04004114 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05004115 buf, count);
4116
4117 phba->sysfs_mbox.offset = off + count;
4118
James Smart2e0fef82007-06-17 19:56:36 -05004119 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004120
4121 return count;
4122}
4123
James Smarte59058c2008-08-24 21:49:00 -04004124/**
James Smart3621a712009-04-06 18:47:14 -04004125 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004126 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004127 * @kobj: kernel kobject that contains the kernel class device.
4128 * @bin_attr: kernel attributes passed to us.
4129 * @buf: contains the data to be read from sysfs mbox.
4130 * @off: offset into buffer to beginning of data.
4131 * @count: bytes to transfer.
4132 *
4133 * Description:
4134 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4135 * Uses the sysfs mbox to receive data from to the adapter.
4136 *
4137 * Returns:
4138 * -ERANGE off greater than mailbox command size
4139 * -EINVAL off, count or buff address invalid
4140 * zero if off and count are zero
4141 * -EACCES adapter over temp
4142 * -EPERM garbage can value to catch a multitude of errors
4143 * -EAGAIN management IO not permitted, state or off error
4144 * -ETIME mailbox timeout
4145 * -ENODEV mailbox error
4146 * count number of bytes transferred
4147 **/
dea31012005-04-17 16:05:31 -05004148static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004149sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4150 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004151 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004152{
Tony Jonesee959b02008-02-22 00:13:36 +01004153 struct device *dev = container_of(kobj, struct device, kobj);
4154 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4156 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004157 int rc;
James Smart04c68492009-05-22 14:52:52 -04004158 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05004159
James Smart1dcb58e2007-04-25 09:51:30 -04004160 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004161 return -ERANGE;
4162
James Smart1dcb58e2007-04-25 09:51:30 -04004163 if ((count + off) > MAILBOX_CMD_SIZE)
4164 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05004165
4166 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4167 return -EINVAL;
4168
4169 if (off && count == 0)
4170 return 0;
4171
James Smart2e0fef82007-06-17 19:56:36 -05004172 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004173
James Smart7af67052007-10-27 13:38:11 -04004174 if (phba->over_temp_state == HBA_OVER_TEMP) {
4175 sysfs_mbox_idle(phba);
4176 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05004177 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04004178 }
4179
dea31012005-04-17 16:05:31 -05004180 if (off == 0 &&
4181 phba->sysfs_mbox.state == SMBOX_WRITING &&
4182 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04004183 pmb = &phba->sysfs_mbox.mbox->u.mb;
4184 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05004185 /* Offline only */
dea31012005-04-17 16:05:31 -05004186 case MBX_INIT_LINK:
4187 case MBX_DOWN_LINK:
4188 case MBX_CONFIG_LINK:
4189 case MBX_CONFIG_RING:
4190 case MBX_RESET_RING:
4191 case MBX_UNREG_LOGIN:
4192 case MBX_CLEAR_LA:
4193 case MBX_DUMP_CONTEXT:
4194 case MBX_RUN_DIAGS:
4195 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05004196 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05004197 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05004198 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05004199 printk(KERN_WARNING "mbox_read:Command 0x%x "
4200 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04004201 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004202 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004203 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004204 return -EPERM;
4205 }
James Smarta8adb832007-10-27 13:37:53 -04004206 case MBX_WRITE_NV:
4207 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05004208 case MBX_LOAD_SM:
4209 case MBX_READ_NV:
4210 case MBX_READ_CONFIG:
4211 case MBX_READ_RCONFIG:
4212 case MBX_READ_STATUS:
4213 case MBX_READ_XRI:
4214 case MBX_READ_REV:
4215 case MBX_READ_LNK_STAT:
4216 case MBX_DUMP_MEMORY:
4217 case MBX_DOWN_LOAD:
4218 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004219 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05004220 case MBX_LOAD_AREA:
4221 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004222 case MBX_BEACON:
4223 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05004224 case MBX_SET_VARIABLE:
4225 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04004226 case MBX_PORT_CAPABILITIES:
4227 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05004228 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04004229 case MBX_SECURITY_MGMT:
4230 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04004231 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4232 printk(KERN_WARNING "mbox_read:Command 0x%x "
4233 "is not permitted\n", pmb->mbxCommand);
4234 sysfs_mbox_idle(phba);
4235 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04004236 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04004237 }
James Smartdcf2a4e2010-09-29 11:18:53 -04004238 break;
dea31012005-04-17 16:05:31 -05004239 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05004240 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05004241 case MBX_REG_LOGIN:
4242 case MBX_REG_LOGIN64:
4243 case MBX_CONFIG_PORT:
4244 case MBX_RUN_BIU_DIAG:
4245 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004246 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004247 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004248 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004249 return -EPERM;
4250 default:
4251 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004252 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004253 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004254 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004255 return -EPERM;
4256 }
4257
James Smart09372822008-01-11 01:52:54 -05004258 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05004259 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05004260 */
James Smartd7c255b2008-08-24 21:50:00 -04004261 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04004262 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4263 pmb->mbxCommand != MBX_RESTART &&
4264 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4265 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04004266 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4267 "1259 mbox: Issued mailbox cmd "
4268 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04004269 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05004270
James Smart92d7f7b2007-06-17 19:56:38 -05004271 phba->sysfs_mbox.mbox->vport = vport;
4272
James Smart58da1ff2008-04-07 10:15:56 -04004273 /* Don't allow mailbox commands to be sent when blocked
4274 * or when in the middle of discovery
4275 */
James Smart495a7142008-06-14 22:52:59 -04004276 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04004277 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004278 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04004279 return -EAGAIN;
4280 }
4281
James Smart2e0fef82007-06-17 19:56:36 -05004282 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004283 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05004284
James Smart2e0fef82007-06-17 19:56:36 -05004285 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004286 rc = lpfc_sli_issue_mbox (phba,
4287 phba->sysfs_mbox.mbox,
4288 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05004289 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004290
4291 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004292 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004293 rc = lpfc_sli_issue_mbox_wait (phba,
4294 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04004295 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05004296 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004297 }
4298
4299 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04004300 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04004301 phba->sysfs_mbox.mbox = NULL;
4302 }
dea31012005-04-17 16:05:31 -05004303 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004304 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004305 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05004306 }
4307 phba->sysfs_mbox.state = SMBOX_READING;
4308 }
4309 else if (phba->sysfs_mbox.offset != off ||
4310 phba->sysfs_mbox.state != SMBOX_READING) {
4311 printk(KERN_WARNING "mbox_read: Bad State\n");
4312 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004313 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004314 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004315 }
4316
James Smart04c68492009-05-22 14:52:52 -04004317 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05004318
4319 phba->sysfs_mbox.offset = off + count;
4320
James Smart1dcb58e2007-04-25 09:51:30 -04004321 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004322 sysfs_mbox_idle(phba);
4323
James Smart2e0fef82007-06-17 19:56:36 -05004324 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004325
4326 return count;
4327}
4328
4329static struct bin_attribute sysfs_mbox_attr = {
4330 .attr = {
4331 .name = "mbox",
4332 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004333 },
James Smartc0c11512011-05-24 11:41:34 -04004334 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004335 .read = sysfs_mbox_read,
4336 .write = sysfs_mbox_write,
4337};
4338
James Smarte59058c2008-08-24 21:49:00 -04004339/**
James Smart3621a712009-04-06 18:47:14 -04004340 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004341 * @vport: address of lpfc vport structure.
4342 *
4343 * Return codes:
4344 * zero on success
4345 * error return code from sysfs_create_bin_file()
4346 **/
dea31012005-04-17 16:05:31 -05004347int
James Smart2e0fef82007-06-17 19:56:36 -05004348lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004349{
James Smart2e0fef82007-06-17 19:56:36 -05004350 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004351 int error;
4352
Tony Jonesee959b02008-02-22 00:13:36 +01004353 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004354 &sysfs_drvr_stat_data_attr);
4355
4356 /* Virtual ports do not need ctrl_reg and mbox */
4357 if (error || vport->port_type == LPFC_NPIV_PORT)
4358 goto out;
4359
4360 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004361 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004362 if (error)
James Smarteada2722008-12-04 22:39:13 -05004363 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004364
Tony Jonesee959b02008-02-22 00:13:36 +01004365 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004366 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004367 if (error)
4368 goto out_remove_ctlreg_attr;
4369
4370 return 0;
4371out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004372 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004373out_remove_stat_attr:
4374 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4375 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004376out:
4377 return error;
4378}
4379
James Smarte59058c2008-08-24 21:49:00 -04004380/**
James Smart3621a712009-04-06 18:47:14 -04004381 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004382 * @vport: address of lpfc vport structure.
4383 **/
dea31012005-04-17 16:05:31 -05004384void
James Smart2e0fef82007-06-17 19:56:36 -05004385lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004386{
James Smart2e0fef82007-06-17 19:56:36 -05004387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004388 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4389 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004390 /* Virtual ports do not need ctrl_reg and mbox */
4391 if (vport->port_type == LPFC_NPIV_PORT)
4392 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004393 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4394 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004395}
4396
4397
4398/*
4399 * Dynamic FC Host Attributes Support
4400 */
4401
James Smarte59058c2008-08-24 21:49:00 -04004402/**
James Smart3621a712009-04-06 18:47:14 -04004403 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004404 * @shost: kernel scsi host pointer.
4405 **/
dea31012005-04-17 16:05:31 -05004406static void
4407lpfc_get_host_port_id(struct Scsi_Host *shost)
4408{
James Smart2e0fef82007-06-17 19:56:36 -05004409 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4410
dea31012005-04-17 16:05:31 -05004411 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004412 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004413}
4414
James Smarte59058c2008-08-24 21:49:00 -04004415/**
James Smart3621a712009-04-06 18:47:14 -04004416 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004417 * @shost: kernel scsi host pointer.
4418 **/
dea31012005-04-17 16:05:31 -05004419static void
4420lpfc_get_host_port_type(struct Scsi_Host *shost)
4421{
James Smart2e0fef82007-06-17 19:56:36 -05004422 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4423 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004424
4425 spin_lock_irq(shost->host_lock);
4426
James Smart92d7f7b2007-06-17 19:56:38 -05004427 if (vport->port_type == LPFC_NPIV_PORT) {
4428 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4429 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004430 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004431 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004432 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4433 else
4434 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4435 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004436 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004437 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4438 else
4439 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4440 }
4441 } else
4442 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4443
4444 spin_unlock_irq(shost->host_lock);
4445}
4446
James Smarte59058c2008-08-24 21:49:00 -04004447/**
James Smart3621a712009-04-06 18:47:14 -04004448 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004449 * @shost: kernel scsi host pointer.
4450 **/
dea31012005-04-17 16:05:31 -05004451static void
4452lpfc_get_host_port_state(struct Scsi_Host *shost)
4453{
James Smart2e0fef82007-06-17 19:56:36 -05004454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4455 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004456
4457 spin_lock_irq(shost->host_lock);
4458
James Smart2e0fef82007-06-17 19:56:36 -05004459 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004460 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4461 else {
James Smart2e0fef82007-06-17 19:56:36 -05004462 switch (phba->link_state) {
4463 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004464 case LPFC_LINK_DOWN:
4465 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4466 break;
4467 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004468 case LPFC_CLEAR_LA:
4469 case LPFC_HBA_READY:
4470 /* Links up, beyond this port_type reports state */
4471 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4472 break;
4473 case LPFC_HBA_ERROR:
4474 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4475 break;
4476 default:
4477 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4478 break;
4479 }
4480 }
4481
4482 spin_unlock_irq(shost->host_lock);
4483}
4484
James Smarte59058c2008-08-24 21:49:00 -04004485/**
James Smart3621a712009-04-06 18:47:14 -04004486 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004487 * @shost: kernel scsi host pointer.
4488 **/
dea31012005-04-17 16:05:31 -05004489static void
4490lpfc_get_host_speed(struct Scsi_Host *shost)
4491{
James Smart2e0fef82007-06-17 19:56:36 -05004492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4493 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004494
4495 spin_lock_irq(shost->host_lock);
4496
James Smart2e0fef82007-06-17 19:56:36 -05004497 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004498 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004499 case LPFC_LINK_SPEED_1GHZ:
4500 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004501 break;
James Smart76a95d72010-11-20 23:11:48 -05004502 case LPFC_LINK_SPEED_2GHZ:
4503 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004504 break;
James Smart76a95d72010-11-20 23:11:48 -05004505 case LPFC_LINK_SPEED_4GHZ:
4506 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004507 break;
James Smart76a95d72010-11-20 23:11:48 -05004508 case LPFC_LINK_SPEED_8GHZ:
4509 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004510 break;
James Smart76a95d72010-11-20 23:11:48 -05004511 case LPFC_LINK_SPEED_10GHZ:
4512 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004513 break;
James Smart76a95d72010-11-20 23:11:48 -05004514 case LPFC_LINK_SPEED_16GHZ:
4515 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4516 break;
4517 default:
4518 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004519 break;
4520 }
James Smart09372822008-01-11 01:52:54 -05004521 } else
4522 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004523
4524 spin_unlock_irq(shost->host_lock);
4525}
4526
James Smarte59058c2008-08-24 21:49:00 -04004527/**
James Smart3621a712009-04-06 18:47:14 -04004528 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004529 * @shost: kernel scsi host pointer.
4530 **/
dea31012005-04-17 16:05:31 -05004531static void
4532lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4533{
James Smart2e0fef82007-06-17 19:56:36 -05004534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4535 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004536 u64 node_name;
dea31012005-04-17 16:05:31 -05004537
4538 spin_lock_irq(shost->host_lock);
4539
James Smart2e0fef82007-06-17 19:56:36 -05004540 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004541 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004542 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004543 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004544 else
4545 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004546 node_name = 0;
dea31012005-04-17 16:05:31 -05004547
4548 spin_unlock_irq(shost->host_lock);
4549
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004550 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004551}
4552
James Smarte59058c2008-08-24 21:49:00 -04004553/**
James Smart3621a712009-04-06 18:47:14 -04004554 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004555 * @shost: kernel scsi host pointer.
4556 *
4557 * Notes:
4558 * NULL on error for link down, no mbox pool, sli2 active,
4559 * management not allowed, memory allocation error, or mbox error.
4560 *
4561 * Returns:
4562 * NULL for error
4563 * address of the adapter host statistics
4564 **/
dea31012005-04-17 16:05:31 -05004565static struct fc_host_statistics *
4566lpfc_get_stats(struct Scsi_Host *shost)
4567{
James Smart2e0fef82007-06-17 19:56:36 -05004568 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4569 struct lpfc_hba *phba = vport->phba;
4570 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004571 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004572 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004573 LPFC_MBOXQ_t *pmboxq;
4574 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004575 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004576 int rc = 0;
dea31012005-04-17 16:05:31 -05004577
James Smart92d7f7b2007-06-17 19:56:38 -05004578 /*
4579 * prevent udev from issuing mailbox commands until the port is
4580 * configured.
4581 */
James Smart2e0fef82007-06-17 19:56:36 -05004582 if (phba->link_state < LPFC_LINK_DOWN ||
4583 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004584 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004585 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004586
4587 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004588 return NULL;
4589
dea31012005-04-17 16:05:31 -05004590 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4591 if (!pmboxq)
4592 return NULL;
4593 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4594
James Smart04c68492009-05-22 14:52:52 -04004595 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004596 pmb->mbxCommand = MBX_READ_STATUS;
4597 pmb->mbxOwner = OWN_HOST;
4598 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004599 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004600
James Smart75baf692010-06-08 18:31:21 -04004601 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004602 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004603 else
dea31012005-04-17 16:05:31 -05004604 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4605
4606 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004607 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004608 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004609 return NULL;
4610 }
4611
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004612 memset(hs, 0, sizeof (struct fc_host_statistics));
4613
dea31012005-04-17 16:05:31 -05004614 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4615 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4616 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4617 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4618
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004619 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004620 pmb->mbxCommand = MBX_READ_LNK_STAT;
4621 pmb->mbxOwner = OWN_HOST;
4622 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004623 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004624
James Smart75baf692010-06-08 18:31:21 -04004625 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004626 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004627 else
dea31012005-04-17 16:05:31 -05004628 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4629
4630 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004631 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004632 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004633 return NULL;
4634 }
4635
4636 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4637 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4638 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4639 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4640 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4641 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4642 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4643
James Smart64ba8812006-08-02 15:24:34 -04004644 hs->link_failure_count -= lso->link_failure_count;
4645 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4646 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4647 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4648 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4649 hs->invalid_crc_count -= lso->invalid_crc_count;
4650 hs->error_frames -= lso->error_frames;
4651
James Smart76a95d72010-11-20 23:11:48 -05004652 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004653 hs->lip_count = -1;
4654 hs->nos_count = (phba->link_events >> 1);
4655 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004656 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004657 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004658 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004659 hs->nos_count = -1;
4660 } else {
4661 hs->lip_count = -1;
4662 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004663 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004664 }
4665
4666 hs->dumped_frames = -1;
4667
James Smart64ba8812006-08-02 15:24:34 -04004668 seconds = get_seconds();
4669 if (seconds < psli->stats_start)
4670 hs->seconds_since_last_reset = seconds +
4671 ((unsigned long)-1 - psli->stats_start);
4672 else
4673 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004674
James Smart1dcb58e2007-04-25 09:51:30 -04004675 mempool_free(pmboxq, phba->mbox_mem_pool);
4676
dea31012005-04-17 16:05:31 -05004677 return hs;
4678}
4679
James Smarte59058c2008-08-24 21:49:00 -04004680/**
James Smart3621a712009-04-06 18:47:14 -04004681 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004682 * @shost: kernel scsi host pointer.
4683 **/
James Smart64ba8812006-08-02 15:24:34 -04004684static void
4685lpfc_reset_stats(struct Scsi_Host *shost)
4686{
James Smart2e0fef82007-06-17 19:56:36 -05004687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4688 struct lpfc_hba *phba = vport->phba;
4689 struct lpfc_sli *psli = &phba->sli;
4690 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004691 LPFC_MBOXQ_t *pmboxq;
4692 MAILBOX_t *pmb;
4693 int rc = 0;
4694
James Smart2e0fef82007-06-17 19:56:36 -05004695 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004696 return;
4697
James Smart64ba8812006-08-02 15:24:34 -04004698 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4699 if (!pmboxq)
4700 return;
4701 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4702
James Smart04c68492009-05-22 14:52:52 -04004703 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004704 pmb->mbxCommand = MBX_READ_STATUS;
4705 pmb->mbxOwner = OWN_HOST;
4706 pmb->un.varWords[0] = 0x1; /* reset request */
4707 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004708 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004709
James Smart2e0fef82007-06-17 19:56:36 -05004710 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004711 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004712 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4713 else
4714 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4715
4716 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004717 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004718 mempool_free(pmboxq, phba->mbox_mem_pool);
4719 return;
4720 }
4721
4722 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4723 pmb->mbxCommand = MBX_READ_LNK_STAT;
4724 pmb->mbxOwner = OWN_HOST;
4725 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004726 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004727
James Smart2e0fef82007-06-17 19:56:36 -05004728 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004729 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004730 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4731 else
4732 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4733
4734 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004735 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004736 mempool_free( pmboxq, phba->mbox_mem_pool);
4737 return;
4738 }
4739
4740 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4741 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4742 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4743 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4744 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4745 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4746 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004747 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004748 lso->link_events = (phba->link_events >> 1);
4749 else
4750 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004751
4752 psli->stats_start = get_seconds();
4753
James Smart1dcb58e2007-04-25 09:51:30 -04004754 mempool_free(pmboxq, phba->mbox_mem_pool);
4755
James Smart64ba8812006-08-02 15:24:34 -04004756 return;
4757}
dea31012005-04-17 16:05:31 -05004758
4759/*
4760 * The LPFC driver treats linkdown handling as target loss events so there
4761 * are no sysfs handlers for link_down_tmo.
4762 */
James Smart685f0bf2007-04-25 09:53:08 -04004763
James Smarte59058c2008-08-24 21:49:00 -04004764/**
James Smart3621a712009-04-06 18:47:14 -04004765 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004766 * @starget: kernel scsi target pointer.
4767 *
4768 * Returns:
4769 * address of the node list if found
4770 * NULL target not found
4771 **/
James Smart685f0bf2007-04-25 09:53:08 -04004772static struct lpfc_nodelist *
4773lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004774{
James Smart2e0fef82007-06-17 19:56:36 -05004775 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004777 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004778
4779 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004780 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004781 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004782 if (NLP_CHK_NODE_ACT(ndlp) &&
4783 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004784 starget->id == ndlp->nlp_sid) {
4785 spin_unlock_irq(shost->host_lock);
4786 return ndlp;
dea31012005-04-17 16:05:31 -05004787 }
4788 }
4789 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004790 return NULL;
4791}
dea31012005-04-17 16:05:31 -05004792
James Smarte59058c2008-08-24 21:49:00 -04004793/**
James Smart3621a712009-04-06 18:47:14 -04004794 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004795 * @starget: kernel scsi target pointer.
4796 **/
James Smart685f0bf2007-04-25 09:53:08 -04004797static void
4798lpfc_get_starget_port_id(struct scsi_target *starget)
4799{
4800 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4801
4802 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004803}
4804
James Smarte59058c2008-08-24 21:49:00 -04004805/**
James Smart3621a712009-04-06 18:47:14 -04004806 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004807 * @starget: kernel scsi target pointer.
4808 *
4809 * Description: Set the target node name to the ndlp node name wwn or zero.
4810 **/
dea31012005-04-17 16:05:31 -05004811static void
4812lpfc_get_starget_node_name(struct scsi_target *starget)
4813{
James Smart685f0bf2007-04-25 09:53:08 -04004814 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004815
James Smart685f0bf2007-04-25 09:53:08 -04004816 fc_starget_node_name(starget) =
4817 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004818}
4819
James Smarte59058c2008-08-24 21:49:00 -04004820/**
James Smart3621a712009-04-06 18:47:14 -04004821 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004822 * @starget: kernel scsi target pointer.
4823 *
4824 * Description: set the target port name to the ndlp port name wwn or zero.
4825 **/
dea31012005-04-17 16:05:31 -05004826static void
4827lpfc_get_starget_port_name(struct scsi_target *starget)
4828{
James Smart685f0bf2007-04-25 09:53:08 -04004829 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004830
James Smart685f0bf2007-04-25 09:53:08 -04004831 fc_starget_port_name(starget) =
4832 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004833}
4834
James Smarte59058c2008-08-24 21:49:00 -04004835/**
James Smart3621a712009-04-06 18:47:14 -04004836 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004837 * @rport: fc rport address.
4838 * @timeout: new value for dev loss tmo.
4839 *
4840 * Description:
4841 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4842 * dev_loss_tmo to one.
4843 **/
dea31012005-04-17 16:05:31 -05004844static void
dea31012005-04-17 16:05:31 -05004845lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4846{
dea31012005-04-17 16:05:31 -05004847 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004848 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004849 else
James Smartc01f3202006-08-18 17:47:08 -04004850 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004851}
4852
James Smarte59058c2008-08-24 21:49:00 -04004853/**
James Smart3621a712009-04-06 18:47:14 -04004854 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004855 *
4856 * Description:
4857 * Macro that uses field to generate a function with the name lpfc_show_rport_
4858 *
4859 * lpfc_show_rport_##field: returns the bytes formatted in buf
4860 * @cdev: class converted to an fc_rport.
4861 * @buf: on return contains the target_field or zero.
4862 *
4863 * Returns: size of formatted string.
4864 **/
dea31012005-04-17 16:05:31 -05004865#define lpfc_rport_show_function(field, format_string, sz, cast) \
4866static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004867lpfc_show_rport_##field (struct device *dev, \
4868 struct device_attribute *attr, \
4869 char *buf) \
dea31012005-04-17 16:05:31 -05004870{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004871 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004872 struct lpfc_rport_data *rdata = rport->hostdata; \
4873 return snprintf(buf, sz, format_string, \
4874 (rdata->target) ? cast rdata->target->field : 0); \
4875}
4876
4877#define lpfc_rport_rd_attr(field, format_string, sz) \
4878 lpfc_rport_show_function(field, format_string, sz, ) \
4879static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4880
James Smarteada2722008-12-04 22:39:13 -05004881/**
James Smart3621a712009-04-06 18:47:14 -04004882 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004883 * @fc_vport: The fc_vport who's symbolic name has been changed.
4884 *
4885 * Description:
4886 * This function is called by the transport after the @fc_vport's symbolic name
4887 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004888 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004889 **/
4890static void
4891lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4892{
4893 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4894
4895 if (vport->port_state == LPFC_VPORT_READY)
4896 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4897}
dea31012005-04-17 16:05:31 -05004898
James Smartf4b4c682009-05-22 14:53:12 -04004899/**
4900 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4901 * @phba: Pointer to lpfc_hba struct.
4902 *
4903 * This function is called by the lpfc_get_cfgparam() routine to set the
4904 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004905 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004906 * before hba port or vport created.
4907 **/
4908static void
4909lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4910{
4911 phba->cfg_log_verbose = verbose;
4912}
4913
dea31012005-04-17 16:05:31 -05004914struct fc_function_template lpfc_transport_functions = {
4915 /* fixed attributes the driver supports */
4916 .show_host_node_name = 1,
4917 .show_host_port_name = 1,
4918 .show_host_supported_classes = 1,
4919 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004920 .show_host_supported_speeds = 1,
4921 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004922 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004923
4924 /* dynamic attributes the driver supports */
4925 .get_host_port_id = lpfc_get_host_port_id,
4926 .show_host_port_id = 1,
4927
4928 .get_host_port_type = lpfc_get_host_port_type,
4929 .show_host_port_type = 1,
4930
4931 .get_host_port_state = lpfc_get_host_port_state,
4932 .show_host_port_state = 1,
4933
4934 /* active_fc4s is shown but doesn't change (thus no get function) */
4935 .show_host_active_fc4s = 1,
4936
4937 .get_host_speed = lpfc_get_host_speed,
4938 .show_host_speed = 1,
4939
4940 .get_host_fabric_name = lpfc_get_host_fabric_name,
4941 .show_host_fabric_name = 1,
4942
4943 /*
4944 * The LPFC driver treats linkdown handling as target loss events
4945 * so there are no sysfs handlers for link_down_tmo.
4946 */
4947
4948 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004949 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004950
4951 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4952 .show_rport_maxframe_size = 1,
4953 .show_rport_supported_classes = 1,
4954
dea31012005-04-17 16:05:31 -05004955 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4956 .show_rport_dev_loss_tmo = 1,
4957
4958 .get_starget_port_id = lpfc_get_starget_port_id,
4959 .show_starget_port_id = 1,
4960
4961 .get_starget_node_name = lpfc_get_starget_node_name,
4962 .show_starget_node_name = 1,
4963
4964 .get_starget_port_name = lpfc_get_starget_port_name,
4965 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004966
4967 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004968 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4969 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004970
James Smart92d7f7b2007-06-17 19:56:38 -05004971 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004972
4973 .vport_disable = lpfc_vport_disable,
4974
4975 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004976
4977 .bsg_request = lpfc_bsg_request,
4978 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004979};
4980
James Smart98c9ea52007-10-27 13:37:33 -04004981struct fc_function_template lpfc_vport_transport_functions = {
4982 /* fixed attributes the driver supports */
4983 .show_host_node_name = 1,
4984 .show_host_port_name = 1,
4985 .show_host_supported_classes = 1,
4986 .show_host_supported_fc4s = 1,
4987 .show_host_supported_speeds = 1,
4988 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004989 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004990
4991 /* dynamic attributes the driver supports */
4992 .get_host_port_id = lpfc_get_host_port_id,
4993 .show_host_port_id = 1,
4994
4995 .get_host_port_type = lpfc_get_host_port_type,
4996 .show_host_port_type = 1,
4997
4998 .get_host_port_state = lpfc_get_host_port_state,
4999 .show_host_port_state = 1,
5000
5001 /* active_fc4s is shown but doesn't change (thus no get function) */
5002 .show_host_active_fc4s = 1,
5003
5004 .get_host_speed = lpfc_get_host_speed,
5005 .show_host_speed = 1,
5006
5007 .get_host_fabric_name = lpfc_get_host_fabric_name,
5008 .show_host_fabric_name = 1,
5009
5010 /*
5011 * The LPFC driver treats linkdown handling as target loss events
5012 * so there are no sysfs handlers for link_down_tmo.
5013 */
5014
5015 .get_fc_host_stats = lpfc_get_stats,
5016 .reset_fc_host_stats = lpfc_reset_stats,
5017
5018 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5019 .show_rport_maxframe_size = 1,
5020 .show_rport_supported_classes = 1,
5021
5022 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5023 .show_rport_dev_loss_tmo = 1,
5024
5025 .get_starget_port_id = lpfc_get_starget_port_id,
5026 .show_starget_port_id = 1,
5027
5028 .get_starget_node_name = lpfc_get_starget_node_name,
5029 .show_starget_node_name = 1,
5030
5031 .get_starget_port_name = lpfc_get_starget_port_name,
5032 .show_starget_port_name = 1,
5033
5034 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5035 .terminate_rport_io = lpfc_terminate_rport_io,
5036
5037 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005038
5039 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005040};
5041
James Smarte59058c2008-08-24 21:49:00 -04005042/**
James Smart3621a712009-04-06 18:47:14 -04005043 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005044 * @phba: lpfc_hba pointer.
5045 **/
dea31012005-04-17 16:05:31 -05005046void
5047lpfc_get_cfgparam(struct lpfc_hba *phba)
5048{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005049 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5050 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005051 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005052 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5053 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005054 lpfc_ack0_init(phba, lpfc_ack0);
5055 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005056 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005057 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005058 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart19ca7602010-11-20 23:11:55 -05005059 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005060 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005061 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5062 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5063 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05005064 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5065 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005066 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005067 if (phba->sli_rev == LPFC_SLI_REV4)
5068 phba->cfg_poll = 0;
5069 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005070 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005071 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005072 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005073 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005074 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005075 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005076 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005077 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005078 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smart84d1b002010-02-12 14:42:33 -05005079 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005080 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005081 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005082 return;
5083}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005084
James Smarte59058c2008-08-24 21:49:00 -04005085/**
James Smart3621a712009-04-06 18:47:14 -04005086 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005087 * @vport: lpfc_vport pointer.
5088 **/
James Smart3de2a652007-08-02 11:09:59 -04005089void
5090lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5091{
James Smarte8b62012007-08-02 11:10:09 -04005092 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005093 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005094 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005095 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5096 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5097 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5098 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5099 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5100 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005101 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005102 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5103 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5104 lpfc_max_luns_init(vport, lpfc_max_luns);
5105 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005106 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005107 return;
5108}