blob: c06491b5862f04137fde8c01f36543460e7818ad [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
James Smart19ca7602010-11-20 23:11:55 -05001980int lpfc_enable_rrq;
1981module_param(lpfc_enable_rrq, int, 0);
1982MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
1983lpfc_param_show(enable_rrq);
1984lpfc_param_init(enable_rrq, 0, 0, 1);
1985static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
1986
dea31012005-04-17 16:05:31 -05001987/*
James Smart84d1b002010-02-12 14:42:33 -05001988# lpfc_suppress_link_up: Bring link up at initialization
1989# 0x0 = bring link up (issue MBX_INIT_LINK)
1990# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1991# 0x2 = never bring up link
1992# Default value is 0.
1993*/
James Smarte40a02c2010-02-26 14:13:54 -05001994LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1995 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1996 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04001997/*
1998# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1999# 1 - (1024)
2000# 2 - (2048)
2001# 3 - (3072)
2002# 4 - (4096)
2003# 5 - (5120)
2004*/
2005static ssize_t
2006lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2007{
2008 struct Scsi_Host *shost = class_to_shost(dev);
2009 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2010
2011 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2012}
2013
2014static DEVICE_ATTR(iocb_hw, S_IRUGO,
2015 lpfc_iocb_hw_show, NULL);
2016static ssize_t
2017lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2018{
2019 struct Scsi_Host *shost = class_to_shost(dev);
2020 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2021
2022 return snprintf(buf, PAGE_SIZE, "%d\n",
2023 phba->sli.ring[LPFC_ELS_RING].txq_max);
2024}
2025
2026static DEVICE_ATTR(txq_hw, S_IRUGO,
2027 lpfc_txq_hw_show, NULL);
2028static ssize_t
2029lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2030 char *buf)
2031{
2032 struct Scsi_Host *shost = class_to_shost(dev);
2033 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2034
2035 return snprintf(buf, PAGE_SIZE, "%d\n",
2036 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2037}
2038
2039static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2040 lpfc_txcmplq_hw_show, NULL);
2041
2042int lpfc_iocb_cnt = 2;
2043module_param(lpfc_iocb_cnt, int, 1);
2044MODULE_PARM_DESC(lpfc_iocb_cnt,
2045 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2046lpfc_param_show(iocb_cnt);
2047lpfc_param_init(iocb_cnt, 2, 1, 5);
2048static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2049 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002050
2051/*
James Smartc01f3202006-08-18 17:47:08 -04002052# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2053# until the timer expires. Value range is [0,255]. Default value is 30.
2054*/
2055static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2056static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2057module_param(lpfc_nodev_tmo, int, 0);
2058MODULE_PARM_DESC(lpfc_nodev_tmo,
2059 "Seconds driver will hold I/O waiting "
2060 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002061
2062/**
James Smart3621a712009-04-06 18:47:14 -04002063 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002064 * @dev: class converted to a Scsi_host structure.
2065 * @attr: device attribute, not used.
2066 * @buf: on return contains the dev loss timeout in decimal.
2067 *
2068 * Returns: size of formatted string.
2069 **/
James Smartc01f3202006-08-18 17:47:08 -04002070static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002071lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2072 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002073{
Tony Jonesee959b02008-02-22 00:13:36 +01002074 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002075 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002076
James Smart3de2a652007-08-02 11:09:59 -04002077 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002078}
2079
James Smarte59058c2008-08-24 21:49:00 -04002080/**
James Smart3621a712009-04-06 18:47:14 -04002081 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002082 * @vport: lpfc vport structure pointer.
2083 * @val: contains the nodev timeout value.
2084 *
2085 * Description:
2086 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2087 * a kernel error message is printed and zero is returned.
2088 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2089 * Otherwise nodev tmo is set to the default value.
2090 *
2091 * Returns:
2092 * zero if already set or if val is in range
2093 * -EINVAL val out of range
2094 **/
James Smartc01f3202006-08-18 17:47:08 -04002095static int
James Smart3de2a652007-08-02 11:09:59 -04002096lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002097{
James Smart3de2a652007-08-02 11:09:59 -04002098 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2099 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2100 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002101 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002102 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002103 "parameter because devloss_tmo is "
2104 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002105 return 0;
2106 }
2107
2108 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002109 vport->cfg_nodev_tmo = val;
2110 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002111 return 0;
2112 }
James Smarte8b62012007-08-02 11:10:09 -04002113 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2114 "0400 lpfc_nodev_tmo attribute cannot be set to"
2115 " %d, allowed range is [%d, %d]\n",
2116 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002117 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002118 return -EINVAL;
2119}
2120
James Smarte59058c2008-08-24 21:49:00 -04002121/**
James Smart3621a712009-04-06 18:47:14 -04002122 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002123 * @vport: lpfc vport structure pointer.
2124 *
2125 * Description:
2126 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2127 **/
James Smart7054a602007-04-25 09:52:34 -04002128static void
James Smart3de2a652007-08-02 11:09:59 -04002129lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002130{
James Smart858c9f62007-06-17 19:56:39 -05002131 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002132 struct lpfc_nodelist *ndlp;
2133
James Smart51ef4c22007-08-02 11:10:31 -04002134 shost = lpfc_shost_from_vport(vport);
2135 spin_lock_irq(shost->host_lock);
2136 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002137 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002138 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2139 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002140}
2141
James Smarte59058c2008-08-24 21:49:00 -04002142/**
James Smart3621a712009-04-06 18:47:14 -04002143 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002144 * @vport: lpfc vport structure pointer.
2145 * @val: contains the tmo value.
2146 *
2147 * Description:
2148 * If the devloss tmo is already set or the vport dev loss tmo has changed
2149 * then a kernel error message is printed and zero is returned.
2150 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2151 * Otherwise nodev tmo is set to the default value.
2152 *
2153 * Returns:
2154 * zero if already set or if val is in range
2155 * -EINVAL val out of range
2156 **/
James Smartc01f3202006-08-18 17:47:08 -04002157static int
James Smart3de2a652007-08-02 11:09:59 -04002158lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002159{
James Smart3de2a652007-08-02 11:09:59 -04002160 if (vport->dev_loss_tmo_changed ||
2161 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002162 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2163 "0401 Ignoring change to nodev_tmo "
2164 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002165 return 0;
2166 }
James Smartc01f3202006-08-18 17:47:08 -04002167 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002168 vport->cfg_nodev_tmo = val;
2169 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002170 /*
2171 * For compat: set the fc_host dev loss so new rports
2172 * will get the value.
2173 */
2174 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002175 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002176 return 0;
2177 }
James Smarte8b62012007-08-02 11:10:09 -04002178 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2179 "0403 lpfc_nodev_tmo attribute cannot be set to"
2180 "%d, allowed range is [%d, %d]\n",
2181 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002182 return -EINVAL;
2183}
2184
James Smart3de2a652007-08-02 11:09:59 -04002185lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002186
Tony Jonesee959b02008-02-22 00:13:36 +01002187static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2188 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002189
2190/*
2191# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2192# disappear until the timer expires. Value range is [0,255]. Default
2193# value is 30.
2194*/
2195module_param(lpfc_devloss_tmo, int, 0);
2196MODULE_PARM_DESC(lpfc_devloss_tmo,
2197 "Seconds driver will hold I/O waiting "
2198 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002199lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2200 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2201lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002202
2203/**
James Smart3621a712009-04-06 18:47:14 -04002204 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002205 * @vport: lpfc vport structure pointer.
2206 * @val: contains the tmo value.
2207 *
2208 * Description:
2209 * If val is in a valid range then set the vport nodev tmo,
2210 * devloss tmo, also set the vport dev loss tmo changed flag.
2211 * Else a kernel error message is printed.
2212 *
2213 * Returns:
2214 * zero if val is in range
2215 * -EINVAL val out of range
2216 **/
James Smartc01f3202006-08-18 17:47:08 -04002217static int
James Smart3de2a652007-08-02 11:09:59 -04002218lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002219{
2220 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002221 vport->cfg_nodev_tmo = val;
2222 vport->cfg_devloss_tmo = val;
2223 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002224 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002225 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002226 return 0;
2227 }
2228
James Smarte8b62012007-08-02 11:10:09 -04002229 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2230 "0404 lpfc_devloss_tmo attribute cannot be set to"
2231 " %d, allowed range is [%d, %d]\n",
2232 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002233 return -EINVAL;
2234}
2235
James Smart3de2a652007-08-02 11:09:59 -04002236lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002237static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2238 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002239
2240/*
dea31012005-04-17 16:05:31 -05002241# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2242# deluged with LOTS of information.
2243# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002244# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002245*/
James Smartf4b4c682009-05-22 14:53:12 -04002246LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002247 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002248
2249/*
James Smart7ee5d432007-10-27 13:37:17 -04002250# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2251# objects that have been registered with the nameserver after login.
2252*/
2253LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2254 "Deregister nameserver objects before LOGO");
2255
2256/*
dea31012005-04-17 16:05:31 -05002257# lun_queue_depth: This parameter is used to limit the number of outstanding
2258# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2259*/
James Smart3de2a652007-08-02 11:09:59 -04002260LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2261 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002262
2263/*
James Smart7dc517d2010-07-14 15:32:10 -04002264# tgt_queue_depth: This parameter is used to limit the number of outstanding
2265# commands per target port. Value range is [10,65535]. Default value is 65535.
2266*/
2267LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2268 "Max number of FCP commands we can queue to a specific target port");
2269
2270/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002271# hba_queue_depth: This parameter is used to limit the number of outstanding
2272# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2273# value is greater than the maximum number of exchanges supported by the HBA,
2274# then maximum number of exchanges supported by the HBA is used to determine
2275# the hba_queue_depth.
2276*/
2277LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2278 "Max number of FCP commands we can queue to a lpfc HBA");
2279
2280/*
James Smart92d7f7b2007-06-17 19:56:38 -05002281# peer_port_login: This parameter allows/prevents logins
2282# between peer ports hosted on the same physical port.
2283# When this parameter is set 0 peer ports of same physical port
2284# are not allowed to login to each other.
2285# When this parameter is set 1 peer ports of same physical port
2286# are allowed to login to each other.
2287# Default value of this parameter is 0.
2288*/
James Smart3de2a652007-08-02 11:09:59 -04002289LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2290 "Allow peer ports on the same physical port to login to each "
2291 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002292
2293/*
James Smart3de2a652007-08-02 11:09:59 -04002294# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002295# between Virtual Ports and remote initiators.
2296# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2297# other initiators and will attempt to PLOGI all remote ports.
2298# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2299# remote ports and will not attempt to PLOGI to other initiators.
2300# This parameter does not restrict to the physical port.
2301# This parameter does not restrict logins to Fabric resident remote ports.
2302# Default value of this parameter is 1.
2303*/
James Smart3de2a652007-08-02 11:09:59 -04002304static int lpfc_restrict_login = 1;
2305module_param(lpfc_restrict_login, int, 0);
2306MODULE_PARM_DESC(lpfc_restrict_login,
2307 "Restrict virtual ports login to remote initiators.");
2308lpfc_vport_param_show(restrict_login);
2309
James Smarte59058c2008-08-24 21:49:00 -04002310/**
James Smart3621a712009-04-06 18:47:14 -04002311 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002312 * @vport: lpfc vport structure pointer.
2313 * @val: contains the restrict login value.
2314 *
2315 * Description:
2316 * If val is not in a valid range then log a kernel error message and set
2317 * the vport restrict login to one.
2318 * If the port type is physical clear the restrict login flag and return.
2319 * Else set the restrict login flag to val.
2320 *
2321 * Returns:
2322 * zero if val is in range
2323 * -EINVAL val out of range
2324 **/
James Smart3de2a652007-08-02 11:09:59 -04002325static int
2326lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2327{
2328 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002329 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002330 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002331 "be set to %d, allowed range is [0, 1]\n",
2332 val);
James Smart3de2a652007-08-02 11:09:59 -04002333 vport->cfg_restrict_login = 1;
2334 return -EINVAL;
2335 }
2336 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2337 vport->cfg_restrict_login = 0;
2338 return 0;
2339 }
2340 vport->cfg_restrict_login = val;
2341 return 0;
2342}
2343
James Smarte59058c2008-08-24 21:49:00 -04002344/**
James Smart3621a712009-04-06 18:47:14 -04002345 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002346 * @vport: lpfc vport structure pointer.
2347 * @val: contains the restrict login value.
2348 *
2349 * Description:
2350 * If val is not in a valid range then log a kernel error message and set
2351 * the vport restrict login to one.
2352 * If the port type is physical and the val is not zero log a kernel
2353 * error message, clear the restrict login flag and return zero.
2354 * Else set the restrict login flag to val.
2355 *
2356 * Returns:
2357 * zero if val is in range
2358 * -EINVAL val out of range
2359 **/
James Smart3de2a652007-08-02 11:09:59 -04002360static int
2361lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2362{
2363 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002364 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002365 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002366 "be set to %d, allowed range is [0, 1]\n",
2367 val);
James Smart3de2a652007-08-02 11:09:59 -04002368 vport->cfg_restrict_login = 1;
2369 return -EINVAL;
2370 }
2371 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002372 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2373 "0468 lpfc_restrict_login must be 0 for "
2374 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002375 vport->cfg_restrict_login = 0;
2376 return 0;
2377 }
2378 vport->cfg_restrict_login = val;
2379 return 0;
2380}
2381lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002382static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2383 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002384
2385/*
dea31012005-04-17 16:05:31 -05002386# Some disk devices have a "select ID" or "select Target" capability.
2387# From a protocol standpoint "select ID" usually means select the
2388# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2389# annex" which contains a table that maps a "select ID" (a number
2390# between 0 and 7F) to an ALPA. By default, for compatibility with
2391# older drivers, the lpfc driver scans this table from low ALPA to high
2392# ALPA.
2393#
2394# Turning on the scan-down variable (on = 1, off = 0) will
2395# cause the lpfc driver to use an inverted table, effectively
2396# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2397#
2398# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2399# and will not work across a fabric. Also this parameter will take
2400# effect only in the case when ALPA map is not available.)
2401*/
James Smart3de2a652007-08-02 11:09:59 -04002402LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2403 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002404
2405/*
dea31012005-04-17 16:05:31 -05002406# lpfc_topology: link topology for init link
2407# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002408# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002409# 0x02 = attempt point-to-point mode only
2410# 0x04 = attempt loop mode only
2411# 0x06 = attempt point-to-point mode then loop
2412# Set point-to-point mode if you want to run as an N_Port.
2413# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2414# Default value is 0.
2415*/
James Smarte59058c2008-08-24 21:49:00 -04002416
2417/**
James Smart3621a712009-04-06 18:47:14 -04002418 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002419 * @phba: lpfc_hba pointer.
2420 * @val: topology value.
2421 *
2422 * Description:
2423 * If val is in a valid range then set the adapter's topology field and
2424 * issue a lip; if the lip fails reset the topology to the old value.
2425 *
2426 * If the value is not in range log a kernel error message and return an error.
2427 *
2428 * Returns:
2429 * zero if val is in range and lip okay
2430 * non-zero return value from lpfc_issue_lip()
2431 * -EINVAL val out of range
2432 **/
James Smarta257bf92009-04-06 18:48:10 -04002433static ssize_t
2434lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2435 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002436{
James Smarta257bf92009-04-06 18:48:10 -04002437 struct Scsi_Host *shost = class_to_shost(dev);
2438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2439 struct lpfc_hba *phba = vport->phba;
2440 int val = 0;
2441 int nolip = 0;
2442 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002443 int err;
2444 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002445
2446 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2447 nolip = 1;
2448 val_buf = &buf[strlen("nolip ")];
2449 }
2450
2451 if (!isdigit(val_buf[0]))
2452 return -EINVAL;
2453 if (sscanf(val_buf, "%i", &val) != 1)
2454 return -EINVAL;
2455
James Smart83108bd2008-01-11 01:53:09 -05002456 if (val >= 0 && val <= 6) {
2457 prev_val = phba->cfg_topology;
2458 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002459 if (nolip)
2460 return strlen(buf);
2461
James Smart83108bd2008-01-11 01:53:09 -05002462 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002463 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002464 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002465 return -EINVAL;
2466 } else
2467 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002468 }
2469 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2470 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2471 "allowed range is [0, 6]\n",
2472 phba->brd_no, val);
2473 return -EINVAL;
2474}
2475static int lpfc_topology = 0;
2476module_param(lpfc_topology, int, 0);
2477MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2478lpfc_param_show(topology)
2479lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002480static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002481 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002482
James Smart21e9a0a2009-05-22 14:53:21 -04002483/**
2484 * lpfc_static_vport_show: Read callback function for
2485 * lpfc_static_vport sysfs file.
2486 * @dev: Pointer to class device object.
2487 * @attr: device attribute structure.
2488 * @buf: Data buffer.
2489 *
2490 * This function is the read call back function for
2491 * lpfc_static_vport sysfs file. The lpfc_static_vport
2492 * sysfs file report the mageability of the vport.
2493 **/
2494static ssize_t
2495lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2496 char *buf)
2497{
2498 struct Scsi_Host *shost = class_to_shost(dev);
2499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2500 if (vport->vport_flag & STATIC_VPORT)
2501 sprintf(buf, "1\n");
2502 else
2503 sprintf(buf, "0\n");
2504
2505 return strlen(buf);
2506}
2507
2508/*
2509 * Sysfs attribute to control the statistical data collection.
2510 */
2511static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2512 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002513
2514/**
James Smart3621a712009-04-06 18:47:14 -04002515 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002516 * @dev: Pointer to class device.
2517 * @buf: Data buffer.
2518 * @count: Size of the data buffer.
2519 *
2520 * This function get called when an user write to the lpfc_stat_data_ctrl
2521 * sysfs file. This function parse the command written to the sysfs file
2522 * and take appropriate action. These commands are used for controlling
2523 * driver statistical data collection.
2524 * Following are the command this function handles.
2525 *
2526 * setbucket <bucket_type> <base> <step>
2527 * = Set the latency buckets.
2528 * destroybucket = destroy all the buckets.
2529 * start = start data collection
2530 * stop = stop data collection
2531 * reset = reset the collected data
2532 **/
2533static ssize_t
2534lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2535 const char *buf, size_t count)
2536{
2537 struct Scsi_Host *shost = class_to_shost(dev);
2538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2539 struct lpfc_hba *phba = vport->phba;
2540#define LPFC_MAX_DATA_CTRL_LEN 1024
2541 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2542 unsigned long i;
2543 char *str_ptr, *token;
2544 struct lpfc_vport **vports;
2545 struct Scsi_Host *v_shost;
2546 char *bucket_type_str, *base_str, *step_str;
2547 unsigned long base, step, bucket_type;
2548
2549 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002550 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002551 return -EINVAL;
2552
2553 strcpy(bucket_data, buf);
2554 str_ptr = &bucket_data[0];
2555 /* Ignore this token - this is command token */
2556 token = strsep(&str_ptr, "\t ");
2557 if (!token)
2558 return -EINVAL;
2559
2560 bucket_type_str = strsep(&str_ptr, "\t ");
2561 if (!bucket_type_str)
2562 return -EINVAL;
2563
2564 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2565 bucket_type = LPFC_LINEAR_BUCKET;
2566 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2567 bucket_type = LPFC_POWER2_BUCKET;
2568 else
2569 return -EINVAL;
2570
2571 base_str = strsep(&str_ptr, "\t ");
2572 if (!base_str)
2573 return -EINVAL;
2574 base = simple_strtoul(base_str, NULL, 0);
2575
2576 step_str = strsep(&str_ptr, "\t ");
2577 if (!step_str)
2578 return -EINVAL;
2579 step = simple_strtoul(step_str, NULL, 0);
2580 if (!step)
2581 return -EINVAL;
2582
2583 /* Block the data collection for every vport */
2584 vports = lpfc_create_vport_work_array(phba);
2585 if (vports == NULL)
2586 return -ENOMEM;
2587
James Smartf4b4c682009-05-22 14:53:12 -04002588 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002589 v_shost = lpfc_shost_from_vport(vports[i]);
2590 spin_lock_irq(v_shost->host_lock);
2591 /* Block and reset data collection */
2592 vports[i]->stat_data_blocked = 1;
2593 if (vports[i]->stat_data_enabled)
2594 lpfc_vport_reset_stat_data(vports[i]);
2595 spin_unlock_irq(v_shost->host_lock);
2596 }
2597
2598 /* Set the bucket attributes */
2599 phba->bucket_type = bucket_type;
2600 phba->bucket_base = base;
2601 phba->bucket_step = step;
2602
James Smartf4b4c682009-05-22 14:53:12 -04002603 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002604 v_shost = lpfc_shost_from_vport(vports[i]);
2605
2606 /* Unblock data collection */
2607 spin_lock_irq(v_shost->host_lock);
2608 vports[i]->stat_data_blocked = 0;
2609 spin_unlock_irq(v_shost->host_lock);
2610 }
2611 lpfc_destroy_vport_work_array(phba, vports);
2612 return strlen(buf);
2613 }
2614
2615 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2616 vports = lpfc_create_vport_work_array(phba);
2617 if (vports == NULL)
2618 return -ENOMEM;
2619
James Smartf4b4c682009-05-22 14:53:12 -04002620 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002621 v_shost = lpfc_shost_from_vport(vports[i]);
2622 spin_lock_irq(shost->host_lock);
2623 vports[i]->stat_data_blocked = 1;
2624 lpfc_free_bucket(vport);
2625 vport->stat_data_enabled = 0;
2626 vports[i]->stat_data_blocked = 0;
2627 spin_unlock_irq(shost->host_lock);
2628 }
2629 lpfc_destroy_vport_work_array(phba, vports);
2630 phba->bucket_type = LPFC_NO_BUCKET;
2631 phba->bucket_base = 0;
2632 phba->bucket_step = 0;
2633 return strlen(buf);
2634 }
2635
2636 if (!strncmp(buf, "start", strlen("start"))) {
2637 /* If no buckets configured return error */
2638 if (phba->bucket_type == LPFC_NO_BUCKET)
2639 return -EINVAL;
2640 spin_lock_irq(shost->host_lock);
2641 if (vport->stat_data_enabled) {
2642 spin_unlock_irq(shost->host_lock);
2643 return strlen(buf);
2644 }
2645 lpfc_alloc_bucket(vport);
2646 vport->stat_data_enabled = 1;
2647 spin_unlock_irq(shost->host_lock);
2648 return strlen(buf);
2649 }
2650
2651 if (!strncmp(buf, "stop", strlen("stop"))) {
2652 spin_lock_irq(shost->host_lock);
2653 if (vport->stat_data_enabled == 0) {
2654 spin_unlock_irq(shost->host_lock);
2655 return strlen(buf);
2656 }
2657 lpfc_free_bucket(vport);
2658 vport->stat_data_enabled = 0;
2659 spin_unlock_irq(shost->host_lock);
2660 return strlen(buf);
2661 }
2662
2663 if (!strncmp(buf, "reset", strlen("reset"))) {
2664 if ((phba->bucket_type == LPFC_NO_BUCKET)
2665 || !vport->stat_data_enabled)
2666 return strlen(buf);
2667 spin_lock_irq(shost->host_lock);
2668 vport->stat_data_blocked = 1;
2669 lpfc_vport_reset_stat_data(vport);
2670 vport->stat_data_blocked = 0;
2671 spin_unlock_irq(shost->host_lock);
2672 return strlen(buf);
2673 }
2674 return -EINVAL;
2675}
2676
2677
2678/**
James Smart3621a712009-04-06 18:47:14 -04002679 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002680 * @dev: Pointer to class device object.
2681 * @buf: Data buffer.
2682 *
2683 * This function is the read call back function for
2684 * lpfc_stat_data_ctrl sysfs file. This function report the
2685 * current statistical data collection state.
2686 **/
2687static ssize_t
2688lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2689 char *buf)
2690{
2691 struct Scsi_Host *shost = class_to_shost(dev);
2692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2693 struct lpfc_hba *phba = vport->phba;
2694 int index = 0;
2695 int i;
2696 char *bucket_type;
2697 unsigned long bucket_value;
2698
2699 switch (phba->bucket_type) {
2700 case LPFC_LINEAR_BUCKET:
2701 bucket_type = "linear";
2702 break;
2703 case LPFC_POWER2_BUCKET:
2704 bucket_type = "power2";
2705 break;
2706 default:
2707 bucket_type = "No Bucket";
2708 break;
2709 }
2710
2711 sprintf(&buf[index], "Statistical Data enabled :%d, "
2712 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2713 " Bucket step :%d\nLatency Ranges :",
2714 vport->stat_data_enabled, vport->stat_data_blocked,
2715 bucket_type, phba->bucket_base, phba->bucket_step);
2716 index = strlen(buf);
2717 if (phba->bucket_type != LPFC_NO_BUCKET) {
2718 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2719 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2720 bucket_value = phba->bucket_base +
2721 phba->bucket_step * i;
2722 else
2723 bucket_value = phba->bucket_base +
2724 (1 << i) * phba->bucket_step;
2725
2726 if (index + 10 > PAGE_SIZE)
2727 break;
2728 sprintf(&buf[index], "%08ld ", bucket_value);
2729 index = strlen(buf);
2730 }
2731 }
2732 sprintf(&buf[index], "\n");
2733 return strlen(buf);
2734}
2735
2736/*
2737 * Sysfs attribute to control the statistical data collection.
2738 */
2739static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2740 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2741
2742/*
2743 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2744 */
2745
2746/*
2747 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2748 * for each target.
2749 */
2750#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2751#define MAX_STAT_DATA_SIZE_PER_TARGET \
2752 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2753
2754
2755/**
James Smart3621a712009-04-06 18:47:14 -04002756 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002757 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002758 * @kobj: Pointer to the kernel object
2759 * @bin_attr: Attribute object
2760 * @buff: Buffer pointer
2761 * @off: File offset
2762 * @count: Buffer size
2763 *
2764 * This function is the read call back function for lpfc_drvr_stat_data
2765 * sysfs file. This function export the statistical data to user
2766 * applications.
2767 **/
2768static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002769sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2770 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002771 char *buf, loff_t off, size_t count)
2772{
2773 struct device *dev = container_of(kobj, struct device,
2774 kobj);
2775 struct Scsi_Host *shost = class_to_shost(dev);
2776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2777 struct lpfc_hba *phba = vport->phba;
2778 int i = 0, index = 0;
2779 unsigned long nport_index;
2780 struct lpfc_nodelist *ndlp = NULL;
2781 nport_index = (unsigned long)off /
2782 MAX_STAT_DATA_SIZE_PER_TARGET;
2783
2784 if (!vport->stat_data_enabled || vport->stat_data_blocked
2785 || (phba->bucket_type == LPFC_NO_BUCKET))
2786 return 0;
2787
2788 spin_lock_irq(shost->host_lock);
2789 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2790 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2791 continue;
2792
2793 if (nport_index > 0) {
2794 nport_index--;
2795 continue;
2796 }
2797
2798 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2799 > count)
2800 break;
2801
2802 if (!ndlp->lat_data)
2803 continue;
2804
2805 /* Print the WWN */
2806 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2807 ndlp->nlp_portname.u.wwn[0],
2808 ndlp->nlp_portname.u.wwn[1],
2809 ndlp->nlp_portname.u.wwn[2],
2810 ndlp->nlp_portname.u.wwn[3],
2811 ndlp->nlp_portname.u.wwn[4],
2812 ndlp->nlp_portname.u.wwn[5],
2813 ndlp->nlp_portname.u.wwn[6],
2814 ndlp->nlp_portname.u.wwn[7]);
2815
2816 index = strlen(buf);
2817
2818 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2819 sprintf(&buf[index], "%010u,",
2820 ndlp->lat_data[i].cmd_count);
2821 index = strlen(buf);
2822 }
2823 sprintf(&buf[index], "\n");
2824 index = strlen(buf);
2825 }
2826 spin_unlock_irq(shost->host_lock);
2827 return index;
2828}
2829
2830static struct bin_attribute sysfs_drvr_stat_data_attr = {
2831 .attr = {
2832 .name = "lpfc_drvr_stat_data",
2833 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04002834 },
2835 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2836 .read = sysfs_drvr_stat_data_read,
2837 .write = NULL,
2838};
2839
dea31012005-04-17 16:05:31 -05002840/*
2841# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2842# connection.
James Smart76a95d72010-11-20 23:11:48 -05002843# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05002844*/
James Smarte59058c2008-08-24 21:49:00 -04002845/**
James Smart3621a712009-04-06 18:47:14 -04002846 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002847 * @phba: lpfc_hba pointer.
2848 * @val: link speed value.
2849 *
2850 * Description:
2851 * If val is in a valid range then set the adapter's link speed field and
2852 * issue a lip; if the lip fails reset the link speed to the old value.
2853 *
2854 * Notes:
2855 * If the value is not in range log a kernel error message and return an error.
2856 *
2857 * Returns:
2858 * zero if val is in range and lip okay.
2859 * non-zero return value from lpfc_issue_lip()
2860 * -EINVAL val out of range
2861 **/
James Smarta257bf92009-04-06 18:48:10 -04002862static ssize_t
2863lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2864 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002865{
James Smarta257bf92009-04-06 18:48:10 -04002866 struct Scsi_Host *shost = class_to_shost(dev);
2867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2868 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05002869 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04002870 int nolip = 0;
2871 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002872 int err;
2873 uint32_t prev_val;
2874
James Smarta257bf92009-04-06 18:48:10 -04002875 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2876 nolip = 1;
2877 val_buf = &buf[strlen("nolip ")];
2878 }
2879
2880 if (!isdigit(val_buf[0]))
2881 return -EINVAL;
2882 if (sscanf(val_buf, "%i", &val) != 1)
2883 return -EINVAL;
2884
James Smart76a95d72010-11-20 23:11:48 -05002885 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2886 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2887 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2888 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2889 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2890 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2892 "2879 lpfc_link_speed attribute cannot be set "
2893 "to %d. Speed is not supported by this port.\n",
2894 val);
James Smart83108bd2008-01-11 01:53:09 -05002895 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05002896 }
2897 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2898 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002899 prev_val = phba->cfg_link_speed;
2900 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002901 if (nolip)
2902 return strlen(buf);
2903
James Smart83108bd2008-01-11 01:53:09 -05002904 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002905 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002906 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002907 return -EINVAL;
2908 } else
2909 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002910 }
James Smart83108bd2008-01-11 01:53:09 -05002911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05002912 "0469 lpfc_link_speed attribute cannot be set to %d, "
2913 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05002914 return -EINVAL;
2915}
2916
2917static int lpfc_link_speed = 0;
2918module_param(lpfc_link_speed, int, 0);
2919MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2920lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002921
2922/**
James Smart3621a712009-04-06 18:47:14 -04002923 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002924 * @phba: lpfc_hba pointer.
2925 * @val: link speed value.
2926 *
2927 * Description:
2928 * If val is in a valid range then set the adapter's link speed field.
2929 *
2930 * Notes:
2931 * If the value is not in range log a kernel error message, clear the link
2932 * speed and return an error.
2933 *
2934 * Returns:
2935 * zero if val saved.
2936 * -EINVAL val out of range
2937 **/
James Smart83108bd2008-01-11 01:53:09 -05002938static int
2939lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2940{
James Smart76a95d72010-11-20 23:11:48 -05002941 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2942 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002943 phba->cfg_link_speed = val;
2944 return 0;
2945 }
2946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002947 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002948 "be set to %d, allowed values are "
2949 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05002950 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05002951 return -EINVAL;
2952}
2953
Tony Jonesee959b02008-02-22 00:13:36 +01002954static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05002955 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002956
2957/*
James Smart0d878412009-10-02 15:16:56 -04002958# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2959# 0 = aer disabled or not supported
2960# 1 = aer supported and enabled (default)
2961# Value range is [0,1]. Default value is 1.
2962*/
2963
2964/**
2965 * lpfc_aer_support_store - Set the adapter for aer support
2966 *
2967 * @dev: class device that is converted into a Scsi_host.
2968 * @attr: device attribute, not used.
2969 * @buf: containing the string "selective".
2970 * @count: unused variable.
2971 *
2972 * Description:
2973 * If the val is 1 and currently the device's AER capability was not
2974 * enabled, invoke the kernel's enable AER helper routine, trying to
2975 * enable the device's AER capability. If the helper routine enabling
2976 * AER returns success, update the device's cfg_aer_support flag to
2977 * indicate AER is supported by the device; otherwise, if the device
2978 * AER capability is already enabled to support AER, then do nothing.
2979 *
2980 * If the val is 0 and currently the device's AER support was enabled,
2981 * invoke the kernel's disable AER helper routine. After that, update
2982 * the device's cfg_aer_support flag to indicate AER is not supported
2983 * by the device; otherwise, if the device AER capability is already
2984 * disabled from supporting AER, then do nothing.
2985 *
2986 * Returns:
2987 * length of the buf on success if val is in range the intended mode
2988 * is supported.
2989 * -EINVAL if val out of range or intended mode is not supported.
2990 **/
2991static ssize_t
2992lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2993 const char *buf, size_t count)
2994{
2995 struct Scsi_Host *shost = class_to_shost(dev);
2996 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2997 struct lpfc_hba *phba = vport->phba;
2998 int val = 0, rc = -EINVAL;
2999
3000 if (!isdigit(buf[0]))
3001 return -EINVAL;
3002 if (sscanf(buf, "%i", &val) != 1)
3003 return -EINVAL;
3004
3005 switch (val) {
3006 case 0:
3007 if (phba->hba_flag & HBA_AER_ENABLED) {
3008 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3009 if (!rc) {
3010 spin_lock_irq(&phba->hbalock);
3011 phba->hba_flag &= ~HBA_AER_ENABLED;
3012 spin_unlock_irq(&phba->hbalock);
3013 phba->cfg_aer_support = 0;
3014 rc = strlen(buf);
3015 } else
James Smart891478a2009-11-18 15:40:23 -05003016 rc = -EPERM;
3017 } else {
James Smart0d878412009-10-02 15:16:56 -04003018 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003019 rc = strlen(buf);
3020 }
James Smart0d878412009-10-02 15:16:56 -04003021 break;
3022 case 1:
3023 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3024 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3025 if (!rc) {
3026 spin_lock_irq(&phba->hbalock);
3027 phba->hba_flag |= HBA_AER_ENABLED;
3028 spin_unlock_irq(&phba->hbalock);
3029 phba->cfg_aer_support = 1;
3030 rc = strlen(buf);
3031 } else
James Smart891478a2009-11-18 15:40:23 -05003032 rc = -EPERM;
3033 } else {
James Smart0d878412009-10-02 15:16:56 -04003034 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003035 rc = strlen(buf);
3036 }
James Smart0d878412009-10-02 15:16:56 -04003037 break;
3038 default:
3039 rc = -EINVAL;
3040 break;
3041 }
3042 return rc;
3043}
3044
3045static int lpfc_aer_support = 1;
3046module_param(lpfc_aer_support, int, 1);
3047MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3048lpfc_param_show(aer_support)
3049
3050/**
3051 * lpfc_aer_support_init - Set the initial adapters aer support flag
3052 * @phba: lpfc_hba pointer.
3053 * @val: link speed value.
3054 *
3055 * Description:
3056 * If val is in a valid range [0,1], then set the adapter's initial
3057 * cfg_aer_support field. It will be up to the driver's probe_one
3058 * routine to determine whether the device's AER support can be set
3059 * or not.
3060 *
3061 * Notes:
3062 * If the value is not in range log a kernel error message, and
3063 * choose the default value of setting AER support and return.
3064 *
3065 * Returns:
3066 * zero if val saved.
3067 * -EINVAL val out of range
3068 **/
3069static int
3070lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3071{
3072 if (val == 0 || val == 1) {
3073 phba->cfg_aer_support = val;
3074 return 0;
3075 }
3076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3077 "2712 lpfc_aer_support attribute value %d out "
3078 "of range, allowed values are 0|1, setting it "
3079 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003080 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003081 phba->cfg_aer_support = 1;
3082 return -EINVAL;
3083}
3084
3085static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3086 lpfc_aer_support_show, lpfc_aer_support_store);
3087
3088/**
3089 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3090 * @dev: class device that is converted into a Scsi_host.
3091 * @attr: device attribute, not used.
3092 * @buf: containing the string "selective".
3093 * @count: unused variable.
3094 *
3095 * Description:
3096 * If the @buf contains 1 and the device currently has the AER support
3097 * enabled, then invokes the kernel AER helper routine
3098 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3099 * error status register.
3100 *
3101 * Notes:
3102 *
3103 * Returns:
3104 * -EINVAL if the buf does not contain the 1 or the device is not currently
3105 * enabled with the AER support.
3106 **/
3107static ssize_t
3108lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3109 const char *buf, size_t count)
3110{
3111 struct Scsi_Host *shost = class_to_shost(dev);
3112 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3113 struct lpfc_hba *phba = vport->phba;
3114 int val, rc = -1;
3115
3116 if (!isdigit(buf[0]))
3117 return -EINVAL;
3118 if (sscanf(buf, "%i", &val) != 1)
3119 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003120 if (val != 1)
3121 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003122
James Smart891478a2009-11-18 15:40:23 -05003123 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003124 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3125
3126 if (rc == 0)
3127 return strlen(buf);
3128 else
James Smart891478a2009-11-18 15:40:23 -05003129 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003130}
3131
3132static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3133 lpfc_aer_cleanup_state);
3134
3135/*
dea31012005-04-17 16:05:31 -05003136# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3137# Value range is [2,3]. Default value is 3.
3138*/
James Smart3de2a652007-08-02 11:09:59 -04003139LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3140 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003141
3142/*
3143# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3144# is [0,1]. Default value is 0.
3145*/
James Smart3de2a652007-08-02 11:09:59 -04003146LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3147 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003148
3149/*
James Smart977b5a02008-09-07 11:52:04 -04003150# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3151# depth. Default value is 0. When the value of this parameter is zero the
3152# SCSI command completion time is not used for controlling I/O queue depth. When
3153# the parameter is set to a non-zero value, the I/O queue depth is controlled
3154# to limit the I/O completion time to the parameter value.
3155# The value is set in milliseconds.
3156*/
3157static int lpfc_max_scsicmpl_time;
3158module_param(lpfc_max_scsicmpl_time, int, 0);
3159MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3160 "Use command completion time to control queue depth");
3161lpfc_vport_param_show(max_scsicmpl_time);
3162lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3163static int
3164lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3165{
3166 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3167 struct lpfc_nodelist *ndlp, *next_ndlp;
3168
3169 if (val == vport->cfg_max_scsicmpl_time)
3170 return 0;
3171 if ((val < 0) || (val > 60000))
3172 return -EINVAL;
3173 vport->cfg_max_scsicmpl_time = val;
3174
3175 spin_lock_irq(shost->host_lock);
3176 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3177 if (!NLP_CHK_NODE_ACT(ndlp))
3178 continue;
3179 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3180 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003181 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003182 }
3183 spin_unlock_irq(shost->host_lock);
3184 return 0;
3185}
3186lpfc_vport_param_store(max_scsicmpl_time);
3187static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3188 lpfc_max_scsicmpl_time_show,
3189 lpfc_max_scsicmpl_time_store);
3190
3191/*
dea31012005-04-17 16:05:31 -05003192# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3193# range is [0,1]. Default value is 0.
3194*/
3195LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3196
3197/*
3198# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3199# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003200# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003201# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3202# cr_delay is set to 0.
3203*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003204LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003205 "interrupt response is generated");
3206
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003207LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003208 "interrupt response is generated");
3209
3210/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003211# lpfc_multi_ring_support: Determines how many rings to spread available
3212# cmd/rsp IOCB entries across.
3213# Value range is [1,2]. Default value is 1.
3214*/
3215LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3216 "SLI rings to spread IOCB entries across");
3217
3218/*
James Smarta4bc3372006-12-02 13:34:16 -05003219# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3220# identifies what rctl value to configure the additional ring for.
3221# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3222*/
James Smart6a9c52c2009-10-02 15:16:51 -04003223LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003224 255, "Identifies RCTL for additional ring configuration");
3225
3226/*
3227# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3228# identifies what type value to configure the additional ring for.
3229# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3230*/
James Smart6a9c52c2009-10-02 15:16:51 -04003231LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003232 255, "Identifies TYPE for additional ring configuration");
3233
3234/*
dea31012005-04-17 16:05:31 -05003235# lpfc_fdmi_on: controls FDMI support.
3236# 0 = no FDMI support
3237# 1 = support FDMI without attribute of hostname
3238# 2 = support FDMI with attribute of hostname
3239# Value range [0,2]. Default value is 0.
3240*/
James Smart3de2a652007-08-02 11:09:59 -04003241LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003242
3243/*
3244# Specifies the maximum number of ELS cmds we can have outstanding (for
3245# discovery). Value range is [1,64]. Default value = 32.
3246*/
James Smart3de2a652007-08-02 11:09:59 -04003247LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003248 "during discovery");
3249
3250/*
James Smart65a29c12006-07-06 15:50:50 -04003251# lpfc_max_luns: maximum allowed LUN.
3252# Value range is [0,65535]. Default value is 255.
3253# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003254*/
James Smart3de2a652007-08-02 11:09:59 -04003255LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003256
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003257/*
3258# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3259# Value range is [1,255], default value is 10.
3260*/
3261LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3262 "Milliseconds driver will wait between polling FCP ring");
3263
James Smart4ff43242006-12-02 13:34:56 -05003264/*
3265# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3266# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003267# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003268# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003269# 2 = MSI-X enabled (default)
3270# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003271*/
George Kadianakis8605c462010-01-17 21:19:31 +02003272LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003273 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003274
James Smart13815c82008-01-11 01:52:48 -05003275/*
James Smartda0436e2009-05-22 14:51:39 -04003276# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3277#
3278# Value range is [636,651042]. Default value is 10000.
3279*/
3280LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3281 "Set the maximum number of fast-path FCP interrupts per second");
3282
3283/*
3284# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3285#
3286# Value range is [1,31]. Default value is 4.
3287*/
3288LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3289 "Set the number of fast-path FCP work queues, if possible");
3290
3291/*
3292# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3293#
3294# Value range is [1,7]. Default value is 1.
3295*/
3296LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3297 "Set the number of fast-path FCP event queues, if possible");
3298
3299/*
James Smart13815c82008-01-11 01:52:48 -05003300# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3301# 0 = HBA resets disabled
3302# 1 = HBA resets enabled (default)
3303# Value range is [0,1]. Default value is 1.
3304*/
3305LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003306
James Smart13815c82008-01-11 01:52:48 -05003307/*
James Smarteb7a3392010-11-20 23:12:02 -05003308# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003309# 0 = HBA Heartbeat disabled
3310# 1 = HBA Heartbeat enabled (default)
3311# Value range is [0,1]. Default value is 1.
3312*/
James Smarteb7a3392010-11-20 23:12:02 -05003313LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003314
James Smart83108bd2008-01-11 01:53:09 -05003315/*
James Smart81301a92008-12-04 22:39:46 -05003316# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3317# 0 = BlockGuard disabled (default)
3318# 1 = BlockGuard enabled
3319# Value range is [0,1]. Default value is 0.
3320*/
3321LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3322
James Smart6fb120a2009-05-22 14:52:59 -04003323/*
James Smart81301a92008-12-04 22:39:46 -05003324# lpfc_prot_mask: i
3325# - Bit mask of host protection capabilities used to register with the
3326# SCSI mid-layer
3327# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3328# - Allows you to ultimately specify which profiles to use
3329# - Default will result in registering capabilities for all profiles.
3330#
3331*/
James Smartbc739052010-08-04 16:11:18 -04003332unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003333
3334module_param(lpfc_prot_mask, uint, 0);
3335MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3336
3337/*
3338# lpfc_prot_guard: i
3339# - Bit mask of protection guard types to register with the SCSI mid-layer
3340# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3341# - Allows you to ultimately specify which profiles to use
3342# - Default will result in registering capabilities for all guard types
3343#
3344*/
3345unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3346module_param(lpfc_prot_guard, byte, 0);
3347MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3348
3349
3350/*
James Smart3621a712009-04-06 18:47:14 -04003351 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003352 * This value can be set to values between 64 and 256. The default value is
3353 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3354 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3355 */
3356LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3357 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3358
James Smart81301a92008-12-04 22:39:46 -05003359LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3360 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3361 "Max Protection Scatter Gather Segment Count");
3362
Tony Jonesee959b02008-02-22 00:13:36 +01003363struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003364 &dev_attr_bg_info,
3365 &dev_attr_bg_guard_err,
3366 &dev_attr_bg_apptag_err,
3367 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003368 &dev_attr_info,
3369 &dev_attr_serialnum,
3370 &dev_attr_modeldesc,
3371 &dev_attr_modelname,
3372 &dev_attr_programtype,
3373 &dev_attr_portnum,
3374 &dev_attr_fwrev,
3375 &dev_attr_hdw,
3376 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003377 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003378 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003379 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003380 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003381 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003382 &dev_attr_lpfc_temp_sensor,
3383 &dev_attr_lpfc_log_verbose,
3384 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003385 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003386 &dev_attr_lpfc_hba_queue_depth,
3387 &dev_attr_lpfc_peer_port_login,
3388 &dev_attr_lpfc_nodev_tmo,
3389 &dev_attr_lpfc_devloss_tmo,
3390 &dev_attr_lpfc_fcp_class,
3391 &dev_attr_lpfc_use_adisc,
3392 &dev_attr_lpfc_ack0,
3393 &dev_attr_lpfc_topology,
3394 &dev_attr_lpfc_scan_down,
3395 &dev_attr_lpfc_link_speed,
3396 &dev_attr_lpfc_cr_delay,
3397 &dev_attr_lpfc_cr_count,
3398 &dev_attr_lpfc_multi_ring_support,
3399 &dev_attr_lpfc_multi_ring_rctl,
3400 &dev_attr_lpfc_multi_ring_type,
3401 &dev_attr_lpfc_fdmi_on,
3402 &dev_attr_lpfc_max_luns,
3403 &dev_attr_lpfc_enable_npiv,
James Smart19ca7602010-11-20 23:11:55 -05003404 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003405 &dev_attr_nport_evt_cnt,
3406 &dev_attr_board_mode,
3407 &dev_attr_max_vpi,
3408 &dev_attr_used_vpi,
3409 &dev_attr_max_rpi,
3410 &dev_attr_used_rpi,
3411 &dev_attr_max_xri,
3412 &dev_attr_used_xri,
3413 &dev_attr_npiv_info,
3414 &dev_attr_issue_reset,
3415 &dev_attr_lpfc_poll,
3416 &dev_attr_lpfc_poll_tmo,
3417 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003418 &dev_attr_lpfc_fcp_imax,
3419 &dev_attr_lpfc_fcp_wq_count,
3420 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003421 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003422 &dev_attr_lpfc_soft_wwnn,
3423 &dev_attr_lpfc_soft_wwpn,
3424 &dev_attr_lpfc_soft_wwn_enable,
3425 &dev_attr_lpfc_enable_hba_reset,
3426 &dev_attr_lpfc_enable_hba_heartbeat,
3427 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003428 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003429 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003430 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003431 &dev_attr_lpfc_aer_support,
3432 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003433 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003434 &dev_attr_lpfc_iocb_cnt,
3435 &dev_attr_iocb_hw,
3436 &dev_attr_txq_hw,
3437 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003438 &dev_attr_lpfc_fips_level,
3439 &dev_attr_lpfc_fips_rev,
dea31012005-04-17 16:05:31 -05003440 NULL,
3441};
3442
Tony Jonesee959b02008-02-22 00:13:36 +01003443struct device_attribute *lpfc_vport_attrs[] = {
3444 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003445 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003446 &dev_attr_num_discovered_ports,
3447 &dev_attr_lpfc_drvr_version,
3448 &dev_attr_lpfc_log_verbose,
3449 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003450 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003451 &dev_attr_lpfc_nodev_tmo,
3452 &dev_attr_lpfc_devloss_tmo,
3453 &dev_attr_lpfc_hba_queue_depth,
3454 &dev_attr_lpfc_peer_port_login,
3455 &dev_attr_lpfc_restrict_login,
3456 &dev_attr_lpfc_fcp_class,
3457 &dev_attr_lpfc_use_adisc,
3458 &dev_attr_lpfc_fdmi_on,
3459 &dev_attr_lpfc_max_luns,
3460 &dev_attr_nport_evt_cnt,
3461 &dev_attr_npiv_info,
3462 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003463 &dev_attr_lpfc_max_scsicmpl_time,
3464 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003465 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003466 &dev_attr_lpfc_fips_level,
3467 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003468 NULL,
3469};
3470
James Smarte59058c2008-08-24 21:49:00 -04003471/**
James Smart3621a712009-04-06 18:47:14 -04003472 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003473 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003474 * @kobj: kernel kobject that contains the kernel class device.
3475 * @bin_attr: kernel attributes passed to us.
3476 * @buf: contains the data to be written to the adapter IOREG space.
3477 * @off: offset into buffer to beginning of data.
3478 * @count: bytes to transfer.
3479 *
3480 * Description:
3481 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3482 * Uses the adapter io control registers to send buf contents to the adapter.
3483 *
3484 * Returns:
3485 * -ERANGE off and count combo out of range
3486 * -EINVAL off, count or buff address invalid
3487 * -EPERM adapter is offline
3488 * value of count, buf contents written
3489 **/
dea31012005-04-17 16:05:31 -05003490static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003491sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3492 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003493 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003494{
3495 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003496 struct device *dev = container_of(kobj, struct device, kobj);
3497 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003498 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3499 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003500
James Smartf1126682009-06-10 17:22:44 -04003501 if (phba->sli_rev >= LPFC_SLI_REV4)
3502 return -EPERM;
3503
dea31012005-04-17 16:05:31 -05003504 if ((off + count) > FF_REG_AREA_SIZE)
3505 return -ERANGE;
3506
3507 if (count == 0) return 0;
3508
3509 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3510 return -EINVAL;
3511
James Smart2e0fef82007-06-17 19:56:36 -05003512 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003513 return -EPERM;
3514 }
3515
James Smart2e0fef82007-06-17 19:56:36 -05003516 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003517 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3518 writel(*((uint32_t *)(buf + buf_off)),
3519 phba->ctrl_regs_memmap_p + off + buf_off);
3520
James Smart2e0fef82007-06-17 19:56:36 -05003521 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003522
3523 return count;
3524}
3525
James Smarte59058c2008-08-24 21:49:00 -04003526/**
James Smart3621a712009-04-06 18:47:14 -04003527 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003528 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003529 * @kobj: kernel kobject that contains the kernel class device.
3530 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003531 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003532 * @off: offset into buffer to beginning of data.
3533 * @count: bytes to transfer.
3534 *
3535 * Description:
3536 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3537 * Uses the adapter io control registers to read data into buf.
3538 *
3539 * Returns:
3540 * -ERANGE off and count combo out of range
3541 * -EINVAL off, count or buff address invalid
3542 * value of count, buf contents read
3543 **/
dea31012005-04-17 16:05:31 -05003544static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003545sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3546 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003547 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003548{
3549 size_t buf_off;
3550 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003551 struct device *dev = container_of(kobj, struct device, kobj);
3552 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3554 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003555
James Smartf1126682009-06-10 17:22:44 -04003556 if (phba->sli_rev >= LPFC_SLI_REV4)
3557 return -EPERM;
3558
dea31012005-04-17 16:05:31 -05003559 if (off > FF_REG_AREA_SIZE)
3560 return -ERANGE;
3561
3562 if ((off + count) > FF_REG_AREA_SIZE)
3563 count = FF_REG_AREA_SIZE - off;
3564
3565 if (count == 0) return 0;
3566
3567 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3568 return -EINVAL;
3569
James Smart2e0fef82007-06-17 19:56:36 -05003570 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003571
3572 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3573 tmp_ptr = (uint32_t *)(buf + buf_off);
3574 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3575 }
3576
James Smart2e0fef82007-06-17 19:56:36 -05003577 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003578
3579 return count;
3580}
3581
3582static struct bin_attribute sysfs_ctlreg_attr = {
3583 .attr = {
3584 .name = "ctlreg",
3585 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003586 },
3587 .size = 256,
3588 .read = sysfs_ctlreg_read,
3589 .write = sysfs_ctlreg_write,
3590};
3591
James Smarte59058c2008-08-24 21:49:00 -04003592/**
James Smart3621a712009-04-06 18:47:14 -04003593 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003594 * @phba: lpfc_hba pointer
3595 **/
dea31012005-04-17 16:05:31 -05003596static void
James Smart2e0fef82007-06-17 19:56:36 -05003597sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003598{
3599 phba->sysfs_mbox.state = SMBOX_IDLE;
3600 phba->sysfs_mbox.offset = 0;
3601
3602 if (phba->sysfs_mbox.mbox) {
3603 mempool_free(phba->sysfs_mbox.mbox,
3604 phba->mbox_mem_pool);
3605 phba->sysfs_mbox.mbox = NULL;
3606 }
3607}
3608
James Smarte59058c2008-08-24 21:49:00 -04003609/**
James Smart3621a712009-04-06 18:47:14 -04003610 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003611 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003612 * @kobj: kernel kobject that contains the kernel class device.
3613 * @bin_attr: kernel attributes passed to us.
3614 * @buf: contains the data to be written to sysfs mbox.
3615 * @off: offset into buffer to beginning of data.
3616 * @count: bytes to transfer.
3617 *
3618 * Description:
3619 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3620 * Uses the sysfs mbox to send buf contents to the adapter.
3621 *
3622 * Returns:
3623 * -ERANGE off and count combo out of range
3624 * -EINVAL off, count or buff address invalid
3625 * zero if count is zero
3626 * -EPERM adapter is offline
3627 * -ENOMEM failed to allocate memory for the mail box
3628 * -EAGAIN offset, state or mbox is NULL
3629 * count number of bytes transferred
3630 **/
dea31012005-04-17 16:05:31 -05003631static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003632sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3633 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003634 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003635{
Tony Jonesee959b02008-02-22 00:13:36 +01003636 struct device *dev = container_of(kobj, struct device, kobj);
3637 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3639 struct lpfc_hba *phba = vport->phba;
3640 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003641
3642 if ((count + off) > MAILBOX_CMD_SIZE)
3643 return -ERANGE;
3644
3645 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3646 return -EINVAL;
3647
3648 if (count == 0)
3649 return 0;
3650
3651 if (off == 0) {
3652 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3653 if (!mbox)
3654 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003655 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003656 }
3657
James Smart2e0fef82007-06-17 19:56:36 -05003658 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003659
3660 if (off == 0) {
3661 if (phba->sysfs_mbox.mbox)
3662 mempool_free(mbox, phba->mbox_mem_pool);
3663 else
3664 phba->sysfs_mbox.mbox = mbox;
3665 phba->sysfs_mbox.state = SMBOX_WRITING;
3666 } else {
3667 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3668 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003669 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003670 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003671 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003672 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003673 }
3674 }
3675
James Smart04c68492009-05-22 14:52:52 -04003676 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003677 buf, count);
3678
3679 phba->sysfs_mbox.offset = off + count;
3680
James Smart2e0fef82007-06-17 19:56:36 -05003681 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003682
3683 return count;
3684}
3685
James Smarte59058c2008-08-24 21:49:00 -04003686/**
James Smart3621a712009-04-06 18:47:14 -04003687 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003688 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003689 * @kobj: kernel kobject that contains the kernel class device.
3690 * @bin_attr: kernel attributes passed to us.
3691 * @buf: contains the data to be read from sysfs mbox.
3692 * @off: offset into buffer to beginning of data.
3693 * @count: bytes to transfer.
3694 *
3695 * Description:
3696 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3697 * Uses the sysfs mbox to receive data from to the adapter.
3698 *
3699 * Returns:
3700 * -ERANGE off greater than mailbox command size
3701 * -EINVAL off, count or buff address invalid
3702 * zero if off and count are zero
3703 * -EACCES adapter over temp
3704 * -EPERM garbage can value to catch a multitude of errors
3705 * -EAGAIN management IO not permitted, state or off error
3706 * -ETIME mailbox timeout
3707 * -ENODEV mailbox error
3708 * count number of bytes transferred
3709 **/
dea31012005-04-17 16:05:31 -05003710static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003711sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3712 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003713 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003714{
Tony Jonesee959b02008-02-22 00:13:36 +01003715 struct device *dev = container_of(kobj, struct device, kobj);
3716 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3718 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003719 int rc;
James Smart04c68492009-05-22 14:52:52 -04003720 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003721
James Smart1dcb58e2007-04-25 09:51:30 -04003722 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003723 return -ERANGE;
3724
James Smart1dcb58e2007-04-25 09:51:30 -04003725 if ((count + off) > MAILBOX_CMD_SIZE)
3726 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003727
3728 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3729 return -EINVAL;
3730
3731 if (off && count == 0)
3732 return 0;
3733
James Smart2e0fef82007-06-17 19:56:36 -05003734 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003735
James Smart7af67052007-10-27 13:38:11 -04003736 if (phba->over_temp_state == HBA_OVER_TEMP) {
3737 sysfs_mbox_idle(phba);
3738 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003739 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003740 }
3741
dea31012005-04-17 16:05:31 -05003742 if (off == 0 &&
3743 phba->sysfs_mbox.state == SMBOX_WRITING &&
3744 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003745 pmb = &phba->sysfs_mbox.mbox->u.mb;
3746 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003747 /* Offline only */
dea31012005-04-17 16:05:31 -05003748 case MBX_INIT_LINK:
3749 case MBX_DOWN_LINK:
3750 case MBX_CONFIG_LINK:
3751 case MBX_CONFIG_RING:
3752 case MBX_RESET_RING:
3753 case MBX_UNREG_LOGIN:
3754 case MBX_CLEAR_LA:
3755 case MBX_DUMP_CONTEXT:
3756 case MBX_RUN_DIAGS:
3757 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003758 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003759 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003760 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003761 printk(KERN_WARNING "mbox_read:Command 0x%x "
3762 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003763 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003764 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003765 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003766 return -EPERM;
3767 }
James Smarta8adb832007-10-27 13:37:53 -04003768 case MBX_WRITE_NV:
3769 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003770 case MBX_LOAD_SM:
3771 case MBX_READ_NV:
3772 case MBX_READ_CONFIG:
3773 case MBX_READ_RCONFIG:
3774 case MBX_READ_STATUS:
3775 case MBX_READ_XRI:
3776 case MBX_READ_REV:
3777 case MBX_READ_LNK_STAT:
3778 case MBX_DUMP_MEMORY:
3779 case MBX_DOWN_LOAD:
3780 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003781 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003782 case MBX_LOAD_AREA:
3783 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003784 case MBX_BEACON:
3785 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003786 case MBX_SET_VARIABLE:
3787 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003788 case MBX_PORT_CAPABILITIES:
3789 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003790 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04003791 case MBX_SECURITY_MGMT:
3792 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04003793 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3794 printk(KERN_WARNING "mbox_read:Command 0x%x "
3795 "is not permitted\n", pmb->mbxCommand);
3796 sysfs_mbox_idle(phba);
3797 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04003798 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04003799 }
James Smartdcf2a4e2010-09-29 11:18:53 -04003800 break;
dea31012005-04-17 16:05:31 -05003801 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05003802 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05003803 case MBX_REG_LOGIN:
3804 case MBX_REG_LOGIN64:
3805 case MBX_CONFIG_PORT:
3806 case MBX_RUN_BIU_DIAG:
3807 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003808 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003809 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003810 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003811 return -EPERM;
3812 default:
3813 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003814 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003815 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003816 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003817 return -EPERM;
3818 }
3819
James Smart09372822008-01-11 01:52:54 -05003820 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003821 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003822 */
James Smartd7c255b2008-08-24 21:50:00 -04003823 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003824 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3825 pmb->mbxCommand != MBX_RESTART &&
3826 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3827 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003828 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3829 "1259 mbox: Issued mailbox cmd "
3830 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003831 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003832
James Smart92d7f7b2007-06-17 19:56:38 -05003833 phba->sysfs_mbox.mbox->vport = vport;
3834
James Smart58da1ff2008-04-07 10:15:56 -04003835 /* Don't allow mailbox commands to be sent when blocked
3836 * or when in the middle of discovery
3837 */
James Smart495a7142008-06-14 22:52:59 -04003838 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003839 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003840 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003841 return -EAGAIN;
3842 }
3843
James Smart2e0fef82007-06-17 19:56:36 -05003844 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003845 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003846
James Smart2e0fef82007-06-17 19:56:36 -05003847 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003848 rc = lpfc_sli_issue_mbox (phba,
3849 phba->sysfs_mbox.mbox,
3850 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003851 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003852
3853 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003854 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003855 rc = lpfc_sli_issue_mbox_wait (phba,
3856 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003857 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003858 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003859 }
3860
3861 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003862 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003863 phba->sysfs_mbox.mbox = NULL;
3864 }
dea31012005-04-17 16:05:31 -05003865 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003866 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003867 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003868 }
3869 phba->sysfs_mbox.state = SMBOX_READING;
3870 }
3871 else if (phba->sysfs_mbox.offset != off ||
3872 phba->sysfs_mbox.state != SMBOX_READING) {
3873 printk(KERN_WARNING "mbox_read: Bad State\n");
3874 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003875 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003876 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003877 }
3878
James Smart04c68492009-05-22 14:52:52 -04003879 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003880
3881 phba->sysfs_mbox.offset = off + count;
3882
James Smart1dcb58e2007-04-25 09:51:30 -04003883 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003884 sysfs_mbox_idle(phba);
3885
James Smart2e0fef82007-06-17 19:56:36 -05003886 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003887
3888 return count;
3889}
3890
3891static struct bin_attribute sysfs_mbox_attr = {
3892 .attr = {
3893 .name = "mbox",
3894 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003895 },
James Smart1dcb58e2007-04-25 09:51:30 -04003896 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003897 .read = sysfs_mbox_read,
3898 .write = sysfs_mbox_write,
3899};
3900
James Smarte59058c2008-08-24 21:49:00 -04003901/**
James Smart3621a712009-04-06 18:47:14 -04003902 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003903 * @vport: address of lpfc vport structure.
3904 *
3905 * Return codes:
3906 * zero on success
3907 * error return code from sysfs_create_bin_file()
3908 **/
dea31012005-04-17 16:05:31 -05003909int
James Smart2e0fef82007-06-17 19:56:36 -05003910lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003911{
James Smart2e0fef82007-06-17 19:56:36 -05003912 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003913 int error;
3914
Tony Jonesee959b02008-02-22 00:13:36 +01003915 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003916 &sysfs_drvr_stat_data_attr);
3917
3918 /* Virtual ports do not need ctrl_reg and mbox */
3919 if (error || vport->port_type == LPFC_NPIV_PORT)
3920 goto out;
3921
3922 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003923 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003924 if (error)
James Smarteada2722008-12-04 22:39:13 -05003925 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003926
Tony Jonesee959b02008-02-22 00:13:36 +01003927 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003928 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003929 if (error)
3930 goto out_remove_ctlreg_attr;
3931
3932 return 0;
3933out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003934 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003935out_remove_stat_attr:
3936 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3937 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003938out:
3939 return error;
3940}
3941
James Smarte59058c2008-08-24 21:49:00 -04003942/**
James Smart3621a712009-04-06 18:47:14 -04003943 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003944 * @vport: address of lpfc vport structure.
3945 **/
dea31012005-04-17 16:05:31 -05003946void
James Smart2e0fef82007-06-17 19:56:36 -05003947lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003948{
James Smart2e0fef82007-06-17 19:56:36 -05003949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003950 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3951 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003952 /* Virtual ports do not need ctrl_reg and mbox */
3953 if (vport->port_type == LPFC_NPIV_PORT)
3954 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003955 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3956 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003957}
3958
3959
3960/*
3961 * Dynamic FC Host Attributes Support
3962 */
3963
James Smarte59058c2008-08-24 21:49:00 -04003964/**
James Smart3621a712009-04-06 18:47:14 -04003965 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003966 * @shost: kernel scsi host pointer.
3967 **/
dea31012005-04-17 16:05:31 -05003968static void
3969lpfc_get_host_port_id(struct Scsi_Host *shost)
3970{
James Smart2e0fef82007-06-17 19:56:36 -05003971 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3972
dea31012005-04-17 16:05:31 -05003973 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003974 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003975}
3976
James Smarte59058c2008-08-24 21:49:00 -04003977/**
James Smart3621a712009-04-06 18:47:14 -04003978 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003979 * @shost: kernel scsi host pointer.
3980 **/
dea31012005-04-17 16:05:31 -05003981static void
3982lpfc_get_host_port_type(struct Scsi_Host *shost)
3983{
James Smart2e0fef82007-06-17 19:56:36 -05003984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3985 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003986
3987 spin_lock_irq(shost->host_lock);
3988
James Smart92d7f7b2007-06-17 19:56:38 -05003989 if (vport->port_type == LPFC_NPIV_PORT) {
3990 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3991 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05003992 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003993 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003994 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3995 else
3996 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3997 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003998 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003999 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4000 else
4001 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4002 }
4003 } else
4004 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4005
4006 spin_unlock_irq(shost->host_lock);
4007}
4008
James Smarte59058c2008-08-24 21:49:00 -04004009/**
James Smart3621a712009-04-06 18:47:14 -04004010 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004011 * @shost: kernel scsi host pointer.
4012 **/
dea31012005-04-17 16:05:31 -05004013static void
4014lpfc_get_host_port_state(struct Scsi_Host *shost)
4015{
James Smart2e0fef82007-06-17 19:56:36 -05004016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4017 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004018
4019 spin_lock_irq(shost->host_lock);
4020
James Smart2e0fef82007-06-17 19:56:36 -05004021 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004022 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4023 else {
James Smart2e0fef82007-06-17 19:56:36 -05004024 switch (phba->link_state) {
4025 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004026 case LPFC_LINK_DOWN:
4027 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4028 break;
4029 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004030 case LPFC_CLEAR_LA:
4031 case LPFC_HBA_READY:
4032 /* Links up, beyond this port_type reports state */
4033 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4034 break;
4035 case LPFC_HBA_ERROR:
4036 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4037 break;
4038 default:
4039 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4040 break;
4041 }
4042 }
4043
4044 spin_unlock_irq(shost->host_lock);
4045}
4046
James Smarte59058c2008-08-24 21:49:00 -04004047/**
James Smart3621a712009-04-06 18:47:14 -04004048 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004049 * @shost: kernel scsi host pointer.
4050 **/
dea31012005-04-17 16:05:31 -05004051static void
4052lpfc_get_host_speed(struct Scsi_Host *shost)
4053{
James Smart2e0fef82007-06-17 19:56:36 -05004054 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4055 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004056
4057 spin_lock_irq(shost->host_lock);
4058
James Smart2e0fef82007-06-17 19:56:36 -05004059 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004060 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004061 case LPFC_LINK_SPEED_1GHZ:
4062 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004063 break;
James Smart76a95d72010-11-20 23:11:48 -05004064 case LPFC_LINK_SPEED_2GHZ:
4065 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004066 break;
James Smart76a95d72010-11-20 23:11:48 -05004067 case LPFC_LINK_SPEED_4GHZ:
4068 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004069 break;
James Smart76a95d72010-11-20 23:11:48 -05004070 case LPFC_LINK_SPEED_8GHZ:
4071 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004072 break;
James Smart76a95d72010-11-20 23:11:48 -05004073 case LPFC_LINK_SPEED_10GHZ:
4074 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004075 break;
James Smart76a95d72010-11-20 23:11:48 -05004076 case LPFC_LINK_SPEED_16GHZ:
4077 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4078 break;
4079 default:
4080 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004081 break;
4082 }
James Smart09372822008-01-11 01:52:54 -05004083 } else
4084 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004085
4086 spin_unlock_irq(shost->host_lock);
4087}
4088
James Smarte59058c2008-08-24 21:49:00 -04004089/**
James Smart3621a712009-04-06 18:47:14 -04004090 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004091 * @shost: kernel scsi host pointer.
4092 **/
dea31012005-04-17 16:05:31 -05004093static void
4094lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4095{
James Smart2e0fef82007-06-17 19:56:36 -05004096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4097 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004098 u64 node_name;
dea31012005-04-17 16:05:31 -05004099
4100 spin_lock_irq(shost->host_lock);
4101
James Smart2e0fef82007-06-17 19:56:36 -05004102 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004103 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004104 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004105 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004106 else
4107 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004108 node_name = 0;
dea31012005-04-17 16:05:31 -05004109
4110 spin_unlock_irq(shost->host_lock);
4111
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004112 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004113}
4114
James Smarte59058c2008-08-24 21:49:00 -04004115/**
James Smart3621a712009-04-06 18:47:14 -04004116 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004117 * @shost: kernel scsi host pointer.
4118 *
4119 * Notes:
4120 * NULL on error for link down, no mbox pool, sli2 active,
4121 * management not allowed, memory allocation error, or mbox error.
4122 *
4123 * Returns:
4124 * NULL for error
4125 * address of the adapter host statistics
4126 **/
dea31012005-04-17 16:05:31 -05004127static struct fc_host_statistics *
4128lpfc_get_stats(struct Scsi_Host *shost)
4129{
James Smart2e0fef82007-06-17 19:56:36 -05004130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4131 struct lpfc_hba *phba = vport->phba;
4132 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004133 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004134 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004135 LPFC_MBOXQ_t *pmboxq;
4136 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004137 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004138 int rc = 0;
dea31012005-04-17 16:05:31 -05004139
James Smart92d7f7b2007-06-17 19:56:38 -05004140 /*
4141 * prevent udev from issuing mailbox commands until the port is
4142 * configured.
4143 */
James Smart2e0fef82007-06-17 19:56:36 -05004144 if (phba->link_state < LPFC_LINK_DOWN ||
4145 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004146 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004147 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004148
4149 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004150 return NULL;
4151
dea31012005-04-17 16:05:31 -05004152 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4153 if (!pmboxq)
4154 return NULL;
4155 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4156
James Smart04c68492009-05-22 14:52:52 -04004157 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004158 pmb->mbxCommand = MBX_READ_STATUS;
4159 pmb->mbxOwner = OWN_HOST;
4160 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004161 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004162
James Smart75baf692010-06-08 18:31:21 -04004163 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004164 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004165 else
dea31012005-04-17 16:05:31 -05004166 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4167
4168 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004169 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004170 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004171 return NULL;
4172 }
4173
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004174 memset(hs, 0, sizeof (struct fc_host_statistics));
4175
dea31012005-04-17 16:05:31 -05004176 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4177 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4178 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4179 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4180
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004181 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004182 pmb->mbxCommand = MBX_READ_LNK_STAT;
4183 pmb->mbxOwner = OWN_HOST;
4184 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004185 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004186
James Smart75baf692010-06-08 18:31:21 -04004187 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004188 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004189 else
dea31012005-04-17 16:05:31 -05004190 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4191
4192 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004193 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004194 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004195 return NULL;
4196 }
4197
4198 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4199 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4200 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4201 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4202 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4203 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4204 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4205
James Smart64ba8812006-08-02 15:24:34 -04004206 hs->link_failure_count -= lso->link_failure_count;
4207 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4208 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4209 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4210 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4211 hs->invalid_crc_count -= lso->invalid_crc_count;
4212 hs->error_frames -= lso->error_frames;
4213
James Smart76a95d72010-11-20 23:11:48 -05004214 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004215 hs->lip_count = -1;
4216 hs->nos_count = (phba->link_events >> 1);
4217 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004218 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004219 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004220 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004221 hs->nos_count = -1;
4222 } else {
4223 hs->lip_count = -1;
4224 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004225 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004226 }
4227
4228 hs->dumped_frames = -1;
4229
James Smart64ba8812006-08-02 15:24:34 -04004230 seconds = get_seconds();
4231 if (seconds < psli->stats_start)
4232 hs->seconds_since_last_reset = seconds +
4233 ((unsigned long)-1 - psli->stats_start);
4234 else
4235 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004236
James Smart1dcb58e2007-04-25 09:51:30 -04004237 mempool_free(pmboxq, phba->mbox_mem_pool);
4238
dea31012005-04-17 16:05:31 -05004239 return hs;
4240}
4241
James Smarte59058c2008-08-24 21:49:00 -04004242/**
James Smart3621a712009-04-06 18:47:14 -04004243 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004244 * @shost: kernel scsi host pointer.
4245 **/
James Smart64ba8812006-08-02 15:24:34 -04004246static void
4247lpfc_reset_stats(struct Scsi_Host *shost)
4248{
James Smart2e0fef82007-06-17 19:56:36 -05004249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4250 struct lpfc_hba *phba = vport->phba;
4251 struct lpfc_sli *psli = &phba->sli;
4252 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004253 LPFC_MBOXQ_t *pmboxq;
4254 MAILBOX_t *pmb;
4255 int rc = 0;
4256
James Smart2e0fef82007-06-17 19:56:36 -05004257 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004258 return;
4259
James Smart64ba8812006-08-02 15:24:34 -04004260 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4261 if (!pmboxq)
4262 return;
4263 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4264
James Smart04c68492009-05-22 14:52:52 -04004265 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004266 pmb->mbxCommand = MBX_READ_STATUS;
4267 pmb->mbxOwner = OWN_HOST;
4268 pmb->un.varWords[0] = 0x1; /* reset request */
4269 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004270 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004271
James Smart2e0fef82007-06-17 19:56:36 -05004272 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004273 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004274 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4275 else
4276 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4277
4278 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004279 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004280 mempool_free(pmboxq, phba->mbox_mem_pool);
4281 return;
4282 }
4283
4284 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4285 pmb->mbxCommand = MBX_READ_LNK_STAT;
4286 pmb->mbxOwner = OWN_HOST;
4287 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004288 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004289
James Smart2e0fef82007-06-17 19:56:36 -05004290 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004291 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004292 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4293 else
4294 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4295
4296 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004297 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004298 mempool_free( pmboxq, phba->mbox_mem_pool);
4299 return;
4300 }
4301
4302 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4303 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4304 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4305 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4306 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4307 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4308 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004309 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004310 lso->link_events = (phba->link_events >> 1);
4311 else
4312 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004313
4314 psli->stats_start = get_seconds();
4315
James Smart1dcb58e2007-04-25 09:51:30 -04004316 mempool_free(pmboxq, phba->mbox_mem_pool);
4317
James Smart64ba8812006-08-02 15:24:34 -04004318 return;
4319}
dea31012005-04-17 16:05:31 -05004320
4321/*
4322 * The LPFC driver treats linkdown handling as target loss events so there
4323 * are no sysfs handlers for link_down_tmo.
4324 */
James Smart685f0bf2007-04-25 09:53:08 -04004325
James Smarte59058c2008-08-24 21:49:00 -04004326/**
James Smart3621a712009-04-06 18:47:14 -04004327 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004328 * @starget: kernel scsi target pointer.
4329 *
4330 * Returns:
4331 * address of the node list if found
4332 * NULL target not found
4333 **/
James Smart685f0bf2007-04-25 09:53:08 -04004334static struct lpfc_nodelist *
4335lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004336{
James Smart2e0fef82007-06-17 19:56:36 -05004337 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004339 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004340
4341 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004342 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004343 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004344 if (NLP_CHK_NODE_ACT(ndlp) &&
4345 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004346 starget->id == ndlp->nlp_sid) {
4347 spin_unlock_irq(shost->host_lock);
4348 return ndlp;
dea31012005-04-17 16:05:31 -05004349 }
4350 }
4351 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004352 return NULL;
4353}
dea31012005-04-17 16:05:31 -05004354
James Smarte59058c2008-08-24 21:49:00 -04004355/**
James Smart3621a712009-04-06 18:47:14 -04004356 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004357 * @starget: kernel scsi target pointer.
4358 **/
James Smart685f0bf2007-04-25 09:53:08 -04004359static void
4360lpfc_get_starget_port_id(struct scsi_target *starget)
4361{
4362 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4363
4364 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004365}
4366
James Smarte59058c2008-08-24 21:49:00 -04004367/**
James Smart3621a712009-04-06 18:47:14 -04004368 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004369 * @starget: kernel scsi target pointer.
4370 *
4371 * Description: Set the target node name to the ndlp node name wwn or zero.
4372 **/
dea31012005-04-17 16:05:31 -05004373static void
4374lpfc_get_starget_node_name(struct scsi_target *starget)
4375{
James Smart685f0bf2007-04-25 09:53:08 -04004376 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004377
James Smart685f0bf2007-04-25 09:53:08 -04004378 fc_starget_node_name(starget) =
4379 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004380}
4381
James Smarte59058c2008-08-24 21:49:00 -04004382/**
James Smart3621a712009-04-06 18:47:14 -04004383 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004384 * @starget: kernel scsi target pointer.
4385 *
4386 * Description: set the target port name to the ndlp port name wwn or zero.
4387 **/
dea31012005-04-17 16:05:31 -05004388static void
4389lpfc_get_starget_port_name(struct scsi_target *starget)
4390{
James Smart685f0bf2007-04-25 09:53:08 -04004391 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004392
James Smart685f0bf2007-04-25 09:53:08 -04004393 fc_starget_port_name(starget) =
4394 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004395}
4396
James Smarte59058c2008-08-24 21:49:00 -04004397/**
James Smart3621a712009-04-06 18:47:14 -04004398 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004399 * @rport: fc rport address.
4400 * @timeout: new value for dev loss tmo.
4401 *
4402 * Description:
4403 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4404 * dev_loss_tmo to one.
4405 **/
dea31012005-04-17 16:05:31 -05004406static void
dea31012005-04-17 16:05:31 -05004407lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4408{
dea31012005-04-17 16:05:31 -05004409 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004410 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004411 else
James Smartc01f3202006-08-18 17:47:08 -04004412 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004413}
4414
James Smarte59058c2008-08-24 21:49:00 -04004415/**
James Smart3621a712009-04-06 18:47:14 -04004416 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004417 *
4418 * Description:
4419 * Macro that uses field to generate a function with the name lpfc_show_rport_
4420 *
4421 * lpfc_show_rport_##field: returns the bytes formatted in buf
4422 * @cdev: class converted to an fc_rport.
4423 * @buf: on return contains the target_field or zero.
4424 *
4425 * Returns: size of formatted string.
4426 **/
dea31012005-04-17 16:05:31 -05004427#define lpfc_rport_show_function(field, format_string, sz, cast) \
4428static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004429lpfc_show_rport_##field (struct device *dev, \
4430 struct device_attribute *attr, \
4431 char *buf) \
dea31012005-04-17 16:05:31 -05004432{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004433 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004434 struct lpfc_rport_data *rdata = rport->hostdata; \
4435 return snprintf(buf, sz, format_string, \
4436 (rdata->target) ? cast rdata->target->field : 0); \
4437}
4438
4439#define lpfc_rport_rd_attr(field, format_string, sz) \
4440 lpfc_rport_show_function(field, format_string, sz, ) \
4441static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4442
James Smarteada2722008-12-04 22:39:13 -05004443/**
James Smart3621a712009-04-06 18:47:14 -04004444 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004445 * @fc_vport: The fc_vport who's symbolic name has been changed.
4446 *
4447 * Description:
4448 * This function is called by the transport after the @fc_vport's symbolic name
4449 * has been changed. This function re-registers the symbolic name with the
4450 * switch to propogate the change into the fabric if the vport is active.
4451 **/
4452static void
4453lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4454{
4455 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4456
4457 if (vport->port_state == LPFC_VPORT_READY)
4458 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4459}
dea31012005-04-17 16:05:31 -05004460
James Smartf4b4c682009-05-22 14:53:12 -04004461/**
4462 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4463 * @phba: Pointer to lpfc_hba struct.
4464 *
4465 * This function is called by the lpfc_get_cfgparam() routine to set the
4466 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4467 * log messsage according to the module's lpfc_log_verbose parameter setting
4468 * before hba port or vport created.
4469 **/
4470static void
4471lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4472{
4473 phba->cfg_log_verbose = verbose;
4474}
4475
dea31012005-04-17 16:05:31 -05004476struct fc_function_template lpfc_transport_functions = {
4477 /* fixed attributes the driver supports */
4478 .show_host_node_name = 1,
4479 .show_host_port_name = 1,
4480 .show_host_supported_classes = 1,
4481 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004482 .show_host_supported_speeds = 1,
4483 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004484 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004485
4486 /* dynamic attributes the driver supports */
4487 .get_host_port_id = lpfc_get_host_port_id,
4488 .show_host_port_id = 1,
4489
4490 .get_host_port_type = lpfc_get_host_port_type,
4491 .show_host_port_type = 1,
4492
4493 .get_host_port_state = lpfc_get_host_port_state,
4494 .show_host_port_state = 1,
4495
4496 /* active_fc4s is shown but doesn't change (thus no get function) */
4497 .show_host_active_fc4s = 1,
4498
4499 .get_host_speed = lpfc_get_host_speed,
4500 .show_host_speed = 1,
4501
4502 .get_host_fabric_name = lpfc_get_host_fabric_name,
4503 .show_host_fabric_name = 1,
4504
4505 /*
4506 * The LPFC driver treats linkdown handling as target loss events
4507 * so there are no sysfs handlers for link_down_tmo.
4508 */
4509
4510 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004511 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004512
4513 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4514 .show_rport_maxframe_size = 1,
4515 .show_rport_supported_classes = 1,
4516
dea31012005-04-17 16:05:31 -05004517 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4518 .show_rport_dev_loss_tmo = 1,
4519
4520 .get_starget_port_id = lpfc_get_starget_port_id,
4521 .show_starget_port_id = 1,
4522
4523 .get_starget_node_name = lpfc_get_starget_node_name,
4524 .show_starget_node_name = 1,
4525
4526 .get_starget_port_name = lpfc_get_starget_port_name,
4527 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004528
4529 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004530 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4531 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004532
James Smart92d7f7b2007-06-17 19:56:38 -05004533 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004534
4535 .vport_disable = lpfc_vport_disable,
4536
4537 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004538
4539 .bsg_request = lpfc_bsg_request,
4540 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004541};
4542
James Smart98c9ea52007-10-27 13:37:33 -04004543struct fc_function_template lpfc_vport_transport_functions = {
4544 /* fixed attributes the driver supports */
4545 .show_host_node_name = 1,
4546 .show_host_port_name = 1,
4547 .show_host_supported_classes = 1,
4548 .show_host_supported_fc4s = 1,
4549 .show_host_supported_speeds = 1,
4550 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004551 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004552
4553 /* dynamic attributes the driver supports */
4554 .get_host_port_id = lpfc_get_host_port_id,
4555 .show_host_port_id = 1,
4556
4557 .get_host_port_type = lpfc_get_host_port_type,
4558 .show_host_port_type = 1,
4559
4560 .get_host_port_state = lpfc_get_host_port_state,
4561 .show_host_port_state = 1,
4562
4563 /* active_fc4s is shown but doesn't change (thus no get function) */
4564 .show_host_active_fc4s = 1,
4565
4566 .get_host_speed = lpfc_get_host_speed,
4567 .show_host_speed = 1,
4568
4569 .get_host_fabric_name = lpfc_get_host_fabric_name,
4570 .show_host_fabric_name = 1,
4571
4572 /*
4573 * The LPFC driver treats linkdown handling as target loss events
4574 * so there are no sysfs handlers for link_down_tmo.
4575 */
4576
4577 .get_fc_host_stats = lpfc_get_stats,
4578 .reset_fc_host_stats = lpfc_reset_stats,
4579
4580 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4581 .show_rport_maxframe_size = 1,
4582 .show_rport_supported_classes = 1,
4583
4584 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4585 .show_rport_dev_loss_tmo = 1,
4586
4587 .get_starget_port_id = lpfc_get_starget_port_id,
4588 .show_starget_port_id = 1,
4589
4590 .get_starget_node_name = lpfc_get_starget_node_name,
4591 .show_starget_node_name = 1,
4592
4593 .get_starget_port_name = lpfc_get_starget_port_name,
4594 .show_starget_port_name = 1,
4595
4596 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4597 .terminate_rport_io = lpfc_terminate_rport_io,
4598
4599 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004600
4601 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004602};
4603
James Smarte59058c2008-08-24 21:49:00 -04004604/**
James Smart3621a712009-04-06 18:47:14 -04004605 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004606 * @phba: lpfc_hba pointer.
4607 **/
dea31012005-04-17 16:05:31 -05004608void
4609lpfc_get_cfgparam(struct lpfc_hba *phba)
4610{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004611 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4612 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004613 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004614 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4615 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004616 lpfc_ack0_init(phba, lpfc_ack0);
4617 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004618 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004619 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004620 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart19ca7602010-11-20 23:11:55 -05004621 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05004622 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004623 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4624 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4625 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004626 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4627 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004628 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004629 if (phba->sli_rev == LPFC_SLI_REV4)
4630 phba->cfg_poll = 0;
4631 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004632 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004633 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004634 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004635 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004636 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004637 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004638 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004639 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004640 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004641 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004642 return;
4643}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004644
James Smarte59058c2008-08-24 21:49:00 -04004645/**
James Smart3621a712009-04-06 18:47:14 -04004646 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004647 * @vport: lpfc_vport pointer.
4648 **/
James Smart3de2a652007-08-02 11:09:59 -04004649void
4650lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4651{
James Smarte8b62012007-08-02 11:10:09 -04004652 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004653 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004654 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004655 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4656 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4657 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4658 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4659 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4660 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004661 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004662 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4663 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4664 lpfc_max_luns_init(vport, lpfc_max_luns);
4665 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004666 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004667 return;
4668}