blob: 745774c5a4be86b352b5de41ae3cfc27f5031615 [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;
James Smartfedd3b72011-02-16 12:39:24 -0500626 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400627
628 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400630 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500631 if (rc == 0)
632 return -ENOMEM;
633
James Smart46fa3112007-04-25 09:51:45 -0400634 wait_for_completion(&online_compl);
635
636 if (status != 0)
637 return -EIO;
638
639 psli = &phba->sli;
640
James Smart09372822008-01-11 01:52:54 -0500641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
643 */
James Smart46fa3112007-04-25 09:51:45 -0400644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400646 while (pring->txcmplq_cnt) {
647 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500648 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400653 break;
654 }
655 }
656 }
657
658 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
662
James Smart46fa3112007-04-25 09:51:45 -0400663 wait_for_completion(&online_compl);
664
665 if (status != 0)
666 return -EIO;
667
668 return 0;
669}
670
James Smarte59058c2008-08-24 21:49:00 -0400671/**
James Smart3621a712009-04-06 18:47:14 -0400672 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400673 * @phba: lpfc_hba pointer.
674 *
675 * Description:
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
678 *
679 * Notes:
680 * Assumes any error from lpfc_do_offline() will be negative.
681 *
682 * Returns:
683 * lpfc_do_offline() return code if not zero
684 * -EIO reset not configured or error posting the event
685 * zero for success
686 **/
James Smart46fa3112007-04-25 09:51:45 -0400687static int
James Smart40496f02006-07-06 15:50:22 -0400688lpfc_selective_reset(struct lpfc_hba *phba)
689{
690 struct completion online_compl;
691 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500692 int rc;
James Smart40496f02006-07-06 15:50:22 -0400693
James Smart13815c82008-01-11 01:52:48 -0500694 if (!phba->cfg_enable_hba_reset)
695 return -EIO;
696
James Smart46fa3112007-04-25 09:51:45 -0400697 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400698
699 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400700 return status;
James Smart40496f02006-07-06 15:50:22 -0400701
702 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500703 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400704 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500705 if (rc == 0)
706 return -ENOMEM;
707
James Smart40496f02006-07-06 15:50:22 -0400708 wait_for_completion(&online_compl);
709
710 if (status != 0)
711 return -EIO;
712
713 return 0;
714}
715
James Smarte59058c2008-08-24 21:49:00 -0400716/**
James Smart3621a712009-04-06 18:47:14 -0400717 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400718 * @dev: class device that is converted into a Scsi_host.
719 * @attr: device attribute, not used.
720 * @buf: containing the string "selective".
721 * @count: unused variable.
722 *
723 * Description:
724 * If the buf contains the string "selective" then lpfc_selective_reset()
725 * is called to perform the reset.
726 *
727 * Notes:
728 * Assumes any error from lpfc_selective_reset() will be negative.
729 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200730 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400731 *
732 * Returns:
733 * -EINVAL if the buffer does not contain the string "selective"
734 * length of buf if lpfc-selective_reset() if the call succeeds
735 * return value of lpfc_selective_reset() if the call fails
736**/
James Smart40496f02006-07-06 15:50:22 -0400737static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100738lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
739 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400740{
Tony Jonesee959b02008-02-22 00:13:36 +0100741 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500742 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
743 struct lpfc_hba *phba = vport->phba;
744
James Smart40496f02006-07-06 15:50:22 -0400745 int status = -EINVAL;
746
747 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
748 status = lpfc_selective_reset(phba);
749
750 if (status == 0)
751 return strlen(buf);
752 else
753 return status;
754}
755
James Smarte59058c2008-08-24 21:49:00 -0400756/**
James Smart3621a712009-04-06 18:47:14 -0400757 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400758 * @dev: class device that is converted into a Scsi_host.
759 * @attr: device attribute, not used.
760 * @buf: on return contains the ascii number of nport events.
761 *
762 * Returns: size of formatted string.
763 **/
dea31012005-04-17 16:05:31 -0500764static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100765lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
766 char *buf)
dea31012005-04-17 16:05:31 -0500767{
Tony Jonesee959b02008-02-22 00:13:36 +0100768 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500769 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
770 struct lpfc_hba *phba = vport->phba;
771
dea31012005-04-17 16:05:31 -0500772 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
773}
774
James Smarte59058c2008-08-24 21:49:00 -0400775/**
James Smart3621a712009-04-06 18:47:14 -0400776 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400777 * @dev: class device that is converted into a Scsi_host.
778 * @attr: device attribute, not used.
779 * @buf: on return contains the state of the adapter.
780 *
781 * Returns: size of formatted string.
782 **/
dea31012005-04-17 16:05:31 -0500783static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100784lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
785 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500786{
Tony Jonesee959b02008-02-22 00:13:36 +0100787 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
789 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500790 char * state;
791
James Smart2e0fef82007-06-17 19:56:36 -0500792 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500793 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500794 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500795 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500796 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500797 state = "offline";
798 else
799 state = "online";
800
801 return snprintf(buf, PAGE_SIZE, "%s\n", state);
802}
803
James Smarte59058c2008-08-24 21:49:00 -0400804/**
James Smart3621a712009-04-06 18:47:14 -0400805 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400806 * @dev: class device that is converted into a Scsi_host.
807 * @attr: device attribute, not used.
808 * @buf: containing one of the strings "online", "offline", "warm" or "error".
809 * @count: unused variable.
810 *
811 * Returns:
812 * -EACCES if enable hba reset not enabled
813 * -EINVAL if the buffer does not contain a valid string (see above)
814 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
815 * buf length greater than zero indicates success
816 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500817static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100818lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
819 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500820{
Tony Jonesee959b02008-02-22 00:13:36 +0100821 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
823 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500824 struct completion online_compl;
825 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500826 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500827
James Smart13815c82008-01-11 01:52:48 -0500828 if (!phba->cfg_enable_hba_reset)
829 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500830 init_completion(&online_compl);
831
James Smart46fa3112007-04-25 09:51:45 -0400832 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500833 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500834 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500835 if (rc == 0)
836 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400837 wait_for_completion(&online_compl);
838 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
839 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500840 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400841 if (phba->sli_rev == LPFC_SLI_REV4)
842 return -EINVAL;
843 else
844 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400845 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400846 if (phba->sli_rev == LPFC_SLI_REV4)
847 return -EINVAL;
848 else
849 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500850 else
851 return -EINVAL;
852
Jamie Wellnitz41415862006-02-28 19:25:27 -0500853 if (!status)
854 return strlen(buf);
855 else
856 return -EIO;
857}
858
James Smarte59058c2008-08-24 21:49:00 -0400859/**
James Smart3621a712009-04-06 18:47:14 -0400860 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400861 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400862 * @mxri: max xri count.
863 * @axri: available xri count.
864 * @mrpi: max rpi count.
865 * @arpi: available rpi count.
866 * @mvpi: max vpi count.
867 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400868 *
869 * Description:
870 * If an integer pointer for an count is not null then the value for the
871 * count is returned.
872 *
873 * Returns:
874 * zero on error
875 * one for success
876 **/
James Smart311464e2007-08-02 11:10:37 -0400877static int
James Smart858c9f62007-06-17 19:56:39 -0500878lpfc_get_hba_info(struct lpfc_hba *phba,
879 uint32_t *mxri, uint32_t *axri,
880 uint32_t *mrpi, uint32_t *arpi,
881 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500882{
James Smart04c68492009-05-22 14:52:52 -0400883 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500884 LPFC_MBOXQ_t *pmboxq;
885 MAILBOX_t *pmb;
886 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400887 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500888
889 /*
890 * prevent udev from issuing mailbox commands until the port is
891 * configured.
892 */
893 if (phba->link_state < LPFC_LINK_DOWN ||
894 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400895 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500896 return 0;
897
898 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
899 return 0;
900
901 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
902 if (!pmboxq)
903 return 0;
904 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
905
James Smart04c68492009-05-22 14:52:52 -0400906 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500907 pmb->mbxCommand = MBX_READ_CONFIG;
908 pmb->mbxOwner = OWN_HOST;
909 pmboxq->context1 = NULL;
910
James Smart75baf692010-06-08 18:31:21 -0400911 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500912 rc = MBX_NOT_FINISHED;
913 else
914 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
915
916 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500917 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500918 mempool_free(pmboxq, phba->mbox_mem_pool);
919 return 0;
920 }
921
James Smartda0436e2009-05-22 14:51:39 -0400922 if (phba->sli_rev == LPFC_SLI_REV4) {
923 rd_config = &pmboxq->u.mqe.un.rd_config;
924 if (mrpi)
925 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
926 if (arpi)
927 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
928 phba->sli4_hba.max_cfg_param.rpi_used;
929 if (mxri)
930 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
931 if (axri)
932 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
933 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400934
935 /* Account for differences with SLI-3. Get vpi count from
936 * mailbox data and subtract one for max vpi value.
937 */
938 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
939 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
940
James Smartda0436e2009-05-22 14:51:39 -0400941 if (mvpi)
James Smart15672312010-04-06 14:49:03 -0400942 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -0400943 if (avpi)
James Smart15672312010-04-06 14:49:03 -0400944 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -0400945 } else {
946 if (mrpi)
947 *mrpi = pmb->un.varRdConfig.max_rpi;
948 if (arpi)
949 *arpi = pmb->un.varRdConfig.avail_rpi;
950 if (mxri)
951 *mxri = pmb->un.varRdConfig.max_xri;
952 if (axri)
953 *axri = pmb->un.varRdConfig.avail_xri;
954 if (mvpi)
955 *mvpi = pmb->un.varRdConfig.max_vpi;
956 if (avpi)
957 *avpi = pmb->un.varRdConfig.avail_vpi;
958 }
James Smart92d7f7b2007-06-17 19:56:38 -0500959
960 mempool_free(pmboxq, phba->mbox_mem_pool);
961 return 1;
962}
963
James Smarte59058c2008-08-24 21:49:00 -0400964/**
James Smart3621a712009-04-06 18:47:14 -0400965 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400966 * @dev: class device that is converted into a Scsi_host.
967 * @attr: device attribute, not used.
968 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
969 *
970 * Description:
971 * Calls lpfc_get_hba_info() asking for just the mrpi count.
972 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
973 * to "Unknown" and the buffer length is returned, therefore the caller
974 * must check for "Unknown" in the buffer to detect a failure.
975 *
976 * Returns: size of formatted string.
977 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500978static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100979lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
980 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500981{
Tony Jonesee959b02008-02-22 00:13:36 +0100982 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
984 struct lpfc_hba *phba = vport->phba;
985 uint32_t cnt;
986
James Smart858c9f62007-06-17 19:56:39 -0500987 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500988 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
989 return snprintf(buf, PAGE_SIZE, "Unknown\n");
990}
991
James Smarte59058c2008-08-24 21:49:00 -0400992/**
James Smart3621a712009-04-06 18:47:14 -0400993 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400994 * @dev: class device that is converted into a Scsi_host.
995 * @attr: device attribute, not used.
996 * @buf: containing the used rpi count in decimal or "Unknown".
997 *
998 * Description:
999 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1000 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1001 * to "Unknown" and the buffer length is returned, therefore the caller
1002 * must check for "Unknown" in the buffer to detect a failure.
1003 *
1004 * Returns: size of formatted string.
1005 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001006static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001007lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1008 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001009{
Tony Jonesee959b02008-02-22 00:13:36 +01001010 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001011 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1012 struct lpfc_hba *phba = vport->phba;
1013 uint32_t cnt, acnt;
1014
James Smart858c9f62007-06-17 19:56:39 -05001015 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001016 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1017 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1018}
1019
James Smarte59058c2008-08-24 21:49:00 -04001020/**
James Smart3621a712009-04-06 18:47:14 -04001021 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001022 * @dev: class device that is converted into a Scsi_host.
1023 * @attr: device attribute, not used.
1024 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1025 *
1026 * Description:
1027 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1028 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1029 * to "Unknown" and the buffer length is returned, therefore the caller
1030 * must check for "Unknown" in the buffer to detect a failure.
1031 *
1032 * Returns: size of formatted string.
1033 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001034static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001035lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1036 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001037{
Tony Jonesee959b02008-02-22 00:13:36 +01001038 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1040 struct lpfc_hba *phba = vport->phba;
1041 uint32_t cnt;
1042
James Smart858c9f62007-06-17 19:56:39 -05001043 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001044 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1045 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1046}
1047
James Smarte59058c2008-08-24 21:49:00 -04001048/**
James Smart3621a712009-04-06 18:47:14 -04001049 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001050 * @dev: class device that is converted into a Scsi_host.
1051 * @attr: device attribute, not used.
1052 * @buf: on return contains the used xri count in decimal or "Unknown".
1053 *
1054 * Description:
1055 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1056 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1057 * to "Unknown" and the buffer length is returned, therefore the caller
1058 * must check for "Unknown" in the buffer to detect a failure.
1059 *
1060 * Returns: size of formatted string.
1061 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001062static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001063lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1064 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001065{
Tony Jonesee959b02008-02-22 00:13:36 +01001066 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001067 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1068 struct lpfc_hba *phba = vport->phba;
1069 uint32_t cnt, acnt;
1070
James Smart858c9f62007-06-17 19:56:39 -05001071 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1072 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1073 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1074}
1075
James Smarte59058c2008-08-24 21:49:00 -04001076/**
James Smart3621a712009-04-06 18:47:14 -04001077 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001078 * @dev: class device that is converted into a Scsi_host.
1079 * @attr: device attribute, not used.
1080 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1081 *
1082 * Description:
1083 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1084 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1085 * to "Unknown" and the buffer length is returned, therefore the caller
1086 * must check for "Unknown" in the buffer to detect a failure.
1087 *
1088 * Returns: size of formatted string.
1089 **/
James Smart858c9f62007-06-17 19:56:39 -05001090static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001091lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1092 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001093{
Tony Jonesee959b02008-02-22 00:13:36 +01001094 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001095 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1096 struct lpfc_hba *phba = vport->phba;
1097 uint32_t cnt;
1098
1099 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1100 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1101 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1102}
1103
James Smarte59058c2008-08-24 21:49:00 -04001104/**
James Smart3621a712009-04-06 18:47:14 -04001105 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001106 * @dev: class device that is converted into a Scsi_host.
1107 * @attr: device attribute, not used.
1108 * @buf: on return contains the used vpi count in decimal or "Unknown".
1109 *
1110 * Description:
1111 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1112 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1113 * to "Unknown" and the buffer length is returned, therefore the caller
1114 * must check for "Unknown" in the buffer to detect a failure.
1115 *
1116 * Returns: size of formatted string.
1117 **/
James Smart858c9f62007-06-17 19:56:39 -05001118static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001119lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1120 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001121{
Tony Jonesee959b02008-02-22 00:13:36 +01001122 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1124 struct lpfc_hba *phba = vport->phba;
1125 uint32_t cnt, acnt;
1126
1127 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001128 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1129 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1130}
1131
James Smarte59058c2008-08-24 21:49:00 -04001132/**
James Smart3621a712009-04-06 18:47:14 -04001133 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001134 * @dev: class device that is converted into a Scsi_host.
1135 * @attr: device attribute, not used.
1136 * @buf: text that must be interpreted to determine if npiv is supported.
1137 *
1138 * Description:
1139 * Buffer will contain text indicating npiv is not suppoerted on the port,
1140 * the port is an NPIV physical port, or it is an npiv virtual port with
1141 * the id of the vport.
1142 *
1143 * Returns: size of formatted string.
1144 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001145static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001146lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1147 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001148{
Tony Jonesee959b02008-02-22 00:13:36 +01001149 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1151 struct lpfc_hba *phba = vport->phba;
1152
1153 if (!(phba->max_vpi))
1154 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1155 if (vport->port_type == LPFC_PHYSICAL_PORT)
1156 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1157 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1158}
1159
James Smarte59058c2008-08-24 21:49:00 -04001160/**
James Smart3621a712009-04-06 18:47:14 -04001161 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001162 * @dev: class device that is converted into a Scsi_host.
1163 * @attr: device attribute, not used.
1164 * @buf: on return contains the cfg_poll in hex.
1165 *
1166 * Notes:
1167 * cfg_poll should be a lpfc_polling_flags type.
1168 *
1169 * Returns: size of formatted string.
1170 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001171static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001172lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1173 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001174{
Tony Jonesee959b02008-02-22 00:13:36 +01001175 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001176 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1177 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001178
1179 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1180}
1181
James Smarte59058c2008-08-24 21:49:00 -04001182/**
James Smart3621a712009-04-06 18:47:14 -04001183 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001184 * @dev: class device that is converted into a Scsi_host.
1185 * @attr: device attribute, not used.
1186 * @buf: one or more lpfc_polling_flags values.
1187 * @count: not used.
1188 *
1189 * Notes:
1190 * buf contents converted to integer and checked for a valid value.
1191 *
1192 * Returns:
1193 * -EINVAL if the buffer connot be converted or is out of range
1194 * length of the buf on success
1195 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001196static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001197lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1198 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001199{
Tony Jonesee959b02008-02-22 00:13:36 +01001200 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001201 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1202 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001203 uint32_t creg_val;
1204 uint32_t old_val;
1205 int val=0;
1206
1207 if (!isdigit(buf[0]))
1208 return -EINVAL;
1209
1210 if (sscanf(buf, "%i", &val) != 1)
1211 return -EINVAL;
1212
1213 if ((val & 0x3) != val)
1214 return -EINVAL;
1215
James Smart45ed1192009-10-02 15:17:02 -04001216 if (phba->sli_rev == LPFC_SLI_REV4)
1217 val = 0;
1218
James Smart2e0fef82007-06-17 19:56:36 -05001219 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001220
1221 old_val = phba->cfg_poll;
1222
1223 if (val & ENABLE_FCP_RING_POLLING) {
1224 if ((val & DISABLE_FCP_RING_INT) &&
1225 !(old_val & DISABLE_FCP_RING_INT)) {
1226 creg_val = readl(phba->HCregaddr);
1227 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1228 writel(creg_val, phba->HCregaddr);
1229 readl(phba->HCregaddr); /* flush */
1230
1231 lpfc_poll_start_timer(phba);
1232 }
1233 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001234 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001235 return -EINVAL;
1236 }
1237
1238 if (!(val & DISABLE_FCP_RING_INT) &&
1239 (old_val & DISABLE_FCP_RING_INT))
1240 {
James Smart2e0fef82007-06-17 19:56:36 -05001241 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001242 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001243 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001244 creg_val = readl(phba->HCregaddr);
1245 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1246 writel(creg_val, phba->HCregaddr);
1247 readl(phba->HCregaddr); /* flush */
1248 }
1249
1250 phba->cfg_poll = val;
1251
James Smart2e0fef82007-06-17 19:56:36 -05001252 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001253
1254 return strlen(buf);
1255}
dea31012005-04-17 16:05:31 -05001256
James Smarte59058c2008-08-24 21:49:00 -04001257/**
James Smartbc739052010-08-04 16:11:18 -04001258 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1259 * @dev: class unused variable.
1260 * @attr: device attribute, not used.
1261 * @buf: on return contains the module description text.
1262 *
1263 * Returns: size of formatted string.
1264 **/
1265static ssize_t
1266lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1267 char *buf)
1268{
1269 struct Scsi_Host *shost = class_to_shost(dev);
1270 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1271 struct lpfc_hba *phba = vport->phba;
1272
1273 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1274}
1275
1276/**
1277 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1278 * @dev: class unused variable.
1279 * @attr: device attribute, not used.
1280 * @buf: on return contains the module description text.
1281 *
1282 * Returns: size of formatted string.
1283 **/
1284static ssize_t
1285lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1286 char *buf)
1287{
1288 struct Scsi_Host *shost = class_to_shost(dev);
1289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1290 struct lpfc_hba *phba = vport->phba;
1291
1292 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1293}
1294
1295/**
James Smart3621a712009-04-06 18:47:14 -04001296 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001297 *
1298 * Description:
1299 * Macro that given an attr e.g. hba_queue_depth expands
1300 * into a function with the name lpfc_hba_queue_depth_show.
1301 *
1302 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1303 * @dev: class device that is converted into a Scsi_host.
1304 * @attr: device attribute, not used.
1305 * @buf: on return contains the attribute value in decimal.
1306 *
1307 * Returns: size of formatted string.
1308 **/
dea31012005-04-17 16:05:31 -05001309#define lpfc_param_show(attr) \
1310static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001311lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1312 char *buf) \
dea31012005-04-17 16:05:31 -05001313{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001314 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001315 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1316 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001317 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001318 val = phba->cfg_##attr;\
1319 return snprintf(buf, PAGE_SIZE, "%d\n",\
1320 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001321}
1322
James Smarte59058c2008-08-24 21:49:00 -04001323/**
James Smart3621a712009-04-06 18:47:14 -04001324 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001325 *
1326 * Description:
1327 * Macro that given an attr e.g. hba_queue_depth expands
1328 * into a function with the name lpfc_hba_queue_depth_show
1329 *
1330 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1331 * @dev: class device that is converted into a Scsi_host.
1332 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001333 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001334 *
1335 * Returns: size of formatted string.
1336 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001337#define lpfc_param_hex_show(attr) \
1338static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001339lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1340 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001341{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001342 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1344 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001345 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001346 val = phba->cfg_##attr;\
1347 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1348 phba->cfg_##attr);\
1349}
1350
James Smarte59058c2008-08-24 21:49:00 -04001351/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001352 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001353 *
1354 * Description:
1355 * Macro that given an attr e.g. hba_queue_depth expands
1356 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1357 * takes a default argument, a minimum and maximum argument.
1358 *
1359 * lpfc_##attr##_init: Initializes an attribute.
1360 * @phba: pointer the the adapter structure.
1361 * @val: integer attribute value.
1362 *
1363 * Validates the min and max values then sets the adapter config field
1364 * accordingly, or uses the default if out of range and prints an error message.
1365 *
1366 * Returns:
1367 * zero on success
1368 * -EINVAL if default used
1369 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001370#define lpfc_param_init(attr, default, minval, maxval) \
1371static int \
James Smart84d1b002010-02-12 14:42:33 -05001372lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001373{ \
1374 if (val >= minval && val <= maxval) {\
1375 phba->cfg_##attr = val;\
1376 return 0;\
1377 }\
1378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001379 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1380 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001381 phba->cfg_##attr = default;\
1382 return -EINVAL;\
1383}
1384
James Smarte59058c2008-08-24 21:49:00 -04001385/**
James Smart3621a712009-04-06 18:47:14 -04001386 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001387 *
1388 * Description:
1389 * Macro that given an attr e.g. hba_queue_depth expands
1390 * into a function with the name lpfc_hba_queue_depth_set
1391 *
1392 * lpfc_##attr##_set: Sets an attribute value.
1393 * @phba: pointer the the adapter structure.
1394 * @val: integer attribute value.
1395 *
1396 * Description:
1397 * Validates the min and max values then sets the
1398 * adapter config field if in the valid range. prints error message
1399 * and does not set the parameter if invalid.
1400 *
1401 * Returns:
1402 * zero on success
1403 * -EINVAL if val is invalid
1404 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001405#define lpfc_param_set(attr, default, minval, maxval) \
1406static int \
James Smart84d1b002010-02-12 14:42:33 -05001407lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001408{ \
1409 if (val >= minval && val <= maxval) {\
1410 phba->cfg_##attr = val;\
1411 return 0;\
1412 }\
1413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001414 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1415 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001416 return -EINVAL;\
1417}
1418
James Smarte59058c2008-08-24 21:49:00 -04001419/**
James Smart3621a712009-04-06 18:47:14 -04001420 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001421 *
1422 * Description:
1423 * Macro that given an attr e.g. hba_queue_depth expands
1424 * into a function with the name lpfc_hba_queue_depth_store.
1425 *
1426 * lpfc_##attr##_store: Set an sttribute value.
1427 * @dev: class device that is converted into a Scsi_host.
1428 * @attr: device attribute, not used.
1429 * @buf: contains the attribute value in ascii.
1430 * @count: not used.
1431 *
1432 * Description:
1433 * Convert the ascii text number to an integer, then
1434 * use the lpfc_##attr##_set function to set the value.
1435 *
1436 * Returns:
1437 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1438 * length of buffer upon success.
1439 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001440#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001441static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001442lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1443 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001444{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001445 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1447 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001448 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001449 if (!isdigit(buf[0]))\
1450 return -EINVAL;\
1451 if (sscanf(buf, "%i", &val) != 1)\
1452 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001453 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001454 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001455 else \
1456 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001457}
1458
James Smarte59058c2008-08-24 21:49:00 -04001459/**
James Smart3621a712009-04-06 18:47:14 -04001460 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001461 *
1462 * Description:
1463 * Macro that given an attr e.g. hba_queue_depth expands
1464 * into a function with the name lpfc_hba_queue_depth_show
1465 *
1466 * lpfc_##attr##_show: prints the attribute value in decimal.
1467 * @dev: class device that is converted into a Scsi_host.
1468 * @attr: device attribute, not used.
1469 * @buf: on return contains the attribute value in decimal.
1470 *
1471 * Returns: length of formatted string.
1472 **/
James Smart3de2a652007-08-02 11:09:59 -04001473#define lpfc_vport_param_show(attr) \
1474static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001475lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1476 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001477{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001478 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001480 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001481 val = vport->cfg_##attr;\
1482 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1483}
1484
James Smarte59058c2008-08-24 21:49:00 -04001485/**
James Smart3621a712009-04-06 18:47:14 -04001486 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001487 *
1488 * Description:
1489 * Macro that given an attr e.g.
1490 * hba_queue_depth expands into a function with the name
1491 * lpfc_hba_queue_depth_show
1492 *
James Smart3621a712009-04-06 18:47:14 -04001493 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001494 * @dev: class device that is converted into a Scsi_host.
1495 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001496 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001497 *
1498 * Returns: length of formatted string.
1499 **/
James Smart3de2a652007-08-02 11:09:59 -04001500#define lpfc_vport_param_hex_show(attr) \
1501static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001502lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1503 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001504{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001505 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001507 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001508 val = vport->cfg_##attr;\
1509 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1510}
1511
James Smarte59058c2008-08-24 21:49:00 -04001512/**
James Smart3621a712009-04-06 18:47:14 -04001513 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001514 *
1515 * Description:
1516 * Macro that given an attr e.g. hba_queue_depth expands
1517 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1518 * takes a default argument, a minimum and maximum argument.
1519 *
1520 * lpfc_##attr##_init: validates the min and max values then sets the
1521 * adapter config field accordingly, or uses the default if out of range
1522 * and prints an error message.
1523 * @phba: pointer the the adapter structure.
1524 * @val: integer attribute value.
1525 *
1526 * Returns:
1527 * zero on success
1528 * -EINVAL if default used
1529 **/
James Smart3de2a652007-08-02 11:09:59 -04001530#define lpfc_vport_param_init(attr, default, minval, maxval) \
1531static int \
James Smart84d1b002010-02-12 14:42:33 -05001532lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001533{ \
1534 if (val >= minval && val <= maxval) {\
1535 vport->cfg_##attr = val;\
1536 return 0;\
1537 }\
James Smarte8b62012007-08-02 11:10:09 -04001538 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001539 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001540 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001541 vport->cfg_##attr = default;\
1542 return -EINVAL;\
1543}
1544
James Smarte59058c2008-08-24 21:49:00 -04001545/**
James Smart3621a712009-04-06 18:47:14 -04001546 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001547 *
1548 * Description:
1549 * Macro that given an attr e.g. hba_queue_depth expands
1550 * into a function with the name lpfc_hba_queue_depth_set
1551 *
1552 * lpfc_##attr##_set: validates the min and max values then sets the
1553 * adapter config field if in the valid range. prints error message
1554 * and does not set the parameter if invalid.
1555 * @phba: pointer the the adapter structure.
1556 * @val: integer attribute value.
1557 *
1558 * Returns:
1559 * zero on success
1560 * -EINVAL if val is invalid
1561 **/
James Smart3de2a652007-08-02 11:09:59 -04001562#define lpfc_vport_param_set(attr, default, minval, maxval) \
1563static int \
James Smart84d1b002010-02-12 14:42:33 -05001564lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001565{ \
1566 if (val >= minval && val <= maxval) {\
1567 vport->cfg_##attr = val;\
1568 return 0;\
1569 }\
James Smarte8b62012007-08-02 11:10:09 -04001570 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001571 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001572 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001573 return -EINVAL;\
1574}
1575
James Smarte59058c2008-08-24 21:49:00 -04001576/**
James Smart3621a712009-04-06 18:47:14 -04001577 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001578 *
1579 * Description:
1580 * Macro that given an attr e.g. hba_queue_depth
1581 * expands into a function with the name lpfc_hba_queue_depth_store
1582 *
1583 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1584 * use the lpfc_##attr##_set function to set the value.
1585 * @cdev: class device that is converted into a Scsi_host.
1586 * @buf: contains the attribute value in decimal.
1587 * @count: not used.
1588 *
1589 * Returns:
1590 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1591 * length of buffer upon success.
1592 **/
James Smart3de2a652007-08-02 11:09:59 -04001593#define lpfc_vport_param_store(attr) \
1594static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001595lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1596 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001597{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001598 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001600 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001601 if (!isdigit(buf[0]))\
1602 return -EINVAL;\
1603 if (sscanf(buf, "%i", &val) != 1)\
1604 return -EINVAL;\
1605 if (lpfc_##attr##_set(vport, val) == 0) \
1606 return strlen(buf);\
1607 else \
1608 return -EINVAL;\
1609}
1610
1611
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001612#define LPFC_ATTR(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);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001616lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001617
1618#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001619static uint lpfc_##name = defval;\
1620module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001621MODULE_PARM_DESC(lpfc_##name, desc);\
1622lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001623lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001624static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001625
1626#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001627static uint lpfc_##name = defval;\
1628module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001629MODULE_PARM_DESC(lpfc_##name, desc);\
1630lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001631lpfc_param_init(name, defval, minval, maxval)\
1632lpfc_param_set(name, defval, minval, maxval)\
1633lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001634static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1635 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001636
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001637#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001638static uint lpfc_##name = defval;\
1639module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001640MODULE_PARM_DESC(lpfc_##name, desc);\
1641lpfc_param_hex_show(name)\
1642lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001643static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001644
1645#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001646static uint lpfc_##name = defval;\
1647module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001648MODULE_PARM_DESC(lpfc_##name, desc);\
1649lpfc_param_hex_show(name)\
1650lpfc_param_init(name, defval, minval, maxval)\
1651lpfc_param_set(name, defval, minval, maxval)\
1652lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001653static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1654 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001655
James Smart3de2a652007-08-02 11:09:59 -04001656#define LPFC_VPORT_ATTR(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_init(name, defval, minval, maxval)
1661
1662#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001663static uint lpfc_##name = defval;\
1664module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001665MODULE_PARM_DESC(lpfc_##name, desc);\
1666lpfc_vport_param_show(name)\
1667lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001668static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001669
1670#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001671static uint lpfc_##name = defval;\
1672module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001673MODULE_PARM_DESC(lpfc_##name, desc);\
1674lpfc_vport_param_show(name)\
1675lpfc_vport_param_init(name, defval, minval, maxval)\
1676lpfc_vport_param_set(name, defval, minval, maxval)\
1677lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001678static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1679 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001680
1681#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001682static uint lpfc_##name = defval;\
1683module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001684MODULE_PARM_DESC(lpfc_##name, desc);\
1685lpfc_vport_param_hex_show(name)\
1686lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001687static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001688
1689#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001690static uint lpfc_##name = defval;\
1691module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001692MODULE_PARM_DESC(lpfc_##name, desc);\
1693lpfc_vport_param_hex_show(name)\
1694lpfc_vport_param_init(name, defval, minval, maxval)\
1695lpfc_vport_param_set(name, defval, minval, maxval)\
1696lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001697static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1698 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001699
James Smart81301a92008-12-04 22:39:46 -05001700static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1701static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1702static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1703static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001704static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1705static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1706static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1707static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1708static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1709static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1710static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1711static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001712static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1713 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001714static DEVICE_ATTR(option_rom_version, S_IRUGO,
1715 lpfc_option_rom_version_show, NULL);
1716static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1717 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001718static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001719static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1720static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001721static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001722static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1723 lpfc_board_mode_show, lpfc_board_mode_store);
1724static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1725static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1726static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1727static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1728static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1729static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1730static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1731static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1732static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001733static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1734static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
dea31012005-04-17 16:05:31 -05001735
James Smartc3f28af2006-08-18 17:47:18 -04001736
James Smarta12e07b2006-12-02 13:35:30 -05001737static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001738
James Smarte59058c2008-08-24 21:49:00 -04001739/**
James Smart3621a712009-04-06 18:47:14 -04001740 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001741 * @dev: class device that is converted into a Scsi_host.
1742 * @attr: device attribute, not used.
1743 * @buf: containing the string lpfc_soft_wwn_key.
1744 * @count: must be size of lpfc_soft_wwn_key.
1745 *
1746 * Returns:
1747 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1748 * length of buf indicates success
1749 **/
James Smartc3f28af2006-08-18 17:47:18 -04001750static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001751lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1752 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001753{
Tony Jonesee959b02008-02-22 00:13:36 +01001754 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1756 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001757 unsigned int cnt = count;
1758
1759 /*
1760 * We're doing a simple sanity check for soft_wwpn setting.
1761 * We require that the user write a specific key to enable
1762 * the soft_wwpn attribute to be settable. Once the attribute
1763 * is written, the enable key resets. If further updates are
1764 * desired, the key must be written again to re-enable the
1765 * attribute.
1766 *
1767 * The "key" is not secret - it is a hardcoded string shown
1768 * here. The intent is to protect against the random user or
1769 * application that is just writing attributes.
1770 */
1771
1772 /* count may include a LF at end of string */
1773 if (buf[cnt-1] == '\n')
1774 cnt--;
1775
James Smarta12e07b2006-12-02 13:35:30 -05001776 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1777 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001778 return -EINVAL;
1779
James Smarta12e07b2006-12-02 13:35:30 -05001780 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001781 return count;
1782}
Tony Jonesee959b02008-02-22 00:13:36 +01001783static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1784 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001785
James Smarte59058c2008-08-24 21:49:00 -04001786/**
James Smart3621a712009-04-06 18:47:14 -04001787 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001788 * @dev: class device that is converted into a Scsi_host.
1789 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001790 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001791 *
1792 * Returns: size of formatted string.
1793 **/
James Smartc3f28af2006-08-18 17:47:18 -04001794static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001795lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1796 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001797{
Tony Jonesee959b02008-02-22 00:13:36 +01001798 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001799 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1800 struct lpfc_hba *phba = vport->phba;
1801
Randy Dunlapafc071e2006-10-23 21:47:13 -07001802 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1803 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001804}
1805
James Smarte59058c2008-08-24 21:49:00 -04001806/**
James Smart3621a712009-04-06 18:47:14 -04001807 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001808 * @dev class device that is converted into a Scsi_host.
1809 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001810 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001811 * @count: number of wwpn bytes in buf
1812 *
1813 * Returns:
1814 * -EACCES hba reset not enabled, adapter over temp
1815 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1816 * -EIO error taking adapter offline or online
1817 * value of count on success
1818 **/
James Smartc3f28af2006-08-18 17:47:18 -04001819static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001820lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1821 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001822{
Tony Jonesee959b02008-02-22 00:13:36 +01001823 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1825 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001826 struct completion online_compl;
1827 int stat1=0, stat2=0;
1828 unsigned int i, j, cnt=count;
1829 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05001830 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04001831
James Smart13815c82008-01-11 01:52:48 -05001832 if (!phba->cfg_enable_hba_reset)
1833 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001834 spin_lock_irq(&phba->hbalock);
1835 if (phba->over_temp_state == HBA_OVER_TEMP) {
1836 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001837 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001838 }
1839 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001840 /* count may include a LF at end of string */
1841 if (buf[cnt-1] == '\n')
1842 cnt--;
1843
James Smarta12e07b2006-12-02 13:35:30 -05001844 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001845 ((cnt == 17) && (*buf++ != 'x')) ||
1846 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1847 return -EINVAL;
1848
James Smarta12e07b2006-12-02 13:35:30 -05001849 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001850
1851 memset(wwpn, 0, sizeof(wwpn));
1852
1853 /* Validate and store the new name */
1854 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001855 int value;
1856
1857 value = hex_to_bin(*buf++);
1858 if (value >= 0)
1859 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04001860 else
1861 return -EINVAL;
1862 if (i % 2) {
1863 wwpn[i/2] = j & 0xff;
1864 j = 0;
1865 }
1866 }
1867 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001868 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001869 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001870 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001871
1872 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1873 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1874
James Smart46fa3112007-04-25 09:51:45 -04001875 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001876 if (stat1)
1877 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001878 "0463 lpfc_soft_wwpn attribute set failed to "
1879 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001880 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001881 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1882 LPFC_EVT_ONLINE);
1883 if (rc == 0)
1884 return -ENOMEM;
1885
James Smartc3f28af2006-08-18 17:47:18 -04001886 wait_for_completion(&online_compl);
1887 if (stat2)
1888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001889 "0464 lpfc_soft_wwpn attribute set failed to "
1890 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001891 return (stat1 || stat2) ? -EIO : count;
1892}
Tony Jonesee959b02008-02-22 00:13:36 +01001893static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1894 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001895
James Smarte59058c2008-08-24 21:49:00 -04001896/**
James Smart3621a712009-04-06 18:47:14 -04001897 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001898 * @dev: class device that is converted into a Scsi_host.
1899 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001900 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001901 *
1902 * Returns: size of formatted string.
1903 **/
James Smarta12e07b2006-12-02 13:35:30 -05001904static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001905lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1906 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001907{
Tony Jonesee959b02008-02-22 00:13:36 +01001908 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001909 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001910 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1911 (unsigned long long)phba->cfg_soft_wwnn);
1912}
1913
James Smarte59058c2008-08-24 21:49:00 -04001914/**
James Smart3621a712009-04-06 18:47:14 -04001915 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001916 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001917 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001918 * @count: number of wwnn bytes in buf.
1919 *
1920 * Returns:
1921 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1922 * value of count on success
1923 **/
James Smarta12e07b2006-12-02 13:35:30 -05001924static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001925lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1926 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001927{
Tony Jonesee959b02008-02-22 00:13:36 +01001928 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001929 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001930 unsigned int i, j, cnt=count;
1931 u8 wwnn[8];
1932
1933 /* count may include a LF at end of string */
1934 if (buf[cnt-1] == '\n')
1935 cnt--;
1936
1937 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1938 ((cnt == 17) && (*buf++ != 'x')) ||
1939 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1940 return -EINVAL;
1941
1942 /*
1943 * Allow wwnn to be set many times, as long as the enable is set.
1944 * However, once the wwpn is set, everything locks.
1945 */
1946
1947 memset(wwnn, 0, sizeof(wwnn));
1948
1949 /* Validate and store the new name */
1950 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001951 int value;
1952
1953 value = hex_to_bin(*buf++);
1954 if (value >= 0)
1955 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05001956 else
1957 return -EINVAL;
1958 if (i % 2) {
1959 wwnn[i/2] = j & 0xff;
1960 j = 0;
1961 }
1962 }
1963 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1964
1965 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1966 "lpfc%d: soft_wwnn set. Value will take effect upon "
1967 "setting of the soft_wwpn\n", phba->brd_no);
1968
1969 return count;
1970}
Tony Jonesee959b02008-02-22 00:13:36 +01001971static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1972 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001973
James Smartc3f28af2006-08-18 17:47:18 -04001974
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001975static int lpfc_poll = 0;
1976module_param(lpfc_poll, int, 0);
1977MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1978 " 0 - none,"
1979 " 1 - poll with interrupts enabled"
1980 " 3 - poll and disable FCP ring interrupts");
1981
Tony Jonesee959b02008-02-22 00:13:36 +01001982static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1983 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001984
James Smart92d7f7b2007-06-17 19:56:38 -05001985int lpfc_sli_mode = 0;
1986module_param(lpfc_sli_mode, int, 0);
1987MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1988 " 0 - auto (SLI-3 if supported),"
1989 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1990 " 3 - select SLI-3");
1991
James Smart15672312010-04-06 14:49:03 -04001992int lpfc_enable_npiv = 1;
James Smart7ee5d432007-10-27 13:37:17 -04001993module_param(lpfc_enable_npiv, int, 0);
1994MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1995lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04001996lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04001997static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001998
James Smart19ca7602010-11-20 23:11:55 -05001999int lpfc_enable_rrq;
2000module_param(lpfc_enable_rrq, int, 0);
2001MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2002lpfc_param_show(enable_rrq);
2003lpfc_param_init(enable_rrq, 0, 0, 1);
2004static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2005
dea31012005-04-17 16:05:31 -05002006/*
James Smart84d1b002010-02-12 14:42:33 -05002007# lpfc_suppress_link_up: Bring link up at initialization
2008# 0x0 = bring link up (issue MBX_INIT_LINK)
2009# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2010# 0x2 = never bring up link
2011# Default value is 0.
2012*/
James Smarte40a02c2010-02-26 14:13:54 -05002013LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2014 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2015 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002016/*
2017# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2018# 1 - (1024)
2019# 2 - (2048)
2020# 3 - (3072)
2021# 4 - (4096)
2022# 5 - (5120)
2023*/
2024static ssize_t
2025lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2026{
2027 struct Scsi_Host *shost = class_to_shost(dev);
2028 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2029
2030 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2031}
2032
2033static DEVICE_ATTR(iocb_hw, S_IRUGO,
2034 lpfc_iocb_hw_show, NULL);
2035static ssize_t
2036lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2037{
2038 struct Scsi_Host *shost = class_to_shost(dev);
2039 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2040
2041 return snprintf(buf, PAGE_SIZE, "%d\n",
2042 phba->sli.ring[LPFC_ELS_RING].txq_max);
2043}
2044
2045static DEVICE_ATTR(txq_hw, S_IRUGO,
2046 lpfc_txq_hw_show, NULL);
2047static ssize_t
2048lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2049 char *buf)
2050{
2051 struct Scsi_Host *shost = class_to_shost(dev);
2052 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2053
2054 return snprintf(buf, PAGE_SIZE, "%d\n",
2055 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2056}
2057
2058static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2059 lpfc_txcmplq_hw_show, NULL);
2060
2061int lpfc_iocb_cnt = 2;
2062module_param(lpfc_iocb_cnt, int, 1);
2063MODULE_PARM_DESC(lpfc_iocb_cnt,
2064 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2065lpfc_param_show(iocb_cnt);
2066lpfc_param_init(iocb_cnt, 2, 1, 5);
2067static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2068 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002069
2070/*
James Smartc01f3202006-08-18 17:47:08 -04002071# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2072# until the timer expires. Value range is [0,255]. Default value is 30.
2073*/
2074static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2075static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2076module_param(lpfc_nodev_tmo, int, 0);
2077MODULE_PARM_DESC(lpfc_nodev_tmo,
2078 "Seconds driver will hold I/O waiting "
2079 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002080
2081/**
James Smart3621a712009-04-06 18:47:14 -04002082 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002083 * @dev: class converted to a Scsi_host structure.
2084 * @attr: device attribute, not used.
2085 * @buf: on return contains the dev loss timeout in decimal.
2086 *
2087 * Returns: size of formatted string.
2088 **/
James Smartc01f3202006-08-18 17:47:08 -04002089static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002090lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2091 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002092{
Tony Jonesee959b02008-02-22 00:13:36 +01002093 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002094 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002095
James Smart3de2a652007-08-02 11:09:59 -04002096 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002097}
2098
James Smarte59058c2008-08-24 21:49:00 -04002099/**
James Smart3621a712009-04-06 18:47:14 -04002100 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002101 * @vport: lpfc vport structure pointer.
2102 * @val: contains the nodev timeout value.
2103 *
2104 * Description:
2105 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2106 * a kernel error message is printed and zero is returned.
2107 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2108 * Otherwise nodev tmo is set to the default value.
2109 *
2110 * Returns:
2111 * zero if already set or if val is in range
2112 * -EINVAL val out of range
2113 **/
James Smartc01f3202006-08-18 17:47:08 -04002114static int
James Smart3de2a652007-08-02 11:09:59 -04002115lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002116{
James Smart3de2a652007-08-02 11:09:59 -04002117 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2118 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2119 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002120 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002121 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002122 "parameter because devloss_tmo is "
2123 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002124 return 0;
2125 }
2126
2127 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002128 vport->cfg_nodev_tmo = val;
2129 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002130 return 0;
2131 }
James Smarte8b62012007-08-02 11:10:09 -04002132 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2133 "0400 lpfc_nodev_tmo attribute cannot be set to"
2134 " %d, allowed range is [%d, %d]\n",
2135 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002136 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002137 return -EINVAL;
2138}
2139
James Smarte59058c2008-08-24 21:49:00 -04002140/**
James Smart3621a712009-04-06 18:47:14 -04002141 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002142 * @vport: lpfc vport structure pointer.
2143 *
2144 * Description:
2145 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2146 **/
James Smart7054a602007-04-25 09:52:34 -04002147static void
James Smart3de2a652007-08-02 11:09:59 -04002148lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002149{
James Smart858c9f62007-06-17 19:56:39 -05002150 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002151 struct lpfc_nodelist *ndlp;
2152
James Smart51ef4c22007-08-02 11:10:31 -04002153 shost = lpfc_shost_from_vport(vport);
2154 spin_lock_irq(shost->host_lock);
2155 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002156 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002157 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2158 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002159}
2160
James Smarte59058c2008-08-24 21:49:00 -04002161/**
James Smart3621a712009-04-06 18:47:14 -04002162 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002163 * @vport: lpfc vport structure pointer.
2164 * @val: contains the tmo value.
2165 *
2166 * Description:
2167 * If the devloss tmo is already set or the vport dev loss tmo has changed
2168 * then a kernel error message is printed and zero is returned.
2169 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2170 * Otherwise nodev tmo is set to the default value.
2171 *
2172 * Returns:
2173 * zero if already set or if val is in range
2174 * -EINVAL val out of range
2175 **/
James Smartc01f3202006-08-18 17:47:08 -04002176static int
James Smart3de2a652007-08-02 11:09:59 -04002177lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002178{
James Smart3de2a652007-08-02 11:09:59 -04002179 if (vport->dev_loss_tmo_changed ||
2180 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002181 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2182 "0401 Ignoring change to nodev_tmo "
2183 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002184 return 0;
2185 }
James Smartc01f3202006-08-18 17:47:08 -04002186 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002187 vport->cfg_nodev_tmo = val;
2188 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002189 /*
2190 * For compat: set the fc_host dev loss so new rports
2191 * will get the value.
2192 */
2193 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002194 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002195 return 0;
2196 }
James Smarte8b62012007-08-02 11:10:09 -04002197 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2198 "0403 lpfc_nodev_tmo attribute cannot be set to"
2199 "%d, allowed range is [%d, %d]\n",
2200 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002201 return -EINVAL;
2202}
2203
James Smart3de2a652007-08-02 11:09:59 -04002204lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002205
Tony Jonesee959b02008-02-22 00:13:36 +01002206static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2207 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002208
2209/*
2210# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2211# disappear until the timer expires. Value range is [0,255]. Default
2212# value is 30.
2213*/
2214module_param(lpfc_devloss_tmo, int, 0);
2215MODULE_PARM_DESC(lpfc_devloss_tmo,
2216 "Seconds driver will hold I/O waiting "
2217 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002218lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2219 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2220lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002221
2222/**
James Smart3621a712009-04-06 18:47:14 -04002223 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002224 * @vport: lpfc vport structure pointer.
2225 * @val: contains the tmo value.
2226 *
2227 * Description:
2228 * If val is in a valid range then set the vport nodev tmo,
2229 * devloss tmo, also set the vport dev loss tmo changed flag.
2230 * Else a kernel error message is printed.
2231 *
2232 * Returns:
2233 * zero if val is in range
2234 * -EINVAL val out of range
2235 **/
James Smartc01f3202006-08-18 17:47:08 -04002236static int
James Smart3de2a652007-08-02 11:09:59 -04002237lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002238{
2239 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002240 vport->cfg_nodev_tmo = val;
2241 vport->cfg_devloss_tmo = val;
2242 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002243 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002244 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002245 return 0;
2246 }
2247
James Smarte8b62012007-08-02 11:10:09 -04002248 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2249 "0404 lpfc_devloss_tmo attribute cannot be set to"
2250 " %d, allowed range is [%d, %d]\n",
2251 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002252 return -EINVAL;
2253}
2254
James Smart3de2a652007-08-02 11:09:59 -04002255lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002256static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2257 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002258
2259/*
dea31012005-04-17 16:05:31 -05002260# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2261# deluged with LOTS of information.
2262# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002263# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002264*/
James Smartf4b4c682009-05-22 14:53:12 -04002265LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002266 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002267
2268/*
James Smart7ee5d432007-10-27 13:37:17 -04002269# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2270# objects that have been registered with the nameserver after login.
2271*/
2272LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2273 "Deregister nameserver objects before LOGO");
2274
2275/*
dea31012005-04-17 16:05:31 -05002276# lun_queue_depth: This parameter is used to limit the number of outstanding
2277# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2278*/
James Smart3de2a652007-08-02 11:09:59 -04002279LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2280 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002281
2282/*
James Smart7dc517d2010-07-14 15:32:10 -04002283# tgt_queue_depth: This parameter is used to limit the number of outstanding
2284# commands per target port. Value range is [10,65535]. Default value is 65535.
2285*/
2286LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2287 "Max number of FCP commands we can queue to a specific target port");
2288
2289/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002290# hba_queue_depth: This parameter is used to limit the number of outstanding
2291# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2292# value is greater than the maximum number of exchanges supported by the HBA,
2293# then maximum number of exchanges supported by the HBA is used to determine
2294# the hba_queue_depth.
2295*/
2296LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2297 "Max number of FCP commands we can queue to a lpfc HBA");
2298
2299/*
James Smart92d7f7b2007-06-17 19:56:38 -05002300# peer_port_login: This parameter allows/prevents logins
2301# between peer ports hosted on the same physical port.
2302# When this parameter is set 0 peer ports of same physical port
2303# are not allowed to login to each other.
2304# When this parameter is set 1 peer ports of same physical port
2305# are allowed to login to each other.
2306# Default value of this parameter is 0.
2307*/
James Smart3de2a652007-08-02 11:09:59 -04002308LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2309 "Allow peer ports on the same physical port to login to each "
2310 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002311
2312/*
James Smart3de2a652007-08-02 11:09:59 -04002313# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002314# between Virtual Ports and remote initiators.
2315# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2316# other initiators and will attempt to PLOGI all remote ports.
2317# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2318# remote ports and will not attempt to PLOGI to other initiators.
2319# This parameter does not restrict to the physical port.
2320# This parameter does not restrict logins to Fabric resident remote ports.
2321# Default value of this parameter is 1.
2322*/
James Smart3de2a652007-08-02 11:09:59 -04002323static int lpfc_restrict_login = 1;
2324module_param(lpfc_restrict_login, int, 0);
2325MODULE_PARM_DESC(lpfc_restrict_login,
2326 "Restrict virtual ports login to remote initiators.");
2327lpfc_vport_param_show(restrict_login);
2328
James Smarte59058c2008-08-24 21:49:00 -04002329/**
James Smart3621a712009-04-06 18:47:14 -04002330 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002331 * @vport: lpfc vport structure pointer.
2332 * @val: contains the restrict login value.
2333 *
2334 * Description:
2335 * If val is not in a valid range then log a kernel error message and set
2336 * the vport restrict login to one.
2337 * If the port type is physical clear the restrict login flag and return.
2338 * Else set the restrict login flag to val.
2339 *
2340 * Returns:
2341 * zero if val is in range
2342 * -EINVAL val out of range
2343 **/
James Smart3de2a652007-08-02 11:09:59 -04002344static int
2345lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2346{
2347 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002348 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002349 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002350 "be set to %d, allowed range is [0, 1]\n",
2351 val);
James Smart3de2a652007-08-02 11:09:59 -04002352 vport->cfg_restrict_login = 1;
2353 return -EINVAL;
2354 }
2355 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2356 vport->cfg_restrict_login = 0;
2357 return 0;
2358 }
2359 vport->cfg_restrict_login = val;
2360 return 0;
2361}
2362
James Smarte59058c2008-08-24 21:49:00 -04002363/**
James Smart3621a712009-04-06 18:47:14 -04002364 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002365 * @vport: lpfc vport structure pointer.
2366 * @val: contains the restrict login value.
2367 *
2368 * Description:
2369 * If val is not in a valid range then log a kernel error message and set
2370 * the vport restrict login to one.
2371 * If the port type is physical and the val is not zero log a kernel
2372 * error message, clear the restrict login flag and return zero.
2373 * Else set the restrict login flag to val.
2374 *
2375 * Returns:
2376 * zero if val is in range
2377 * -EINVAL val out of range
2378 **/
James Smart3de2a652007-08-02 11:09:59 -04002379static int
2380lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2381{
2382 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002383 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002384 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002385 "be set to %d, allowed range is [0, 1]\n",
2386 val);
James Smart3de2a652007-08-02 11:09:59 -04002387 vport->cfg_restrict_login = 1;
2388 return -EINVAL;
2389 }
2390 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002391 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2392 "0468 lpfc_restrict_login must be 0 for "
2393 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002394 vport->cfg_restrict_login = 0;
2395 return 0;
2396 }
2397 vport->cfg_restrict_login = val;
2398 return 0;
2399}
2400lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002401static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2402 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002403
2404/*
dea31012005-04-17 16:05:31 -05002405# Some disk devices have a "select ID" or "select Target" capability.
2406# From a protocol standpoint "select ID" usually means select the
2407# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2408# annex" which contains a table that maps a "select ID" (a number
2409# between 0 and 7F) to an ALPA. By default, for compatibility with
2410# older drivers, the lpfc driver scans this table from low ALPA to high
2411# ALPA.
2412#
2413# Turning on the scan-down variable (on = 1, off = 0) will
2414# cause the lpfc driver to use an inverted table, effectively
2415# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2416#
2417# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2418# and will not work across a fabric. Also this parameter will take
2419# effect only in the case when ALPA map is not available.)
2420*/
James Smart3de2a652007-08-02 11:09:59 -04002421LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2422 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002423
2424/*
dea31012005-04-17 16:05:31 -05002425# lpfc_topology: link topology for init link
2426# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002427# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002428# 0x02 = attempt point-to-point mode only
2429# 0x04 = attempt loop mode only
2430# 0x06 = attempt point-to-point mode then loop
2431# Set point-to-point mode if you want to run as an N_Port.
2432# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2433# Default value is 0.
2434*/
James Smarte59058c2008-08-24 21:49:00 -04002435
2436/**
James Smart3621a712009-04-06 18:47:14 -04002437 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002438 * @phba: lpfc_hba pointer.
2439 * @val: topology value.
2440 *
2441 * Description:
2442 * If val is in a valid range then set the adapter's topology field and
2443 * issue a lip; if the lip fails reset the topology to the old value.
2444 *
2445 * If the value is not in range log a kernel error message and return an error.
2446 *
2447 * Returns:
2448 * zero if val is in range and lip okay
2449 * non-zero return value from lpfc_issue_lip()
2450 * -EINVAL val out of range
2451 **/
James Smarta257bf92009-04-06 18:48:10 -04002452static ssize_t
2453lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2454 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002455{
James Smarta257bf92009-04-06 18:48:10 -04002456 struct Scsi_Host *shost = class_to_shost(dev);
2457 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2458 struct lpfc_hba *phba = vport->phba;
2459 int val = 0;
2460 int nolip = 0;
2461 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002462 int err;
2463 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002464
2465 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2466 nolip = 1;
2467 val_buf = &buf[strlen("nolip ")];
2468 }
2469
2470 if (!isdigit(val_buf[0]))
2471 return -EINVAL;
2472 if (sscanf(val_buf, "%i", &val) != 1)
2473 return -EINVAL;
2474
James Smart83108bd2008-01-11 01:53:09 -05002475 if (val >= 0 && val <= 6) {
2476 prev_val = phba->cfg_topology;
2477 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002478 if (nolip)
2479 return strlen(buf);
2480
James Smart83108bd2008-01-11 01:53:09 -05002481 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002482 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002483 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002484 return -EINVAL;
2485 } else
2486 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002487 }
2488 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2489 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2490 "allowed range is [0, 6]\n",
2491 phba->brd_no, val);
2492 return -EINVAL;
2493}
2494static int lpfc_topology = 0;
2495module_param(lpfc_topology, int, 0);
2496MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2497lpfc_param_show(topology)
2498lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002499static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002500 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002501
James Smart21e9a0a2009-05-22 14:53:21 -04002502/**
2503 * lpfc_static_vport_show: Read callback function for
2504 * lpfc_static_vport sysfs file.
2505 * @dev: Pointer to class device object.
2506 * @attr: device attribute structure.
2507 * @buf: Data buffer.
2508 *
2509 * This function is the read call back function for
2510 * lpfc_static_vport sysfs file. The lpfc_static_vport
2511 * sysfs file report the mageability of the vport.
2512 **/
2513static ssize_t
2514lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2515 char *buf)
2516{
2517 struct Scsi_Host *shost = class_to_shost(dev);
2518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2519 if (vport->vport_flag & STATIC_VPORT)
2520 sprintf(buf, "1\n");
2521 else
2522 sprintf(buf, "0\n");
2523
2524 return strlen(buf);
2525}
2526
2527/*
2528 * Sysfs attribute to control the statistical data collection.
2529 */
2530static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2531 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002532
2533/**
James Smart3621a712009-04-06 18:47:14 -04002534 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002535 * @dev: Pointer to class device.
2536 * @buf: Data buffer.
2537 * @count: Size of the data buffer.
2538 *
2539 * This function get called when an user write to the lpfc_stat_data_ctrl
2540 * sysfs file. This function parse the command written to the sysfs file
2541 * and take appropriate action. These commands are used for controlling
2542 * driver statistical data collection.
2543 * Following are the command this function handles.
2544 *
2545 * setbucket <bucket_type> <base> <step>
2546 * = Set the latency buckets.
2547 * destroybucket = destroy all the buckets.
2548 * start = start data collection
2549 * stop = stop data collection
2550 * reset = reset the collected data
2551 **/
2552static ssize_t
2553lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2554 const char *buf, size_t count)
2555{
2556 struct Scsi_Host *shost = class_to_shost(dev);
2557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2558 struct lpfc_hba *phba = vport->phba;
2559#define LPFC_MAX_DATA_CTRL_LEN 1024
2560 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2561 unsigned long i;
2562 char *str_ptr, *token;
2563 struct lpfc_vport **vports;
2564 struct Scsi_Host *v_shost;
2565 char *bucket_type_str, *base_str, *step_str;
2566 unsigned long base, step, bucket_type;
2567
2568 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002569 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002570 return -EINVAL;
2571
2572 strcpy(bucket_data, buf);
2573 str_ptr = &bucket_data[0];
2574 /* Ignore this token - this is command token */
2575 token = strsep(&str_ptr, "\t ");
2576 if (!token)
2577 return -EINVAL;
2578
2579 bucket_type_str = strsep(&str_ptr, "\t ");
2580 if (!bucket_type_str)
2581 return -EINVAL;
2582
2583 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2584 bucket_type = LPFC_LINEAR_BUCKET;
2585 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2586 bucket_type = LPFC_POWER2_BUCKET;
2587 else
2588 return -EINVAL;
2589
2590 base_str = strsep(&str_ptr, "\t ");
2591 if (!base_str)
2592 return -EINVAL;
2593 base = simple_strtoul(base_str, NULL, 0);
2594
2595 step_str = strsep(&str_ptr, "\t ");
2596 if (!step_str)
2597 return -EINVAL;
2598 step = simple_strtoul(step_str, NULL, 0);
2599 if (!step)
2600 return -EINVAL;
2601
2602 /* Block the data collection for every vport */
2603 vports = lpfc_create_vport_work_array(phba);
2604 if (vports == NULL)
2605 return -ENOMEM;
2606
James Smartf4b4c682009-05-22 14:53:12 -04002607 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002608 v_shost = lpfc_shost_from_vport(vports[i]);
2609 spin_lock_irq(v_shost->host_lock);
2610 /* Block and reset data collection */
2611 vports[i]->stat_data_blocked = 1;
2612 if (vports[i]->stat_data_enabled)
2613 lpfc_vport_reset_stat_data(vports[i]);
2614 spin_unlock_irq(v_shost->host_lock);
2615 }
2616
2617 /* Set the bucket attributes */
2618 phba->bucket_type = bucket_type;
2619 phba->bucket_base = base;
2620 phba->bucket_step = step;
2621
James Smartf4b4c682009-05-22 14:53:12 -04002622 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002623 v_shost = lpfc_shost_from_vport(vports[i]);
2624
2625 /* Unblock data collection */
2626 spin_lock_irq(v_shost->host_lock);
2627 vports[i]->stat_data_blocked = 0;
2628 spin_unlock_irq(v_shost->host_lock);
2629 }
2630 lpfc_destroy_vport_work_array(phba, vports);
2631 return strlen(buf);
2632 }
2633
2634 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2635 vports = lpfc_create_vport_work_array(phba);
2636 if (vports == NULL)
2637 return -ENOMEM;
2638
James Smartf4b4c682009-05-22 14:53:12 -04002639 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002640 v_shost = lpfc_shost_from_vport(vports[i]);
2641 spin_lock_irq(shost->host_lock);
2642 vports[i]->stat_data_blocked = 1;
2643 lpfc_free_bucket(vport);
2644 vport->stat_data_enabled = 0;
2645 vports[i]->stat_data_blocked = 0;
2646 spin_unlock_irq(shost->host_lock);
2647 }
2648 lpfc_destroy_vport_work_array(phba, vports);
2649 phba->bucket_type = LPFC_NO_BUCKET;
2650 phba->bucket_base = 0;
2651 phba->bucket_step = 0;
2652 return strlen(buf);
2653 }
2654
2655 if (!strncmp(buf, "start", strlen("start"))) {
2656 /* If no buckets configured return error */
2657 if (phba->bucket_type == LPFC_NO_BUCKET)
2658 return -EINVAL;
2659 spin_lock_irq(shost->host_lock);
2660 if (vport->stat_data_enabled) {
2661 spin_unlock_irq(shost->host_lock);
2662 return strlen(buf);
2663 }
2664 lpfc_alloc_bucket(vport);
2665 vport->stat_data_enabled = 1;
2666 spin_unlock_irq(shost->host_lock);
2667 return strlen(buf);
2668 }
2669
2670 if (!strncmp(buf, "stop", strlen("stop"))) {
2671 spin_lock_irq(shost->host_lock);
2672 if (vport->stat_data_enabled == 0) {
2673 spin_unlock_irq(shost->host_lock);
2674 return strlen(buf);
2675 }
2676 lpfc_free_bucket(vport);
2677 vport->stat_data_enabled = 0;
2678 spin_unlock_irq(shost->host_lock);
2679 return strlen(buf);
2680 }
2681
2682 if (!strncmp(buf, "reset", strlen("reset"))) {
2683 if ((phba->bucket_type == LPFC_NO_BUCKET)
2684 || !vport->stat_data_enabled)
2685 return strlen(buf);
2686 spin_lock_irq(shost->host_lock);
2687 vport->stat_data_blocked = 1;
2688 lpfc_vport_reset_stat_data(vport);
2689 vport->stat_data_blocked = 0;
2690 spin_unlock_irq(shost->host_lock);
2691 return strlen(buf);
2692 }
2693 return -EINVAL;
2694}
2695
2696
2697/**
James Smart3621a712009-04-06 18:47:14 -04002698 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002699 * @dev: Pointer to class device object.
2700 * @buf: Data buffer.
2701 *
2702 * This function is the read call back function for
2703 * lpfc_stat_data_ctrl sysfs file. This function report the
2704 * current statistical data collection state.
2705 **/
2706static ssize_t
2707lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2708 char *buf)
2709{
2710 struct Scsi_Host *shost = class_to_shost(dev);
2711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2712 struct lpfc_hba *phba = vport->phba;
2713 int index = 0;
2714 int i;
2715 char *bucket_type;
2716 unsigned long bucket_value;
2717
2718 switch (phba->bucket_type) {
2719 case LPFC_LINEAR_BUCKET:
2720 bucket_type = "linear";
2721 break;
2722 case LPFC_POWER2_BUCKET:
2723 bucket_type = "power2";
2724 break;
2725 default:
2726 bucket_type = "No Bucket";
2727 break;
2728 }
2729
2730 sprintf(&buf[index], "Statistical Data enabled :%d, "
2731 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2732 " Bucket step :%d\nLatency Ranges :",
2733 vport->stat_data_enabled, vport->stat_data_blocked,
2734 bucket_type, phba->bucket_base, phba->bucket_step);
2735 index = strlen(buf);
2736 if (phba->bucket_type != LPFC_NO_BUCKET) {
2737 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2738 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2739 bucket_value = phba->bucket_base +
2740 phba->bucket_step * i;
2741 else
2742 bucket_value = phba->bucket_base +
2743 (1 << i) * phba->bucket_step;
2744
2745 if (index + 10 > PAGE_SIZE)
2746 break;
2747 sprintf(&buf[index], "%08ld ", bucket_value);
2748 index = strlen(buf);
2749 }
2750 }
2751 sprintf(&buf[index], "\n");
2752 return strlen(buf);
2753}
2754
2755/*
2756 * Sysfs attribute to control the statistical data collection.
2757 */
2758static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2759 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2760
2761/*
2762 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2763 */
2764
2765/*
2766 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2767 * for each target.
2768 */
2769#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2770#define MAX_STAT_DATA_SIZE_PER_TARGET \
2771 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2772
2773
2774/**
James Smart3621a712009-04-06 18:47:14 -04002775 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002776 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002777 * @kobj: Pointer to the kernel object
2778 * @bin_attr: Attribute object
2779 * @buff: Buffer pointer
2780 * @off: File offset
2781 * @count: Buffer size
2782 *
2783 * This function is the read call back function for lpfc_drvr_stat_data
2784 * sysfs file. This function export the statistical data to user
2785 * applications.
2786 **/
2787static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002788sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2789 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002790 char *buf, loff_t off, size_t count)
2791{
2792 struct device *dev = container_of(kobj, struct device,
2793 kobj);
2794 struct Scsi_Host *shost = class_to_shost(dev);
2795 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2796 struct lpfc_hba *phba = vport->phba;
2797 int i = 0, index = 0;
2798 unsigned long nport_index;
2799 struct lpfc_nodelist *ndlp = NULL;
2800 nport_index = (unsigned long)off /
2801 MAX_STAT_DATA_SIZE_PER_TARGET;
2802
2803 if (!vport->stat_data_enabled || vport->stat_data_blocked
2804 || (phba->bucket_type == LPFC_NO_BUCKET))
2805 return 0;
2806
2807 spin_lock_irq(shost->host_lock);
2808 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2809 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2810 continue;
2811
2812 if (nport_index > 0) {
2813 nport_index--;
2814 continue;
2815 }
2816
2817 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2818 > count)
2819 break;
2820
2821 if (!ndlp->lat_data)
2822 continue;
2823
2824 /* Print the WWN */
2825 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2826 ndlp->nlp_portname.u.wwn[0],
2827 ndlp->nlp_portname.u.wwn[1],
2828 ndlp->nlp_portname.u.wwn[2],
2829 ndlp->nlp_portname.u.wwn[3],
2830 ndlp->nlp_portname.u.wwn[4],
2831 ndlp->nlp_portname.u.wwn[5],
2832 ndlp->nlp_portname.u.wwn[6],
2833 ndlp->nlp_portname.u.wwn[7]);
2834
2835 index = strlen(buf);
2836
2837 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2838 sprintf(&buf[index], "%010u,",
2839 ndlp->lat_data[i].cmd_count);
2840 index = strlen(buf);
2841 }
2842 sprintf(&buf[index], "\n");
2843 index = strlen(buf);
2844 }
2845 spin_unlock_irq(shost->host_lock);
2846 return index;
2847}
2848
2849static struct bin_attribute sysfs_drvr_stat_data_attr = {
2850 .attr = {
2851 .name = "lpfc_drvr_stat_data",
2852 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04002853 },
2854 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2855 .read = sysfs_drvr_stat_data_read,
2856 .write = NULL,
2857};
2858
dea31012005-04-17 16:05:31 -05002859/*
2860# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2861# connection.
James Smart76a95d72010-11-20 23:11:48 -05002862# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05002863*/
James Smarte59058c2008-08-24 21:49:00 -04002864/**
James Smart3621a712009-04-06 18:47:14 -04002865 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002866 * @phba: lpfc_hba pointer.
2867 * @val: link speed value.
2868 *
2869 * Description:
2870 * If val is in a valid range then set the adapter's link speed field and
2871 * issue a lip; if the lip fails reset the link speed to the old value.
2872 *
2873 * Notes:
2874 * If the value is not in range log a kernel error message and return an error.
2875 *
2876 * Returns:
2877 * zero if val is in range and lip okay.
2878 * non-zero return value from lpfc_issue_lip()
2879 * -EINVAL val out of range
2880 **/
James Smarta257bf92009-04-06 18:48:10 -04002881static ssize_t
2882lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2883 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002884{
James Smarta257bf92009-04-06 18:48:10 -04002885 struct Scsi_Host *shost = class_to_shost(dev);
2886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2887 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05002888 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04002889 int nolip = 0;
2890 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002891 int err;
2892 uint32_t prev_val;
2893
James Smarta257bf92009-04-06 18:48:10 -04002894 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2895 nolip = 1;
2896 val_buf = &buf[strlen("nolip ")];
2897 }
2898
2899 if (!isdigit(val_buf[0]))
2900 return -EINVAL;
2901 if (sscanf(val_buf, "%i", &val) != 1)
2902 return -EINVAL;
2903
James Smart76a95d72010-11-20 23:11:48 -05002904 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2905 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2906 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2907 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2908 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2909 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2911 "2879 lpfc_link_speed attribute cannot be set "
2912 "to %d. Speed is not supported by this port.\n",
2913 val);
James Smart83108bd2008-01-11 01:53:09 -05002914 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05002915 }
2916 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2917 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002918 prev_val = phba->cfg_link_speed;
2919 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002920 if (nolip)
2921 return strlen(buf);
2922
James Smart83108bd2008-01-11 01:53:09 -05002923 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002924 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002925 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002926 return -EINVAL;
2927 } else
2928 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002929 }
James Smart83108bd2008-01-11 01:53:09 -05002930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05002931 "0469 lpfc_link_speed attribute cannot be set to %d, "
2932 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05002933 return -EINVAL;
2934}
2935
2936static int lpfc_link_speed = 0;
2937module_param(lpfc_link_speed, int, 0);
2938MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2939lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002940
2941/**
James Smart3621a712009-04-06 18:47:14 -04002942 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002943 * @phba: lpfc_hba pointer.
2944 * @val: link speed value.
2945 *
2946 * Description:
2947 * If val is in a valid range then set the adapter's link speed field.
2948 *
2949 * Notes:
2950 * If the value is not in range log a kernel error message, clear the link
2951 * speed and return an error.
2952 *
2953 * Returns:
2954 * zero if val saved.
2955 * -EINVAL val out of range
2956 **/
James Smart83108bd2008-01-11 01:53:09 -05002957static int
2958lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2959{
James Smart76a95d72010-11-20 23:11:48 -05002960 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2961 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002962 phba->cfg_link_speed = val;
2963 return 0;
2964 }
2965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002966 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002967 "be set to %d, allowed values are "
2968 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05002969 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05002970 return -EINVAL;
2971}
2972
Tony Jonesee959b02008-02-22 00:13:36 +01002973static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05002974 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002975
2976/*
James Smart0d878412009-10-02 15:16:56 -04002977# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2978# 0 = aer disabled or not supported
2979# 1 = aer supported and enabled (default)
2980# Value range is [0,1]. Default value is 1.
2981*/
2982
2983/**
2984 * lpfc_aer_support_store - Set the adapter for aer support
2985 *
2986 * @dev: class device that is converted into a Scsi_host.
2987 * @attr: device attribute, not used.
2988 * @buf: containing the string "selective".
2989 * @count: unused variable.
2990 *
2991 * Description:
2992 * If the val is 1 and currently the device's AER capability was not
2993 * enabled, invoke the kernel's enable AER helper routine, trying to
2994 * enable the device's AER capability. If the helper routine enabling
2995 * AER returns success, update the device's cfg_aer_support flag to
2996 * indicate AER is supported by the device; otherwise, if the device
2997 * AER capability is already enabled to support AER, then do nothing.
2998 *
2999 * If the val is 0 and currently the device's AER support was enabled,
3000 * invoke the kernel's disable AER helper routine. After that, update
3001 * the device's cfg_aer_support flag to indicate AER is not supported
3002 * by the device; otherwise, if the device AER capability is already
3003 * disabled from supporting AER, then do nothing.
3004 *
3005 * Returns:
3006 * length of the buf on success if val is in range the intended mode
3007 * is supported.
3008 * -EINVAL if val out of range or intended mode is not supported.
3009 **/
3010static ssize_t
3011lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3012 const char *buf, size_t count)
3013{
3014 struct Scsi_Host *shost = class_to_shost(dev);
3015 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3016 struct lpfc_hba *phba = vport->phba;
3017 int val = 0, rc = -EINVAL;
3018
3019 if (!isdigit(buf[0]))
3020 return -EINVAL;
3021 if (sscanf(buf, "%i", &val) != 1)
3022 return -EINVAL;
3023
3024 switch (val) {
3025 case 0:
3026 if (phba->hba_flag & HBA_AER_ENABLED) {
3027 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3028 if (!rc) {
3029 spin_lock_irq(&phba->hbalock);
3030 phba->hba_flag &= ~HBA_AER_ENABLED;
3031 spin_unlock_irq(&phba->hbalock);
3032 phba->cfg_aer_support = 0;
3033 rc = strlen(buf);
3034 } else
James Smart891478a2009-11-18 15:40:23 -05003035 rc = -EPERM;
3036 } else {
James Smart0d878412009-10-02 15:16:56 -04003037 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003038 rc = strlen(buf);
3039 }
James Smart0d878412009-10-02 15:16:56 -04003040 break;
3041 case 1:
3042 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3043 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3044 if (!rc) {
3045 spin_lock_irq(&phba->hbalock);
3046 phba->hba_flag |= HBA_AER_ENABLED;
3047 spin_unlock_irq(&phba->hbalock);
3048 phba->cfg_aer_support = 1;
3049 rc = strlen(buf);
3050 } else
James Smart891478a2009-11-18 15:40:23 -05003051 rc = -EPERM;
3052 } else {
James Smart0d878412009-10-02 15:16:56 -04003053 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003054 rc = strlen(buf);
3055 }
James Smart0d878412009-10-02 15:16:56 -04003056 break;
3057 default:
3058 rc = -EINVAL;
3059 break;
3060 }
3061 return rc;
3062}
3063
3064static int lpfc_aer_support = 1;
3065module_param(lpfc_aer_support, int, 1);
3066MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3067lpfc_param_show(aer_support)
3068
3069/**
3070 * lpfc_aer_support_init - Set the initial adapters aer support flag
3071 * @phba: lpfc_hba pointer.
3072 * @val: link speed value.
3073 *
3074 * Description:
3075 * If val is in a valid range [0,1], then set the adapter's initial
3076 * cfg_aer_support field. It will be up to the driver's probe_one
3077 * routine to determine whether the device's AER support can be set
3078 * or not.
3079 *
3080 * Notes:
3081 * If the value is not in range log a kernel error message, and
3082 * choose the default value of setting AER support and return.
3083 *
3084 * Returns:
3085 * zero if val saved.
3086 * -EINVAL val out of range
3087 **/
3088static int
3089lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3090{
3091 if (val == 0 || val == 1) {
3092 phba->cfg_aer_support = val;
3093 return 0;
3094 }
3095 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3096 "2712 lpfc_aer_support attribute value %d out "
3097 "of range, allowed values are 0|1, setting it "
3098 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003099 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003100 phba->cfg_aer_support = 1;
3101 return -EINVAL;
3102}
3103
3104static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3105 lpfc_aer_support_show, lpfc_aer_support_store);
3106
3107/**
3108 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3109 * @dev: class device that is converted into a Scsi_host.
3110 * @attr: device attribute, not used.
3111 * @buf: containing the string "selective".
3112 * @count: unused variable.
3113 *
3114 * Description:
3115 * If the @buf contains 1 and the device currently has the AER support
3116 * enabled, then invokes the kernel AER helper routine
3117 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3118 * error status register.
3119 *
3120 * Notes:
3121 *
3122 * Returns:
3123 * -EINVAL if the buf does not contain the 1 or the device is not currently
3124 * enabled with the AER support.
3125 **/
3126static ssize_t
3127lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3128 const char *buf, size_t count)
3129{
3130 struct Scsi_Host *shost = class_to_shost(dev);
3131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3132 struct lpfc_hba *phba = vport->phba;
3133 int val, rc = -1;
3134
3135 if (!isdigit(buf[0]))
3136 return -EINVAL;
3137 if (sscanf(buf, "%i", &val) != 1)
3138 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003139 if (val != 1)
3140 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003141
James Smart891478a2009-11-18 15:40:23 -05003142 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003143 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3144
3145 if (rc == 0)
3146 return strlen(buf);
3147 else
James Smart891478a2009-11-18 15:40:23 -05003148 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003149}
3150
3151static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3152 lpfc_aer_cleanup_state);
3153
3154/*
dea31012005-04-17 16:05:31 -05003155# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3156# Value range is [2,3]. Default value is 3.
3157*/
James Smart3de2a652007-08-02 11:09:59 -04003158LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3159 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003160
3161/*
3162# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3163# is [0,1]. Default value is 0.
3164*/
James Smart3de2a652007-08-02 11:09:59 -04003165LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3166 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003167
3168/*
James Smart977b5a02008-09-07 11:52:04 -04003169# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3170# depth. Default value is 0. When the value of this parameter is zero the
3171# SCSI command completion time is not used for controlling I/O queue depth. When
3172# the parameter is set to a non-zero value, the I/O queue depth is controlled
3173# to limit the I/O completion time to the parameter value.
3174# The value is set in milliseconds.
3175*/
3176static int lpfc_max_scsicmpl_time;
3177module_param(lpfc_max_scsicmpl_time, int, 0);
3178MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3179 "Use command completion time to control queue depth");
3180lpfc_vport_param_show(max_scsicmpl_time);
3181lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3182static int
3183lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3184{
3185 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3186 struct lpfc_nodelist *ndlp, *next_ndlp;
3187
3188 if (val == vport->cfg_max_scsicmpl_time)
3189 return 0;
3190 if ((val < 0) || (val > 60000))
3191 return -EINVAL;
3192 vport->cfg_max_scsicmpl_time = val;
3193
3194 spin_lock_irq(shost->host_lock);
3195 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3196 if (!NLP_CHK_NODE_ACT(ndlp))
3197 continue;
3198 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3199 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003200 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003201 }
3202 spin_unlock_irq(shost->host_lock);
3203 return 0;
3204}
3205lpfc_vport_param_store(max_scsicmpl_time);
3206static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3207 lpfc_max_scsicmpl_time_show,
3208 lpfc_max_scsicmpl_time_store);
3209
3210/*
dea31012005-04-17 16:05:31 -05003211# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3212# range is [0,1]. Default value is 0.
3213*/
3214LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3215
3216/*
3217# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3218# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003219# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003220# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3221# cr_delay is set to 0.
3222*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003223LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003224 "interrupt response is generated");
3225
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003226LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003227 "interrupt response is generated");
3228
3229/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003230# lpfc_multi_ring_support: Determines how many rings to spread available
3231# cmd/rsp IOCB entries across.
3232# Value range is [1,2]. Default value is 1.
3233*/
3234LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3235 "SLI rings to spread IOCB entries across");
3236
3237/*
James Smarta4bc3372006-12-02 13:34:16 -05003238# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3239# identifies what rctl value to configure the additional ring for.
3240# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3241*/
James Smart6a9c52c2009-10-02 15:16:51 -04003242LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003243 255, "Identifies RCTL for additional ring configuration");
3244
3245/*
3246# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3247# identifies what type value to configure the additional ring for.
3248# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3249*/
James Smart6a9c52c2009-10-02 15:16:51 -04003250LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003251 255, "Identifies TYPE for additional ring configuration");
3252
3253/*
dea31012005-04-17 16:05:31 -05003254# lpfc_fdmi_on: controls FDMI support.
3255# 0 = no FDMI support
3256# 1 = support FDMI without attribute of hostname
3257# 2 = support FDMI with attribute of hostname
3258# Value range [0,2]. Default value is 0.
3259*/
James Smart3de2a652007-08-02 11:09:59 -04003260LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003261
3262/*
3263# Specifies the maximum number of ELS cmds we can have outstanding (for
3264# discovery). Value range is [1,64]. Default value = 32.
3265*/
James Smart3de2a652007-08-02 11:09:59 -04003266LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003267 "during discovery");
3268
3269/*
James Smart65a29c12006-07-06 15:50:50 -04003270# lpfc_max_luns: maximum allowed LUN.
3271# Value range is [0,65535]. Default value is 255.
3272# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003273*/
James Smart3de2a652007-08-02 11:09:59 -04003274LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003275
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003276/*
3277# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3278# Value range is [1,255], default value is 10.
3279*/
3280LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3281 "Milliseconds driver will wait between polling FCP ring");
3282
James Smart4ff43242006-12-02 13:34:56 -05003283/*
3284# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3285# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003286# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003287# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003288# 2 = MSI-X enabled (default)
3289# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003290*/
George Kadianakis8605c462010-01-17 21:19:31 +02003291LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003292 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003293
James Smart13815c82008-01-11 01:52:48 -05003294/*
James Smartda0436e2009-05-22 14:51:39 -04003295# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3296#
3297# Value range is [636,651042]. Default value is 10000.
3298*/
3299LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3300 "Set the maximum number of fast-path FCP interrupts per second");
3301
3302/*
3303# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3304#
3305# Value range is [1,31]. Default value is 4.
3306*/
3307LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3308 "Set the number of fast-path FCP work queues, if possible");
3309
3310/*
3311# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3312#
3313# Value range is [1,7]. Default value is 1.
3314*/
3315LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3316 "Set the number of fast-path FCP event queues, if possible");
3317
3318/*
James Smart13815c82008-01-11 01:52:48 -05003319# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3320# 0 = HBA resets disabled
3321# 1 = HBA resets enabled (default)
3322# Value range is [0,1]. Default value is 1.
3323*/
3324LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003325
James Smart13815c82008-01-11 01:52:48 -05003326/*
James Smarteb7a3392010-11-20 23:12:02 -05003327# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003328# 0 = HBA Heartbeat disabled
3329# 1 = HBA Heartbeat enabled (default)
3330# Value range is [0,1]. Default value is 1.
3331*/
James Smarteb7a3392010-11-20 23:12:02 -05003332LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003333
James Smart83108bd2008-01-11 01:53:09 -05003334/*
James Smart81301a92008-12-04 22:39:46 -05003335# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3336# 0 = BlockGuard disabled (default)
3337# 1 = BlockGuard enabled
3338# Value range is [0,1]. Default value is 0.
3339*/
3340LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3341
James Smart6fb120a2009-05-22 14:52:59 -04003342/*
James Smart81301a92008-12-04 22:39:46 -05003343# lpfc_prot_mask: i
3344# - Bit mask of host protection capabilities used to register with the
3345# SCSI mid-layer
3346# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3347# - Allows you to ultimately specify which profiles to use
3348# - Default will result in registering capabilities for all profiles.
3349#
3350*/
James Smartbc739052010-08-04 16:11:18 -04003351unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003352
3353module_param(lpfc_prot_mask, uint, 0);
3354MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3355
3356/*
3357# lpfc_prot_guard: i
3358# - Bit mask of protection guard types to register with the SCSI mid-layer
3359# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3360# - Allows you to ultimately specify which profiles to use
3361# - Default will result in registering capabilities for all guard types
3362#
3363*/
3364unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3365module_param(lpfc_prot_guard, byte, 0);
3366MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3367
3368
3369/*
James Smart3621a712009-04-06 18:47:14 -04003370 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003371 * This value can be set to values between 64 and 256. The default value is
3372 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3373 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3374 */
3375LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3376 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3377
James Smart81301a92008-12-04 22:39:46 -05003378LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3379 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3380 "Max Protection Scatter Gather Segment Count");
3381
Tony Jonesee959b02008-02-22 00:13:36 +01003382struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003383 &dev_attr_bg_info,
3384 &dev_attr_bg_guard_err,
3385 &dev_attr_bg_apptag_err,
3386 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003387 &dev_attr_info,
3388 &dev_attr_serialnum,
3389 &dev_attr_modeldesc,
3390 &dev_attr_modelname,
3391 &dev_attr_programtype,
3392 &dev_attr_portnum,
3393 &dev_attr_fwrev,
3394 &dev_attr_hdw,
3395 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003396 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003397 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003398 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003399 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003400 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003401 &dev_attr_lpfc_temp_sensor,
3402 &dev_attr_lpfc_log_verbose,
3403 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003404 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003405 &dev_attr_lpfc_hba_queue_depth,
3406 &dev_attr_lpfc_peer_port_login,
3407 &dev_attr_lpfc_nodev_tmo,
3408 &dev_attr_lpfc_devloss_tmo,
3409 &dev_attr_lpfc_fcp_class,
3410 &dev_attr_lpfc_use_adisc,
3411 &dev_attr_lpfc_ack0,
3412 &dev_attr_lpfc_topology,
3413 &dev_attr_lpfc_scan_down,
3414 &dev_attr_lpfc_link_speed,
3415 &dev_attr_lpfc_cr_delay,
3416 &dev_attr_lpfc_cr_count,
3417 &dev_attr_lpfc_multi_ring_support,
3418 &dev_attr_lpfc_multi_ring_rctl,
3419 &dev_attr_lpfc_multi_ring_type,
3420 &dev_attr_lpfc_fdmi_on,
3421 &dev_attr_lpfc_max_luns,
3422 &dev_attr_lpfc_enable_npiv,
James Smart19ca7602010-11-20 23:11:55 -05003423 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003424 &dev_attr_nport_evt_cnt,
3425 &dev_attr_board_mode,
3426 &dev_attr_max_vpi,
3427 &dev_attr_used_vpi,
3428 &dev_attr_max_rpi,
3429 &dev_attr_used_rpi,
3430 &dev_attr_max_xri,
3431 &dev_attr_used_xri,
3432 &dev_attr_npiv_info,
3433 &dev_attr_issue_reset,
3434 &dev_attr_lpfc_poll,
3435 &dev_attr_lpfc_poll_tmo,
3436 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003437 &dev_attr_lpfc_fcp_imax,
3438 &dev_attr_lpfc_fcp_wq_count,
3439 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003440 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003441 &dev_attr_lpfc_soft_wwnn,
3442 &dev_attr_lpfc_soft_wwpn,
3443 &dev_attr_lpfc_soft_wwn_enable,
3444 &dev_attr_lpfc_enable_hba_reset,
3445 &dev_attr_lpfc_enable_hba_heartbeat,
3446 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003447 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003448 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003449 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003450 &dev_attr_lpfc_aer_support,
3451 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003452 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003453 &dev_attr_lpfc_iocb_cnt,
3454 &dev_attr_iocb_hw,
3455 &dev_attr_txq_hw,
3456 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003457 &dev_attr_lpfc_fips_level,
3458 &dev_attr_lpfc_fips_rev,
dea31012005-04-17 16:05:31 -05003459 NULL,
3460};
3461
Tony Jonesee959b02008-02-22 00:13:36 +01003462struct device_attribute *lpfc_vport_attrs[] = {
3463 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003464 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003465 &dev_attr_num_discovered_ports,
3466 &dev_attr_lpfc_drvr_version,
3467 &dev_attr_lpfc_log_verbose,
3468 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003469 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003470 &dev_attr_lpfc_nodev_tmo,
3471 &dev_attr_lpfc_devloss_tmo,
3472 &dev_attr_lpfc_hba_queue_depth,
3473 &dev_attr_lpfc_peer_port_login,
3474 &dev_attr_lpfc_restrict_login,
3475 &dev_attr_lpfc_fcp_class,
3476 &dev_attr_lpfc_use_adisc,
3477 &dev_attr_lpfc_fdmi_on,
3478 &dev_attr_lpfc_max_luns,
3479 &dev_attr_nport_evt_cnt,
3480 &dev_attr_npiv_info,
3481 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003482 &dev_attr_lpfc_max_scsicmpl_time,
3483 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003484 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003485 &dev_attr_lpfc_fips_level,
3486 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003487 NULL,
3488};
3489
James Smarte59058c2008-08-24 21:49:00 -04003490/**
James Smart3621a712009-04-06 18:47:14 -04003491 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003492 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003493 * @kobj: kernel kobject that contains the kernel class device.
3494 * @bin_attr: kernel attributes passed to us.
3495 * @buf: contains the data to be written to the adapter IOREG space.
3496 * @off: offset into buffer to beginning of data.
3497 * @count: bytes to transfer.
3498 *
3499 * Description:
3500 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3501 * Uses the adapter io control registers to send buf contents to the adapter.
3502 *
3503 * Returns:
3504 * -ERANGE off and count combo out of range
3505 * -EINVAL off, count or buff address invalid
3506 * -EPERM adapter is offline
3507 * value of count, buf contents written
3508 **/
dea31012005-04-17 16:05:31 -05003509static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003510sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3511 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003512 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003513{
3514 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003515 struct device *dev = container_of(kobj, struct device, kobj);
3516 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003517 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3518 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003519
James Smartf1126682009-06-10 17:22:44 -04003520 if (phba->sli_rev >= LPFC_SLI_REV4)
3521 return -EPERM;
3522
dea31012005-04-17 16:05:31 -05003523 if ((off + count) > FF_REG_AREA_SIZE)
3524 return -ERANGE;
3525
3526 if (count == 0) return 0;
3527
3528 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3529 return -EINVAL;
3530
James Smart2e0fef82007-06-17 19:56:36 -05003531 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003532 return -EPERM;
3533 }
3534
James Smart2e0fef82007-06-17 19:56:36 -05003535 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003536 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3537 writel(*((uint32_t *)(buf + buf_off)),
3538 phba->ctrl_regs_memmap_p + off + buf_off);
3539
James Smart2e0fef82007-06-17 19:56:36 -05003540 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003541
3542 return count;
3543}
3544
James Smarte59058c2008-08-24 21:49:00 -04003545/**
James Smart3621a712009-04-06 18:47:14 -04003546 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003547 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003548 * @kobj: kernel kobject that contains the kernel class device.
3549 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003550 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003551 * @off: offset into buffer to beginning of data.
3552 * @count: bytes to transfer.
3553 *
3554 * Description:
3555 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3556 * Uses the adapter io control registers to read data into buf.
3557 *
3558 * Returns:
3559 * -ERANGE off and count combo out of range
3560 * -EINVAL off, count or buff address invalid
3561 * value of count, buf contents read
3562 **/
dea31012005-04-17 16:05:31 -05003563static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003564sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3565 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003566 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003567{
3568 size_t buf_off;
3569 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003570 struct device *dev = container_of(kobj, struct device, kobj);
3571 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3573 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003574
James Smartf1126682009-06-10 17:22:44 -04003575 if (phba->sli_rev >= LPFC_SLI_REV4)
3576 return -EPERM;
3577
dea31012005-04-17 16:05:31 -05003578 if (off > FF_REG_AREA_SIZE)
3579 return -ERANGE;
3580
3581 if ((off + count) > FF_REG_AREA_SIZE)
3582 count = FF_REG_AREA_SIZE - off;
3583
3584 if (count == 0) return 0;
3585
3586 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3587 return -EINVAL;
3588
James Smart2e0fef82007-06-17 19:56:36 -05003589 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003590
3591 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3592 tmp_ptr = (uint32_t *)(buf + buf_off);
3593 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3594 }
3595
James Smart2e0fef82007-06-17 19:56:36 -05003596 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003597
3598 return count;
3599}
3600
3601static struct bin_attribute sysfs_ctlreg_attr = {
3602 .attr = {
3603 .name = "ctlreg",
3604 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003605 },
3606 .size = 256,
3607 .read = sysfs_ctlreg_read,
3608 .write = sysfs_ctlreg_write,
3609};
3610
James Smarte59058c2008-08-24 21:49:00 -04003611/**
James Smart3621a712009-04-06 18:47:14 -04003612 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003613 * @phba: lpfc_hba pointer
3614 **/
dea31012005-04-17 16:05:31 -05003615static void
James Smart2e0fef82007-06-17 19:56:36 -05003616sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003617{
3618 phba->sysfs_mbox.state = SMBOX_IDLE;
3619 phba->sysfs_mbox.offset = 0;
3620
3621 if (phba->sysfs_mbox.mbox) {
3622 mempool_free(phba->sysfs_mbox.mbox,
3623 phba->mbox_mem_pool);
3624 phba->sysfs_mbox.mbox = NULL;
3625 }
3626}
3627
James Smarte59058c2008-08-24 21:49:00 -04003628/**
James Smart3621a712009-04-06 18:47:14 -04003629 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003630 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003631 * @kobj: kernel kobject that contains the kernel class device.
3632 * @bin_attr: kernel attributes passed to us.
3633 * @buf: contains the data to be written to sysfs mbox.
3634 * @off: offset into buffer to beginning of data.
3635 * @count: bytes to transfer.
3636 *
3637 * Description:
3638 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3639 * Uses the sysfs mbox to send buf contents to the adapter.
3640 *
3641 * Returns:
3642 * -ERANGE off and count combo out of range
3643 * -EINVAL off, count or buff address invalid
3644 * zero if count is zero
3645 * -EPERM adapter is offline
3646 * -ENOMEM failed to allocate memory for the mail box
3647 * -EAGAIN offset, state or mbox is NULL
3648 * count number of bytes transferred
3649 **/
dea31012005-04-17 16:05:31 -05003650static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003651sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3652 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003653 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003654{
Tony Jonesee959b02008-02-22 00:13:36 +01003655 struct device *dev = container_of(kobj, struct device, kobj);
3656 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3658 struct lpfc_hba *phba = vport->phba;
3659 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003660
3661 if ((count + off) > MAILBOX_CMD_SIZE)
3662 return -ERANGE;
3663
3664 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3665 return -EINVAL;
3666
3667 if (count == 0)
3668 return 0;
3669
3670 if (off == 0) {
3671 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3672 if (!mbox)
3673 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003674 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003675 }
3676
James Smart2e0fef82007-06-17 19:56:36 -05003677 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003678
3679 if (off == 0) {
3680 if (phba->sysfs_mbox.mbox)
3681 mempool_free(mbox, phba->mbox_mem_pool);
3682 else
3683 phba->sysfs_mbox.mbox = mbox;
3684 phba->sysfs_mbox.state = SMBOX_WRITING;
3685 } else {
3686 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3687 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003688 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003689 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003690 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003691 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003692 }
3693 }
3694
James Smart04c68492009-05-22 14:52:52 -04003695 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003696 buf, count);
3697
3698 phba->sysfs_mbox.offset = off + count;
3699
James Smart2e0fef82007-06-17 19:56:36 -05003700 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003701
3702 return count;
3703}
3704
James Smarte59058c2008-08-24 21:49:00 -04003705/**
James Smart3621a712009-04-06 18:47:14 -04003706 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003707 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003708 * @kobj: kernel kobject that contains the kernel class device.
3709 * @bin_attr: kernel attributes passed to us.
3710 * @buf: contains the data to be read from sysfs mbox.
3711 * @off: offset into buffer to beginning of data.
3712 * @count: bytes to transfer.
3713 *
3714 * Description:
3715 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3716 * Uses the sysfs mbox to receive data from to the adapter.
3717 *
3718 * Returns:
3719 * -ERANGE off greater than mailbox command size
3720 * -EINVAL off, count or buff address invalid
3721 * zero if off and count are zero
3722 * -EACCES adapter over temp
3723 * -EPERM garbage can value to catch a multitude of errors
3724 * -EAGAIN management IO not permitted, state or off error
3725 * -ETIME mailbox timeout
3726 * -ENODEV mailbox error
3727 * count number of bytes transferred
3728 **/
dea31012005-04-17 16:05:31 -05003729static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003730sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3731 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003732 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003733{
Tony Jonesee959b02008-02-22 00:13:36 +01003734 struct device *dev = container_of(kobj, struct device, kobj);
3735 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003736 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3737 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003738 int rc;
James Smart04c68492009-05-22 14:52:52 -04003739 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003740
James Smart1dcb58e2007-04-25 09:51:30 -04003741 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003742 return -ERANGE;
3743
James Smart1dcb58e2007-04-25 09:51:30 -04003744 if ((count + off) > MAILBOX_CMD_SIZE)
3745 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003746
3747 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3748 return -EINVAL;
3749
3750 if (off && count == 0)
3751 return 0;
3752
James Smart2e0fef82007-06-17 19:56:36 -05003753 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003754
James Smart7af67052007-10-27 13:38:11 -04003755 if (phba->over_temp_state == HBA_OVER_TEMP) {
3756 sysfs_mbox_idle(phba);
3757 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003758 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003759 }
3760
dea31012005-04-17 16:05:31 -05003761 if (off == 0 &&
3762 phba->sysfs_mbox.state == SMBOX_WRITING &&
3763 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003764 pmb = &phba->sysfs_mbox.mbox->u.mb;
3765 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003766 /* Offline only */
dea31012005-04-17 16:05:31 -05003767 case MBX_INIT_LINK:
3768 case MBX_DOWN_LINK:
3769 case MBX_CONFIG_LINK:
3770 case MBX_CONFIG_RING:
3771 case MBX_RESET_RING:
3772 case MBX_UNREG_LOGIN:
3773 case MBX_CLEAR_LA:
3774 case MBX_DUMP_CONTEXT:
3775 case MBX_RUN_DIAGS:
3776 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003777 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003778 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003779 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003780 printk(KERN_WARNING "mbox_read:Command 0x%x "
3781 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003782 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003783 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003784 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003785 return -EPERM;
3786 }
James Smarta8adb832007-10-27 13:37:53 -04003787 case MBX_WRITE_NV:
3788 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003789 case MBX_LOAD_SM:
3790 case MBX_READ_NV:
3791 case MBX_READ_CONFIG:
3792 case MBX_READ_RCONFIG:
3793 case MBX_READ_STATUS:
3794 case MBX_READ_XRI:
3795 case MBX_READ_REV:
3796 case MBX_READ_LNK_STAT:
3797 case MBX_DUMP_MEMORY:
3798 case MBX_DOWN_LOAD:
3799 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003800 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003801 case MBX_LOAD_AREA:
3802 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003803 case MBX_BEACON:
3804 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003805 case MBX_SET_VARIABLE:
3806 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003807 case MBX_PORT_CAPABILITIES:
3808 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003809 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04003810 case MBX_SECURITY_MGMT:
3811 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04003812 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3813 printk(KERN_WARNING "mbox_read:Command 0x%x "
3814 "is not permitted\n", pmb->mbxCommand);
3815 sysfs_mbox_idle(phba);
3816 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04003817 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04003818 }
James Smartdcf2a4e2010-09-29 11:18:53 -04003819 break;
dea31012005-04-17 16:05:31 -05003820 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05003821 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05003822 case MBX_REG_LOGIN:
3823 case MBX_REG_LOGIN64:
3824 case MBX_CONFIG_PORT:
3825 case MBX_RUN_BIU_DIAG:
3826 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003827 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003828 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003829 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003830 return -EPERM;
3831 default:
3832 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003833 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003834 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003835 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003836 return -EPERM;
3837 }
3838
James Smart09372822008-01-11 01:52:54 -05003839 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003840 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003841 */
James Smartd7c255b2008-08-24 21:50:00 -04003842 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003843 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3844 pmb->mbxCommand != MBX_RESTART &&
3845 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3846 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003847 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3848 "1259 mbox: Issued mailbox cmd "
3849 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003850 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003851
James Smart92d7f7b2007-06-17 19:56:38 -05003852 phba->sysfs_mbox.mbox->vport = vport;
3853
James Smart58da1ff2008-04-07 10:15:56 -04003854 /* Don't allow mailbox commands to be sent when blocked
3855 * or when in the middle of discovery
3856 */
James Smart495a7142008-06-14 22:52:59 -04003857 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003858 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003859 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003860 return -EAGAIN;
3861 }
3862
James Smart2e0fef82007-06-17 19:56:36 -05003863 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003864 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003865
James Smart2e0fef82007-06-17 19:56:36 -05003866 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003867 rc = lpfc_sli_issue_mbox (phba,
3868 phba->sysfs_mbox.mbox,
3869 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003870 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003871
3872 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003873 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003874 rc = lpfc_sli_issue_mbox_wait (phba,
3875 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003876 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003877 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003878 }
3879
3880 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003881 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003882 phba->sysfs_mbox.mbox = NULL;
3883 }
dea31012005-04-17 16:05:31 -05003884 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003885 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003886 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003887 }
3888 phba->sysfs_mbox.state = SMBOX_READING;
3889 }
3890 else if (phba->sysfs_mbox.offset != off ||
3891 phba->sysfs_mbox.state != SMBOX_READING) {
3892 printk(KERN_WARNING "mbox_read: Bad State\n");
3893 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003894 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003895 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003896 }
3897
James Smart04c68492009-05-22 14:52:52 -04003898 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003899
3900 phba->sysfs_mbox.offset = off + count;
3901
James Smart1dcb58e2007-04-25 09:51:30 -04003902 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003903 sysfs_mbox_idle(phba);
3904
James Smart2e0fef82007-06-17 19:56:36 -05003905 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003906
3907 return count;
3908}
3909
3910static struct bin_attribute sysfs_mbox_attr = {
3911 .attr = {
3912 .name = "mbox",
3913 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003914 },
James Smart1dcb58e2007-04-25 09:51:30 -04003915 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003916 .read = sysfs_mbox_read,
3917 .write = sysfs_mbox_write,
3918};
3919
James Smarte59058c2008-08-24 21:49:00 -04003920/**
James Smart3621a712009-04-06 18:47:14 -04003921 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003922 * @vport: address of lpfc vport structure.
3923 *
3924 * Return codes:
3925 * zero on success
3926 * error return code from sysfs_create_bin_file()
3927 **/
dea31012005-04-17 16:05:31 -05003928int
James Smart2e0fef82007-06-17 19:56:36 -05003929lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003930{
James Smart2e0fef82007-06-17 19:56:36 -05003931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003932 int error;
3933
Tony Jonesee959b02008-02-22 00:13:36 +01003934 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003935 &sysfs_drvr_stat_data_attr);
3936
3937 /* Virtual ports do not need ctrl_reg and mbox */
3938 if (error || vport->port_type == LPFC_NPIV_PORT)
3939 goto out;
3940
3941 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003942 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003943 if (error)
James Smarteada2722008-12-04 22:39:13 -05003944 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003945
Tony Jonesee959b02008-02-22 00:13:36 +01003946 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003947 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003948 if (error)
3949 goto out_remove_ctlreg_attr;
3950
3951 return 0;
3952out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003953 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003954out_remove_stat_attr:
3955 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3956 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003957out:
3958 return error;
3959}
3960
James Smarte59058c2008-08-24 21:49:00 -04003961/**
James Smart3621a712009-04-06 18:47:14 -04003962 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003963 * @vport: address of lpfc vport structure.
3964 **/
dea31012005-04-17 16:05:31 -05003965void
James Smart2e0fef82007-06-17 19:56:36 -05003966lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003967{
James Smart2e0fef82007-06-17 19:56:36 -05003968 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003969 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3970 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003971 /* Virtual ports do not need ctrl_reg and mbox */
3972 if (vport->port_type == LPFC_NPIV_PORT)
3973 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003974 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3975 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003976}
3977
3978
3979/*
3980 * Dynamic FC Host Attributes Support
3981 */
3982
James Smarte59058c2008-08-24 21:49:00 -04003983/**
James Smart3621a712009-04-06 18:47:14 -04003984 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003985 * @shost: kernel scsi host pointer.
3986 **/
dea31012005-04-17 16:05:31 -05003987static void
3988lpfc_get_host_port_id(struct Scsi_Host *shost)
3989{
James Smart2e0fef82007-06-17 19:56:36 -05003990 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3991
dea31012005-04-17 16:05:31 -05003992 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003993 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003994}
3995
James Smarte59058c2008-08-24 21:49:00 -04003996/**
James Smart3621a712009-04-06 18:47:14 -04003997 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003998 * @shost: kernel scsi host pointer.
3999 **/
dea31012005-04-17 16:05:31 -05004000static void
4001lpfc_get_host_port_type(struct Scsi_Host *shost)
4002{
James Smart2e0fef82007-06-17 19:56:36 -05004003 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4004 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004005
4006 spin_lock_irq(shost->host_lock);
4007
James Smart92d7f7b2007-06-17 19:56:38 -05004008 if (vport->port_type == LPFC_NPIV_PORT) {
4009 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4010 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004011 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004012 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004013 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4014 else
4015 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4016 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004017 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004018 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4019 else
4020 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4021 }
4022 } else
4023 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4024
4025 spin_unlock_irq(shost->host_lock);
4026}
4027
James Smarte59058c2008-08-24 21:49:00 -04004028/**
James Smart3621a712009-04-06 18:47:14 -04004029 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004030 * @shost: kernel scsi host pointer.
4031 **/
dea31012005-04-17 16:05:31 -05004032static void
4033lpfc_get_host_port_state(struct Scsi_Host *shost)
4034{
James Smart2e0fef82007-06-17 19:56:36 -05004035 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004037
4038 spin_lock_irq(shost->host_lock);
4039
James Smart2e0fef82007-06-17 19:56:36 -05004040 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004041 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4042 else {
James Smart2e0fef82007-06-17 19:56:36 -05004043 switch (phba->link_state) {
4044 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004045 case LPFC_LINK_DOWN:
4046 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4047 break;
4048 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004049 case LPFC_CLEAR_LA:
4050 case LPFC_HBA_READY:
4051 /* Links up, beyond this port_type reports state */
4052 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4053 break;
4054 case LPFC_HBA_ERROR:
4055 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4056 break;
4057 default:
4058 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4059 break;
4060 }
4061 }
4062
4063 spin_unlock_irq(shost->host_lock);
4064}
4065
James Smarte59058c2008-08-24 21:49:00 -04004066/**
James Smart3621a712009-04-06 18:47:14 -04004067 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004068 * @shost: kernel scsi host pointer.
4069 **/
dea31012005-04-17 16:05:31 -05004070static void
4071lpfc_get_host_speed(struct Scsi_Host *shost)
4072{
James Smart2e0fef82007-06-17 19:56:36 -05004073 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4074 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004075
4076 spin_lock_irq(shost->host_lock);
4077
James Smart2e0fef82007-06-17 19:56:36 -05004078 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004079 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004080 case LPFC_LINK_SPEED_1GHZ:
4081 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004082 break;
James Smart76a95d72010-11-20 23:11:48 -05004083 case LPFC_LINK_SPEED_2GHZ:
4084 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004085 break;
James Smart76a95d72010-11-20 23:11:48 -05004086 case LPFC_LINK_SPEED_4GHZ:
4087 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004088 break;
James Smart76a95d72010-11-20 23:11:48 -05004089 case LPFC_LINK_SPEED_8GHZ:
4090 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004091 break;
James Smart76a95d72010-11-20 23:11:48 -05004092 case LPFC_LINK_SPEED_10GHZ:
4093 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004094 break;
James Smart76a95d72010-11-20 23:11:48 -05004095 case LPFC_LINK_SPEED_16GHZ:
4096 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4097 break;
4098 default:
4099 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004100 break;
4101 }
James Smart09372822008-01-11 01:52:54 -05004102 } else
4103 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004104
4105 spin_unlock_irq(shost->host_lock);
4106}
4107
James Smarte59058c2008-08-24 21:49:00 -04004108/**
James Smart3621a712009-04-06 18:47:14 -04004109 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004110 * @shost: kernel scsi host pointer.
4111 **/
dea31012005-04-17 16:05:31 -05004112static void
4113lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4114{
James Smart2e0fef82007-06-17 19:56:36 -05004115 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4116 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004117 u64 node_name;
dea31012005-04-17 16:05:31 -05004118
4119 spin_lock_irq(shost->host_lock);
4120
James Smart2e0fef82007-06-17 19:56:36 -05004121 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004122 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004123 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004124 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004125 else
4126 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004127 node_name = 0;
dea31012005-04-17 16:05:31 -05004128
4129 spin_unlock_irq(shost->host_lock);
4130
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004131 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004132}
4133
James Smarte59058c2008-08-24 21:49:00 -04004134/**
James Smart3621a712009-04-06 18:47:14 -04004135 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004136 * @shost: kernel scsi host pointer.
4137 *
4138 * Notes:
4139 * NULL on error for link down, no mbox pool, sli2 active,
4140 * management not allowed, memory allocation error, or mbox error.
4141 *
4142 * Returns:
4143 * NULL for error
4144 * address of the adapter host statistics
4145 **/
dea31012005-04-17 16:05:31 -05004146static struct fc_host_statistics *
4147lpfc_get_stats(struct Scsi_Host *shost)
4148{
James Smart2e0fef82007-06-17 19:56:36 -05004149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4150 struct lpfc_hba *phba = vport->phba;
4151 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004152 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004153 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004154 LPFC_MBOXQ_t *pmboxq;
4155 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004156 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004157 int rc = 0;
dea31012005-04-17 16:05:31 -05004158
James Smart92d7f7b2007-06-17 19:56:38 -05004159 /*
4160 * prevent udev from issuing mailbox commands until the port is
4161 * configured.
4162 */
James Smart2e0fef82007-06-17 19:56:36 -05004163 if (phba->link_state < LPFC_LINK_DOWN ||
4164 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004165 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004166 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004167
4168 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004169 return NULL;
4170
dea31012005-04-17 16:05:31 -05004171 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4172 if (!pmboxq)
4173 return NULL;
4174 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4175
James Smart04c68492009-05-22 14:52:52 -04004176 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004177 pmb->mbxCommand = MBX_READ_STATUS;
4178 pmb->mbxOwner = OWN_HOST;
4179 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004180 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004181
James Smart75baf692010-06-08 18:31:21 -04004182 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004183 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004184 else
dea31012005-04-17 16:05:31 -05004185 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4186
4187 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004188 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004189 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004190 return NULL;
4191 }
4192
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004193 memset(hs, 0, sizeof (struct fc_host_statistics));
4194
dea31012005-04-17 16:05:31 -05004195 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4196 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4197 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4198 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4199
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004200 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004201 pmb->mbxCommand = MBX_READ_LNK_STAT;
4202 pmb->mbxOwner = OWN_HOST;
4203 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004204 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004205
James Smart75baf692010-06-08 18:31:21 -04004206 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004207 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004208 else
dea31012005-04-17 16:05:31 -05004209 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4210
4211 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004212 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004213 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004214 return NULL;
4215 }
4216
4217 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4218 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4219 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4220 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4221 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4222 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4223 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4224
James Smart64ba8812006-08-02 15:24:34 -04004225 hs->link_failure_count -= lso->link_failure_count;
4226 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4227 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4228 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4229 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4230 hs->invalid_crc_count -= lso->invalid_crc_count;
4231 hs->error_frames -= lso->error_frames;
4232
James Smart76a95d72010-11-20 23:11:48 -05004233 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004234 hs->lip_count = -1;
4235 hs->nos_count = (phba->link_events >> 1);
4236 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004237 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004238 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004239 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004240 hs->nos_count = -1;
4241 } else {
4242 hs->lip_count = -1;
4243 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004244 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004245 }
4246
4247 hs->dumped_frames = -1;
4248
James Smart64ba8812006-08-02 15:24:34 -04004249 seconds = get_seconds();
4250 if (seconds < psli->stats_start)
4251 hs->seconds_since_last_reset = seconds +
4252 ((unsigned long)-1 - psli->stats_start);
4253 else
4254 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004255
James Smart1dcb58e2007-04-25 09:51:30 -04004256 mempool_free(pmboxq, phba->mbox_mem_pool);
4257
dea31012005-04-17 16:05:31 -05004258 return hs;
4259}
4260
James Smarte59058c2008-08-24 21:49:00 -04004261/**
James Smart3621a712009-04-06 18:47:14 -04004262 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004263 * @shost: kernel scsi host pointer.
4264 **/
James Smart64ba8812006-08-02 15:24:34 -04004265static void
4266lpfc_reset_stats(struct Scsi_Host *shost)
4267{
James Smart2e0fef82007-06-17 19:56:36 -05004268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4269 struct lpfc_hba *phba = vport->phba;
4270 struct lpfc_sli *psli = &phba->sli;
4271 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004272 LPFC_MBOXQ_t *pmboxq;
4273 MAILBOX_t *pmb;
4274 int rc = 0;
4275
James Smart2e0fef82007-06-17 19:56:36 -05004276 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004277 return;
4278
James Smart64ba8812006-08-02 15:24:34 -04004279 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4280 if (!pmboxq)
4281 return;
4282 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4283
James Smart04c68492009-05-22 14:52:52 -04004284 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004285 pmb->mbxCommand = MBX_READ_STATUS;
4286 pmb->mbxOwner = OWN_HOST;
4287 pmb->un.varWords[0] = 0x1; /* reset request */
4288 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004289 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004290
James Smart2e0fef82007-06-17 19:56:36 -05004291 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004292 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004293 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4294 else
4295 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4296
4297 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004298 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004299 mempool_free(pmboxq, phba->mbox_mem_pool);
4300 return;
4301 }
4302
4303 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4304 pmb->mbxCommand = MBX_READ_LNK_STAT;
4305 pmb->mbxOwner = OWN_HOST;
4306 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004307 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004308
James Smart2e0fef82007-06-17 19:56:36 -05004309 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004310 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004311 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4312 else
4313 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4314
4315 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004316 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004317 mempool_free( pmboxq, phba->mbox_mem_pool);
4318 return;
4319 }
4320
4321 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4322 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4323 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4324 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4325 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4326 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4327 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004328 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004329 lso->link_events = (phba->link_events >> 1);
4330 else
4331 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004332
4333 psli->stats_start = get_seconds();
4334
James Smart1dcb58e2007-04-25 09:51:30 -04004335 mempool_free(pmboxq, phba->mbox_mem_pool);
4336
James Smart64ba8812006-08-02 15:24:34 -04004337 return;
4338}
dea31012005-04-17 16:05:31 -05004339
4340/*
4341 * The LPFC driver treats linkdown handling as target loss events so there
4342 * are no sysfs handlers for link_down_tmo.
4343 */
James Smart685f0bf2007-04-25 09:53:08 -04004344
James Smarte59058c2008-08-24 21:49:00 -04004345/**
James Smart3621a712009-04-06 18:47:14 -04004346 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004347 * @starget: kernel scsi target pointer.
4348 *
4349 * Returns:
4350 * address of the node list if found
4351 * NULL target not found
4352 **/
James Smart685f0bf2007-04-25 09:53:08 -04004353static struct lpfc_nodelist *
4354lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004355{
James Smart2e0fef82007-06-17 19:56:36 -05004356 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4357 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004358 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004359
4360 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004361 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004362 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004363 if (NLP_CHK_NODE_ACT(ndlp) &&
4364 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004365 starget->id == ndlp->nlp_sid) {
4366 spin_unlock_irq(shost->host_lock);
4367 return ndlp;
dea31012005-04-17 16:05:31 -05004368 }
4369 }
4370 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004371 return NULL;
4372}
dea31012005-04-17 16:05:31 -05004373
James Smarte59058c2008-08-24 21:49:00 -04004374/**
James Smart3621a712009-04-06 18:47:14 -04004375 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004376 * @starget: kernel scsi target pointer.
4377 **/
James Smart685f0bf2007-04-25 09:53:08 -04004378static void
4379lpfc_get_starget_port_id(struct scsi_target *starget)
4380{
4381 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4382
4383 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004384}
4385
James Smarte59058c2008-08-24 21:49:00 -04004386/**
James Smart3621a712009-04-06 18:47:14 -04004387 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004388 * @starget: kernel scsi target pointer.
4389 *
4390 * Description: Set the target node name to the ndlp node name wwn or zero.
4391 **/
dea31012005-04-17 16:05:31 -05004392static void
4393lpfc_get_starget_node_name(struct scsi_target *starget)
4394{
James Smart685f0bf2007-04-25 09:53:08 -04004395 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004396
James Smart685f0bf2007-04-25 09:53:08 -04004397 fc_starget_node_name(starget) =
4398 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004399}
4400
James Smarte59058c2008-08-24 21:49:00 -04004401/**
James Smart3621a712009-04-06 18:47:14 -04004402 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004403 * @starget: kernel scsi target pointer.
4404 *
4405 * Description: set the target port name to the ndlp port name wwn or zero.
4406 **/
dea31012005-04-17 16:05:31 -05004407static void
4408lpfc_get_starget_port_name(struct scsi_target *starget)
4409{
James Smart685f0bf2007-04-25 09:53:08 -04004410 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004411
James Smart685f0bf2007-04-25 09:53:08 -04004412 fc_starget_port_name(starget) =
4413 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004414}
4415
James Smarte59058c2008-08-24 21:49:00 -04004416/**
James Smart3621a712009-04-06 18:47:14 -04004417 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004418 * @rport: fc rport address.
4419 * @timeout: new value for dev loss tmo.
4420 *
4421 * Description:
4422 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4423 * dev_loss_tmo to one.
4424 **/
dea31012005-04-17 16:05:31 -05004425static void
dea31012005-04-17 16:05:31 -05004426lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4427{
dea31012005-04-17 16:05:31 -05004428 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004429 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004430 else
James Smartc01f3202006-08-18 17:47:08 -04004431 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004432}
4433
James Smarte59058c2008-08-24 21:49:00 -04004434/**
James Smart3621a712009-04-06 18:47:14 -04004435 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004436 *
4437 * Description:
4438 * Macro that uses field to generate a function with the name lpfc_show_rport_
4439 *
4440 * lpfc_show_rport_##field: returns the bytes formatted in buf
4441 * @cdev: class converted to an fc_rport.
4442 * @buf: on return contains the target_field or zero.
4443 *
4444 * Returns: size of formatted string.
4445 **/
dea31012005-04-17 16:05:31 -05004446#define lpfc_rport_show_function(field, format_string, sz, cast) \
4447static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004448lpfc_show_rport_##field (struct device *dev, \
4449 struct device_attribute *attr, \
4450 char *buf) \
dea31012005-04-17 16:05:31 -05004451{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004452 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004453 struct lpfc_rport_data *rdata = rport->hostdata; \
4454 return snprintf(buf, sz, format_string, \
4455 (rdata->target) ? cast rdata->target->field : 0); \
4456}
4457
4458#define lpfc_rport_rd_attr(field, format_string, sz) \
4459 lpfc_rport_show_function(field, format_string, sz, ) \
4460static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4461
James Smarteada2722008-12-04 22:39:13 -05004462/**
James Smart3621a712009-04-06 18:47:14 -04004463 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004464 * @fc_vport: The fc_vport who's symbolic name has been changed.
4465 *
4466 * Description:
4467 * This function is called by the transport after the @fc_vport's symbolic name
4468 * has been changed. This function re-registers the symbolic name with the
4469 * switch to propogate the change into the fabric if the vport is active.
4470 **/
4471static void
4472lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4473{
4474 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4475
4476 if (vport->port_state == LPFC_VPORT_READY)
4477 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4478}
dea31012005-04-17 16:05:31 -05004479
James Smartf4b4c682009-05-22 14:53:12 -04004480/**
4481 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4482 * @phba: Pointer to lpfc_hba struct.
4483 *
4484 * This function is called by the lpfc_get_cfgparam() routine to set the
4485 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4486 * log messsage according to the module's lpfc_log_verbose parameter setting
4487 * before hba port or vport created.
4488 **/
4489static void
4490lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4491{
4492 phba->cfg_log_verbose = verbose;
4493}
4494
dea31012005-04-17 16:05:31 -05004495struct fc_function_template lpfc_transport_functions = {
4496 /* fixed attributes the driver supports */
4497 .show_host_node_name = 1,
4498 .show_host_port_name = 1,
4499 .show_host_supported_classes = 1,
4500 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004501 .show_host_supported_speeds = 1,
4502 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004503 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004504
4505 /* dynamic attributes the driver supports */
4506 .get_host_port_id = lpfc_get_host_port_id,
4507 .show_host_port_id = 1,
4508
4509 .get_host_port_type = lpfc_get_host_port_type,
4510 .show_host_port_type = 1,
4511
4512 .get_host_port_state = lpfc_get_host_port_state,
4513 .show_host_port_state = 1,
4514
4515 /* active_fc4s is shown but doesn't change (thus no get function) */
4516 .show_host_active_fc4s = 1,
4517
4518 .get_host_speed = lpfc_get_host_speed,
4519 .show_host_speed = 1,
4520
4521 .get_host_fabric_name = lpfc_get_host_fabric_name,
4522 .show_host_fabric_name = 1,
4523
4524 /*
4525 * The LPFC driver treats linkdown handling as target loss events
4526 * so there are no sysfs handlers for link_down_tmo.
4527 */
4528
4529 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004530 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004531
4532 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4533 .show_rport_maxframe_size = 1,
4534 .show_rport_supported_classes = 1,
4535
dea31012005-04-17 16:05:31 -05004536 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4537 .show_rport_dev_loss_tmo = 1,
4538
4539 .get_starget_port_id = lpfc_get_starget_port_id,
4540 .show_starget_port_id = 1,
4541
4542 .get_starget_node_name = lpfc_get_starget_node_name,
4543 .show_starget_node_name = 1,
4544
4545 .get_starget_port_name = lpfc_get_starget_port_name,
4546 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004547
4548 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004549 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4550 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004551
James Smart92d7f7b2007-06-17 19:56:38 -05004552 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004553
4554 .vport_disable = lpfc_vport_disable,
4555
4556 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004557
4558 .bsg_request = lpfc_bsg_request,
4559 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004560};
4561
James Smart98c9ea52007-10-27 13:37:33 -04004562struct fc_function_template lpfc_vport_transport_functions = {
4563 /* fixed attributes the driver supports */
4564 .show_host_node_name = 1,
4565 .show_host_port_name = 1,
4566 .show_host_supported_classes = 1,
4567 .show_host_supported_fc4s = 1,
4568 .show_host_supported_speeds = 1,
4569 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004570 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004571
4572 /* dynamic attributes the driver supports */
4573 .get_host_port_id = lpfc_get_host_port_id,
4574 .show_host_port_id = 1,
4575
4576 .get_host_port_type = lpfc_get_host_port_type,
4577 .show_host_port_type = 1,
4578
4579 .get_host_port_state = lpfc_get_host_port_state,
4580 .show_host_port_state = 1,
4581
4582 /* active_fc4s is shown but doesn't change (thus no get function) */
4583 .show_host_active_fc4s = 1,
4584
4585 .get_host_speed = lpfc_get_host_speed,
4586 .show_host_speed = 1,
4587
4588 .get_host_fabric_name = lpfc_get_host_fabric_name,
4589 .show_host_fabric_name = 1,
4590
4591 /*
4592 * The LPFC driver treats linkdown handling as target loss events
4593 * so there are no sysfs handlers for link_down_tmo.
4594 */
4595
4596 .get_fc_host_stats = lpfc_get_stats,
4597 .reset_fc_host_stats = lpfc_reset_stats,
4598
4599 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4600 .show_rport_maxframe_size = 1,
4601 .show_rport_supported_classes = 1,
4602
4603 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4604 .show_rport_dev_loss_tmo = 1,
4605
4606 .get_starget_port_id = lpfc_get_starget_port_id,
4607 .show_starget_port_id = 1,
4608
4609 .get_starget_node_name = lpfc_get_starget_node_name,
4610 .show_starget_node_name = 1,
4611
4612 .get_starget_port_name = lpfc_get_starget_port_name,
4613 .show_starget_port_name = 1,
4614
4615 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4616 .terminate_rport_io = lpfc_terminate_rport_io,
4617
4618 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004619
4620 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004621};
4622
James Smarte59058c2008-08-24 21:49:00 -04004623/**
James Smart3621a712009-04-06 18:47:14 -04004624 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004625 * @phba: lpfc_hba pointer.
4626 **/
dea31012005-04-17 16:05:31 -05004627void
4628lpfc_get_cfgparam(struct lpfc_hba *phba)
4629{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004630 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4631 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004632 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004633 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4634 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004635 lpfc_ack0_init(phba, lpfc_ack0);
4636 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004637 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004638 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004639 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart19ca7602010-11-20 23:11:55 -05004640 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05004641 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004642 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4643 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4644 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004645 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4646 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004647 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004648 if (phba->sli_rev == LPFC_SLI_REV4)
4649 phba->cfg_poll = 0;
4650 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004651 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004652 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004653 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004654 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004655 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004656 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004657 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004658 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004659 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004660 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004661 return;
4662}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004663
James Smarte59058c2008-08-24 21:49:00 -04004664/**
James Smart3621a712009-04-06 18:47:14 -04004665 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004666 * @vport: lpfc_vport pointer.
4667 **/
James Smart3de2a652007-08-02 11:09:59 -04004668void
4669lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4670{
James Smarte8b62012007-08-02 11:10:09 -04004671 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004672 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004673 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004674 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4675 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4676 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4677 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4678 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4679 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004680 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004681 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4682 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4683 lpfc_max_luns_init(vport, lpfc_max_luns);
4684 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004685 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004686 return;
4687}