blob: 45bd72a9f60e38c400bf5e9735e1b17396a7f1a7 [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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;
626
627 init_completion(&online_compl);
628 lpfc_workq_post_event(phba, &status, &online_compl,
629 LPFC_EVT_OFFLINE_PREP);
630 wait_for_completion(&online_compl);
631
632 if (status != 0)
633 return -EIO;
634
635 psli = &phba->sli;
636
James Smart09372822008-01-11 01:52:54 -0500637 /* Wait a little for things to settle down, but not
638 * long enough for dev loss timeout to expire.
639 */
James Smart46fa3112007-04-25 09:51:45 -0400640 for (i = 0; i < psli->num_rings; i++) {
641 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400642 while (pring->txcmplq_cnt) {
643 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500644 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400645 lpfc_printf_log(phba,
646 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400647 "0466 Outstanding IO when "
648 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400649 break;
650 }
651 }
652 }
653
654 init_completion(&online_compl);
655 lpfc_workq_post_event(phba, &status, &online_compl, type);
656 wait_for_completion(&online_compl);
657
658 if (status != 0)
659 return -EIO;
660
661 return 0;
662}
663
James Smarte59058c2008-08-24 21:49:00 -0400664/**
James Smart3621a712009-04-06 18:47:14 -0400665 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400666 * @phba: lpfc_hba pointer.
667 *
668 * Description:
669 * If the port is configured to allow a reset then the hba is brought
670 * offline then online.
671 *
672 * Notes:
673 * Assumes any error from lpfc_do_offline() will be negative.
674 *
675 * Returns:
676 * lpfc_do_offline() return code if not zero
677 * -EIO reset not configured or error posting the event
678 * zero for success
679 **/
James Smart46fa3112007-04-25 09:51:45 -0400680static int
James Smart40496f02006-07-06 15:50:22 -0400681lpfc_selective_reset(struct lpfc_hba *phba)
682{
683 struct completion online_compl;
684 int status = 0;
685
James Smart13815c82008-01-11 01:52:48 -0500686 if (!phba->cfg_enable_hba_reset)
687 return -EIO;
688
James Smart46fa3112007-04-25 09:51:45 -0400689 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400690
691 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400692 return status;
James Smart40496f02006-07-06 15:50:22 -0400693
694 init_completion(&online_compl);
695 lpfc_workq_post_event(phba, &status, &online_compl,
696 LPFC_EVT_ONLINE);
697 wait_for_completion(&online_compl);
698
699 if (status != 0)
700 return -EIO;
701
702 return 0;
703}
704
James Smarte59058c2008-08-24 21:49:00 -0400705/**
James Smart3621a712009-04-06 18:47:14 -0400706 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400707 * @dev: class device that is converted into a Scsi_host.
708 * @attr: device attribute, not used.
709 * @buf: containing the string "selective".
710 * @count: unused variable.
711 *
712 * Description:
713 * If the buf contains the string "selective" then lpfc_selective_reset()
714 * is called to perform the reset.
715 *
716 * Notes:
717 * Assumes any error from lpfc_selective_reset() will be negative.
718 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200719 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400720 *
721 * Returns:
722 * -EINVAL if the buffer does not contain the string "selective"
723 * length of buf if lpfc-selective_reset() if the call succeeds
724 * return value of lpfc_selective_reset() if the call fails
725**/
James Smart40496f02006-07-06 15:50:22 -0400726static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100727lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
728 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400729{
Tony Jonesee959b02008-02-22 00:13:36 +0100730 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
732 struct lpfc_hba *phba = vport->phba;
733
James Smart40496f02006-07-06 15:50:22 -0400734 int status = -EINVAL;
735
736 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
737 status = lpfc_selective_reset(phba);
738
739 if (status == 0)
740 return strlen(buf);
741 else
742 return status;
743}
744
James Smarte59058c2008-08-24 21:49:00 -0400745/**
James Smart3621a712009-04-06 18:47:14 -0400746 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400747 * @dev: class device that is converted into a Scsi_host.
748 * @attr: device attribute, not used.
749 * @buf: on return contains the ascii number of nport events.
750 *
751 * Returns: size of formatted string.
752 **/
dea31012005-04-17 16:05:31 -0500753static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100754lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
755 char *buf)
dea31012005-04-17 16:05:31 -0500756{
Tony Jonesee959b02008-02-22 00:13:36 +0100757 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 struct lpfc_hba *phba = vport->phba;
760
dea31012005-04-17 16:05:31 -0500761 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
762}
763
James Smarte59058c2008-08-24 21:49:00 -0400764/**
James Smart3621a712009-04-06 18:47:14 -0400765 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400766 * @dev: class device that is converted into a Scsi_host.
767 * @attr: device attribute, not used.
768 * @buf: on return contains the state of the adapter.
769 *
770 * Returns: size of formatted string.
771 **/
dea31012005-04-17 16:05:31 -0500772static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100773lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
774 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500775{
Tony Jonesee959b02008-02-22 00:13:36 +0100776 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
778 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500779 char * state;
780
James Smart2e0fef82007-06-17 19:56:36 -0500781 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500782 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500783 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500784 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500785 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500786 state = "offline";
787 else
788 state = "online";
789
790 return snprintf(buf, PAGE_SIZE, "%s\n", state);
791}
792
James Smarte59058c2008-08-24 21:49:00 -0400793/**
James Smart3621a712009-04-06 18:47:14 -0400794 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400795 * @dev: class device that is converted into a Scsi_host.
796 * @attr: device attribute, not used.
797 * @buf: containing one of the strings "online", "offline", "warm" or "error".
798 * @count: unused variable.
799 *
800 * Returns:
801 * -EACCES if enable hba reset not enabled
802 * -EINVAL if the buffer does not contain a valid string (see above)
803 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
804 * buf length greater than zero indicates success
805 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500806static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100807lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
808 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500809{
Tony Jonesee959b02008-02-22 00:13:36 +0100810 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500813 struct completion online_compl;
814 int status=0;
815
James Smart13815c82008-01-11 01:52:48 -0500816 if (!phba->cfg_enable_hba_reset)
817 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500818 init_completion(&online_compl);
819
James Smart46fa3112007-04-25 09:51:45 -0400820 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500821 lpfc_workq_post_event(phba, &status, &online_compl,
822 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400823 wait_for_completion(&online_compl);
824 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
825 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500826 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400827 if (phba->sli_rev == LPFC_SLI_REV4)
828 return -EINVAL;
829 else
830 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400831 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400832 if (phba->sli_rev == LPFC_SLI_REV4)
833 return -EINVAL;
834 else
835 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500836 else
837 return -EINVAL;
838
Jamie Wellnitz41415862006-02-28 19:25:27 -0500839 if (!status)
840 return strlen(buf);
841 else
842 return -EIO;
843}
844
James Smarte59058c2008-08-24 21:49:00 -0400845/**
James Smart3621a712009-04-06 18:47:14 -0400846 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400847 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400848 * @mxri: max xri count.
849 * @axri: available xri count.
850 * @mrpi: max rpi count.
851 * @arpi: available rpi count.
852 * @mvpi: max vpi count.
853 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400854 *
855 * Description:
856 * If an integer pointer for an count is not null then the value for the
857 * count is returned.
858 *
859 * Returns:
860 * zero on error
861 * one for success
862 **/
James Smart311464e2007-08-02 11:10:37 -0400863static int
James Smart858c9f62007-06-17 19:56:39 -0500864lpfc_get_hba_info(struct lpfc_hba *phba,
865 uint32_t *mxri, uint32_t *axri,
866 uint32_t *mrpi, uint32_t *arpi,
867 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500868{
James Smart04c68492009-05-22 14:52:52 -0400869 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500870 LPFC_MBOXQ_t *pmboxq;
871 MAILBOX_t *pmb;
872 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400873 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500874
875 /*
876 * prevent udev from issuing mailbox commands until the port is
877 * configured.
878 */
879 if (phba->link_state < LPFC_LINK_DOWN ||
880 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400881 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500882 return 0;
883
884 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
885 return 0;
886
887 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
888 if (!pmboxq)
889 return 0;
890 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
891
James Smart04c68492009-05-22 14:52:52 -0400892 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500893 pmb->mbxCommand = MBX_READ_CONFIG;
894 pmb->mbxOwner = OWN_HOST;
895 pmboxq->context1 = NULL;
896
James Smart75baf692010-06-08 18:31:21 -0400897 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500898 rc = MBX_NOT_FINISHED;
899 else
900 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
901
902 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500903 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500904 mempool_free(pmboxq, phba->mbox_mem_pool);
905 return 0;
906 }
907
James Smartda0436e2009-05-22 14:51:39 -0400908 if (phba->sli_rev == LPFC_SLI_REV4) {
909 rd_config = &pmboxq->u.mqe.un.rd_config;
910 if (mrpi)
911 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
912 if (arpi)
913 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
914 phba->sli4_hba.max_cfg_param.rpi_used;
915 if (mxri)
916 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
917 if (axri)
918 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
919 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400920
921 /* Account for differences with SLI-3. Get vpi count from
922 * mailbox data and subtract one for max vpi value.
923 */
924 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
925 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
926
James Smartda0436e2009-05-22 14:51:39 -0400927 if (mvpi)
James Smart15672312010-04-06 14:49:03 -0400928 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -0400929 if (avpi)
James Smart15672312010-04-06 14:49:03 -0400930 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -0400931 } else {
932 if (mrpi)
933 *mrpi = pmb->un.varRdConfig.max_rpi;
934 if (arpi)
935 *arpi = pmb->un.varRdConfig.avail_rpi;
936 if (mxri)
937 *mxri = pmb->un.varRdConfig.max_xri;
938 if (axri)
939 *axri = pmb->un.varRdConfig.avail_xri;
940 if (mvpi)
941 *mvpi = pmb->un.varRdConfig.max_vpi;
942 if (avpi)
943 *avpi = pmb->un.varRdConfig.avail_vpi;
944 }
James Smart92d7f7b2007-06-17 19:56:38 -0500945
946 mempool_free(pmboxq, phba->mbox_mem_pool);
947 return 1;
948}
949
James Smarte59058c2008-08-24 21:49:00 -0400950/**
James Smart3621a712009-04-06 18:47:14 -0400951 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400952 * @dev: class device that is converted into a Scsi_host.
953 * @attr: device attribute, not used.
954 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
955 *
956 * Description:
957 * Calls lpfc_get_hba_info() asking for just the mrpi count.
958 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
959 * to "Unknown" and the buffer length is returned, therefore the caller
960 * must check for "Unknown" in the buffer to detect a failure.
961 *
962 * Returns: size of formatted string.
963 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500964static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100965lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
966 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500967{
Tony Jonesee959b02008-02-22 00:13:36 +0100968 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
970 struct lpfc_hba *phba = vport->phba;
971 uint32_t cnt;
972
James Smart858c9f62007-06-17 19:56:39 -0500973 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500974 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
975 return snprintf(buf, PAGE_SIZE, "Unknown\n");
976}
977
James Smarte59058c2008-08-24 21:49:00 -0400978/**
James Smart3621a712009-04-06 18:47:14 -0400979 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400980 * @dev: class device that is converted into a Scsi_host.
981 * @attr: device attribute, not used.
982 * @buf: containing the used rpi count in decimal or "Unknown".
983 *
984 * Description:
985 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
986 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
987 * to "Unknown" and the buffer length is returned, therefore the caller
988 * must check for "Unknown" in the buffer to detect a failure.
989 *
990 * Returns: size of formatted string.
991 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500992static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100993lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
994 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500995{
Tony Jonesee959b02008-02-22 00:13:36 +0100996 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
998 struct lpfc_hba *phba = vport->phba;
999 uint32_t cnt, acnt;
1000
James Smart858c9f62007-06-17 19:56:39 -05001001 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001002 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1003 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1004}
1005
James Smarte59058c2008-08-24 21:49:00 -04001006/**
James Smart3621a712009-04-06 18:47:14 -04001007 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001008 * @dev: class device that is converted into a Scsi_host.
1009 * @attr: device attribute, not used.
1010 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1011 *
1012 * Description:
1013 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1014 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1015 * to "Unknown" and the buffer length is returned, therefore the caller
1016 * must check for "Unknown" in the buffer to detect a failure.
1017 *
1018 * Returns: size of formatted string.
1019 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001020static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001021lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1022 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001023{
Tony Jonesee959b02008-02-22 00:13:36 +01001024 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001025 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1026 struct lpfc_hba *phba = vport->phba;
1027 uint32_t cnt;
1028
James Smart858c9f62007-06-17 19:56:39 -05001029 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001030 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1031 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1032}
1033
James Smarte59058c2008-08-24 21:49:00 -04001034/**
James Smart3621a712009-04-06 18:47:14 -04001035 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001036 * @dev: class device that is converted into a Scsi_host.
1037 * @attr: device attribute, not used.
1038 * @buf: on return contains the used xri count in decimal or "Unknown".
1039 *
1040 * Description:
1041 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1042 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1043 * to "Unknown" and the buffer length is returned, therefore the caller
1044 * must check for "Unknown" in the buffer to detect a failure.
1045 *
1046 * Returns: size of formatted string.
1047 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001048static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001049lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1050 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001051{
Tony Jonesee959b02008-02-22 00:13:36 +01001052 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1054 struct lpfc_hba *phba = vport->phba;
1055 uint32_t cnt, acnt;
1056
James Smart858c9f62007-06-17 19:56:39 -05001057 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1058 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1059 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1060}
1061
James Smarte59058c2008-08-24 21:49:00 -04001062/**
James Smart3621a712009-04-06 18:47:14 -04001063 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001064 * @dev: class device that is converted into a Scsi_host.
1065 * @attr: device attribute, not used.
1066 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1067 *
1068 * Description:
1069 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1070 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1071 * to "Unknown" and the buffer length is returned, therefore the caller
1072 * must check for "Unknown" in the buffer to detect a failure.
1073 *
1074 * Returns: size of formatted string.
1075 **/
James Smart858c9f62007-06-17 19:56:39 -05001076static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001077lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1078 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001079{
Tony Jonesee959b02008-02-22 00:13:36 +01001080 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1082 struct lpfc_hba *phba = vport->phba;
1083 uint32_t cnt;
1084
1085 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1086 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1087 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1088}
1089
James Smarte59058c2008-08-24 21:49:00 -04001090/**
James Smart3621a712009-04-06 18:47:14 -04001091 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001092 * @dev: class device that is converted into a Scsi_host.
1093 * @attr: device attribute, not used.
1094 * @buf: on return contains the used vpi count in decimal or "Unknown".
1095 *
1096 * Description:
1097 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1098 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1099 * to "Unknown" and the buffer length is returned, therefore the caller
1100 * must check for "Unknown" in the buffer to detect a failure.
1101 *
1102 * Returns: size of formatted string.
1103 **/
James Smart858c9f62007-06-17 19:56:39 -05001104static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001105lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1106 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001107{
Tony Jonesee959b02008-02-22 00:13:36 +01001108 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1110 struct lpfc_hba *phba = vport->phba;
1111 uint32_t cnt, acnt;
1112
1113 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001114 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1115 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1116}
1117
James Smarte59058c2008-08-24 21:49:00 -04001118/**
James Smart3621a712009-04-06 18:47:14 -04001119 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001120 * @dev: class device that is converted into a Scsi_host.
1121 * @attr: device attribute, not used.
1122 * @buf: text that must be interpreted to determine if npiv is supported.
1123 *
1124 * Description:
1125 * Buffer will contain text indicating npiv is not suppoerted on the port,
1126 * the port is an NPIV physical port, or it is an npiv virtual port with
1127 * the id of the vport.
1128 *
1129 * Returns: size of formatted string.
1130 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001131static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001132lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1133 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001134{
Tony Jonesee959b02008-02-22 00:13:36 +01001135 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1137 struct lpfc_hba *phba = vport->phba;
1138
1139 if (!(phba->max_vpi))
1140 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1141 if (vport->port_type == LPFC_PHYSICAL_PORT)
1142 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1143 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1144}
1145
James Smarte59058c2008-08-24 21:49:00 -04001146/**
James Smart3621a712009-04-06 18:47:14 -04001147 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001148 * @dev: class device that is converted into a Scsi_host.
1149 * @attr: device attribute, not used.
1150 * @buf: on return contains the cfg_poll in hex.
1151 *
1152 * Notes:
1153 * cfg_poll should be a lpfc_polling_flags type.
1154 *
1155 * Returns: size of formatted string.
1156 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001157static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001158lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1159 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001160{
Tony Jonesee959b02008-02-22 00:13:36 +01001161 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1163 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001164
1165 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1166}
1167
James Smarte59058c2008-08-24 21:49:00 -04001168/**
James Smart3621a712009-04-06 18:47:14 -04001169 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001170 * @dev: class device that is converted into a Scsi_host.
1171 * @attr: device attribute, not used.
1172 * @buf: one or more lpfc_polling_flags values.
1173 * @count: not used.
1174 *
1175 * Notes:
1176 * buf contents converted to integer and checked for a valid value.
1177 *
1178 * Returns:
1179 * -EINVAL if the buffer connot be converted or is out of range
1180 * length of the buf on success
1181 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001182static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001183lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1184 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001185{
Tony Jonesee959b02008-02-22 00:13:36 +01001186 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001187 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1188 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001189 uint32_t creg_val;
1190 uint32_t old_val;
1191 int val=0;
1192
1193 if (!isdigit(buf[0]))
1194 return -EINVAL;
1195
1196 if (sscanf(buf, "%i", &val) != 1)
1197 return -EINVAL;
1198
1199 if ((val & 0x3) != val)
1200 return -EINVAL;
1201
James Smart45ed1192009-10-02 15:17:02 -04001202 if (phba->sli_rev == LPFC_SLI_REV4)
1203 val = 0;
1204
James Smart2e0fef82007-06-17 19:56:36 -05001205 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001206
1207 old_val = phba->cfg_poll;
1208
1209 if (val & ENABLE_FCP_RING_POLLING) {
1210 if ((val & DISABLE_FCP_RING_INT) &&
1211 !(old_val & DISABLE_FCP_RING_INT)) {
1212 creg_val = readl(phba->HCregaddr);
1213 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1214 writel(creg_val, phba->HCregaddr);
1215 readl(phba->HCregaddr); /* flush */
1216
1217 lpfc_poll_start_timer(phba);
1218 }
1219 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001220 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001221 return -EINVAL;
1222 }
1223
1224 if (!(val & DISABLE_FCP_RING_INT) &&
1225 (old_val & DISABLE_FCP_RING_INT))
1226 {
James Smart2e0fef82007-06-17 19:56:36 -05001227 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001228 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001229 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001230 creg_val = readl(phba->HCregaddr);
1231 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1232 writel(creg_val, phba->HCregaddr);
1233 readl(phba->HCregaddr); /* flush */
1234 }
1235
1236 phba->cfg_poll = val;
1237
James Smart2e0fef82007-06-17 19:56:36 -05001238 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001239
1240 return strlen(buf);
1241}
dea31012005-04-17 16:05:31 -05001242
James Smarte59058c2008-08-24 21:49:00 -04001243/**
James Smartbc739052010-08-04 16:11:18 -04001244 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1245 * @dev: class unused variable.
1246 * @attr: device attribute, not used.
1247 * @buf: on return contains the module description text.
1248 *
1249 * Returns: size of formatted string.
1250 **/
1251static ssize_t
1252lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1253 char *buf)
1254{
1255 struct Scsi_Host *shost = class_to_shost(dev);
1256 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1257 struct lpfc_hba *phba = vport->phba;
1258
1259 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1260}
1261
1262/**
1263 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1264 * @dev: class unused variable.
1265 * @attr: device attribute, not used.
1266 * @buf: on return contains the module description text.
1267 *
1268 * Returns: size of formatted string.
1269 **/
1270static ssize_t
1271lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1272 char *buf)
1273{
1274 struct Scsi_Host *shost = class_to_shost(dev);
1275 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1276 struct lpfc_hba *phba = vport->phba;
1277
1278 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1279}
1280
1281/**
James Smart3621a712009-04-06 18:47:14 -04001282 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001283 *
1284 * Description:
1285 * Macro that given an attr e.g. hba_queue_depth expands
1286 * into a function with the name lpfc_hba_queue_depth_show.
1287 *
1288 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1289 * @dev: class device that is converted into a Scsi_host.
1290 * @attr: device attribute, not used.
1291 * @buf: on return contains the attribute value in decimal.
1292 *
1293 * Returns: size of formatted string.
1294 **/
dea31012005-04-17 16:05:31 -05001295#define lpfc_param_show(attr) \
1296static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001297lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1298 char *buf) \
dea31012005-04-17 16:05:31 -05001299{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001300 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1302 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001303 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001304 val = phba->cfg_##attr;\
1305 return snprintf(buf, PAGE_SIZE, "%d\n",\
1306 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001307}
1308
James Smarte59058c2008-08-24 21:49:00 -04001309/**
James Smart3621a712009-04-06 18:47:14 -04001310 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001311 *
1312 * Description:
1313 * Macro that given an attr e.g. hba_queue_depth expands
1314 * into a function with the name lpfc_hba_queue_depth_show
1315 *
1316 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1317 * @dev: class device that is converted into a Scsi_host.
1318 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001319 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001320 *
1321 * Returns: size of formatted string.
1322 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001323#define lpfc_param_hex_show(attr) \
1324static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001325lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1326 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001327{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001328 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001329 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1330 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001331 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001332 val = phba->cfg_##attr;\
1333 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1334 phba->cfg_##attr);\
1335}
1336
James Smarte59058c2008-08-24 21:49:00 -04001337/**
James Smart3621a712009-04-06 18:47:14 -04001338 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001339 *
1340 * Description:
1341 * Macro that given an attr e.g. hba_queue_depth expands
1342 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1343 * takes a default argument, a minimum and maximum argument.
1344 *
1345 * lpfc_##attr##_init: Initializes an attribute.
1346 * @phba: pointer the the adapter structure.
1347 * @val: integer attribute value.
1348 *
1349 * Validates the min and max values then sets the adapter config field
1350 * accordingly, or uses the default if out of range and prints an error message.
1351 *
1352 * Returns:
1353 * zero on success
1354 * -EINVAL if default used
1355 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001356#define lpfc_param_init(attr, default, minval, maxval) \
1357static int \
James Smart84d1b002010-02-12 14:42:33 -05001358lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001359{ \
1360 if (val >= minval && val <= maxval) {\
1361 phba->cfg_##attr = val;\
1362 return 0;\
1363 }\
1364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001365 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1366 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001367 phba->cfg_##attr = default;\
1368 return -EINVAL;\
1369}
1370
James Smarte59058c2008-08-24 21:49:00 -04001371/**
James Smart3621a712009-04-06 18:47:14 -04001372 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001373 *
1374 * Description:
1375 * Macro that given an attr e.g. hba_queue_depth expands
1376 * into a function with the name lpfc_hba_queue_depth_set
1377 *
1378 * lpfc_##attr##_set: Sets an attribute value.
1379 * @phba: pointer the the adapter structure.
1380 * @val: integer attribute value.
1381 *
1382 * Description:
1383 * Validates the min and max values then sets the
1384 * adapter config field if in the valid range. prints error message
1385 * and does not set the parameter if invalid.
1386 *
1387 * Returns:
1388 * zero on success
1389 * -EINVAL if val is invalid
1390 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001391#define lpfc_param_set(attr, default, minval, maxval) \
1392static int \
James Smart84d1b002010-02-12 14:42:33 -05001393lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001394{ \
1395 if (val >= minval && val <= maxval) {\
1396 phba->cfg_##attr = val;\
1397 return 0;\
1398 }\
1399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001400 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1401 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001402 return -EINVAL;\
1403}
1404
James Smarte59058c2008-08-24 21:49:00 -04001405/**
James Smart3621a712009-04-06 18:47:14 -04001406 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001407 *
1408 * Description:
1409 * Macro that given an attr e.g. hba_queue_depth expands
1410 * into a function with the name lpfc_hba_queue_depth_store.
1411 *
1412 * lpfc_##attr##_store: Set an sttribute value.
1413 * @dev: class device that is converted into a Scsi_host.
1414 * @attr: device attribute, not used.
1415 * @buf: contains the attribute value in ascii.
1416 * @count: not used.
1417 *
1418 * Description:
1419 * Convert the ascii text number to an integer, then
1420 * use the lpfc_##attr##_set function to set the value.
1421 *
1422 * Returns:
1423 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1424 * length of buffer upon success.
1425 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001426#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001427static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001428lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1429 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001430{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001431 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1433 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001434 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001435 if (!isdigit(buf[0]))\
1436 return -EINVAL;\
1437 if (sscanf(buf, "%i", &val) != 1)\
1438 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001439 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001440 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001441 else \
1442 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001443}
1444
James Smarte59058c2008-08-24 21:49:00 -04001445/**
James Smart3621a712009-04-06 18:47:14 -04001446 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001447 *
1448 * Description:
1449 * Macro that given an attr e.g. hba_queue_depth expands
1450 * into a function with the name lpfc_hba_queue_depth_show
1451 *
1452 * lpfc_##attr##_show: prints the attribute value in decimal.
1453 * @dev: class device that is converted into a Scsi_host.
1454 * @attr: device attribute, not used.
1455 * @buf: on return contains the attribute value in decimal.
1456 *
1457 * Returns: length of formatted string.
1458 **/
James Smart3de2a652007-08-02 11:09:59 -04001459#define lpfc_vport_param_show(attr) \
1460static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001461lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1462 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001463{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001464 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001465 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001466 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001467 val = vport->cfg_##attr;\
1468 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1469}
1470
James Smarte59058c2008-08-24 21:49:00 -04001471/**
James Smart3621a712009-04-06 18:47:14 -04001472 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001473 *
1474 * Description:
1475 * Macro that given an attr e.g.
1476 * hba_queue_depth expands into a function with the name
1477 * lpfc_hba_queue_depth_show
1478 *
James Smart3621a712009-04-06 18:47:14 -04001479 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001480 * @dev: class device that is converted into a Scsi_host.
1481 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001482 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001483 *
1484 * Returns: length of formatted string.
1485 **/
James Smart3de2a652007-08-02 11:09:59 -04001486#define lpfc_vport_param_hex_show(attr) \
1487static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001488lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1489 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001490{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001491 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001493 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001494 val = vport->cfg_##attr;\
1495 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1496}
1497
James Smarte59058c2008-08-24 21:49:00 -04001498/**
James Smart3621a712009-04-06 18:47:14 -04001499 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001500 *
1501 * Description:
1502 * Macro that given an attr e.g. hba_queue_depth expands
1503 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1504 * takes a default argument, a minimum and maximum argument.
1505 *
1506 * lpfc_##attr##_init: validates the min and max values then sets the
1507 * adapter config field accordingly, or uses the default if out of range
1508 * and prints an error message.
1509 * @phba: pointer the the adapter structure.
1510 * @val: integer attribute value.
1511 *
1512 * Returns:
1513 * zero on success
1514 * -EINVAL if default used
1515 **/
James Smart3de2a652007-08-02 11:09:59 -04001516#define lpfc_vport_param_init(attr, default, minval, maxval) \
1517static int \
James Smart84d1b002010-02-12 14:42:33 -05001518lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001519{ \
1520 if (val >= minval && val <= maxval) {\
1521 vport->cfg_##attr = val;\
1522 return 0;\
1523 }\
James Smarte8b62012007-08-02 11:10:09 -04001524 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001525 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001526 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001527 vport->cfg_##attr = default;\
1528 return -EINVAL;\
1529}
1530
James Smarte59058c2008-08-24 21:49:00 -04001531/**
James Smart3621a712009-04-06 18:47:14 -04001532 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001533 *
1534 * Description:
1535 * Macro that given an attr e.g. hba_queue_depth expands
1536 * into a function with the name lpfc_hba_queue_depth_set
1537 *
1538 * lpfc_##attr##_set: validates the min and max values then sets the
1539 * adapter config field if in the valid range. prints error message
1540 * and does not set the parameter if invalid.
1541 * @phba: pointer the the adapter structure.
1542 * @val: integer attribute value.
1543 *
1544 * Returns:
1545 * zero on success
1546 * -EINVAL if val is invalid
1547 **/
James Smart3de2a652007-08-02 11:09:59 -04001548#define lpfc_vport_param_set(attr, default, minval, maxval) \
1549static int \
James Smart84d1b002010-02-12 14:42:33 -05001550lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001551{ \
1552 if (val >= minval && val <= maxval) {\
1553 vport->cfg_##attr = val;\
1554 return 0;\
1555 }\
James Smarte8b62012007-08-02 11:10:09 -04001556 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001557 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001558 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001559 return -EINVAL;\
1560}
1561
James Smarte59058c2008-08-24 21:49:00 -04001562/**
James Smart3621a712009-04-06 18:47:14 -04001563 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001564 *
1565 * Description:
1566 * Macro that given an attr e.g. hba_queue_depth
1567 * expands into a function with the name lpfc_hba_queue_depth_store
1568 *
1569 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1570 * use the lpfc_##attr##_set function to set the value.
1571 * @cdev: class device that is converted into a Scsi_host.
1572 * @buf: contains the attribute value in decimal.
1573 * @count: not used.
1574 *
1575 * Returns:
1576 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1577 * length of buffer upon success.
1578 **/
James Smart3de2a652007-08-02 11:09:59 -04001579#define lpfc_vport_param_store(attr) \
1580static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001581lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1582 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001583{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001584 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001585 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001586 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001587 if (!isdigit(buf[0]))\
1588 return -EINVAL;\
1589 if (sscanf(buf, "%i", &val) != 1)\
1590 return -EINVAL;\
1591 if (lpfc_##attr##_set(vport, val) == 0) \
1592 return strlen(buf);\
1593 else \
1594 return -EINVAL;\
1595}
1596
1597
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001598#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001599static uint lpfc_##name = defval;\
1600module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001601MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001602lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001603
1604#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001605static uint lpfc_##name = defval;\
1606module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001607MODULE_PARM_DESC(lpfc_##name, desc);\
1608lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001609lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001610static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001611
1612#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001613static uint lpfc_##name = defval;\
1614module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001615MODULE_PARM_DESC(lpfc_##name, desc);\
1616lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001617lpfc_param_init(name, defval, minval, maxval)\
1618lpfc_param_set(name, defval, minval, maxval)\
1619lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001620static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1621 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001622
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001623#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001624static uint lpfc_##name = defval;\
1625module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001626MODULE_PARM_DESC(lpfc_##name, desc);\
1627lpfc_param_hex_show(name)\
1628lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001629static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001630
1631#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001632static uint lpfc_##name = defval;\
1633module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001634MODULE_PARM_DESC(lpfc_##name, desc);\
1635lpfc_param_hex_show(name)\
1636lpfc_param_init(name, defval, minval, maxval)\
1637lpfc_param_set(name, defval, minval, maxval)\
1638lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001639static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1640 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001641
James Smart3de2a652007-08-02 11:09:59 -04001642#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001643static uint lpfc_##name = defval;\
1644module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001645MODULE_PARM_DESC(lpfc_##name, desc);\
1646lpfc_vport_param_init(name, defval, minval, maxval)
1647
1648#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001649static uint lpfc_##name = defval;\
1650module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001651MODULE_PARM_DESC(lpfc_##name, desc);\
1652lpfc_vport_param_show(name)\
1653lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001654static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001655
1656#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001657static uint lpfc_##name = defval;\
1658module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001659MODULE_PARM_DESC(lpfc_##name, desc);\
1660lpfc_vport_param_show(name)\
1661lpfc_vport_param_init(name, defval, minval, maxval)\
1662lpfc_vport_param_set(name, defval, minval, maxval)\
1663lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001664static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1665 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001666
1667#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001668static uint lpfc_##name = defval;\
1669module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001670MODULE_PARM_DESC(lpfc_##name, desc);\
1671lpfc_vport_param_hex_show(name)\
1672lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001673static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001674
1675#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001676static uint lpfc_##name = defval;\
1677module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001678MODULE_PARM_DESC(lpfc_##name, desc);\
1679lpfc_vport_param_hex_show(name)\
1680lpfc_vport_param_init(name, defval, minval, maxval)\
1681lpfc_vport_param_set(name, defval, minval, maxval)\
1682lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001683static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1684 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001685
James Smart81301a92008-12-04 22:39:46 -05001686static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1687static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1688static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1689static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001690static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1691static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1692static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1693static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1694static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1695static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1696static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1697static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001698static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1699 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001700static DEVICE_ATTR(option_rom_version, S_IRUGO,
1701 lpfc_option_rom_version_show, NULL);
1702static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1703 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001704static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001705static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1706static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001707static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001708static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1709 lpfc_board_mode_show, lpfc_board_mode_store);
1710static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1711static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1712static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1713static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1714static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1715static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1716static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1717static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1718static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001719static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1720static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
dea31012005-04-17 16:05:31 -05001721
James Smartc3f28af2006-08-18 17:47:18 -04001722
James Smarta12e07b2006-12-02 13:35:30 -05001723static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001724
James Smarte59058c2008-08-24 21:49:00 -04001725/**
James Smart3621a712009-04-06 18:47:14 -04001726 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001727 * @dev: class device that is converted into a Scsi_host.
1728 * @attr: device attribute, not used.
1729 * @buf: containing the string lpfc_soft_wwn_key.
1730 * @count: must be size of lpfc_soft_wwn_key.
1731 *
1732 * Returns:
1733 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1734 * length of buf indicates success
1735 **/
James Smartc3f28af2006-08-18 17:47:18 -04001736static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001737lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1738 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001739{
Tony Jonesee959b02008-02-22 00:13:36 +01001740 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001741 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1742 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001743 unsigned int cnt = count;
1744
1745 /*
1746 * We're doing a simple sanity check for soft_wwpn setting.
1747 * We require that the user write a specific key to enable
1748 * the soft_wwpn attribute to be settable. Once the attribute
1749 * is written, the enable key resets. If further updates are
1750 * desired, the key must be written again to re-enable the
1751 * attribute.
1752 *
1753 * The "key" is not secret - it is a hardcoded string shown
1754 * here. The intent is to protect against the random user or
1755 * application that is just writing attributes.
1756 */
1757
1758 /* count may include a LF at end of string */
1759 if (buf[cnt-1] == '\n')
1760 cnt--;
1761
James Smarta12e07b2006-12-02 13:35:30 -05001762 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1763 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001764 return -EINVAL;
1765
James Smarta12e07b2006-12-02 13:35:30 -05001766 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001767 return count;
1768}
Tony Jonesee959b02008-02-22 00:13:36 +01001769static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1770 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001771
James Smarte59058c2008-08-24 21:49:00 -04001772/**
James Smart3621a712009-04-06 18:47:14 -04001773 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001774 * @dev: class device that is converted into a Scsi_host.
1775 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001776 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001777 *
1778 * Returns: size of formatted string.
1779 **/
James Smartc3f28af2006-08-18 17:47:18 -04001780static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001781lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1782 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001783{
Tony Jonesee959b02008-02-22 00:13:36 +01001784 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001785 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1786 struct lpfc_hba *phba = vport->phba;
1787
Randy Dunlapafc071e2006-10-23 21:47:13 -07001788 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1789 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001790}
1791
James Smarte59058c2008-08-24 21:49:00 -04001792/**
James Smart3621a712009-04-06 18:47:14 -04001793 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001794 * @dev class device that is converted into a Scsi_host.
1795 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001796 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001797 * @count: number of wwpn bytes in buf
1798 *
1799 * Returns:
1800 * -EACCES hba reset not enabled, adapter over temp
1801 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1802 * -EIO error taking adapter offline or online
1803 * value of count on success
1804 **/
James Smartc3f28af2006-08-18 17:47:18 -04001805static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001806lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1807 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001808{
Tony Jonesee959b02008-02-22 00:13:36 +01001809 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001810 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1811 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001812 struct completion online_compl;
1813 int stat1=0, stat2=0;
1814 unsigned int i, j, cnt=count;
1815 u8 wwpn[8];
1816
James Smart13815c82008-01-11 01:52:48 -05001817 if (!phba->cfg_enable_hba_reset)
1818 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001819 spin_lock_irq(&phba->hbalock);
1820 if (phba->over_temp_state == HBA_OVER_TEMP) {
1821 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001822 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001823 }
1824 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001825 /* count may include a LF at end of string */
1826 if (buf[cnt-1] == '\n')
1827 cnt--;
1828
James Smarta12e07b2006-12-02 13:35:30 -05001829 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001830 ((cnt == 17) && (*buf++ != 'x')) ||
1831 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1832 return -EINVAL;
1833
James Smarta12e07b2006-12-02 13:35:30 -05001834 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001835
1836 memset(wwpn, 0, sizeof(wwpn));
1837
1838 /* Validate and store the new name */
1839 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001840 int value;
1841
1842 value = hex_to_bin(*buf++);
1843 if (value >= 0)
1844 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04001845 else
1846 return -EINVAL;
1847 if (i % 2) {
1848 wwpn[i/2] = j & 0xff;
1849 j = 0;
1850 }
1851 }
1852 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001853 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001854 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001855 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001856
1857 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1858 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1859
James Smart46fa3112007-04-25 09:51:45 -04001860 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001861 if (stat1)
1862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001863 "0463 lpfc_soft_wwpn attribute set failed to "
1864 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001865 init_completion(&online_compl);
1866 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1867 wait_for_completion(&online_compl);
1868 if (stat2)
1869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001870 "0464 lpfc_soft_wwpn attribute set failed to "
1871 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001872 return (stat1 || stat2) ? -EIO : count;
1873}
Tony Jonesee959b02008-02-22 00:13:36 +01001874static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1875 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001876
James Smarte59058c2008-08-24 21:49:00 -04001877/**
James Smart3621a712009-04-06 18:47:14 -04001878 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001879 * @dev: class device that is converted into a Scsi_host.
1880 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001881 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001882 *
1883 * Returns: size of formatted string.
1884 **/
James Smarta12e07b2006-12-02 13:35:30 -05001885static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001886lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1887 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001888{
Tony Jonesee959b02008-02-22 00:13:36 +01001889 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001890 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001891 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1892 (unsigned long long)phba->cfg_soft_wwnn);
1893}
1894
James Smarte59058c2008-08-24 21:49:00 -04001895/**
James Smart3621a712009-04-06 18:47:14 -04001896 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001897 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001898 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001899 * @count: number of wwnn bytes in buf.
1900 *
1901 * Returns:
1902 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1903 * value of count on success
1904 **/
James Smarta12e07b2006-12-02 13:35:30 -05001905static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001906lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1907 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001908{
Tony Jonesee959b02008-02-22 00:13:36 +01001909 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001910 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001911 unsigned int i, j, cnt=count;
1912 u8 wwnn[8];
1913
1914 /* count may include a LF at end of string */
1915 if (buf[cnt-1] == '\n')
1916 cnt--;
1917
1918 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1919 ((cnt == 17) && (*buf++ != 'x')) ||
1920 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1921 return -EINVAL;
1922
1923 /*
1924 * Allow wwnn to be set many times, as long as the enable is set.
1925 * However, once the wwpn is set, everything locks.
1926 */
1927
1928 memset(wwnn, 0, sizeof(wwnn));
1929
1930 /* Validate and store the new name */
1931 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001932 int value;
1933
1934 value = hex_to_bin(*buf++);
1935 if (value >= 0)
1936 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05001937 else
1938 return -EINVAL;
1939 if (i % 2) {
1940 wwnn[i/2] = j & 0xff;
1941 j = 0;
1942 }
1943 }
1944 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1945
1946 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1947 "lpfc%d: soft_wwnn set. Value will take effect upon "
1948 "setting of the soft_wwpn\n", phba->brd_no);
1949
1950 return count;
1951}
Tony Jonesee959b02008-02-22 00:13:36 +01001952static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1953 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001954
James Smartc3f28af2006-08-18 17:47:18 -04001955
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001956static int lpfc_poll = 0;
1957module_param(lpfc_poll, int, 0);
1958MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1959 " 0 - none,"
1960 " 1 - poll with interrupts enabled"
1961 " 3 - poll and disable FCP ring interrupts");
1962
Tony Jonesee959b02008-02-22 00:13:36 +01001963static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1964 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001965
James Smart92d7f7b2007-06-17 19:56:38 -05001966int lpfc_sli_mode = 0;
1967module_param(lpfc_sli_mode, int, 0);
1968MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1969 " 0 - auto (SLI-3 if supported),"
1970 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1971 " 3 - select SLI-3");
1972
James Smart15672312010-04-06 14:49:03 -04001973int lpfc_enable_npiv = 1;
James Smart7ee5d432007-10-27 13:37:17 -04001974module_param(lpfc_enable_npiv, int, 0);
1975MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1976lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04001977lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04001978static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001979
dea31012005-04-17 16:05:31 -05001980/*
James Smart84d1b002010-02-12 14:42:33 -05001981# lpfc_suppress_link_up: Bring link up at initialization
1982# 0x0 = bring link up (issue MBX_INIT_LINK)
1983# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1984# 0x2 = never bring up link
1985# Default value is 0.
1986*/
James Smarte40a02c2010-02-26 14:13:54 -05001987LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1988 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1989 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04001990/*
1991# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1992# 1 - (1024)
1993# 2 - (2048)
1994# 3 - (3072)
1995# 4 - (4096)
1996# 5 - (5120)
1997*/
1998static ssize_t
1999lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2000{
2001 struct Scsi_Host *shost = class_to_shost(dev);
2002 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2003
2004 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2005}
2006
2007static DEVICE_ATTR(iocb_hw, S_IRUGO,
2008 lpfc_iocb_hw_show, NULL);
2009static ssize_t
2010lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2011{
2012 struct Scsi_Host *shost = class_to_shost(dev);
2013 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2014
2015 return snprintf(buf, PAGE_SIZE, "%d\n",
2016 phba->sli.ring[LPFC_ELS_RING].txq_max);
2017}
2018
2019static DEVICE_ATTR(txq_hw, S_IRUGO,
2020 lpfc_txq_hw_show, NULL);
2021static ssize_t
2022lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2023 char *buf)
2024{
2025 struct Scsi_Host *shost = class_to_shost(dev);
2026 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2027
2028 return snprintf(buf, PAGE_SIZE, "%d\n",
2029 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2030}
2031
2032static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2033 lpfc_txcmplq_hw_show, NULL);
2034
2035int lpfc_iocb_cnt = 2;
2036module_param(lpfc_iocb_cnt, int, 1);
2037MODULE_PARM_DESC(lpfc_iocb_cnt,
2038 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2039lpfc_param_show(iocb_cnt);
2040lpfc_param_init(iocb_cnt, 2, 1, 5);
2041static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2042 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002043
2044/*
James Smartc01f3202006-08-18 17:47:08 -04002045# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2046# until the timer expires. Value range is [0,255]. Default value is 30.
2047*/
2048static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2049static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2050module_param(lpfc_nodev_tmo, int, 0);
2051MODULE_PARM_DESC(lpfc_nodev_tmo,
2052 "Seconds driver will hold I/O waiting "
2053 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002054
2055/**
James Smart3621a712009-04-06 18:47:14 -04002056 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002057 * @dev: class converted to a Scsi_host structure.
2058 * @attr: device attribute, not used.
2059 * @buf: on return contains the dev loss timeout in decimal.
2060 *
2061 * Returns: size of formatted string.
2062 **/
James Smartc01f3202006-08-18 17:47:08 -04002063static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002064lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2065 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002066{
Tony Jonesee959b02008-02-22 00:13:36 +01002067 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002069
James Smart3de2a652007-08-02 11:09:59 -04002070 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002071}
2072
James Smarte59058c2008-08-24 21:49:00 -04002073/**
James Smart3621a712009-04-06 18:47:14 -04002074 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002075 * @vport: lpfc vport structure pointer.
2076 * @val: contains the nodev timeout value.
2077 *
2078 * Description:
2079 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2080 * a kernel error message is printed and zero is returned.
2081 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2082 * Otherwise nodev tmo is set to the default value.
2083 *
2084 * Returns:
2085 * zero if already set or if val is in range
2086 * -EINVAL val out of range
2087 **/
James Smartc01f3202006-08-18 17:47:08 -04002088static int
James Smart3de2a652007-08-02 11:09:59 -04002089lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002090{
James Smart3de2a652007-08-02 11:09:59 -04002091 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2092 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2093 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002094 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002095 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002096 "parameter because devloss_tmo is "
2097 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002098 return 0;
2099 }
2100
2101 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002102 vport->cfg_nodev_tmo = val;
2103 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002104 return 0;
2105 }
James Smarte8b62012007-08-02 11:10:09 -04002106 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2107 "0400 lpfc_nodev_tmo attribute cannot be set to"
2108 " %d, allowed range is [%d, %d]\n",
2109 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002110 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002111 return -EINVAL;
2112}
2113
James Smarte59058c2008-08-24 21:49:00 -04002114/**
James Smart3621a712009-04-06 18:47:14 -04002115 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002116 * @vport: lpfc vport structure pointer.
2117 *
2118 * Description:
2119 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2120 **/
James Smart7054a602007-04-25 09:52:34 -04002121static void
James Smart3de2a652007-08-02 11:09:59 -04002122lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002123{
James Smart858c9f62007-06-17 19:56:39 -05002124 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002125 struct lpfc_nodelist *ndlp;
2126
James Smart51ef4c22007-08-02 11:10:31 -04002127 shost = lpfc_shost_from_vport(vport);
2128 spin_lock_irq(shost->host_lock);
2129 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002130 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002131 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2132 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002133}
2134
James Smarte59058c2008-08-24 21:49:00 -04002135/**
James Smart3621a712009-04-06 18:47:14 -04002136 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002137 * @vport: lpfc vport structure pointer.
2138 * @val: contains the tmo value.
2139 *
2140 * Description:
2141 * If the devloss tmo is already set or the vport dev loss tmo has changed
2142 * then a kernel error message is printed and zero is returned.
2143 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2144 * Otherwise nodev tmo is set to the default value.
2145 *
2146 * Returns:
2147 * zero if already set or if val is in range
2148 * -EINVAL val out of range
2149 **/
James Smartc01f3202006-08-18 17:47:08 -04002150static int
James Smart3de2a652007-08-02 11:09:59 -04002151lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002152{
James Smart3de2a652007-08-02 11:09:59 -04002153 if (vport->dev_loss_tmo_changed ||
2154 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002155 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2156 "0401 Ignoring change to nodev_tmo "
2157 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002158 return 0;
2159 }
James Smartc01f3202006-08-18 17:47:08 -04002160 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002161 vport->cfg_nodev_tmo = val;
2162 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002163 /*
2164 * For compat: set the fc_host dev loss so new rports
2165 * will get the value.
2166 */
2167 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002168 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002169 return 0;
2170 }
James Smarte8b62012007-08-02 11:10:09 -04002171 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2172 "0403 lpfc_nodev_tmo attribute cannot be set to"
2173 "%d, allowed range is [%d, %d]\n",
2174 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002175 return -EINVAL;
2176}
2177
James Smart3de2a652007-08-02 11:09:59 -04002178lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002179
Tony Jonesee959b02008-02-22 00:13:36 +01002180static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2181 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002182
2183/*
2184# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2185# disappear until the timer expires. Value range is [0,255]. Default
2186# value is 30.
2187*/
2188module_param(lpfc_devloss_tmo, int, 0);
2189MODULE_PARM_DESC(lpfc_devloss_tmo,
2190 "Seconds driver will hold I/O waiting "
2191 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002192lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2193 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2194lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002195
2196/**
James Smart3621a712009-04-06 18:47:14 -04002197 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002198 * @vport: lpfc vport structure pointer.
2199 * @val: contains the tmo value.
2200 *
2201 * Description:
2202 * If val is in a valid range then set the vport nodev tmo,
2203 * devloss tmo, also set the vport dev loss tmo changed flag.
2204 * Else a kernel error message is printed.
2205 *
2206 * Returns:
2207 * zero if val is in range
2208 * -EINVAL val out of range
2209 **/
James Smartc01f3202006-08-18 17:47:08 -04002210static int
James Smart3de2a652007-08-02 11:09:59 -04002211lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002212{
2213 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002214 vport->cfg_nodev_tmo = val;
2215 vport->cfg_devloss_tmo = val;
2216 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002217 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002218 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002219 return 0;
2220 }
2221
James Smarte8b62012007-08-02 11:10:09 -04002222 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2223 "0404 lpfc_devloss_tmo attribute cannot be set to"
2224 " %d, allowed range is [%d, %d]\n",
2225 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002226 return -EINVAL;
2227}
2228
James Smart3de2a652007-08-02 11:09:59 -04002229lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002230static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2231 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002232
2233/*
dea31012005-04-17 16:05:31 -05002234# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2235# deluged with LOTS of information.
2236# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002237# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002238*/
James Smartf4b4c682009-05-22 14:53:12 -04002239LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002240 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002241
2242/*
James Smart7ee5d432007-10-27 13:37:17 -04002243# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2244# objects that have been registered with the nameserver after login.
2245*/
2246LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2247 "Deregister nameserver objects before LOGO");
2248
2249/*
dea31012005-04-17 16:05:31 -05002250# lun_queue_depth: This parameter is used to limit the number of outstanding
2251# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2252*/
James Smart3de2a652007-08-02 11:09:59 -04002253LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2254 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002255
2256/*
James Smart7dc517d2010-07-14 15:32:10 -04002257# tgt_queue_depth: This parameter is used to limit the number of outstanding
2258# commands per target port. Value range is [10,65535]. Default value is 65535.
2259*/
2260LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2261 "Max number of FCP commands we can queue to a specific target port");
2262
2263/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002264# hba_queue_depth: This parameter is used to limit the number of outstanding
2265# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2266# value is greater than the maximum number of exchanges supported by the HBA,
2267# then maximum number of exchanges supported by the HBA is used to determine
2268# the hba_queue_depth.
2269*/
2270LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2271 "Max number of FCP commands we can queue to a lpfc HBA");
2272
2273/*
James Smart92d7f7b2007-06-17 19:56:38 -05002274# peer_port_login: This parameter allows/prevents logins
2275# between peer ports hosted on the same physical port.
2276# When this parameter is set 0 peer ports of same physical port
2277# are not allowed to login to each other.
2278# When this parameter is set 1 peer ports of same physical port
2279# are allowed to login to each other.
2280# Default value of this parameter is 0.
2281*/
James Smart3de2a652007-08-02 11:09:59 -04002282LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2283 "Allow peer ports on the same physical port to login to each "
2284 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002285
2286/*
James Smart3de2a652007-08-02 11:09:59 -04002287# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002288# between Virtual Ports and remote initiators.
2289# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2290# other initiators and will attempt to PLOGI all remote ports.
2291# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2292# remote ports and will not attempt to PLOGI to other initiators.
2293# This parameter does not restrict to the physical port.
2294# This parameter does not restrict logins to Fabric resident remote ports.
2295# Default value of this parameter is 1.
2296*/
James Smart3de2a652007-08-02 11:09:59 -04002297static int lpfc_restrict_login = 1;
2298module_param(lpfc_restrict_login, int, 0);
2299MODULE_PARM_DESC(lpfc_restrict_login,
2300 "Restrict virtual ports login to remote initiators.");
2301lpfc_vport_param_show(restrict_login);
2302
James Smarte59058c2008-08-24 21:49:00 -04002303/**
James Smart3621a712009-04-06 18:47:14 -04002304 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002305 * @vport: lpfc vport structure pointer.
2306 * @val: contains the restrict login value.
2307 *
2308 * Description:
2309 * If val is not in a valid range then log a kernel error message and set
2310 * the vport restrict login to one.
2311 * If the port type is physical clear the restrict login flag and return.
2312 * Else set the restrict login flag to val.
2313 *
2314 * Returns:
2315 * zero if val is in range
2316 * -EINVAL val out of range
2317 **/
James Smart3de2a652007-08-02 11:09:59 -04002318static int
2319lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2320{
2321 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002322 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002323 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002324 "be set to %d, allowed range is [0, 1]\n",
2325 val);
James Smart3de2a652007-08-02 11:09:59 -04002326 vport->cfg_restrict_login = 1;
2327 return -EINVAL;
2328 }
2329 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2330 vport->cfg_restrict_login = 0;
2331 return 0;
2332 }
2333 vport->cfg_restrict_login = val;
2334 return 0;
2335}
2336
James Smarte59058c2008-08-24 21:49:00 -04002337/**
James Smart3621a712009-04-06 18:47:14 -04002338 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002339 * @vport: lpfc vport structure pointer.
2340 * @val: contains the restrict login value.
2341 *
2342 * Description:
2343 * If val is not in a valid range then log a kernel error message and set
2344 * the vport restrict login to one.
2345 * If the port type is physical and the val is not zero log a kernel
2346 * error message, clear the restrict login flag and return zero.
2347 * Else set the restrict login flag to val.
2348 *
2349 * Returns:
2350 * zero if val is in range
2351 * -EINVAL val out of range
2352 **/
James Smart3de2a652007-08-02 11:09:59 -04002353static int
2354lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2355{
2356 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002357 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002358 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002359 "be set to %d, allowed range is [0, 1]\n",
2360 val);
James Smart3de2a652007-08-02 11:09:59 -04002361 vport->cfg_restrict_login = 1;
2362 return -EINVAL;
2363 }
2364 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002365 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2366 "0468 lpfc_restrict_login must be 0 for "
2367 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002368 vport->cfg_restrict_login = 0;
2369 return 0;
2370 }
2371 vport->cfg_restrict_login = val;
2372 return 0;
2373}
2374lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002375static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2376 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002377
2378/*
dea31012005-04-17 16:05:31 -05002379# Some disk devices have a "select ID" or "select Target" capability.
2380# From a protocol standpoint "select ID" usually means select the
2381# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2382# annex" which contains a table that maps a "select ID" (a number
2383# between 0 and 7F) to an ALPA. By default, for compatibility with
2384# older drivers, the lpfc driver scans this table from low ALPA to high
2385# ALPA.
2386#
2387# Turning on the scan-down variable (on = 1, off = 0) will
2388# cause the lpfc driver to use an inverted table, effectively
2389# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2390#
2391# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2392# and will not work across a fabric. Also this parameter will take
2393# effect only in the case when ALPA map is not available.)
2394*/
James Smart3de2a652007-08-02 11:09:59 -04002395LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2396 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002397
2398/*
dea31012005-04-17 16:05:31 -05002399# lpfc_topology: link topology for init link
2400# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002401# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002402# 0x02 = attempt point-to-point mode only
2403# 0x04 = attempt loop mode only
2404# 0x06 = attempt point-to-point mode then loop
2405# Set point-to-point mode if you want to run as an N_Port.
2406# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2407# Default value is 0.
2408*/
James Smarte59058c2008-08-24 21:49:00 -04002409
2410/**
James Smart3621a712009-04-06 18:47:14 -04002411 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002412 * @phba: lpfc_hba pointer.
2413 * @val: topology value.
2414 *
2415 * Description:
2416 * If val is in a valid range then set the adapter's topology field and
2417 * issue a lip; if the lip fails reset the topology to the old value.
2418 *
2419 * If the value is not in range log a kernel error message and return an error.
2420 *
2421 * Returns:
2422 * zero if val is in range and lip okay
2423 * non-zero return value from lpfc_issue_lip()
2424 * -EINVAL val out of range
2425 **/
James Smarta257bf92009-04-06 18:48:10 -04002426static ssize_t
2427lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2428 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002429{
James Smarta257bf92009-04-06 18:48:10 -04002430 struct Scsi_Host *shost = class_to_shost(dev);
2431 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2432 struct lpfc_hba *phba = vport->phba;
2433 int val = 0;
2434 int nolip = 0;
2435 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002436 int err;
2437 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002438
2439 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2440 nolip = 1;
2441 val_buf = &buf[strlen("nolip ")];
2442 }
2443
2444 if (!isdigit(val_buf[0]))
2445 return -EINVAL;
2446 if (sscanf(val_buf, "%i", &val) != 1)
2447 return -EINVAL;
2448
James Smart83108bd2008-01-11 01:53:09 -05002449 if (val >= 0 && val <= 6) {
2450 prev_val = phba->cfg_topology;
2451 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002452 if (nolip)
2453 return strlen(buf);
2454
James Smart83108bd2008-01-11 01:53:09 -05002455 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002456 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002457 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002458 return -EINVAL;
2459 } else
2460 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002461 }
2462 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2463 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2464 "allowed range is [0, 6]\n",
2465 phba->brd_no, val);
2466 return -EINVAL;
2467}
2468static int lpfc_topology = 0;
2469module_param(lpfc_topology, int, 0);
2470MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2471lpfc_param_show(topology)
2472lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002473static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002474 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002475
James Smart21e9a0a2009-05-22 14:53:21 -04002476/**
2477 * lpfc_static_vport_show: Read callback function for
2478 * lpfc_static_vport sysfs file.
2479 * @dev: Pointer to class device object.
2480 * @attr: device attribute structure.
2481 * @buf: Data buffer.
2482 *
2483 * This function is the read call back function for
2484 * lpfc_static_vport sysfs file. The lpfc_static_vport
2485 * sysfs file report the mageability of the vport.
2486 **/
2487static ssize_t
2488lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2489 char *buf)
2490{
2491 struct Scsi_Host *shost = class_to_shost(dev);
2492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2493 if (vport->vport_flag & STATIC_VPORT)
2494 sprintf(buf, "1\n");
2495 else
2496 sprintf(buf, "0\n");
2497
2498 return strlen(buf);
2499}
2500
2501/*
2502 * Sysfs attribute to control the statistical data collection.
2503 */
2504static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2505 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002506
2507/**
James Smart3621a712009-04-06 18:47:14 -04002508 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002509 * @dev: Pointer to class device.
2510 * @buf: Data buffer.
2511 * @count: Size of the data buffer.
2512 *
2513 * This function get called when an user write to the lpfc_stat_data_ctrl
2514 * sysfs file. This function parse the command written to the sysfs file
2515 * and take appropriate action. These commands are used for controlling
2516 * driver statistical data collection.
2517 * Following are the command this function handles.
2518 *
2519 * setbucket <bucket_type> <base> <step>
2520 * = Set the latency buckets.
2521 * destroybucket = destroy all the buckets.
2522 * start = start data collection
2523 * stop = stop data collection
2524 * reset = reset the collected data
2525 **/
2526static ssize_t
2527lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2528 const char *buf, size_t count)
2529{
2530 struct Scsi_Host *shost = class_to_shost(dev);
2531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2532 struct lpfc_hba *phba = vport->phba;
2533#define LPFC_MAX_DATA_CTRL_LEN 1024
2534 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2535 unsigned long i;
2536 char *str_ptr, *token;
2537 struct lpfc_vport **vports;
2538 struct Scsi_Host *v_shost;
2539 char *bucket_type_str, *base_str, *step_str;
2540 unsigned long base, step, bucket_type;
2541
2542 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002543 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002544 return -EINVAL;
2545
2546 strcpy(bucket_data, buf);
2547 str_ptr = &bucket_data[0];
2548 /* Ignore this token - this is command token */
2549 token = strsep(&str_ptr, "\t ");
2550 if (!token)
2551 return -EINVAL;
2552
2553 bucket_type_str = strsep(&str_ptr, "\t ");
2554 if (!bucket_type_str)
2555 return -EINVAL;
2556
2557 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2558 bucket_type = LPFC_LINEAR_BUCKET;
2559 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2560 bucket_type = LPFC_POWER2_BUCKET;
2561 else
2562 return -EINVAL;
2563
2564 base_str = strsep(&str_ptr, "\t ");
2565 if (!base_str)
2566 return -EINVAL;
2567 base = simple_strtoul(base_str, NULL, 0);
2568
2569 step_str = strsep(&str_ptr, "\t ");
2570 if (!step_str)
2571 return -EINVAL;
2572 step = simple_strtoul(step_str, NULL, 0);
2573 if (!step)
2574 return -EINVAL;
2575
2576 /* Block the data collection for every vport */
2577 vports = lpfc_create_vport_work_array(phba);
2578 if (vports == NULL)
2579 return -ENOMEM;
2580
James Smartf4b4c682009-05-22 14:53:12 -04002581 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002582 v_shost = lpfc_shost_from_vport(vports[i]);
2583 spin_lock_irq(v_shost->host_lock);
2584 /* Block and reset data collection */
2585 vports[i]->stat_data_blocked = 1;
2586 if (vports[i]->stat_data_enabled)
2587 lpfc_vport_reset_stat_data(vports[i]);
2588 spin_unlock_irq(v_shost->host_lock);
2589 }
2590
2591 /* Set the bucket attributes */
2592 phba->bucket_type = bucket_type;
2593 phba->bucket_base = base;
2594 phba->bucket_step = step;
2595
James Smartf4b4c682009-05-22 14:53:12 -04002596 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002597 v_shost = lpfc_shost_from_vport(vports[i]);
2598
2599 /* Unblock data collection */
2600 spin_lock_irq(v_shost->host_lock);
2601 vports[i]->stat_data_blocked = 0;
2602 spin_unlock_irq(v_shost->host_lock);
2603 }
2604 lpfc_destroy_vport_work_array(phba, vports);
2605 return strlen(buf);
2606 }
2607
2608 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2609 vports = lpfc_create_vport_work_array(phba);
2610 if (vports == NULL)
2611 return -ENOMEM;
2612
James Smartf4b4c682009-05-22 14:53:12 -04002613 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002614 v_shost = lpfc_shost_from_vport(vports[i]);
2615 spin_lock_irq(shost->host_lock);
2616 vports[i]->stat_data_blocked = 1;
2617 lpfc_free_bucket(vport);
2618 vport->stat_data_enabled = 0;
2619 vports[i]->stat_data_blocked = 0;
2620 spin_unlock_irq(shost->host_lock);
2621 }
2622 lpfc_destroy_vport_work_array(phba, vports);
2623 phba->bucket_type = LPFC_NO_BUCKET;
2624 phba->bucket_base = 0;
2625 phba->bucket_step = 0;
2626 return strlen(buf);
2627 }
2628
2629 if (!strncmp(buf, "start", strlen("start"))) {
2630 /* If no buckets configured return error */
2631 if (phba->bucket_type == LPFC_NO_BUCKET)
2632 return -EINVAL;
2633 spin_lock_irq(shost->host_lock);
2634 if (vport->stat_data_enabled) {
2635 spin_unlock_irq(shost->host_lock);
2636 return strlen(buf);
2637 }
2638 lpfc_alloc_bucket(vport);
2639 vport->stat_data_enabled = 1;
2640 spin_unlock_irq(shost->host_lock);
2641 return strlen(buf);
2642 }
2643
2644 if (!strncmp(buf, "stop", strlen("stop"))) {
2645 spin_lock_irq(shost->host_lock);
2646 if (vport->stat_data_enabled == 0) {
2647 spin_unlock_irq(shost->host_lock);
2648 return strlen(buf);
2649 }
2650 lpfc_free_bucket(vport);
2651 vport->stat_data_enabled = 0;
2652 spin_unlock_irq(shost->host_lock);
2653 return strlen(buf);
2654 }
2655
2656 if (!strncmp(buf, "reset", strlen("reset"))) {
2657 if ((phba->bucket_type == LPFC_NO_BUCKET)
2658 || !vport->stat_data_enabled)
2659 return strlen(buf);
2660 spin_lock_irq(shost->host_lock);
2661 vport->stat_data_blocked = 1;
2662 lpfc_vport_reset_stat_data(vport);
2663 vport->stat_data_blocked = 0;
2664 spin_unlock_irq(shost->host_lock);
2665 return strlen(buf);
2666 }
2667 return -EINVAL;
2668}
2669
2670
2671/**
James Smart3621a712009-04-06 18:47:14 -04002672 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002673 * @dev: Pointer to class device object.
2674 * @buf: Data buffer.
2675 *
2676 * This function is the read call back function for
2677 * lpfc_stat_data_ctrl sysfs file. This function report the
2678 * current statistical data collection state.
2679 **/
2680static ssize_t
2681lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2682 char *buf)
2683{
2684 struct Scsi_Host *shost = class_to_shost(dev);
2685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2686 struct lpfc_hba *phba = vport->phba;
2687 int index = 0;
2688 int i;
2689 char *bucket_type;
2690 unsigned long bucket_value;
2691
2692 switch (phba->bucket_type) {
2693 case LPFC_LINEAR_BUCKET:
2694 bucket_type = "linear";
2695 break;
2696 case LPFC_POWER2_BUCKET:
2697 bucket_type = "power2";
2698 break;
2699 default:
2700 bucket_type = "No Bucket";
2701 break;
2702 }
2703
2704 sprintf(&buf[index], "Statistical Data enabled :%d, "
2705 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2706 " Bucket step :%d\nLatency Ranges :",
2707 vport->stat_data_enabled, vport->stat_data_blocked,
2708 bucket_type, phba->bucket_base, phba->bucket_step);
2709 index = strlen(buf);
2710 if (phba->bucket_type != LPFC_NO_BUCKET) {
2711 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2712 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2713 bucket_value = phba->bucket_base +
2714 phba->bucket_step * i;
2715 else
2716 bucket_value = phba->bucket_base +
2717 (1 << i) * phba->bucket_step;
2718
2719 if (index + 10 > PAGE_SIZE)
2720 break;
2721 sprintf(&buf[index], "%08ld ", bucket_value);
2722 index = strlen(buf);
2723 }
2724 }
2725 sprintf(&buf[index], "\n");
2726 return strlen(buf);
2727}
2728
2729/*
2730 * Sysfs attribute to control the statistical data collection.
2731 */
2732static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2733 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2734
2735/*
2736 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2737 */
2738
2739/*
2740 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2741 * for each target.
2742 */
2743#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2744#define MAX_STAT_DATA_SIZE_PER_TARGET \
2745 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2746
2747
2748/**
James Smart3621a712009-04-06 18:47:14 -04002749 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002750 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002751 * @kobj: Pointer to the kernel object
2752 * @bin_attr: Attribute object
2753 * @buff: Buffer pointer
2754 * @off: File offset
2755 * @count: Buffer size
2756 *
2757 * This function is the read call back function for lpfc_drvr_stat_data
2758 * sysfs file. This function export the statistical data to user
2759 * applications.
2760 **/
2761static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002762sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2763 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002764 char *buf, loff_t off, size_t count)
2765{
2766 struct device *dev = container_of(kobj, struct device,
2767 kobj);
2768 struct Scsi_Host *shost = class_to_shost(dev);
2769 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2770 struct lpfc_hba *phba = vport->phba;
2771 int i = 0, index = 0;
2772 unsigned long nport_index;
2773 struct lpfc_nodelist *ndlp = NULL;
2774 nport_index = (unsigned long)off /
2775 MAX_STAT_DATA_SIZE_PER_TARGET;
2776
2777 if (!vport->stat_data_enabled || vport->stat_data_blocked
2778 || (phba->bucket_type == LPFC_NO_BUCKET))
2779 return 0;
2780
2781 spin_lock_irq(shost->host_lock);
2782 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2783 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2784 continue;
2785
2786 if (nport_index > 0) {
2787 nport_index--;
2788 continue;
2789 }
2790
2791 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2792 > count)
2793 break;
2794
2795 if (!ndlp->lat_data)
2796 continue;
2797
2798 /* Print the WWN */
2799 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2800 ndlp->nlp_portname.u.wwn[0],
2801 ndlp->nlp_portname.u.wwn[1],
2802 ndlp->nlp_portname.u.wwn[2],
2803 ndlp->nlp_portname.u.wwn[3],
2804 ndlp->nlp_portname.u.wwn[4],
2805 ndlp->nlp_portname.u.wwn[5],
2806 ndlp->nlp_portname.u.wwn[6],
2807 ndlp->nlp_portname.u.wwn[7]);
2808
2809 index = strlen(buf);
2810
2811 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2812 sprintf(&buf[index], "%010u,",
2813 ndlp->lat_data[i].cmd_count);
2814 index = strlen(buf);
2815 }
2816 sprintf(&buf[index], "\n");
2817 index = strlen(buf);
2818 }
2819 spin_unlock_irq(shost->host_lock);
2820 return index;
2821}
2822
2823static struct bin_attribute sysfs_drvr_stat_data_attr = {
2824 .attr = {
2825 .name = "lpfc_drvr_stat_data",
2826 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04002827 },
2828 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2829 .read = sysfs_drvr_stat_data_read,
2830 .write = NULL,
2831};
2832
dea31012005-04-17 16:05:31 -05002833/*
2834# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2835# connection.
James Smart76a95d72010-11-20 23:11:48 -05002836# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05002837*/
James Smarte59058c2008-08-24 21:49:00 -04002838/**
James Smart3621a712009-04-06 18:47:14 -04002839 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002840 * @phba: lpfc_hba pointer.
2841 * @val: link speed value.
2842 *
2843 * Description:
2844 * If val is in a valid range then set the adapter's link speed field and
2845 * issue a lip; if the lip fails reset the link speed to the old value.
2846 *
2847 * Notes:
2848 * If the value is not in range log a kernel error message and return an error.
2849 *
2850 * Returns:
2851 * zero if val is in range and lip okay.
2852 * non-zero return value from lpfc_issue_lip()
2853 * -EINVAL val out of range
2854 **/
James Smarta257bf92009-04-06 18:48:10 -04002855static ssize_t
2856lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2857 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002858{
James Smarta257bf92009-04-06 18:48:10 -04002859 struct Scsi_Host *shost = class_to_shost(dev);
2860 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2861 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05002862 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04002863 int nolip = 0;
2864 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002865 int err;
2866 uint32_t prev_val;
2867
James Smarta257bf92009-04-06 18:48:10 -04002868 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2869 nolip = 1;
2870 val_buf = &buf[strlen("nolip ")];
2871 }
2872
2873 if (!isdigit(val_buf[0]))
2874 return -EINVAL;
2875 if (sscanf(val_buf, "%i", &val) != 1)
2876 return -EINVAL;
2877
James Smart76a95d72010-11-20 23:11:48 -05002878 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2879 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2880 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2881 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2882 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2883 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2884 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2885 "2879 lpfc_link_speed attribute cannot be set "
2886 "to %d. Speed is not supported by this port.\n",
2887 val);
James Smart83108bd2008-01-11 01:53:09 -05002888 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05002889 }
2890 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2891 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002892 prev_val = phba->cfg_link_speed;
2893 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002894 if (nolip)
2895 return strlen(buf);
2896
James Smart83108bd2008-01-11 01:53:09 -05002897 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002898 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002899 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002900 return -EINVAL;
2901 } else
2902 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002903 }
James Smart83108bd2008-01-11 01:53:09 -05002904 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05002905 "0469 lpfc_link_speed attribute cannot be set to %d, "
2906 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05002907 return -EINVAL;
2908}
2909
2910static int lpfc_link_speed = 0;
2911module_param(lpfc_link_speed, int, 0);
2912MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2913lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002914
2915/**
James Smart3621a712009-04-06 18:47:14 -04002916 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002917 * @phba: lpfc_hba pointer.
2918 * @val: link speed value.
2919 *
2920 * Description:
2921 * If val is in a valid range then set the adapter's link speed field.
2922 *
2923 * Notes:
2924 * If the value is not in range log a kernel error message, clear the link
2925 * speed and return an error.
2926 *
2927 * Returns:
2928 * zero if val saved.
2929 * -EINVAL val out of range
2930 **/
James Smart83108bd2008-01-11 01:53:09 -05002931static int
2932lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2933{
James Smart76a95d72010-11-20 23:11:48 -05002934 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2935 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002936 phba->cfg_link_speed = val;
2937 return 0;
2938 }
2939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002940 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002941 "be set to %d, allowed values are "
2942 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05002943 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05002944 return -EINVAL;
2945}
2946
Tony Jonesee959b02008-02-22 00:13:36 +01002947static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05002948 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002949
2950/*
James Smart0d878412009-10-02 15:16:56 -04002951# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2952# 0 = aer disabled or not supported
2953# 1 = aer supported and enabled (default)
2954# Value range is [0,1]. Default value is 1.
2955*/
2956
2957/**
2958 * lpfc_aer_support_store - Set the adapter for aer support
2959 *
2960 * @dev: class device that is converted into a Scsi_host.
2961 * @attr: device attribute, not used.
2962 * @buf: containing the string "selective".
2963 * @count: unused variable.
2964 *
2965 * Description:
2966 * If the val is 1 and currently the device's AER capability was not
2967 * enabled, invoke the kernel's enable AER helper routine, trying to
2968 * enable the device's AER capability. If the helper routine enabling
2969 * AER returns success, update the device's cfg_aer_support flag to
2970 * indicate AER is supported by the device; otherwise, if the device
2971 * AER capability is already enabled to support AER, then do nothing.
2972 *
2973 * If the val is 0 and currently the device's AER support was enabled,
2974 * invoke the kernel's disable AER helper routine. After that, update
2975 * the device's cfg_aer_support flag to indicate AER is not supported
2976 * by the device; otherwise, if the device AER capability is already
2977 * disabled from supporting AER, then do nothing.
2978 *
2979 * Returns:
2980 * length of the buf on success if val is in range the intended mode
2981 * is supported.
2982 * -EINVAL if val out of range or intended mode is not supported.
2983 **/
2984static ssize_t
2985lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2986 const char *buf, size_t count)
2987{
2988 struct Scsi_Host *shost = class_to_shost(dev);
2989 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2990 struct lpfc_hba *phba = vport->phba;
2991 int val = 0, rc = -EINVAL;
2992
2993 if (!isdigit(buf[0]))
2994 return -EINVAL;
2995 if (sscanf(buf, "%i", &val) != 1)
2996 return -EINVAL;
2997
2998 switch (val) {
2999 case 0:
3000 if (phba->hba_flag & HBA_AER_ENABLED) {
3001 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3002 if (!rc) {
3003 spin_lock_irq(&phba->hbalock);
3004 phba->hba_flag &= ~HBA_AER_ENABLED;
3005 spin_unlock_irq(&phba->hbalock);
3006 phba->cfg_aer_support = 0;
3007 rc = strlen(buf);
3008 } else
James Smart891478a2009-11-18 15:40:23 -05003009 rc = -EPERM;
3010 } else {
James Smart0d878412009-10-02 15:16:56 -04003011 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003012 rc = strlen(buf);
3013 }
James Smart0d878412009-10-02 15:16:56 -04003014 break;
3015 case 1:
3016 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3017 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3018 if (!rc) {
3019 spin_lock_irq(&phba->hbalock);
3020 phba->hba_flag |= HBA_AER_ENABLED;
3021 spin_unlock_irq(&phba->hbalock);
3022 phba->cfg_aer_support = 1;
3023 rc = strlen(buf);
3024 } else
James Smart891478a2009-11-18 15:40:23 -05003025 rc = -EPERM;
3026 } else {
James Smart0d878412009-10-02 15:16:56 -04003027 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003028 rc = strlen(buf);
3029 }
James Smart0d878412009-10-02 15:16:56 -04003030 break;
3031 default:
3032 rc = -EINVAL;
3033 break;
3034 }
3035 return rc;
3036}
3037
3038static int lpfc_aer_support = 1;
3039module_param(lpfc_aer_support, int, 1);
3040MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3041lpfc_param_show(aer_support)
3042
3043/**
3044 * lpfc_aer_support_init - Set the initial adapters aer support flag
3045 * @phba: lpfc_hba pointer.
3046 * @val: link speed value.
3047 *
3048 * Description:
3049 * If val is in a valid range [0,1], then set the adapter's initial
3050 * cfg_aer_support field. It will be up to the driver's probe_one
3051 * routine to determine whether the device's AER support can be set
3052 * or not.
3053 *
3054 * Notes:
3055 * If the value is not in range log a kernel error message, and
3056 * choose the default value of setting AER support and return.
3057 *
3058 * Returns:
3059 * zero if val saved.
3060 * -EINVAL val out of range
3061 **/
3062static int
3063lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3064{
3065 if (val == 0 || val == 1) {
3066 phba->cfg_aer_support = val;
3067 return 0;
3068 }
3069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3070 "2712 lpfc_aer_support attribute value %d out "
3071 "of range, allowed values are 0|1, setting it "
3072 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003073 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003074 phba->cfg_aer_support = 1;
3075 return -EINVAL;
3076}
3077
3078static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3079 lpfc_aer_support_show, lpfc_aer_support_store);
3080
3081/**
3082 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3083 * @dev: class device that is converted into a Scsi_host.
3084 * @attr: device attribute, not used.
3085 * @buf: containing the string "selective".
3086 * @count: unused variable.
3087 *
3088 * Description:
3089 * If the @buf contains 1 and the device currently has the AER support
3090 * enabled, then invokes the kernel AER helper routine
3091 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3092 * error status register.
3093 *
3094 * Notes:
3095 *
3096 * Returns:
3097 * -EINVAL if the buf does not contain the 1 or the device is not currently
3098 * enabled with the AER support.
3099 **/
3100static ssize_t
3101lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3102 const char *buf, size_t count)
3103{
3104 struct Scsi_Host *shost = class_to_shost(dev);
3105 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3106 struct lpfc_hba *phba = vport->phba;
3107 int val, rc = -1;
3108
3109 if (!isdigit(buf[0]))
3110 return -EINVAL;
3111 if (sscanf(buf, "%i", &val) != 1)
3112 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003113 if (val != 1)
3114 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003115
James Smart891478a2009-11-18 15:40:23 -05003116 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003117 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3118
3119 if (rc == 0)
3120 return strlen(buf);
3121 else
James Smart891478a2009-11-18 15:40:23 -05003122 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003123}
3124
3125static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3126 lpfc_aer_cleanup_state);
3127
3128/*
dea31012005-04-17 16:05:31 -05003129# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3130# Value range is [2,3]. Default value is 3.
3131*/
James Smart3de2a652007-08-02 11:09:59 -04003132LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3133 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003134
3135/*
3136# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3137# is [0,1]. Default value is 0.
3138*/
James Smart3de2a652007-08-02 11:09:59 -04003139LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3140 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003141
3142/*
James Smart977b5a02008-09-07 11:52:04 -04003143# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3144# depth. Default value is 0. When the value of this parameter is zero the
3145# SCSI command completion time is not used for controlling I/O queue depth. When
3146# the parameter is set to a non-zero value, the I/O queue depth is controlled
3147# to limit the I/O completion time to the parameter value.
3148# The value is set in milliseconds.
3149*/
3150static int lpfc_max_scsicmpl_time;
3151module_param(lpfc_max_scsicmpl_time, int, 0);
3152MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3153 "Use command completion time to control queue depth");
3154lpfc_vport_param_show(max_scsicmpl_time);
3155lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3156static int
3157lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3158{
3159 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3160 struct lpfc_nodelist *ndlp, *next_ndlp;
3161
3162 if (val == vport->cfg_max_scsicmpl_time)
3163 return 0;
3164 if ((val < 0) || (val > 60000))
3165 return -EINVAL;
3166 vport->cfg_max_scsicmpl_time = val;
3167
3168 spin_lock_irq(shost->host_lock);
3169 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3170 if (!NLP_CHK_NODE_ACT(ndlp))
3171 continue;
3172 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3173 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003174 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003175 }
3176 spin_unlock_irq(shost->host_lock);
3177 return 0;
3178}
3179lpfc_vport_param_store(max_scsicmpl_time);
3180static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3181 lpfc_max_scsicmpl_time_show,
3182 lpfc_max_scsicmpl_time_store);
3183
3184/*
dea31012005-04-17 16:05:31 -05003185# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3186# range is [0,1]. Default value is 0.
3187*/
3188LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3189
3190/*
3191# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3192# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003193# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003194# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3195# cr_delay is set to 0.
3196*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003197LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003198 "interrupt response is generated");
3199
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003200LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003201 "interrupt response is generated");
3202
3203/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003204# lpfc_multi_ring_support: Determines how many rings to spread available
3205# cmd/rsp IOCB entries across.
3206# Value range is [1,2]. Default value is 1.
3207*/
3208LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3209 "SLI rings to spread IOCB entries across");
3210
3211/*
James Smarta4bc3372006-12-02 13:34:16 -05003212# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3213# identifies what rctl value to configure the additional ring for.
3214# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3215*/
James Smart6a9c52c2009-10-02 15:16:51 -04003216LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003217 255, "Identifies RCTL for additional ring configuration");
3218
3219/*
3220# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3221# identifies what type value to configure the additional ring for.
3222# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3223*/
James Smart6a9c52c2009-10-02 15:16:51 -04003224LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003225 255, "Identifies TYPE for additional ring configuration");
3226
3227/*
dea31012005-04-17 16:05:31 -05003228# lpfc_fdmi_on: controls FDMI support.
3229# 0 = no FDMI support
3230# 1 = support FDMI without attribute of hostname
3231# 2 = support FDMI with attribute of hostname
3232# Value range [0,2]. Default value is 0.
3233*/
James Smart3de2a652007-08-02 11:09:59 -04003234LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003235
3236/*
3237# Specifies the maximum number of ELS cmds we can have outstanding (for
3238# discovery). Value range is [1,64]. Default value = 32.
3239*/
James Smart3de2a652007-08-02 11:09:59 -04003240LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003241 "during discovery");
3242
3243/*
James Smart65a29c12006-07-06 15:50:50 -04003244# lpfc_max_luns: maximum allowed LUN.
3245# Value range is [0,65535]. Default value is 255.
3246# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003247*/
James Smart3de2a652007-08-02 11:09:59 -04003248LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003249
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003250/*
3251# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3252# Value range is [1,255], default value is 10.
3253*/
3254LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3255 "Milliseconds driver will wait between polling FCP ring");
3256
James Smart4ff43242006-12-02 13:34:56 -05003257/*
3258# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3259# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003260# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003261# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003262# 2 = MSI-X enabled (default)
3263# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003264*/
George Kadianakis8605c462010-01-17 21:19:31 +02003265LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003266 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003267
James Smart13815c82008-01-11 01:52:48 -05003268/*
James Smartda0436e2009-05-22 14:51:39 -04003269# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3270#
3271# Value range is [636,651042]. Default value is 10000.
3272*/
3273LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3274 "Set the maximum number of fast-path FCP interrupts per second");
3275
3276/*
3277# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3278#
3279# Value range is [1,31]. Default value is 4.
3280*/
3281LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3282 "Set the number of fast-path FCP work queues, if possible");
3283
3284/*
3285# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3286#
3287# Value range is [1,7]. Default value is 1.
3288*/
3289LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3290 "Set the number of fast-path FCP event queues, if possible");
3291
3292/*
James Smart13815c82008-01-11 01:52:48 -05003293# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3294# 0 = HBA resets disabled
3295# 1 = HBA resets enabled (default)
3296# Value range is [0,1]. Default value is 1.
3297*/
3298LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003299
James Smart13815c82008-01-11 01:52:48 -05003300/*
3301# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3302# 0 = HBA Heartbeat disabled
3303# 1 = HBA Heartbeat enabled (default)
3304# Value range is [0,1]. Default value is 1.
3305*/
3306LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003307
James Smart83108bd2008-01-11 01:53:09 -05003308/*
James Smart81301a92008-12-04 22:39:46 -05003309# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3310# 0 = BlockGuard disabled (default)
3311# 1 = BlockGuard enabled
3312# Value range is [0,1]. Default value is 0.
3313*/
3314LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3315
James Smart6fb120a2009-05-22 14:52:59 -04003316/*
James Smart81301a92008-12-04 22:39:46 -05003317# lpfc_prot_mask: i
3318# - Bit mask of host protection capabilities used to register with the
3319# SCSI mid-layer
3320# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3321# - Allows you to ultimately specify which profiles to use
3322# - Default will result in registering capabilities for all profiles.
3323#
3324*/
James Smartbc739052010-08-04 16:11:18 -04003325unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003326
3327module_param(lpfc_prot_mask, uint, 0);
3328MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3329
3330/*
3331# lpfc_prot_guard: i
3332# - Bit mask of protection guard types to register with the SCSI mid-layer
3333# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3334# - Allows you to ultimately specify which profiles to use
3335# - Default will result in registering capabilities for all guard types
3336#
3337*/
3338unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3339module_param(lpfc_prot_guard, byte, 0);
3340MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3341
3342
3343/*
James Smart3621a712009-04-06 18:47:14 -04003344 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003345 * This value can be set to values between 64 and 256. The default value is
3346 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3347 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3348 */
3349LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3350 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3351
James Smart81301a92008-12-04 22:39:46 -05003352LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3353 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3354 "Max Protection Scatter Gather Segment Count");
3355
Tony Jonesee959b02008-02-22 00:13:36 +01003356struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003357 &dev_attr_bg_info,
3358 &dev_attr_bg_guard_err,
3359 &dev_attr_bg_apptag_err,
3360 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003361 &dev_attr_info,
3362 &dev_attr_serialnum,
3363 &dev_attr_modeldesc,
3364 &dev_attr_modelname,
3365 &dev_attr_programtype,
3366 &dev_attr_portnum,
3367 &dev_attr_fwrev,
3368 &dev_attr_hdw,
3369 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003370 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003371 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003372 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003373 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003374 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003375 &dev_attr_lpfc_temp_sensor,
3376 &dev_attr_lpfc_log_verbose,
3377 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003378 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003379 &dev_attr_lpfc_hba_queue_depth,
3380 &dev_attr_lpfc_peer_port_login,
3381 &dev_attr_lpfc_nodev_tmo,
3382 &dev_attr_lpfc_devloss_tmo,
3383 &dev_attr_lpfc_fcp_class,
3384 &dev_attr_lpfc_use_adisc,
3385 &dev_attr_lpfc_ack0,
3386 &dev_attr_lpfc_topology,
3387 &dev_attr_lpfc_scan_down,
3388 &dev_attr_lpfc_link_speed,
3389 &dev_attr_lpfc_cr_delay,
3390 &dev_attr_lpfc_cr_count,
3391 &dev_attr_lpfc_multi_ring_support,
3392 &dev_attr_lpfc_multi_ring_rctl,
3393 &dev_attr_lpfc_multi_ring_type,
3394 &dev_attr_lpfc_fdmi_on,
3395 &dev_attr_lpfc_max_luns,
3396 &dev_attr_lpfc_enable_npiv,
3397 &dev_attr_nport_evt_cnt,
3398 &dev_attr_board_mode,
3399 &dev_attr_max_vpi,
3400 &dev_attr_used_vpi,
3401 &dev_attr_max_rpi,
3402 &dev_attr_used_rpi,
3403 &dev_attr_max_xri,
3404 &dev_attr_used_xri,
3405 &dev_attr_npiv_info,
3406 &dev_attr_issue_reset,
3407 &dev_attr_lpfc_poll,
3408 &dev_attr_lpfc_poll_tmo,
3409 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003410 &dev_attr_lpfc_fcp_imax,
3411 &dev_attr_lpfc_fcp_wq_count,
3412 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003413 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003414 &dev_attr_lpfc_soft_wwnn,
3415 &dev_attr_lpfc_soft_wwpn,
3416 &dev_attr_lpfc_soft_wwn_enable,
3417 &dev_attr_lpfc_enable_hba_reset,
3418 &dev_attr_lpfc_enable_hba_heartbeat,
3419 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003420 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003421 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003422 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003423 &dev_attr_lpfc_aer_support,
3424 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003425 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003426 &dev_attr_lpfc_iocb_cnt,
3427 &dev_attr_iocb_hw,
3428 &dev_attr_txq_hw,
3429 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003430 &dev_attr_lpfc_fips_level,
3431 &dev_attr_lpfc_fips_rev,
dea31012005-04-17 16:05:31 -05003432 NULL,
3433};
3434
Tony Jonesee959b02008-02-22 00:13:36 +01003435struct device_attribute *lpfc_vport_attrs[] = {
3436 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003437 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003438 &dev_attr_num_discovered_ports,
3439 &dev_attr_lpfc_drvr_version,
3440 &dev_attr_lpfc_log_verbose,
3441 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003442 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003443 &dev_attr_lpfc_nodev_tmo,
3444 &dev_attr_lpfc_devloss_tmo,
3445 &dev_attr_lpfc_hba_queue_depth,
3446 &dev_attr_lpfc_peer_port_login,
3447 &dev_attr_lpfc_restrict_login,
3448 &dev_attr_lpfc_fcp_class,
3449 &dev_attr_lpfc_use_adisc,
3450 &dev_attr_lpfc_fdmi_on,
3451 &dev_attr_lpfc_max_luns,
3452 &dev_attr_nport_evt_cnt,
3453 &dev_attr_npiv_info,
3454 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003455 &dev_attr_lpfc_max_scsicmpl_time,
3456 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003457 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003458 &dev_attr_lpfc_fips_level,
3459 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003460 NULL,
3461};
3462
James Smarte59058c2008-08-24 21:49:00 -04003463/**
James Smart3621a712009-04-06 18:47:14 -04003464 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003465 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003466 * @kobj: kernel kobject that contains the kernel class device.
3467 * @bin_attr: kernel attributes passed to us.
3468 * @buf: contains the data to be written to the adapter IOREG space.
3469 * @off: offset into buffer to beginning of data.
3470 * @count: bytes to transfer.
3471 *
3472 * Description:
3473 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3474 * Uses the adapter io control registers to send buf contents to the adapter.
3475 *
3476 * Returns:
3477 * -ERANGE off and count combo out of range
3478 * -EINVAL off, count or buff address invalid
3479 * -EPERM adapter is offline
3480 * value of count, buf contents written
3481 **/
dea31012005-04-17 16:05:31 -05003482static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003483sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3484 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003485 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003486{
3487 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003488 struct device *dev = container_of(kobj, struct device, kobj);
3489 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003490 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3491 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003492
James Smartf1126682009-06-10 17:22:44 -04003493 if (phba->sli_rev >= LPFC_SLI_REV4)
3494 return -EPERM;
3495
dea31012005-04-17 16:05:31 -05003496 if ((off + count) > FF_REG_AREA_SIZE)
3497 return -ERANGE;
3498
3499 if (count == 0) return 0;
3500
3501 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3502 return -EINVAL;
3503
James Smart2e0fef82007-06-17 19:56:36 -05003504 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003505 return -EPERM;
3506 }
3507
James Smart2e0fef82007-06-17 19:56:36 -05003508 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003509 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3510 writel(*((uint32_t *)(buf + buf_off)),
3511 phba->ctrl_regs_memmap_p + off + buf_off);
3512
James Smart2e0fef82007-06-17 19:56:36 -05003513 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003514
3515 return count;
3516}
3517
James Smarte59058c2008-08-24 21:49:00 -04003518/**
James Smart3621a712009-04-06 18:47:14 -04003519 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003520 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003521 * @kobj: kernel kobject that contains the kernel class device.
3522 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003523 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003524 * @off: offset into buffer to beginning of data.
3525 * @count: bytes to transfer.
3526 *
3527 * Description:
3528 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3529 * Uses the adapter io control registers to read data into buf.
3530 *
3531 * Returns:
3532 * -ERANGE off and count combo out of range
3533 * -EINVAL off, count or buff address invalid
3534 * value of count, buf contents read
3535 **/
dea31012005-04-17 16:05:31 -05003536static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003537sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3538 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003539 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003540{
3541 size_t buf_off;
3542 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003543 struct device *dev = container_of(kobj, struct device, kobj);
3544 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003545 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3546 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003547
James Smartf1126682009-06-10 17:22:44 -04003548 if (phba->sli_rev >= LPFC_SLI_REV4)
3549 return -EPERM;
3550
dea31012005-04-17 16:05:31 -05003551 if (off > FF_REG_AREA_SIZE)
3552 return -ERANGE;
3553
3554 if ((off + count) > FF_REG_AREA_SIZE)
3555 count = FF_REG_AREA_SIZE - off;
3556
3557 if (count == 0) return 0;
3558
3559 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3560 return -EINVAL;
3561
James Smart2e0fef82007-06-17 19:56:36 -05003562 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003563
3564 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3565 tmp_ptr = (uint32_t *)(buf + buf_off);
3566 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3567 }
3568
James Smart2e0fef82007-06-17 19:56:36 -05003569 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003570
3571 return count;
3572}
3573
3574static struct bin_attribute sysfs_ctlreg_attr = {
3575 .attr = {
3576 .name = "ctlreg",
3577 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003578 },
3579 .size = 256,
3580 .read = sysfs_ctlreg_read,
3581 .write = sysfs_ctlreg_write,
3582};
3583
James Smarte59058c2008-08-24 21:49:00 -04003584/**
James Smart3621a712009-04-06 18:47:14 -04003585 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003586 * @phba: lpfc_hba pointer
3587 **/
dea31012005-04-17 16:05:31 -05003588static void
James Smart2e0fef82007-06-17 19:56:36 -05003589sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003590{
3591 phba->sysfs_mbox.state = SMBOX_IDLE;
3592 phba->sysfs_mbox.offset = 0;
3593
3594 if (phba->sysfs_mbox.mbox) {
3595 mempool_free(phba->sysfs_mbox.mbox,
3596 phba->mbox_mem_pool);
3597 phba->sysfs_mbox.mbox = NULL;
3598 }
3599}
3600
James Smarte59058c2008-08-24 21:49:00 -04003601/**
James Smart3621a712009-04-06 18:47:14 -04003602 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003603 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003604 * @kobj: kernel kobject that contains the kernel class device.
3605 * @bin_attr: kernel attributes passed to us.
3606 * @buf: contains the data to be written to sysfs mbox.
3607 * @off: offset into buffer to beginning of data.
3608 * @count: bytes to transfer.
3609 *
3610 * Description:
3611 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3612 * Uses the sysfs mbox to send buf contents to the adapter.
3613 *
3614 * Returns:
3615 * -ERANGE off and count combo out of range
3616 * -EINVAL off, count or buff address invalid
3617 * zero if count is zero
3618 * -EPERM adapter is offline
3619 * -ENOMEM failed to allocate memory for the mail box
3620 * -EAGAIN offset, state or mbox is NULL
3621 * count number of bytes transferred
3622 **/
dea31012005-04-17 16:05:31 -05003623static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003624sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3625 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003626 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003627{
Tony Jonesee959b02008-02-22 00:13:36 +01003628 struct device *dev = container_of(kobj, struct device, kobj);
3629 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003630 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3631 struct lpfc_hba *phba = vport->phba;
3632 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003633
3634 if ((count + off) > MAILBOX_CMD_SIZE)
3635 return -ERANGE;
3636
3637 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3638 return -EINVAL;
3639
3640 if (count == 0)
3641 return 0;
3642
3643 if (off == 0) {
3644 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3645 if (!mbox)
3646 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003647 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003648 }
3649
James Smart2e0fef82007-06-17 19:56:36 -05003650 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003651
3652 if (off == 0) {
3653 if (phba->sysfs_mbox.mbox)
3654 mempool_free(mbox, phba->mbox_mem_pool);
3655 else
3656 phba->sysfs_mbox.mbox = mbox;
3657 phba->sysfs_mbox.state = SMBOX_WRITING;
3658 } else {
3659 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3660 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003661 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003662 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003663 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003664 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003665 }
3666 }
3667
James Smart04c68492009-05-22 14:52:52 -04003668 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003669 buf, count);
3670
3671 phba->sysfs_mbox.offset = off + count;
3672
James Smart2e0fef82007-06-17 19:56:36 -05003673 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003674
3675 return count;
3676}
3677
James Smarte59058c2008-08-24 21:49:00 -04003678/**
James Smart3621a712009-04-06 18:47:14 -04003679 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003680 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003681 * @kobj: kernel kobject that contains the kernel class device.
3682 * @bin_attr: kernel attributes passed to us.
3683 * @buf: contains the data to be read from sysfs mbox.
3684 * @off: offset into buffer to beginning of data.
3685 * @count: bytes to transfer.
3686 *
3687 * Description:
3688 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3689 * Uses the sysfs mbox to receive data from to the adapter.
3690 *
3691 * Returns:
3692 * -ERANGE off greater than mailbox command size
3693 * -EINVAL off, count or buff address invalid
3694 * zero if off and count are zero
3695 * -EACCES adapter over temp
3696 * -EPERM garbage can value to catch a multitude of errors
3697 * -EAGAIN management IO not permitted, state or off error
3698 * -ETIME mailbox timeout
3699 * -ENODEV mailbox error
3700 * count number of bytes transferred
3701 **/
dea31012005-04-17 16:05:31 -05003702static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003703sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3704 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003705 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003706{
Tony Jonesee959b02008-02-22 00:13:36 +01003707 struct device *dev = container_of(kobj, struct device, kobj);
3708 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003709 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3710 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003711 int rc;
James Smart04c68492009-05-22 14:52:52 -04003712 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003713
James Smart1dcb58e2007-04-25 09:51:30 -04003714 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003715 return -ERANGE;
3716
James Smart1dcb58e2007-04-25 09:51:30 -04003717 if ((count + off) > MAILBOX_CMD_SIZE)
3718 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003719
3720 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3721 return -EINVAL;
3722
3723 if (off && count == 0)
3724 return 0;
3725
James Smart2e0fef82007-06-17 19:56:36 -05003726 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003727
James Smart7af67052007-10-27 13:38:11 -04003728 if (phba->over_temp_state == HBA_OVER_TEMP) {
3729 sysfs_mbox_idle(phba);
3730 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003731 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003732 }
3733
dea31012005-04-17 16:05:31 -05003734 if (off == 0 &&
3735 phba->sysfs_mbox.state == SMBOX_WRITING &&
3736 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003737 pmb = &phba->sysfs_mbox.mbox->u.mb;
3738 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003739 /* Offline only */
dea31012005-04-17 16:05:31 -05003740 case MBX_INIT_LINK:
3741 case MBX_DOWN_LINK:
3742 case MBX_CONFIG_LINK:
3743 case MBX_CONFIG_RING:
3744 case MBX_RESET_RING:
3745 case MBX_UNREG_LOGIN:
3746 case MBX_CLEAR_LA:
3747 case MBX_DUMP_CONTEXT:
3748 case MBX_RUN_DIAGS:
3749 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003750 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003751 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003752 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003753 printk(KERN_WARNING "mbox_read:Command 0x%x "
3754 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003755 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003756 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003757 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003758 return -EPERM;
3759 }
James Smarta8adb832007-10-27 13:37:53 -04003760 case MBX_WRITE_NV:
3761 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003762 case MBX_LOAD_SM:
3763 case MBX_READ_NV:
3764 case MBX_READ_CONFIG:
3765 case MBX_READ_RCONFIG:
3766 case MBX_READ_STATUS:
3767 case MBX_READ_XRI:
3768 case MBX_READ_REV:
3769 case MBX_READ_LNK_STAT:
3770 case MBX_DUMP_MEMORY:
3771 case MBX_DOWN_LOAD:
3772 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003773 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003774 case MBX_LOAD_AREA:
3775 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003776 case MBX_BEACON:
3777 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003778 case MBX_SET_VARIABLE:
3779 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003780 case MBX_PORT_CAPABILITIES:
3781 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003782 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04003783 case MBX_SECURITY_MGMT:
3784 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04003785 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3786 printk(KERN_WARNING "mbox_read:Command 0x%x "
3787 "is not permitted\n", pmb->mbxCommand);
3788 sysfs_mbox_idle(phba);
3789 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04003790 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04003791 }
James Smartdcf2a4e2010-09-29 11:18:53 -04003792 break;
dea31012005-04-17 16:05:31 -05003793 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05003794 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05003795 case MBX_REG_LOGIN:
3796 case MBX_REG_LOGIN64:
3797 case MBX_CONFIG_PORT:
3798 case MBX_RUN_BIU_DIAG:
3799 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003800 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003801 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003802 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003803 return -EPERM;
3804 default:
3805 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003806 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003807 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003808 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003809 return -EPERM;
3810 }
3811
James Smart09372822008-01-11 01:52:54 -05003812 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003813 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003814 */
James Smartd7c255b2008-08-24 21:50:00 -04003815 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003816 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3817 pmb->mbxCommand != MBX_RESTART &&
3818 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3819 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003820 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3821 "1259 mbox: Issued mailbox cmd "
3822 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003823 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003824
James Smart92d7f7b2007-06-17 19:56:38 -05003825 phba->sysfs_mbox.mbox->vport = vport;
3826
James Smart58da1ff2008-04-07 10:15:56 -04003827 /* Don't allow mailbox commands to be sent when blocked
3828 * or when in the middle of discovery
3829 */
James Smart495a7142008-06-14 22:52:59 -04003830 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003831 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003832 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003833 return -EAGAIN;
3834 }
3835
James Smart2e0fef82007-06-17 19:56:36 -05003836 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003837 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003838
James Smart2e0fef82007-06-17 19:56:36 -05003839 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003840 rc = lpfc_sli_issue_mbox (phba,
3841 phba->sysfs_mbox.mbox,
3842 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003843 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003844
3845 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003846 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003847 rc = lpfc_sli_issue_mbox_wait (phba,
3848 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003849 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003850 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003851 }
3852
3853 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003854 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003855 phba->sysfs_mbox.mbox = NULL;
3856 }
dea31012005-04-17 16:05:31 -05003857 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003858 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003859 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003860 }
3861 phba->sysfs_mbox.state = SMBOX_READING;
3862 }
3863 else if (phba->sysfs_mbox.offset != off ||
3864 phba->sysfs_mbox.state != SMBOX_READING) {
3865 printk(KERN_WARNING "mbox_read: Bad State\n");
3866 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003867 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003868 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003869 }
3870
James Smart04c68492009-05-22 14:52:52 -04003871 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003872
3873 phba->sysfs_mbox.offset = off + count;
3874
James Smart1dcb58e2007-04-25 09:51:30 -04003875 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003876 sysfs_mbox_idle(phba);
3877
James Smart2e0fef82007-06-17 19:56:36 -05003878 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003879
3880 return count;
3881}
3882
3883static struct bin_attribute sysfs_mbox_attr = {
3884 .attr = {
3885 .name = "mbox",
3886 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003887 },
James Smart1dcb58e2007-04-25 09:51:30 -04003888 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003889 .read = sysfs_mbox_read,
3890 .write = sysfs_mbox_write,
3891};
3892
James Smarte59058c2008-08-24 21:49:00 -04003893/**
James Smart3621a712009-04-06 18:47:14 -04003894 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003895 * @vport: address of lpfc vport structure.
3896 *
3897 * Return codes:
3898 * zero on success
3899 * error return code from sysfs_create_bin_file()
3900 **/
dea31012005-04-17 16:05:31 -05003901int
James Smart2e0fef82007-06-17 19:56:36 -05003902lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003903{
James Smart2e0fef82007-06-17 19:56:36 -05003904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003905 int error;
3906
Tony Jonesee959b02008-02-22 00:13:36 +01003907 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003908 &sysfs_drvr_stat_data_attr);
3909
3910 /* Virtual ports do not need ctrl_reg and mbox */
3911 if (error || vport->port_type == LPFC_NPIV_PORT)
3912 goto out;
3913
3914 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003915 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003916 if (error)
James Smarteada2722008-12-04 22:39:13 -05003917 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003918
Tony Jonesee959b02008-02-22 00:13:36 +01003919 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003920 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003921 if (error)
3922 goto out_remove_ctlreg_attr;
3923
3924 return 0;
3925out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003926 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003927out_remove_stat_attr:
3928 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3929 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003930out:
3931 return error;
3932}
3933
James Smarte59058c2008-08-24 21:49:00 -04003934/**
James Smart3621a712009-04-06 18:47:14 -04003935 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003936 * @vport: address of lpfc vport structure.
3937 **/
dea31012005-04-17 16:05:31 -05003938void
James Smart2e0fef82007-06-17 19:56:36 -05003939lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003940{
James Smart2e0fef82007-06-17 19:56:36 -05003941 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003942 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3943 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003944 /* Virtual ports do not need ctrl_reg and mbox */
3945 if (vport->port_type == LPFC_NPIV_PORT)
3946 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003947 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3948 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003949}
3950
3951
3952/*
3953 * Dynamic FC Host Attributes Support
3954 */
3955
James Smarte59058c2008-08-24 21:49:00 -04003956/**
James Smart3621a712009-04-06 18:47:14 -04003957 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003958 * @shost: kernel scsi host pointer.
3959 **/
dea31012005-04-17 16:05:31 -05003960static void
3961lpfc_get_host_port_id(struct Scsi_Host *shost)
3962{
James Smart2e0fef82007-06-17 19:56:36 -05003963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3964
dea31012005-04-17 16:05:31 -05003965 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003966 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003967}
3968
James Smarte59058c2008-08-24 21:49:00 -04003969/**
James Smart3621a712009-04-06 18:47:14 -04003970 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003971 * @shost: kernel scsi host pointer.
3972 **/
dea31012005-04-17 16:05:31 -05003973static void
3974lpfc_get_host_port_type(struct Scsi_Host *shost)
3975{
James Smart2e0fef82007-06-17 19:56:36 -05003976 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3977 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003978
3979 spin_lock_irq(shost->host_lock);
3980
James Smart92d7f7b2007-06-17 19:56:38 -05003981 if (vport->port_type == LPFC_NPIV_PORT) {
3982 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3983 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05003984 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003985 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003986 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3987 else
3988 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3989 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003990 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003991 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3992 else
3993 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3994 }
3995 } else
3996 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3997
3998 spin_unlock_irq(shost->host_lock);
3999}
4000
James Smarte59058c2008-08-24 21:49:00 -04004001/**
James Smart3621a712009-04-06 18:47:14 -04004002 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004003 * @shost: kernel scsi host pointer.
4004 **/
dea31012005-04-17 16:05:31 -05004005static void
4006lpfc_get_host_port_state(struct Scsi_Host *shost)
4007{
James Smart2e0fef82007-06-17 19:56:36 -05004008 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4009 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004010
4011 spin_lock_irq(shost->host_lock);
4012
James Smart2e0fef82007-06-17 19:56:36 -05004013 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004014 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4015 else {
James Smart2e0fef82007-06-17 19:56:36 -05004016 switch (phba->link_state) {
4017 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004018 case LPFC_LINK_DOWN:
4019 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4020 break;
4021 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004022 case LPFC_CLEAR_LA:
4023 case LPFC_HBA_READY:
4024 /* Links up, beyond this port_type reports state */
4025 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4026 break;
4027 case LPFC_HBA_ERROR:
4028 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4029 break;
4030 default:
4031 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4032 break;
4033 }
4034 }
4035
4036 spin_unlock_irq(shost->host_lock);
4037}
4038
James Smarte59058c2008-08-24 21:49:00 -04004039/**
James Smart3621a712009-04-06 18:47:14 -04004040 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004041 * @shost: kernel scsi host pointer.
4042 **/
dea31012005-04-17 16:05:31 -05004043static void
4044lpfc_get_host_speed(struct Scsi_Host *shost)
4045{
James Smart2e0fef82007-06-17 19:56:36 -05004046 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4047 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004048
4049 spin_lock_irq(shost->host_lock);
4050
James Smart2e0fef82007-06-17 19:56:36 -05004051 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004052 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004053 case LPFC_LINK_SPEED_1GHZ:
4054 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004055 break;
James Smart76a95d72010-11-20 23:11:48 -05004056 case LPFC_LINK_SPEED_2GHZ:
4057 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004058 break;
James Smart76a95d72010-11-20 23:11:48 -05004059 case LPFC_LINK_SPEED_4GHZ:
4060 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004061 break;
James Smart76a95d72010-11-20 23:11:48 -05004062 case LPFC_LINK_SPEED_8GHZ:
4063 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004064 break;
James Smart76a95d72010-11-20 23:11:48 -05004065 case LPFC_LINK_SPEED_10GHZ:
4066 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004067 break;
James Smart76a95d72010-11-20 23:11:48 -05004068 case LPFC_LINK_SPEED_16GHZ:
4069 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4070 break;
4071 default:
4072 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004073 break;
4074 }
James Smart09372822008-01-11 01:52:54 -05004075 } else
4076 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004077
4078 spin_unlock_irq(shost->host_lock);
4079}
4080
James Smarte59058c2008-08-24 21:49:00 -04004081/**
James Smart3621a712009-04-06 18:47:14 -04004082 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004083 * @shost: kernel scsi host pointer.
4084 **/
dea31012005-04-17 16:05:31 -05004085static void
4086lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4087{
James Smart2e0fef82007-06-17 19:56:36 -05004088 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4089 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004090 u64 node_name;
dea31012005-04-17 16:05:31 -05004091
4092 spin_lock_irq(shost->host_lock);
4093
James Smart2e0fef82007-06-17 19:56:36 -05004094 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004095 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004096 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004097 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004098 else
4099 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004100 node_name = 0;
dea31012005-04-17 16:05:31 -05004101
4102 spin_unlock_irq(shost->host_lock);
4103
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004104 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004105}
4106
James Smarte59058c2008-08-24 21:49:00 -04004107/**
James Smart3621a712009-04-06 18:47:14 -04004108 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004109 * @shost: kernel scsi host pointer.
4110 *
4111 * Notes:
4112 * NULL on error for link down, no mbox pool, sli2 active,
4113 * management not allowed, memory allocation error, or mbox error.
4114 *
4115 * Returns:
4116 * NULL for error
4117 * address of the adapter host statistics
4118 **/
dea31012005-04-17 16:05:31 -05004119static struct fc_host_statistics *
4120lpfc_get_stats(struct Scsi_Host *shost)
4121{
James Smart2e0fef82007-06-17 19:56:36 -05004122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4123 struct lpfc_hba *phba = vport->phba;
4124 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004125 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004126 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004127 LPFC_MBOXQ_t *pmboxq;
4128 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004129 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004130 int rc = 0;
dea31012005-04-17 16:05:31 -05004131
James Smart92d7f7b2007-06-17 19:56:38 -05004132 /*
4133 * prevent udev from issuing mailbox commands until the port is
4134 * configured.
4135 */
James Smart2e0fef82007-06-17 19:56:36 -05004136 if (phba->link_state < LPFC_LINK_DOWN ||
4137 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004138 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004139 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004140
4141 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004142 return NULL;
4143
dea31012005-04-17 16:05:31 -05004144 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4145 if (!pmboxq)
4146 return NULL;
4147 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4148
James Smart04c68492009-05-22 14:52:52 -04004149 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004150 pmb->mbxCommand = MBX_READ_STATUS;
4151 pmb->mbxOwner = OWN_HOST;
4152 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004153 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004154
James Smart75baf692010-06-08 18:31:21 -04004155 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004156 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004157 else
dea31012005-04-17 16:05:31 -05004158 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4159
4160 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004161 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004162 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004163 return NULL;
4164 }
4165
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004166 memset(hs, 0, sizeof (struct fc_host_statistics));
4167
dea31012005-04-17 16:05:31 -05004168 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4169 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4170 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4171 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4172
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004173 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004174 pmb->mbxCommand = MBX_READ_LNK_STAT;
4175 pmb->mbxOwner = OWN_HOST;
4176 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004177 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004178
James Smart75baf692010-06-08 18:31:21 -04004179 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004180 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004181 else
dea31012005-04-17 16:05:31 -05004182 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4183
4184 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004185 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004186 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004187 return NULL;
4188 }
4189
4190 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4191 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4192 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4193 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4194 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4195 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4196 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4197
James Smart64ba8812006-08-02 15:24:34 -04004198 hs->link_failure_count -= lso->link_failure_count;
4199 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4200 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4201 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4202 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4203 hs->invalid_crc_count -= lso->invalid_crc_count;
4204 hs->error_frames -= lso->error_frames;
4205
James Smart76a95d72010-11-20 23:11:48 -05004206 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004207 hs->lip_count = -1;
4208 hs->nos_count = (phba->link_events >> 1);
4209 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004210 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004211 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004212 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004213 hs->nos_count = -1;
4214 } else {
4215 hs->lip_count = -1;
4216 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004217 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004218 }
4219
4220 hs->dumped_frames = -1;
4221
James Smart64ba8812006-08-02 15:24:34 -04004222 seconds = get_seconds();
4223 if (seconds < psli->stats_start)
4224 hs->seconds_since_last_reset = seconds +
4225 ((unsigned long)-1 - psli->stats_start);
4226 else
4227 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004228
James Smart1dcb58e2007-04-25 09:51:30 -04004229 mempool_free(pmboxq, phba->mbox_mem_pool);
4230
dea31012005-04-17 16:05:31 -05004231 return hs;
4232}
4233
James Smarte59058c2008-08-24 21:49:00 -04004234/**
James Smart3621a712009-04-06 18:47:14 -04004235 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004236 * @shost: kernel scsi host pointer.
4237 **/
James Smart64ba8812006-08-02 15:24:34 -04004238static void
4239lpfc_reset_stats(struct Scsi_Host *shost)
4240{
James Smart2e0fef82007-06-17 19:56:36 -05004241 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4242 struct lpfc_hba *phba = vport->phba;
4243 struct lpfc_sli *psli = &phba->sli;
4244 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004245 LPFC_MBOXQ_t *pmboxq;
4246 MAILBOX_t *pmb;
4247 int rc = 0;
4248
James Smart2e0fef82007-06-17 19:56:36 -05004249 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004250 return;
4251
James Smart64ba8812006-08-02 15:24:34 -04004252 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4253 if (!pmboxq)
4254 return;
4255 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4256
James Smart04c68492009-05-22 14:52:52 -04004257 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004258 pmb->mbxCommand = MBX_READ_STATUS;
4259 pmb->mbxOwner = OWN_HOST;
4260 pmb->un.varWords[0] = 0x1; /* reset request */
4261 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004262 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004263
James Smart2e0fef82007-06-17 19:56:36 -05004264 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004265 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004266 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4267 else
4268 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4269
4270 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004271 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004272 mempool_free(pmboxq, phba->mbox_mem_pool);
4273 return;
4274 }
4275
4276 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4277 pmb->mbxCommand = MBX_READ_LNK_STAT;
4278 pmb->mbxOwner = OWN_HOST;
4279 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004280 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004281
James Smart2e0fef82007-06-17 19:56:36 -05004282 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004283 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004284 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4285 else
4286 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4287
4288 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004289 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004290 mempool_free( pmboxq, phba->mbox_mem_pool);
4291 return;
4292 }
4293
4294 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4295 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4296 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4297 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4298 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4299 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4300 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004301 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004302 lso->link_events = (phba->link_events >> 1);
4303 else
4304 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004305
4306 psli->stats_start = get_seconds();
4307
James Smart1dcb58e2007-04-25 09:51:30 -04004308 mempool_free(pmboxq, phba->mbox_mem_pool);
4309
James Smart64ba8812006-08-02 15:24:34 -04004310 return;
4311}
dea31012005-04-17 16:05:31 -05004312
4313/*
4314 * The LPFC driver treats linkdown handling as target loss events so there
4315 * are no sysfs handlers for link_down_tmo.
4316 */
James Smart685f0bf2007-04-25 09:53:08 -04004317
James Smarte59058c2008-08-24 21:49:00 -04004318/**
James Smart3621a712009-04-06 18:47:14 -04004319 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004320 * @starget: kernel scsi target pointer.
4321 *
4322 * Returns:
4323 * address of the node list if found
4324 * NULL target not found
4325 **/
James Smart685f0bf2007-04-25 09:53:08 -04004326static struct lpfc_nodelist *
4327lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004328{
James Smart2e0fef82007-06-17 19:56:36 -05004329 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4330 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004331 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004332
4333 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004334 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004335 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004336 if (NLP_CHK_NODE_ACT(ndlp) &&
4337 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004338 starget->id == ndlp->nlp_sid) {
4339 spin_unlock_irq(shost->host_lock);
4340 return ndlp;
dea31012005-04-17 16:05:31 -05004341 }
4342 }
4343 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004344 return NULL;
4345}
dea31012005-04-17 16:05:31 -05004346
James Smarte59058c2008-08-24 21:49:00 -04004347/**
James Smart3621a712009-04-06 18:47:14 -04004348 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004349 * @starget: kernel scsi target pointer.
4350 **/
James Smart685f0bf2007-04-25 09:53:08 -04004351static void
4352lpfc_get_starget_port_id(struct scsi_target *starget)
4353{
4354 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4355
4356 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004357}
4358
James Smarte59058c2008-08-24 21:49:00 -04004359/**
James Smart3621a712009-04-06 18:47:14 -04004360 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004361 * @starget: kernel scsi target pointer.
4362 *
4363 * Description: Set the target node name to the ndlp node name wwn or zero.
4364 **/
dea31012005-04-17 16:05:31 -05004365static void
4366lpfc_get_starget_node_name(struct scsi_target *starget)
4367{
James Smart685f0bf2007-04-25 09:53:08 -04004368 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004369
James Smart685f0bf2007-04-25 09:53:08 -04004370 fc_starget_node_name(starget) =
4371 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004372}
4373
James Smarte59058c2008-08-24 21:49:00 -04004374/**
James Smart3621a712009-04-06 18:47:14 -04004375 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004376 * @starget: kernel scsi target pointer.
4377 *
4378 * Description: set the target port name to the ndlp port name wwn or zero.
4379 **/
dea31012005-04-17 16:05:31 -05004380static void
4381lpfc_get_starget_port_name(struct scsi_target *starget)
4382{
James Smart685f0bf2007-04-25 09:53:08 -04004383 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004384
James Smart685f0bf2007-04-25 09:53:08 -04004385 fc_starget_port_name(starget) =
4386 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004387}
4388
James Smarte59058c2008-08-24 21:49:00 -04004389/**
James Smart3621a712009-04-06 18:47:14 -04004390 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004391 * @rport: fc rport address.
4392 * @timeout: new value for dev loss tmo.
4393 *
4394 * Description:
4395 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4396 * dev_loss_tmo to one.
4397 **/
dea31012005-04-17 16:05:31 -05004398static void
dea31012005-04-17 16:05:31 -05004399lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4400{
dea31012005-04-17 16:05:31 -05004401 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004402 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004403 else
James Smartc01f3202006-08-18 17:47:08 -04004404 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004405}
4406
James Smarte59058c2008-08-24 21:49:00 -04004407/**
James Smart3621a712009-04-06 18:47:14 -04004408 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004409 *
4410 * Description:
4411 * Macro that uses field to generate a function with the name lpfc_show_rport_
4412 *
4413 * lpfc_show_rport_##field: returns the bytes formatted in buf
4414 * @cdev: class converted to an fc_rport.
4415 * @buf: on return contains the target_field or zero.
4416 *
4417 * Returns: size of formatted string.
4418 **/
dea31012005-04-17 16:05:31 -05004419#define lpfc_rport_show_function(field, format_string, sz, cast) \
4420static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004421lpfc_show_rport_##field (struct device *dev, \
4422 struct device_attribute *attr, \
4423 char *buf) \
dea31012005-04-17 16:05:31 -05004424{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004425 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004426 struct lpfc_rport_data *rdata = rport->hostdata; \
4427 return snprintf(buf, sz, format_string, \
4428 (rdata->target) ? cast rdata->target->field : 0); \
4429}
4430
4431#define lpfc_rport_rd_attr(field, format_string, sz) \
4432 lpfc_rport_show_function(field, format_string, sz, ) \
4433static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4434
James Smarteada2722008-12-04 22:39:13 -05004435/**
James Smart3621a712009-04-06 18:47:14 -04004436 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004437 * @fc_vport: The fc_vport who's symbolic name has been changed.
4438 *
4439 * Description:
4440 * This function is called by the transport after the @fc_vport's symbolic name
4441 * has been changed. This function re-registers the symbolic name with the
4442 * switch to propogate the change into the fabric if the vport is active.
4443 **/
4444static void
4445lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4446{
4447 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4448
4449 if (vport->port_state == LPFC_VPORT_READY)
4450 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4451}
dea31012005-04-17 16:05:31 -05004452
James Smartf4b4c682009-05-22 14:53:12 -04004453/**
4454 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4455 * @phba: Pointer to lpfc_hba struct.
4456 *
4457 * This function is called by the lpfc_get_cfgparam() routine to set the
4458 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4459 * log messsage according to the module's lpfc_log_verbose parameter setting
4460 * before hba port or vport created.
4461 **/
4462static void
4463lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4464{
4465 phba->cfg_log_verbose = verbose;
4466}
4467
dea31012005-04-17 16:05:31 -05004468struct fc_function_template lpfc_transport_functions = {
4469 /* fixed attributes the driver supports */
4470 .show_host_node_name = 1,
4471 .show_host_port_name = 1,
4472 .show_host_supported_classes = 1,
4473 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004474 .show_host_supported_speeds = 1,
4475 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004476 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004477
4478 /* dynamic attributes the driver supports */
4479 .get_host_port_id = lpfc_get_host_port_id,
4480 .show_host_port_id = 1,
4481
4482 .get_host_port_type = lpfc_get_host_port_type,
4483 .show_host_port_type = 1,
4484
4485 .get_host_port_state = lpfc_get_host_port_state,
4486 .show_host_port_state = 1,
4487
4488 /* active_fc4s is shown but doesn't change (thus no get function) */
4489 .show_host_active_fc4s = 1,
4490
4491 .get_host_speed = lpfc_get_host_speed,
4492 .show_host_speed = 1,
4493
4494 .get_host_fabric_name = lpfc_get_host_fabric_name,
4495 .show_host_fabric_name = 1,
4496
4497 /*
4498 * The LPFC driver treats linkdown handling as target loss events
4499 * so there are no sysfs handlers for link_down_tmo.
4500 */
4501
4502 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004503 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004504
4505 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4506 .show_rport_maxframe_size = 1,
4507 .show_rport_supported_classes = 1,
4508
dea31012005-04-17 16:05:31 -05004509 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4510 .show_rport_dev_loss_tmo = 1,
4511
4512 .get_starget_port_id = lpfc_get_starget_port_id,
4513 .show_starget_port_id = 1,
4514
4515 .get_starget_node_name = lpfc_get_starget_node_name,
4516 .show_starget_node_name = 1,
4517
4518 .get_starget_port_name = lpfc_get_starget_port_name,
4519 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004520
4521 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004522 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4523 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004524
James Smart92d7f7b2007-06-17 19:56:38 -05004525 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004526
4527 .vport_disable = lpfc_vport_disable,
4528
4529 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004530
4531 .bsg_request = lpfc_bsg_request,
4532 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004533};
4534
James Smart98c9ea52007-10-27 13:37:33 -04004535struct fc_function_template lpfc_vport_transport_functions = {
4536 /* fixed attributes the driver supports */
4537 .show_host_node_name = 1,
4538 .show_host_port_name = 1,
4539 .show_host_supported_classes = 1,
4540 .show_host_supported_fc4s = 1,
4541 .show_host_supported_speeds = 1,
4542 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004543 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004544
4545 /* dynamic attributes the driver supports */
4546 .get_host_port_id = lpfc_get_host_port_id,
4547 .show_host_port_id = 1,
4548
4549 .get_host_port_type = lpfc_get_host_port_type,
4550 .show_host_port_type = 1,
4551
4552 .get_host_port_state = lpfc_get_host_port_state,
4553 .show_host_port_state = 1,
4554
4555 /* active_fc4s is shown but doesn't change (thus no get function) */
4556 .show_host_active_fc4s = 1,
4557
4558 .get_host_speed = lpfc_get_host_speed,
4559 .show_host_speed = 1,
4560
4561 .get_host_fabric_name = lpfc_get_host_fabric_name,
4562 .show_host_fabric_name = 1,
4563
4564 /*
4565 * The LPFC driver treats linkdown handling as target loss events
4566 * so there are no sysfs handlers for link_down_tmo.
4567 */
4568
4569 .get_fc_host_stats = lpfc_get_stats,
4570 .reset_fc_host_stats = lpfc_reset_stats,
4571
4572 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4573 .show_rport_maxframe_size = 1,
4574 .show_rport_supported_classes = 1,
4575
4576 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4577 .show_rport_dev_loss_tmo = 1,
4578
4579 .get_starget_port_id = lpfc_get_starget_port_id,
4580 .show_starget_port_id = 1,
4581
4582 .get_starget_node_name = lpfc_get_starget_node_name,
4583 .show_starget_node_name = 1,
4584
4585 .get_starget_port_name = lpfc_get_starget_port_name,
4586 .show_starget_port_name = 1,
4587
4588 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4589 .terminate_rport_io = lpfc_terminate_rport_io,
4590
4591 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004592
4593 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004594};
4595
James Smarte59058c2008-08-24 21:49:00 -04004596/**
James Smart3621a712009-04-06 18:47:14 -04004597 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004598 * @phba: lpfc_hba pointer.
4599 **/
dea31012005-04-17 16:05:31 -05004600void
4601lpfc_get_cfgparam(struct lpfc_hba *phba)
4602{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004603 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4604 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004605 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004606 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4607 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004608 lpfc_ack0_init(phba, lpfc_ack0);
4609 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004610 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004611 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004612 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004613 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004614 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4615 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4616 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004617 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4618 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004619 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004620 if (phba->sli_rev == LPFC_SLI_REV4)
4621 phba->cfg_poll = 0;
4622 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004623 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004624 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004625 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004626 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004627 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004628 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004629 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004630 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004631 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004632 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004633 return;
4634}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004635
James Smarte59058c2008-08-24 21:49:00 -04004636/**
James Smart3621a712009-04-06 18:47:14 -04004637 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004638 * @vport: lpfc_vport pointer.
4639 **/
James Smart3de2a652007-08-02 11:09:59 -04004640void
4641lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4642{
James Smarte8b62012007-08-02 11:10:09 -04004643 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004644 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004645 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004646 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4647 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4648 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4649 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4650 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4651 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004652 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004653 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4654 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4655 lpfc_max_luns_init(vport, lpfc_max_luns);
4656 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004657 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004658 return;
4659}