blob: e7c020df12fa23df0bc7b252fa816bc579cafd3f [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
James Smart0d878412009-10-02 15:16:56 -040026#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070028#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050029
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
33#include <scsi/scsi_tcq.h>
34#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040035#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050036
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_version.h"
47#include "lpfc_compat.h"
48#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050049#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050050
James Smartc01f3202006-08-18 17:47:08 -040051#define LPFC_DEF_DEVLOSS_TMO 30
52#define LPFC_MIN_DEVLOSS_TMO 1
53#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050054
James Smarte59058c2008-08-24 21:49:00 -040055/**
James Smart3621a712009-04-06 18:47:14 -040056 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040057 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
dea31012005-04-17 16:05:31 -050070static void
71lpfc_jedec_to_ascii(int incr, char hdw[])
72{
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84}
85
James Smarte59058c2008-08-24 21:49:00 -040086/**
James Smart3621a712009-04-06 18:47:14 -040087 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040088 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
dea31012005-04-17 16:05:31 -050094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010095lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
dea31012005-04-17 16:05:31 -050097{
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99}
100
James Smart45ed1192009-10-02 15:17:02 -0400101/**
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
106 *
107 * Returns: size of formatted string.
108 **/
109static ssize_t
110lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
111 char *buf)
112{
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
116
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
119 else
120 return snprintf(buf, PAGE_SIZE, "0\n");
121}
122
James Smart81301a92008-12-04 22:39:46 -0500123static ssize_t
124lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
126{
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
134 else
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
140}
141
142static ssize_t
143lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
149
James Smart87b5c322008-12-16 10:34:09 -0500150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500152}
153
154static ssize_t
155lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
156 char *buf)
157{
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
161
James Smart87b5c322008-12-16 10:34:09 -0500162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500164}
165
166static ssize_t
167lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
169{
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173
James Smart87b5c322008-12-16 10:34:09 -0500174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500176}
177
James Smarte59058c2008-08-24 21:49:00 -0400178/**
James Smart3621a712009-04-06 18:47:14 -0400179 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
183 *
184 * Returns: size of formatted string.
185 **/
dea31012005-04-17 16:05:31 -0500186static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100187lpfc_info_show(struct device *dev, struct device_attribute *attr,
188 char *buf)
dea31012005-04-17 16:05:31 -0500189{
Tony Jonesee959b02008-02-22 00:13:36 +0100190 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500191
dea31012005-04-17 16:05:31 -0500192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
193}
194
James Smarte59058c2008-08-24 21:49:00 -0400195/**
James Smart3621a712009-04-06 18:47:14 -0400196 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
200 *
201 * Returns: size of formatted string.
202 **/
dea31012005-04-17 16:05:31 -0500203static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100204lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
dea31012005-04-17 16:05:31 -0500206{
Tony Jonesee959b02008-02-22 00:13:36 +0100207 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
210
dea31012005-04-17 16:05:31 -0500211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
212}
213
James Smarte59058c2008-08-24 21:49:00 -0400214/**
James Smart3621a712009-04-06 18:47:14 -0400215 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
219 *
220 * Description:
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
223 *
224 * Returns: size of formatted string.
225 **/
dea31012005-04-17 16:05:31 -0500226static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100227lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
228 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400229{
Tony Jonesee959b02008-02-22 00:13:36 +0100230 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
234}
235
James Smarte59058c2008-08-24 21:49:00 -0400236/**
James Smart3621a712009-04-06 18:47:14 -0400237 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
241 *
242 * Returns: size of formatted string.
243 **/
James Smart57127f12007-10-27 13:37:05 -0400244static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100245lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
dea31012005-04-17 16:05:31 -0500247{
Tony Jonesee959b02008-02-22 00:13:36 +0100248 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
251
dea31012005-04-17 16:05:31 -0500252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
253}
254
James Smarte59058c2008-08-24 21:49:00 -0400255/**
James Smart3621a712009-04-06 18:47:14 -0400256 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
260 *
261 * Returns: size of formatted string.
262 **/
dea31012005-04-17 16:05:31 -0500263static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100264lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
265 char *buf)
dea31012005-04-17 16:05:31 -0500266{
Tony Jonesee959b02008-02-22 00:13:36 +0100267 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
270
dea31012005-04-17 16:05:31 -0500271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
272}
273
James Smarte59058c2008-08-24 21:49:00 -0400274/**
James Smart3621a712009-04-06 18:47:14 -0400275 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
279 *
280 * Returns: size of formatted string.
281 **/
dea31012005-04-17 16:05:31 -0500282static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100283lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
dea31012005-04-17 16:05:31 -0500285{
Tony Jonesee959b02008-02-22 00:13:36 +0100286 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
289
dea31012005-04-17 16:05:31 -0500290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
291}
292
James Smarte59058c2008-08-24 21:49:00 -0400293/**
James Smart3621a712009-04-06 18:47:14 -0400294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
298 *
299 * Returns: size of formatted string.
300 **/
301static ssize_t
302lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
303{
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
307
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
310}
311
312/**
James Smart3621a712009-04-06 18:47:14 -0400313 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
317 *
318 * Returns: size of formatted string.
319 **/
dea31012005-04-17 16:05:31 -0500320static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100321lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
322 char *buf)
dea31012005-04-17 16:05:31 -0500323{
Tony Jonesee959b02008-02-22 00:13:36 +0100324 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
327
dea31012005-04-17 16:05:31 -0500328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
329}
330
James Smarte59058c2008-08-24 21:49:00 -0400331/**
James Smart3621a712009-04-06 18:47:14 -0400332 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
336 *
337 * Returns: size of formatted string.
338 **/
dea31012005-04-17 16:05:31 -0500339static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100340lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
341 char *buf)
dea31012005-04-17 16:05:31 -0500342{
Tony Jonesee959b02008-02-22 00:13:36 +0100343 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500346 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500347
dea31012005-04-17 16:05:31 -0500348 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500350}
351
James Smarte59058c2008-08-24 21:49:00 -0400352/**
James Smart3621a712009-04-06 18:47:14 -0400353 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
357 *
358 * Returns: size of formatted string.
359 **/
dea31012005-04-17 16:05:31 -0500360static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100361lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500362{
363 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100364 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500367 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500368
dea31012005-04-17 16:05:31 -0500369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
371}
James Smarte59058c2008-08-24 21:49:00 -0400372
373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
dea31012005-04-17 16:05:31 -0500384{
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
dea31012005-04-17 16:05:31 -0500389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
390}
James Smarte59058c2008-08-24 21:49:00 -0400391
392/**
James Smart3621a712009-04-06 18:47:14 -0400393 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
397 *
398 * Notes:
399 * The switch statement has no default so zero will be returned.
400 *
401 * Returns: size of formatted string.
402 **/
dea31012005-04-17 16:05:31 -0500403static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100404lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
dea31012005-04-17 16:05:31 -0500406{
Tony Jonesee959b02008-02-22 00:13:36 +0100407 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
410 int len = 0;
411
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500414 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
417 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500418 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
422 else
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down\n");
dea31012005-04-17 16:05:31 -0500425 break;
426 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500427 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500428 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500430
431 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500434 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500435 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500436 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500437 case LPFC_FLOGI:
438 case LPFC_FABRIC_CFG_LINK:
439 case LPFC_NS_REG:
440 case LPFC_NS_QRY:
441 case LPFC_BUILD_DISC_LIST:
442 case LPFC_DISC_AUTH:
443 len += snprintf(buf + len, PAGE_SIZE - len,
444 "Discovery\n");
445 break;
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
448 break;
449
James Smart92d7f7b2007-06-17 19:56:38 -0500450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
452 break;
453
454 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500455 len += snprintf(buf + len, PAGE_SIZE - len,
456 "Unknown\n");
457 break;
458 }
James Smart84774a42008-08-24 21:50:06 -0400459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500463 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500464 len += snprintf(buf + len, PAGE_SIZE-len,
465 " Public Loop\n");
466 else
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Private Loop\n");
469 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500470 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Fabric\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Point-2-Point\n");
476 }
477 }
James Smart2e0fef82007-06-17 19:56:36 -0500478
dea31012005-04-17 16:05:31 -0500479 return len;
480}
481
James Smarte59058c2008-08-24 21:49:00 -0400482/**
James Smart84d1b002010-02-12 14:42:33 -0500483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
487 * @count: not used.
488 *
489 * Returns:
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
493 **/
494static ssize_t
495lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
497{
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
501
502 int status = -EINVAL;
503
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500510
511 if (status == 0)
512 return strlen(buf);
513 else
514 return status;
515}
516
517/**
James Smart3621a712009-04-06 18:47:14 -0400518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
522 *
523 * Description:
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
525 * vport counts.
526 *
527 * Returns: size of formatted string.
528 **/
dea31012005-04-17 16:05:31 -0500529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100530lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500532{
Tony Jonesee959b02008-02-22 00:13:36 +0100533 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500538}
539
James Smarte59058c2008-08-24 21:49:00 -0400540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400542 * @shost: Scsi_Host pointer.
543 *
544 * Description:
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
547 *
548 * Returns:
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
552 * zero for success
553 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700554static int
James Smart2e0fef82007-06-17 19:56:36 -0500555lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500556{
James Smart2e0fef82007-06-17 19:56:36 -0500557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
561
James Smart2e0fef82007-06-17 19:56:36 -0500562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500564 return -EPERM;
565
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
567
568 if (!pmboxq)
569 return -ENOMEM;
570
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400574
James Smart33ccf8d2006-08-17 11:57:58 -0400575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500576
James Smart04c68492009-05-22 14:52:52 -0400577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
584 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400590 }
591
James Smart5b8bd0c2007-04-25 09:52:49 -0400592 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500593 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400594 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500595
596 if (mbxstatus == MBXERR_ERROR)
597 return -EIO;
598
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700599 return 0;
dea31012005-04-17 16:05:31 -0500600}
601
James Smarte59058c2008-08-24 21:49:00 -0400602/**
James Smart3621a712009-04-06 18:47:14 -0400603 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
606 *
607 * Notes:
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400612 *
613 * Returns:
614 * -EIO error posting the event
615 * zero for success
616 **/
James Smart40496f02006-07-06 15:50:22 -0400617static int
James Smart46fa3112007-04-25 09:51:45 -0400618lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
619{
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
623 int status = 0;
624 int cnt = 0;
625 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500626 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400627
628 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400630 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500631 if (rc == 0)
632 return -ENOMEM;
633
James Smart46fa3112007-04-25 09:51:45 -0400634 wait_for_completion(&online_compl);
635
636 if (status != 0)
637 return -EIO;
638
639 psli = &phba->sli;
640
James Smart09372822008-01-11 01:52:54 -0500641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
643 */
James Smart46fa3112007-04-25 09:51:45 -0400644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400646 while (pring->txcmplq_cnt) {
647 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500648 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400653 break;
654 }
655 }
656 }
657
658 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
662
James Smart46fa3112007-04-25 09:51:45 -0400663 wait_for_completion(&online_compl);
664
665 if (status != 0)
666 return -EIO;
667
668 return 0;
669}
670
James Smarte59058c2008-08-24 21:49:00 -0400671/**
James Smart3621a712009-04-06 18:47:14 -0400672 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400673 * @phba: lpfc_hba pointer.
674 *
675 * Description:
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
678 *
679 * Notes:
680 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500681 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400682 *
683 * Returns:
684 * lpfc_do_offline() return code if not zero
685 * -EIO reset not configured or error posting the event
686 * zero for success
687 **/
James Smart46fa3112007-04-25 09:51:45 -0400688static int
James Smart40496f02006-07-06 15:50:22 -0400689lpfc_selective_reset(struct lpfc_hba *phba)
690{
691 struct completion online_compl;
692 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500693 int rc;
James Smart40496f02006-07-06 15:50:22 -0400694
James Smart13815c82008-01-11 01:52:48 -0500695 if (!phba->cfg_enable_hba_reset)
696 return -EIO;
697
James Smart46fa3112007-04-25 09:51:45 -0400698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400699
700 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400701 return status;
James Smart40496f02006-07-06 15:50:22 -0400702
703 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400705 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500706 if (rc == 0)
707 return -ENOMEM;
708
James Smart40496f02006-07-06 15:50:22 -0400709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 return 0;
715}
716
James Smarte59058c2008-08-24 21:49:00 -0400717/**
James Smart3621a712009-04-06 18:47:14 -0400718 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400719 * @dev: class device that is converted into a Scsi_host.
720 * @attr: device attribute, not used.
721 * @buf: containing the string "selective".
722 * @count: unused variable.
723 *
724 * Description:
725 * If the buf contains the string "selective" then lpfc_selective_reset()
726 * is called to perform the reset.
727 *
728 * Notes:
729 * Assumes any error from lpfc_selective_reset() will be negative.
730 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200731 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400732 *
733 * Returns:
734 * -EINVAL if the buffer does not contain the string "selective"
735 * length of buf if lpfc-selective_reset() if the call succeeds
736 * return value of lpfc_selective_reset() if the call fails
737**/
James Smart40496f02006-07-06 15:50:22 -0400738static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100739lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
740 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400741{
Tony Jonesee959b02008-02-22 00:13:36 +0100742 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
744 struct lpfc_hba *phba = vport->phba;
745
James Smart40496f02006-07-06 15:50:22 -0400746 int status = -EINVAL;
747
748 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
749 status = lpfc_selective_reset(phba);
750
751 if (status == 0)
752 return strlen(buf);
753 else
754 return status;
755}
756
James Smarte59058c2008-08-24 21:49:00 -0400757/**
James Smart3621a712009-04-06 18:47:14 -0400758 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400759 * @dev: class device that is converted into a Scsi_host.
760 * @attr: device attribute, not used.
761 * @buf: on return contains the ascii number of nport events.
762 *
763 * Returns: size of formatted string.
764 **/
dea31012005-04-17 16:05:31 -0500765static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100766lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
767 char *buf)
dea31012005-04-17 16:05:31 -0500768{
Tony Jonesee959b02008-02-22 00:13:36 +0100769 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
771 struct lpfc_hba *phba = vport->phba;
772
dea31012005-04-17 16:05:31 -0500773 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
774}
775
James Smarte59058c2008-08-24 21:49:00 -0400776/**
James Smart3621a712009-04-06 18:47:14 -0400777 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400778 * @dev: class device that is converted into a Scsi_host.
779 * @attr: device attribute, not used.
780 * @buf: on return contains the state of the adapter.
781 *
782 * Returns: size of formatted string.
783 **/
dea31012005-04-17 16:05:31 -0500784static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100785lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
786 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500787{
Tony Jonesee959b02008-02-22 00:13:36 +0100788 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500789 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
790 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500791 char * state;
792
James Smart2e0fef82007-06-17 19:56:36 -0500793 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500794 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500795 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500796 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500797 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500798 state = "offline";
799 else
800 state = "online";
801
802 return snprintf(buf, PAGE_SIZE, "%s\n", state);
803}
804
James Smarte59058c2008-08-24 21:49:00 -0400805/**
James Smart3621a712009-04-06 18:47:14 -0400806 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400807 * @dev: class device that is converted into a Scsi_host.
808 * @attr: device attribute, not used.
809 * @buf: containing one of the strings "online", "offline", "warm" or "error".
810 * @count: unused variable.
811 *
812 * Returns:
813 * -EACCES if enable hba reset not enabled
814 * -EINVAL if the buffer does not contain a valid string (see above)
815 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
816 * buf length greater than zero indicates success
817 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500818static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100819lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
820 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500821{
Tony Jonesee959b02008-02-22 00:13:36 +0100822 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
824 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500825 struct completion online_compl;
826 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500827 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500828
James Smart13815c82008-01-11 01:52:48 -0500829 if (!phba->cfg_enable_hba_reset)
830 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500831 init_completion(&online_compl);
832
James Smart46fa3112007-04-25 09:51:45 -0400833 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500834 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500835 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500836 if (rc == 0)
837 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400838 wait_for_completion(&online_compl);
839 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
840 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500841 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400842 if (phba->sli_rev == LPFC_SLI_REV4)
843 return -EINVAL;
844 else
845 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400846 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400847 if (phba->sli_rev == LPFC_SLI_REV4)
848 return -EINVAL;
849 else
850 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500851 else
852 return -EINVAL;
853
Jamie Wellnitz41415862006-02-28 19:25:27 -0500854 if (!status)
855 return strlen(buf);
856 else
857 return -EIO;
858}
859
James Smarte59058c2008-08-24 21:49:00 -0400860/**
James Smart3621a712009-04-06 18:47:14 -0400861 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400862 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400863 * @mxri: max xri count.
864 * @axri: available xri count.
865 * @mrpi: max rpi count.
866 * @arpi: available rpi count.
867 * @mvpi: max vpi count.
868 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400869 *
870 * Description:
871 * If an integer pointer for an count is not null then the value for the
872 * count is returned.
873 *
874 * Returns:
875 * zero on error
876 * one for success
877 **/
James Smart311464e2007-08-02 11:10:37 -0400878static int
James Smart858c9f62007-06-17 19:56:39 -0500879lpfc_get_hba_info(struct lpfc_hba *phba,
880 uint32_t *mxri, uint32_t *axri,
881 uint32_t *mrpi, uint32_t *arpi,
882 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500883{
James Smart04c68492009-05-22 14:52:52 -0400884 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500885 LPFC_MBOXQ_t *pmboxq;
886 MAILBOX_t *pmb;
887 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400888 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500889
890 /*
891 * prevent udev from issuing mailbox commands until the port is
892 * configured.
893 */
894 if (phba->link_state < LPFC_LINK_DOWN ||
895 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400896 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500897 return 0;
898
899 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
900 return 0;
901
902 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
903 if (!pmboxq)
904 return 0;
905 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
906
James Smart04c68492009-05-22 14:52:52 -0400907 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500908 pmb->mbxCommand = MBX_READ_CONFIG;
909 pmb->mbxOwner = OWN_HOST;
910 pmboxq->context1 = NULL;
911
James Smart75baf692010-06-08 18:31:21 -0400912 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500913 rc = MBX_NOT_FINISHED;
914 else
915 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
916
917 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500918 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500919 mempool_free(pmboxq, phba->mbox_mem_pool);
920 return 0;
921 }
922
James Smartda0436e2009-05-22 14:51:39 -0400923 if (phba->sli_rev == LPFC_SLI_REV4) {
924 rd_config = &pmboxq->u.mqe.un.rd_config;
925 if (mrpi)
926 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
927 if (arpi)
928 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
929 phba->sli4_hba.max_cfg_param.rpi_used;
930 if (mxri)
931 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
932 if (axri)
933 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
934 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400935
936 /* Account for differences with SLI-3. Get vpi count from
937 * mailbox data and subtract one for max vpi value.
938 */
939 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
940 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
941
James Smartda0436e2009-05-22 14:51:39 -0400942 if (mvpi)
James Smart15672312010-04-06 14:49:03 -0400943 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -0400944 if (avpi)
James Smart15672312010-04-06 14:49:03 -0400945 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -0400946 } else {
947 if (mrpi)
948 *mrpi = pmb->un.varRdConfig.max_rpi;
949 if (arpi)
950 *arpi = pmb->un.varRdConfig.avail_rpi;
951 if (mxri)
952 *mxri = pmb->un.varRdConfig.max_xri;
953 if (axri)
954 *axri = pmb->un.varRdConfig.avail_xri;
955 if (mvpi)
956 *mvpi = pmb->un.varRdConfig.max_vpi;
957 if (avpi)
958 *avpi = pmb->un.varRdConfig.avail_vpi;
959 }
James Smart92d7f7b2007-06-17 19:56:38 -0500960
961 mempool_free(pmboxq, phba->mbox_mem_pool);
962 return 1;
963}
964
James Smarte59058c2008-08-24 21:49:00 -0400965/**
James Smart3621a712009-04-06 18:47:14 -0400966 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400967 * @dev: class device that is converted into a Scsi_host.
968 * @attr: device attribute, not used.
969 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
970 *
971 * Description:
972 * Calls lpfc_get_hba_info() asking for just the mrpi count.
973 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
974 * to "Unknown" and the buffer length is returned, therefore the caller
975 * must check for "Unknown" in the buffer to detect a failure.
976 *
977 * Returns: size of formatted string.
978 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500979static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100980lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
981 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500982{
Tony Jonesee959b02008-02-22 00:13:36 +0100983 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
985 struct lpfc_hba *phba = vport->phba;
986 uint32_t cnt;
987
James Smart858c9f62007-06-17 19:56:39 -0500988 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500989 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
990 return snprintf(buf, PAGE_SIZE, "Unknown\n");
991}
992
James Smarte59058c2008-08-24 21:49:00 -0400993/**
James Smart3621a712009-04-06 18:47:14 -0400994 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400995 * @dev: class device that is converted into a Scsi_host.
996 * @attr: device attribute, not used.
997 * @buf: containing the used rpi count in decimal or "Unknown".
998 *
999 * Description:
1000 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1001 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1002 * to "Unknown" and the buffer length is returned, therefore the caller
1003 * must check for "Unknown" in the buffer to detect a failure.
1004 *
1005 * Returns: size of formatted string.
1006 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001007static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001008lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1009 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001010{
Tony Jonesee959b02008-02-22 00:13:36 +01001011 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001012 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1013 struct lpfc_hba *phba = vport->phba;
1014 uint32_t cnt, acnt;
1015
James Smart858c9f62007-06-17 19:56:39 -05001016 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001017 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1018 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1026 *
1027 * Description:
1028 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1029 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1030 * to "Unknown" and the buffer length is returned, therefore the caller
1031 * must check for "Unknown" in the buffer to detect a failure.
1032 *
1033 * Returns: size of formatted string.
1034 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001035static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001036lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1037 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001038{
Tony Jonesee959b02008-02-22 00:13:36 +01001039 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1041 struct lpfc_hba *phba = vport->phba;
1042 uint32_t cnt;
1043
James Smart858c9f62007-06-17 19:56:39 -05001044 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001045 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1046 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1047}
1048
James Smarte59058c2008-08-24 21:49:00 -04001049/**
James Smart3621a712009-04-06 18:47:14 -04001050 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001051 * @dev: class device that is converted into a Scsi_host.
1052 * @attr: device attribute, not used.
1053 * @buf: on return contains the used xri count in decimal or "Unknown".
1054 *
1055 * Description:
1056 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1057 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1058 * to "Unknown" and the buffer length is returned, therefore the caller
1059 * must check for "Unknown" in the buffer to detect a failure.
1060 *
1061 * Returns: size of formatted string.
1062 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001063static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001064lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1065 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001066{
Tony Jonesee959b02008-02-22 00:13:36 +01001067 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1069 struct lpfc_hba *phba = vport->phba;
1070 uint32_t cnt, acnt;
1071
James Smart858c9f62007-06-17 19:56:39 -05001072 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1073 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1074 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1075}
1076
James Smarte59058c2008-08-24 21:49:00 -04001077/**
James Smart3621a712009-04-06 18:47:14 -04001078 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001079 * @dev: class device that is converted into a Scsi_host.
1080 * @attr: device attribute, not used.
1081 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1082 *
1083 * Description:
1084 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1085 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1086 * to "Unknown" and the buffer length is returned, therefore the caller
1087 * must check for "Unknown" in the buffer to detect a failure.
1088 *
1089 * Returns: size of formatted string.
1090 **/
James Smart858c9f62007-06-17 19:56:39 -05001091static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001092lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1093 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001094{
Tony Jonesee959b02008-02-22 00:13:36 +01001095 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
1098 uint32_t cnt;
1099
1100 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1101 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1102 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1103}
1104
James Smarte59058c2008-08-24 21:49:00 -04001105/**
James Smart3621a712009-04-06 18:47:14 -04001106 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001107 * @dev: class device that is converted into a Scsi_host.
1108 * @attr: device attribute, not used.
1109 * @buf: on return contains the used vpi count in decimal or "Unknown".
1110 *
1111 * Description:
1112 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1113 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1114 * to "Unknown" and the buffer length is returned, therefore the caller
1115 * must check for "Unknown" in the buffer to detect a failure.
1116 *
1117 * Returns: size of formatted string.
1118 **/
James Smart858c9f62007-06-17 19:56:39 -05001119static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001120lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1121 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001122{
Tony Jonesee959b02008-02-22 00:13:36 +01001123 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001124 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1125 struct lpfc_hba *phba = vport->phba;
1126 uint32_t cnt, acnt;
1127
1128 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001129 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1130 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1131}
1132
James Smarte59058c2008-08-24 21:49:00 -04001133/**
James Smart3621a712009-04-06 18:47:14 -04001134 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001135 * @dev: class device that is converted into a Scsi_host.
1136 * @attr: device attribute, not used.
1137 * @buf: text that must be interpreted to determine if npiv is supported.
1138 *
1139 * Description:
1140 * Buffer will contain text indicating npiv is not suppoerted on the port,
1141 * the port is an NPIV physical port, or it is an npiv virtual port with
1142 * the id of the vport.
1143 *
1144 * Returns: size of formatted string.
1145 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001146static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001147lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1148 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001149{
Tony Jonesee959b02008-02-22 00:13:36 +01001150 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1152 struct lpfc_hba *phba = vport->phba;
1153
1154 if (!(phba->max_vpi))
1155 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1156 if (vport->port_type == LPFC_PHYSICAL_PORT)
1157 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1158 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1159}
1160
James Smarte59058c2008-08-24 21:49:00 -04001161/**
James Smart3621a712009-04-06 18:47:14 -04001162 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001163 * @dev: class device that is converted into a Scsi_host.
1164 * @attr: device attribute, not used.
1165 * @buf: on return contains the cfg_poll in hex.
1166 *
1167 * Notes:
1168 * cfg_poll should be a lpfc_polling_flags type.
1169 *
1170 * Returns: size of formatted string.
1171 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001172static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001173lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1174 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001175{
Tony Jonesee959b02008-02-22 00:13:36 +01001176 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001177 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1178 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001179
1180 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1181}
1182
James Smarte59058c2008-08-24 21:49:00 -04001183/**
James Smart3621a712009-04-06 18:47:14 -04001184 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001185 * @dev: class device that is converted into a Scsi_host.
1186 * @attr: device attribute, not used.
1187 * @buf: one or more lpfc_polling_flags values.
1188 * @count: not used.
1189 *
1190 * Notes:
1191 * buf contents converted to integer and checked for a valid value.
1192 *
1193 * Returns:
1194 * -EINVAL if the buffer connot be converted or is out of range
1195 * length of the buf on success
1196 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001197static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001198lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1199 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001200{
Tony Jonesee959b02008-02-22 00:13:36 +01001201 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1203 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001204 uint32_t creg_val;
1205 uint32_t old_val;
1206 int val=0;
1207
1208 if (!isdigit(buf[0]))
1209 return -EINVAL;
1210
1211 if (sscanf(buf, "%i", &val) != 1)
1212 return -EINVAL;
1213
1214 if ((val & 0x3) != val)
1215 return -EINVAL;
1216
James Smart45ed1192009-10-02 15:17:02 -04001217 if (phba->sli_rev == LPFC_SLI_REV4)
1218 val = 0;
1219
James Smart2e0fef82007-06-17 19:56:36 -05001220 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001221
1222 old_val = phba->cfg_poll;
1223
1224 if (val & ENABLE_FCP_RING_POLLING) {
1225 if ((val & DISABLE_FCP_RING_INT) &&
1226 !(old_val & DISABLE_FCP_RING_INT)) {
1227 creg_val = readl(phba->HCregaddr);
1228 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1229 writel(creg_val, phba->HCregaddr);
1230 readl(phba->HCregaddr); /* flush */
1231
1232 lpfc_poll_start_timer(phba);
1233 }
1234 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001235 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001236 return -EINVAL;
1237 }
1238
1239 if (!(val & DISABLE_FCP_RING_INT) &&
1240 (old_val & DISABLE_FCP_RING_INT))
1241 {
James Smart2e0fef82007-06-17 19:56:36 -05001242 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001243 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001244 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001245 creg_val = readl(phba->HCregaddr);
1246 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1247 writel(creg_val, phba->HCregaddr);
1248 readl(phba->HCregaddr); /* flush */
1249 }
1250
1251 phba->cfg_poll = val;
1252
James Smart2e0fef82007-06-17 19:56:36 -05001253 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001254
1255 return strlen(buf);
1256}
dea31012005-04-17 16:05:31 -05001257
James Smarte59058c2008-08-24 21:49:00 -04001258/**
James Smartbc739052010-08-04 16:11:18 -04001259 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1260 * @dev: class unused variable.
1261 * @attr: device attribute, not used.
1262 * @buf: on return contains the module description text.
1263 *
1264 * Returns: size of formatted string.
1265 **/
1266static ssize_t
1267lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1268 char *buf)
1269{
1270 struct Scsi_Host *shost = class_to_shost(dev);
1271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1272 struct lpfc_hba *phba = vport->phba;
1273
1274 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1275}
1276
1277/**
1278 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1279 * @dev: class unused variable.
1280 * @attr: device attribute, not used.
1281 * @buf: on return contains the module description text.
1282 *
1283 * Returns: size of formatted string.
1284 **/
1285static ssize_t
1286lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1287 char *buf)
1288{
1289 struct Scsi_Host *shost = class_to_shost(dev);
1290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1291 struct lpfc_hba *phba = vport->phba;
1292
1293 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1294}
1295
1296/**
James Smartab56dc22011-02-16 12:39:57 -05001297 * lpfc_dss_show - Return the current state of dss and the configured state
1298 * @dev: class converted to a Scsi_host structure.
1299 * @attr: device attribute, not used.
1300 * @buf: on return contains the formatted text.
1301 *
1302 * Returns: size of formatted string.
1303 **/
1304static ssize_t
1305lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1306 char *buf)
1307{
1308 struct Scsi_Host *shost = class_to_shost(dev);
1309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1310 struct lpfc_hba *phba = vport->phba;
1311
1312 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1313 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1314 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1315 "" : "Not ");
1316}
1317
1318/**
James Smart3621a712009-04-06 18:47:14 -04001319 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001320 *
1321 * Description:
1322 * Macro that given an attr e.g. hba_queue_depth expands
1323 * into a function with the name lpfc_hba_queue_depth_show.
1324 *
1325 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1326 * @dev: class device that is converted into a Scsi_host.
1327 * @attr: device attribute, not used.
1328 * @buf: on return contains the attribute value in decimal.
1329 *
1330 * Returns: size of formatted string.
1331 **/
dea31012005-04-17 16:05:31 -05001332#define lpfc_param_show(attr) \
1333static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001334lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1335 char *buf) \
dea31012005-04-17 16:05:31 -05001336{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001337 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1339 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001340 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001341 val = phba->cfg_##attr;\
1342 return snprintf(buf, PAGE_SIZE, "%d\n",\
1343 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001344}
1345
James Smarte59058c2008-08-24 21:49:00 -04001346/**
James Smart3621a712009-04-06 18:47:14 -04001347 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001348 *
1349 * Description:
1350 * Macro that given an attr e.g. hba_queue_depth expands
1351 * into a function with the name lpfc_hba_queue_depth_show
1352 *
1353 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1354 * @dev: class device that is converted into a Scsi_host.
1355 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001356 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001357 *
1358 * Returns: size of formatted string.
1359 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001360#define lpfc_param_hex_show(attr) \
1361static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001362lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1363 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001364{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001365 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1367 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001368 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001369 val = phba->cfg_##attr;\
1370 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1371 phba->cfg_##attr);\
1372}
1373
James Smarte59058c2008-08-24 21:49:00 -04001374/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001375 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001376 *
1377 * Description:
1378 * Macro that given an attr e.g. hba_queue_depth expands
1379 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1380 * takes a default argument, a minimum and maximum argument.
1381 *
1382 * lpfc_##attr##_init: Initializes an attribute.
1383 * @phba: pointer the the adapter structure.
1384 * @val: integer attribute value.
1385 *
1386 * Validates the min and max values then sets the adapter config field
1387 * accordingly, or uses the default if out of range and prints an error message.
1388 *
1389 * Returns:
1390 * zero on success
1391 * -EINVAL if default used
1392 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001393#define lpfc_param_init(attr, default, minval, maxval) \
1394static int \
James Smart84d1b002010-02-12 14:42:33 -05001395lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001396{ \
1397 if (val >= minval && val <= maxval) {\
1398 phba->cfg_##attr = val;\
1399 return 0;\
1400 }\
1401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001402 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1403 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001404 phba->cfg_##attr = default;\
1405 return -EINVAL;\
1406}
1407
James Smarte59058c2008-08-24 21:49:00 -04001408/**
James Smart3621a712009-04-06 18:47:14 -04001409 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001410 *
1411 * Description:
1412 * Macro that given an attr e.g. hba_queue_depth expands
1413 * into a function with the name lpfc_hba_queue_depth_set
1414 *
1415 * lpfc_##attr##_set: Sets an attribute value.
1416 * @phba: pointer the the adapter structure.
1417 * @val: integer attribute value.
1418 *
1419 * Description:
1420 * Validates the min and max values then sets the
1421 * adapter config field if in the valid range. prints error message
1422 * and does not set the parameter if invalid.
1423 *
1424 * Returns:
1425 * zero on success
1426 * -EINVAL if val is invalid
1427 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001428#define lpfc_param_set(attr, default, minval, maxval) \
1429static int \
James Smart84d1b002010-02-12 14:42:33 -05001430lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001431{ \
1432 if (val >= minval && val <= maxval) {\
1433 phba->cfg_##attr = val;\
1434 return 0;\
1435 }\
1436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001437 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1438 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001439 return -EINVAL;\
1440}
1441
James Smarte59058c2008-08-24 21:49:00 -04001442/**
James Smart3621a712009-04-06 18:47:14 -04001443 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001444 *
1445 * Description:
1446 * Macro that given an attr e.g. hba_queue_depth expands
1447 * into a function with the name lpfc_hba_queue_depth_store.
1448 *
1449 * lpfc_##attr##_store: Set an sttribute value.
1450 * @dev: class device that is converted into a Scsi_host.
1451 * @attr: device attribute, not used.
1452 * @buf: contains the attribute value in ascii.
1453 * @count: not used.
1454 *
1455 * Description:
1456 * Convert the ascii text number to an integer, then
1457 * use the lpfc_##attr##_set function to set the value.
1458 *
1459 * Returns:
1460 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1461 * length of buffer upon success.
1462 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001463#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001464static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001465lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1466 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001467{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001468 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001469 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1470 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001471 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001472 if (!isdigit(buf[0]))\
1473 return -EINVAL;\
1474 if (sscanf(buf, "%i", &val) != 1)\
1475 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001476 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001477 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001478 else \
1479 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001480}
1481
James Smarte59058c2008-08-24 21:49:00 -04001482/**
James Smart3621a712009-04-06 18:47:14 -04001483 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001484 *
1485 * Description:
1486 * Macro that given an attr e.g. hba_queue_depth expands
1487 * into a function with the name lpfc_hba_queue_depth_show
1488 *
1489 * lpfc_##attr##_show: prints the attribute value in decimal.
1490 * @dev: class device that is converted into a Scsi_host.
1491 * @attr: device attribute, not used.
1492 * @buf: on return contains the attribute value in decimal.
1493 *
1494 * Returns: length of formatted string.
1495 **/
James Smart3de2a652007-08-02 11:09:59 -04001496#define lpfc_vport_param_show(attr) \
1497static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001498lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1499 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001500{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001501 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001503 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001504 val = vport->cfg_##attr;\
1505 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1506}
1507
James Smarte59058c2008-08-24 21:49:00 -04001508/**
James Smart3621a712009-04-06 18:47:14 -04001509 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001510 *
1511 * Description:
1512 * Macro that given an attr e.g.
1513 * hba_queue_depth expands into a function with the name
1514 * lpfc_hba_queue_depth_show
1515 *
James Smart3621a712009-04-06 18:47:14 -04001516 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001517 * @dev: class device that is converted into a Scsi_host.
1518 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001519 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001520 *
1521 * Returns: length of formatted string.
1522 **/
James Smart3de2a652007-08-02 11:09:59 -04001523#define lpfc_vport_param_hex_show(attr) \
1524static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001525lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1526 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001527{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001528 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001529 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001530 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001531 val = vport->cfg_##attr;\
1532 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1533}
1534
James Smarte59058c2008-08-24 21:49:00 -04001535/**
James Smart3621a712009-04-06 18:47:14 -04001536 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001537 *
1538 * Description:
1539 * Macro that given an attr e.g. hba_queue_depth expands
1540 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1541 * takes a default argument, a minimum and maximum argument.
1542 *
1543 * lpfc_##attr##_init: validates the min and max values then sets the
1544 * adapter config field accordingly, or uses the default if out of range
1545 * and prints an error message.
1546 * @phba: pointer the the adapter structure.
1547 * @val: integer attribute value.
1548 *
1549 * Returns:
1550 * zero on success
1551 * -EINVAL if default used
1552 **/
James Smart3de2a652007-08-02 11:09:59 -04001553#define lpfc_vport_param_init(attr, default, minval, maxval) \
1554static int \
James Smart84d1b002010-02-12 14:42:33 -05001555lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001556{ \
1557 if (val >= minval && val <= maxval) {\
1558 vport->cfg_##attr = val;\
1559 return 0;\
1560 }\
James Smarte8b62012007-08-02 11:10:09 -04001561 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001562 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001563 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001564 vport->cfg_##attr = default;\
1565 return -EINVAL;\
1566}
1567
James Smarte59058c2008-08-24 21:49:00 -04001568/**
James Smart3621a712009-04-06 18:47:14 -04001569 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001570 *
1571 * Description:
1572 * Macro that given an attr e.g. hba_queue_depth expands
1573 * into a function with the name lpfc_hba_queue_depth_set
1574 *
1575 * lpfc_##attr##_set: validates the min and max values then sets the
1576 * adapter config field if in the valid range. prints error message
1577 * and does not set the parameter if invalid.
1578 * @phba: pointer the the adapter structure.
1579 * @val: integer attribute value.
1580 *
1581 * Returns:
1582 * zero on success
1583 * -EINVAL if val is invalid
1584 **/
James Smart3de2a652007-08-02 11:09:59 -04001585#define lpfc_vport_param_set(attr, default, minval, maxval) \
1586static int \
James Smart84d1b002010-02-12 14:42:33 -05001587lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001588{ \
1589 if (val >= minval && val <= maxval) {\
1590 vport->cfg_##attr = val;\
1591 return 0;\
1592 }\
James Smarte8b62012007-08-02 11:10:09 -04001593 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001594 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001595 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001596 return -EINVAL;\
1597}
1598
James Smarte59058c2008-08-24 21:49:00 -04001599/**
James Smart3621a712009-04-06 18:47:14 -04001600 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001601 *
1602 * Description:
1603 * Macro that given an attr e.g. hba_queue_depth
1604 * expands into a function with the name lpfc_hba_queue_depth_store
1605 *
1606 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1607 * use the lpfc_##attr##_set function to set the value.
1608 * @cdev: class device that is converted into a Scsi_host.
1609 * @buf: contains the attribute value in decimal.
1610 * @count: not used.
1611 *
1612 * Returns:
1613 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1614 * length of buffer upon success.
1615 **/
James Smart3de2a652007-08-02 11:09:59 -04001616#define lpfc_vport_param_store(attr) \
1617static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001618lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1619 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001620{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001621 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001622 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001623 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001624 if (!isdigit(buf[0]))\
1625 return -EINVAL;\
1626 if (sscanf(buf, "%i", &val) != 1)\
1627 return -EINVAL;\
1628 if (lpfc_##attr##_set(vport, val) == 0) \
1629 return strlen(buf);\
1630 else \
1631 return -EINVAL;\
1632}
1633
1634
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001635#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001636static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001637module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001638MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001639lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001640
1641#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001642static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001643module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001644MODULE_PARM_DESC(lpfc_##name, desc);\
1645lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001646lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001647static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001648
1649#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001650static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001651module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001652MODULE_PARM_DESC(lpfc_##name, desc);\
1653lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001654lpfc_param_init(name, defval, minval, maxval)\
1655lpfc_param_set(name, defval, minval, maxval)\
1656lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001657static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1658 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001659
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001660#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001661static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001662module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001663MODULE_PARM_DESC(lpfc_##name, desc);\
1664lpfc_param_hex_show(name)\
1665lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001666static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001667
1668#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001669static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001670module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001671MODULE_PARM_DESC(lpfc_##name, desc);\
1672lpfc_param_hex_show(name)\
1673lpfc_param_init(name, defval, minval, maxval)\
1674lpfc_param_set(name, defval, minval, maxval)\
1675lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001676static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1677 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001678
James Smart3de2a652007-08-02 11:09:59 -04001679#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001680static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001681module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001682MODULE_PARM_DESC(lpfc_##name, desc);\
1683lpfc_vport_param_init(name, defval, minval, maxval)
1684
1685#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001686static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001687module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001688MODULE_PARM_DESC(lpfc_##name, desc);\
1689lpfc_vport_param_show(name)\
1690lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001691static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001692
1693#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001694static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001695module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001696MODULE_PARM_DESC(lpfc_##name, desc);\
1697lpfc_vport_param_show(name)\
1698lpfc_vport_param_init(name, defval, minval, maxval)\
1699lpfc_vport_param_set(name, defval, minval, maxval)\
1700lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001701static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1702 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001703
1704#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001705static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001706module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001707MODULE_PARM_DESC(lpfc_##name, desc);\
1708lpfc_vport_param_hex_show(name)\
1709lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001710static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001711
1712#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001713static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001714module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001715MODULE_PARM_DESC(lpfc_##name, desc);\
1716lpfc_vport_param_hex_show(name)\
1717lpfc_vport_param_init(name, defval, minval, maxval)\
1718lpfc_vport_param_set(name, defval, minval, maxval)\
1719lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001720static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1721 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001722
James Smart81301a92008-12-04 22:39:46 -05001723static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1724static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1725static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1726static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001727static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1728static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1729static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1730static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1731static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1732static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1733static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1734static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001735static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1736 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001737static DEVICE_ATTR(option_rom_version, S_IRUGO,
1738 lpfc_option_rom_version_show, NULL);
1739static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1740 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001741static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001742static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1743static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001744static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001745static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1746 lpfc_board_mode_show, lpfc_board_mode_store);
1747static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1748static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1749static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1750static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1751static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1752static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1753static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1754static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1755static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001756static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1757static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001758static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001759
James Smarta12e07b2006-12-02 13:35:30 -05001760static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001761
James Smarte59058c2008-08-24 21:49:00 -04001762/**
James Smart3621a712009-04-06 18:47:14 -04001763 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001764 * @dev: class device that is converted into a Scsi_host.
1765 * @attr: device attribute, not used.
1766 * @buf: containing the string lpfc_soft_wwn_key.
1767 * @count: must be size of lpfc_soft_wwn_key.
1768 *
1769 * Returns:
1770 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1771 * length of buf indicates success
1772 **/
James Smartc3f28af2006-08-18 17:47:18 -04001773static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001774lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1775 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001776{
Tony Jonesee959b02008-02-22 00:13:36 +01001777 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001778 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1779 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001780 unsigned int cnt = count;
1781
1782 /*
1783 * We're doing a simple sanity check for soft_wwpn setting.
1784 * We require that the user write a specific key to enable
1785 * the soft_wwpn attribute to be settable. Once the attribute
1786 * is written, the enable key resets. If further updates are
1787 * desired, the key must be written again to re-enable the
1788 * attribute.
1789 *
1790 * The "key" is not secret - it is a hardcoded string shown
1791 * here. The intent is to protect against the random user or
1792 * application that is just writing attributes.
1793 */
1794
1795 /* count may include a LF at end of string */
1796 if (buf[cnt-1] == '\n')
1797 cnt--;
1798
James Smarta12e07b2006-12-02 13:35:30 -05001799 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1800 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001801 return -EINVAL;
1802
James Smarta12e07b2006-12-02 13:35:30 -05001803 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001804 return count;
1805}
Tony Jonesee959b02008-02-22 00:13:36 +01001806static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1807 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001808
James Smarte59058c2008-08-24 21:49:00 -04001809/**
James Smart3621a712009-04-06 18:47:14 -04001810 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001811 * @dev: class device that is converted into a Scsi_host.
1812 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001813 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001814 *
1815 * Returns: size of formatted string.
1816 **/
James Smartc3f28af2006-08-18 17:47:18 -04001817static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001818lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1819 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001820{
Tony Jonesee959b02008-02-22 00:13:36 +01001821 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1823 struct lpfc_hba *phba = vport->phba;
1824
Randy Dunlapafc071e2006-10-23 21:47:13 -07001825 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1826 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001827}
1828
James Smarte59058c2008-08-24 21:49:00 -04001829/**
James Smart3621a712009-04-06 18:47:14 -04001830 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001831 * @dev class device that is converted into a Scsi_host.
1832 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001833 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001834 * @count: number of wwpn bytes in buf
1835 *
1836 * Returns:
1837 * -EACCES hba reset not enabled, adapter over temp
1838 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1839 * -EIO error taking adapter offline or online
1840 * value of count on success
1841 **/
James Smartc3f28af2006-08-18 17:47:18 -04001842static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001843lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1844 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001845{
Tony Jonesee959b02008-02-22 00:13:36 +01001846 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001847 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1848 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001849 struct completion online_compl;
1850 int stat1=0, stat2=0;
1851 unsigned int i, j, cnt=count;
1852 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05001853 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04001854
James Smart13815c82008-01-11 01:52:48 -05001855 if (!phba->cfg_enable_hba_reset)
1856 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001857 spin_lock_irq(&phba->hbalock);
1858 if (phba->over_temp_state == HBA_OVER_TEMP) {
1859 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001860 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001861 }
1862 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001863 /* count may include a LF at end of string */
1864 if (buf[cnt-1] == '\n')
1865 cnt--;
1866
James Smarta12e07b2006-12-02 13:35:30 -05001867 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001868 ((cnt == 17) && (*buf++ != 'x')) ||
1869 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1870 return -EINVAL;
1871
James Smarta12e07b2006-12-02 13:35:30 -05001872 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001873
1874 memset(wwpn, 0, sizeof(wwpn));
1875
1876 /* Validate and store the new name */
1877 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001878 int value;
1879
1880 value = hex_to_bin(*buf++);
1881 if (value >= 0)
1882 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04001883 else
1884 return -EINVAL;
1885 if (i % 2) {
1886 wwpn[i/2] = j & 0xff;
1887 j = 0;
1888 }
1889 }
1890 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001891 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001892 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001893 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001894
1895 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1896 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1897
James Smart46fa3112007-04-25 09:51:45 -04001898 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001899 if (stat1)
1900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001901 "0463 lpfc_soft_wwpn attribute set failed to "
1902 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001903 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001904 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1905 LPFC_EVT_ONLINE);
1906 if (rc == 0)
1907 return -ENOMEM;
1908
James Smartc3f28af2006-08-18 17:47:18 -04001909 wait_for_completion(&online_compl);
1910 if (stat2)
1911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001912 "0464 lpfc_soft_wwpn attribute set failed to "
1913 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001914 return (stat1 || stat2) ? -EIO : count;
1915}
Tony Jonesee959b02008-02-22 00:13:36 +01001916static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1917 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001918
James Smarte59058c2008-08-24 21:49:00 -04001919/**
James Smart3621a712009-04-06 18:47:14 -04001920 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001921 * @dev: class device that is converted into a Scsi_host.
1922 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001923 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001924 *
1925 * Returns: size of formatted string.
1926 **/
James Smarta12e07b2006-12-02 13:35:30 -05001927static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001928lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1929 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001930{
Tony Jonesee959b02008-02-22 00:13:36 +01001931 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001932 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001933 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1934 (unsigned long long)phba->cfg_soft_wwnn);
1935}
1936
James Smarte59058c2008-08-24 21:49:00 -04001937/**
James Smart3621a712009-04-06 18:47:14 -04001938 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001939 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001940 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001941 * @count: number of wwnn bytes in buf.
1942 *
1943 * Returns:
1944 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1945 * value of count on success
1946 **/
James Smarta12e07b2006-12-02 13:35:30 -05001947static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001948lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1949 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001950{
Tony Jonesee959b02008-02-22 00:13:36 +01001951 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001952 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001953 unsigned int i, j, cnt=count;
1954 u8 wwnn[8];
1955
1956 /* count may include a LF at end of string */
1957 if (buf[cnt-1] == '\n')
1958 cnt--;
1959
1960 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1961 ((cnt == 17) && (*buf++ != 'x')) ||
1962 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1963 return -EINVAL;
1964
1965 /*
1966 * Allow wwnn to be set many times, as long as the enable is set.
1967 * However, once the wwpn is set, everything locks.
1968 */
1969
1970 memset(wwnn, 0, sizeof(wwnn));
1971
1972 /* Validate and store the new name */
1973 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001974 int value;
1975
1976 value = hex_to_bin(*buf++);
1977 if (value >= 0)
1978 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05001979 else
1980 return -EINVAL;
1981 if (i % 2) {
1982 wwnn[i/2] = j & 0xff;
1983 j = 0;
1984 }
1985 }
1986 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1987
1988 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1989 "lpfc%d: soft_wwnn set. Value will take effect upon "
1990 "setting of the soft_wwpn\n", phba->brd_no);
1991
1992 return count;
1993}
Tony Jonesee959b02008-02-22 00:13:36 +01001994static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1995 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001996
James Smartc3f28af2006-08-18 17:47:18 -04001997
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001998static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05001999module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002000MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2001 " 0 - none,"
2002 " 1 - poll with interrupts enabled"
2003 " 3 - poll and disable FCP ring interrupts");
2004
Tony Jonesee959b02008-02-22 00:13:36 +01002005static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2006 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002007
James Smart92d7f7b2007-06-17 19:56:38 -05002008int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002009module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002010MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2011 " 0 - auto (SLI-3 if supported),"
2012 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2013 " 3 - select SLI-3");
2014
James Smart15672312010-04-06 14:49:03 -04002015int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002016module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002017MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2018lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002019lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002020static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002021
James Smart19ca7602010-11-20 23:11:55 -05002022int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002023module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002024MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2025lpfc_param_show(enable_rrq);
2026lpfc_param_init(enable_rrq, 0, 0, 1);
2027static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2028
dea31012005-04-17 16:05:31 -05002029/*
James Smart84d1b002010-02-12 14:42:33 -05002030# lpfc_suppress_link_up: Bring link up at initialization
2031# 0x0 = bring link up (issue MBX_INIT_LINK)
2032# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2033# 0x2 = never bring up link
2034# Default value is 0.
2035*/
James Smarte40a02c2010-02-26 14:13:54 -05002036LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2037 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2038 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002039/*
2040# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2041# 1 - (1024)
2042# 2 - (2048)
2043# 3 - (3072)
2044# 4 - (4096)
2045# 5 - (5120)
2046*/
2047static ssize_t
2048lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2049{
2050 struct Scsi_Host *shost = class_to_shost(dev);
2051 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2052
2053 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2054}
2055
2056static DEVICE_ATTR(iocb_hw, S_IRUGO,
2057 lpfc_iocb_hw_show, NULL);
2058static ssize_t
2059lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2060{
2061 struct Scsi_Host *shost = class_to_shost(dev);
2062 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2063
2064 return snprintf(buf, PAGE_SIZE, "%d\n",
2065 phba->sli.ring[LPFC_ELS_RING].txq_max);
2066}
2067
2068static DEVICE_ATTR(txq_hw, S_IRUGO,
2069 lpfc_txq_hw_show, NULL);
2070static ssize_t
2071lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2072 char *buf)
2073{
2074 struct Scsi_Host *shost = class_to_shost(dev);
2075 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2076
2077 return snprintf(buf, PAGE_SIZE, "%d\n",
2078 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2079}
2080
2081static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2082 lpfc_txcmplq_hw_show, NULL);
2083
2084int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002085module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002086MODULE_PARM_DESC(lpfc_iocb_cnt,
2087 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2088lpfc_param_show(iocb_cnt);
2089lpfc_param_init(iocb_cnt, 2, 1, 5);
2090static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2091 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002092
2093/*
James Smartc01f3202006-08-18 17:47:08 -04002094# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2095# until the timer expires. Value range is [0,255]. Default value is 30.
2096*/
2097static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2098static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2099module_param(lpfc_nodev_tmo, int, 0);
2100MODULE_PARM_DESC(lpfc_nodev_tmo,
2101 "Seconds driver will hold I/O waiting "
2102 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002103
2104/**
James Smart3621a712009-04-06 18:47:14 -04002105 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002106 * @dev: class converted to a Scsi_host structure.
2107 * @attr: device attribute, not used.
2108 * @buf: on return contains the dev loss timeout in decimal.
2109 *
2110 * Returns: size of formatted string.
2111 **/
James Smartc01f3202006-08-18 17:47:08 -04002112static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002113lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2114 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002115{
Tony Jonesee959b02008-02-22 00:13:36 +01002116 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002118
James Smart3de2a652007-08-02 11:09:59 -04002119 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002120}
2121
James Smarte59058c2008-08-24 21:49:00 -04002122/**
James Smart3621a712009-04-06 18:47:14 -04002123 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002124 * @vport: lpfc vport structure pointer.
2125 * @val: contains the nodev timeout value.
2126 *
2127 * Description:
2128 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2129 * a kernel error message is printed and zero is returned.
2130 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2131 * Otherwise nodev tmo is set to the default value.
2132 *
2133 * Returns:
2134 * zero if already set or if val is in range
2135 * -EINVAL val out of range
2136 **/
James Smartc01f3202006-08-18 17:47:08 -04002137static int
James Smart3de2a652007-08-02 11:09:59 -04002138lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002139{
James Smart3de2a652007-08-02 11:09:59 -04002140 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2141 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2142 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002143 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002144 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002145 "parameter because devloss_tmo is "
2146 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002147 return 0;
2148 }
2149
2150 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002151 vport->cfg_nodev_tmo = val;
2152 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002153 return 0;
2154 }
James Smarte8b62012007-08-02 11:10:09 -04002155 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2156 "0400 lpfc_nodev_tmo attribute cannot be set to"
2157 " %d, allowed range is [%d, %d]\n",
2158 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002159 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002160 return -EINVAL;
2161}
2162
James Smarte59058c2008-08-24 21:49:00 -04002163/**
James Smart3621a712009-04-06 18:47:14 -04002164 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002165 * @vport: lpfc vport structure pointer.
2166 *
2167 * Description:
2168 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2169 **/
James Smart7054a602007-04-25 09:52:34 -04002170static void
James Smart3de2a652007-08-02 11:09:59 -04002171lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002172{
James Smart858c9f62007-06-17 19:56:39 -05002173 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002174 struct lpfc_nodelist *ndlp;
2175
James Smart51ef4c22007-08-02 11:10:31 -04002176 shost = lpfc_shost_from_vport(vport);
2177 spin_lock_irq(shost->host_lock);
2178 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002179 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002180 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2181 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002182}
2183
James Smarte59058c2008-08-24 21:49:00 -04002184/**
James Smart3621a712009-04-06 18:47:14 -04002185 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002186 * @vport: lpfc vport structure pointer.
2187 * @val: contains the tmo value.
2188 *
2189 * Description:
2190 * If the devloss tmo is already set or the vport dev loss tmo has changed
2191 * then a kernel error message is printed and zero is returned.
2192 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2193 * Otherwise nodev tmo is set to the default value.
2194 *
2195 * Returns:
2196 * zero if already set or if val is in range
2197 * -EINVAL val out of range
2198 **/
James Smartc01f3202006-08-18 17:47:08 -04002199static int
James Smart3de2a652007-08-02 11:09:59 -04002200lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002201{
James Smart3de2a652007-08-02 11:09:59 -04002202 if (vport->dev_loss_tmo_changed ||
2203 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002204 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2205 "0401 Ignoring change to nodev_tmo "
2206 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002207 return 0;
2208 }
James Smartc01f3202006-08-18 17:47:08 -04002209 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002210 vport->cfg_nodev_tmo = val;
2211 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002212 /*
2213 * For compat: set the fc_host dev loss so new rports
2214 * will get the value.
2215 */
2216 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002217 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002218 return 0;
2219 }
James Smarte8b62012007-08-02 11:10:09 -04002220 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2221 "0403 lpfc_nodev_tmo attribute cannot be set to"
2222 "%d, allowed range is [%d, %d]\n",
2223 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002224 return -EINVAL;
2225}
2226
James Smart3de2a652007-08-02 11:09:59 -04002227lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002228
Tony Jonesee959b02008-02-22 00:13:36 +01002229static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2230 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002231
2232/*
2233# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2234# disappear until the timer expires. Value range is [0,255]. Default
2235# value is 30.
2236*/
James Smartab56dc22011-02-16 12:39:57 -05002237module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002238MODULE_PARM_DESC(lpfc_devloss_tmo,
2239 "Seconds driver will hold I/O waiting "
2240 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002241lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2242 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2243lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002244
2245/**
James Smart3621a712009-04-06 18:47:14 -04002246 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002247 * @vport: lpfc vport structure pointer.
2248 * @val: contains the tmo value.
2249 *
2250 * Description:
2251 * If val is in a valid range then set the vport nodev tmo,
2252 * devloss tmo, also set the vport dev loss tmo changed flag.
2253 * Else a kernel error message is printed.
2254 *
2255 * Returns:
2256 * zero if val is in range
2257 * -EINVAL val out of range
2258 **/
James Smartc01f3202006-08-18 17:47:08 -04002259static int
James Smart3de2a652007-08-02 11:09:59 -04002260lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002261{
2262 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002263 vport->cfg_nodev_tmo = val;
2264 vport->cfg_devloss_tmo = val;
2265 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002266 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002267 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002268 return 0;
2269 }
2270
James Smarte8b62012007-08-02 11:10:09 -04002271 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2272 "0404 lpfc_devloss_tmo attribute cannot be set to"
2273 " %d, allowed range is [%d, %d]\n",
2274 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002275 return -EINVAL;
2276}
2277
James Smart3de2a652007-08-02 11:09:59 -04002278lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002279static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2280 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002281
2282/*
dea31012005-04-17 16:05:31 -05002283# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2284# deluged with LOTS of information.
2285# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002286# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002287*/
James Smartf4b4c682009-05-22 14:53:12 -04002288LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002289 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002290
2291/*
James Smart7ee5d432007-10-27 13:37:17 -04002292# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2293# objects that have been registered with the nameserver after login.
2294*/
2295LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2296 "Deregister nameserver objects before LOGO");
2297
2298/*
dea31012005-04-17 16:05:31 -05002299# lun_queue_depth: This parameter is used to limit the number of outstanding
2300# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2301*/
James Smart3de2a652007-08-02 11:09:59 -04002302LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2303 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002304
2305/*
James Smart7dc517d2010-07-14 15:32:10 -04002306# tgt_queue_depth: This parameter is used to limit the number of outstanding
2307# commands per target port. Value range is [10,65535]. Default value is 65535.
2308*/
2309LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2310 "Max number of FCP commands we can queue to a specific target port");
2311
2312/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002313# hba_queue_depth: This parameter is used to limit the number of outstanding
2314# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2315# value is greater than the maximum number of exchanges supported by the HBA,
2316# then maximum number of exchanges supported by the HBA is used to determine
2317# the hba_queue_depth.
2318*/
2319LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2320 "Max number of FCP commands we can queue to a lpfc HBA");
2321
2322/*
James Smart92d7f7b2007-06-17 19:56:38 -05002323# peer_port_login: This parameter allows/prevents logins
2324# between peer ports hosted on the same physical port.
2325# When this parameter is set 0 peer ports of same physical port
2326# are not allowed to login to each other.
2327# When this parameter is set 1 peer ports of same physical port
2328# are allowed to login to each other.
2329# Default value of this parameter is 0.
2330*/
James Smart3de2a652007-08-02 11:09:59 -04002331LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2332 "Allow peer ports on the same physical port to login to each "
2333 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002334
2335/*
James Smart3de2a652007-08-02 11:09:59 -04002336# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002337# between Virtual Ports and remote initiators.
2338# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2339# other initiators and will attempt to PLOGI all remote ports.
2340# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2341# remote ports and will not attempt to PLOGI to other initiators.
2342# This parameter does not restrict to the physical port.
2343# This parameter does not restrict logins to Fabric resident remote ports.
2344# Default value of this parameter is 1.
2345*/
James Smart3de2a652007-08-02 11:09:59 -04002346static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002347module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002348MODULE_PARM_DESC(lpfc_restrict_login,
2349 "Restrict virtual ports login to remote initiators.");
2350lpfc_vport_param_show(restrict_login);
2351
James Smarte59058c2008-08-24 21:49:00 -04002352/**
James Smart3621a712009-04-06 18:47:14 -04002353 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002354 * @vport: lpfc vport structure pointer.
2355 * @val: contains the restrict login value.
2356 *
2357 * Description:
2358 * If val is not in a valid range then log a kernel error message and set
2359 * the vport restrict login to one.
2360 * If the port type is physical clear the restrict login flag and return.
2361 * Else set the restrict login flag to val.
2362 *
2363 * Returns:
2364 * zero if val is in range
2365 * -EINVAL val out of range
2366 **/
James Smart3de2a652007-08-02 11:09:59 -04002367static int
2368lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2369{
2370 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002371 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002372 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002373 "be set to %d, allowed range is [0, 1]\n",
2374 val);
James Smart3de2a652007-08-02 11:09:59 -04002375 vport->cfg_restrict_login = 1;
2376 return -EINVAL;
2377 }
2378 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2379 vport->cfg_restrict_login = 0;
2380 return 0;
2381 }
2382 vport->cfg_restrict_login = val;
2383 return 0;
2384}
2385
James Smarte59058c2008-08-24 21:49:00 -04002386/**
James Smart3621a712009-04-06 18:47:14 -04002387 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002388 * @vport: lpfc vport structure pointer.
2389 * @val: contains the restrict login value.
2390 *
2391 * Description:
2392 * If val is not in a valid range then log a kernel error message and set
2393 * the vport restrict login to one.
2394 * If the port type is physical and the val is not zero log a kernel
2395 * error message, clear the restrict login flag and return zero.
2396 * Else set the restrict login flag to val.
2397 *
2398 * Returns:
2399 * zero if val is in range
2400 * -EINVAL val out of range
2401 **/
James Smart3de2a652007-08-02 11:09:59 -04002402static int
2403lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2404{
2405 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002406 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002407 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002408 "be set to %d, allowed range is [0, 1]\n",
2409 val);
James Smart3de2a652007-08-02 11:09:59 -04002410 vport->cfg_restrict_login = 1;
2411 return -EINVAL;
2412 }
2413 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002414 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2415 "0468 lpfc_restrict_login must be 0 for "
2416 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002417 vport->cfg_restrict_login = 0;
2418 return 0;
2419 }
2420 vport->cfg_restrict_login = val;
2421 return 0;
2422}
2423lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002424static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2425 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002426
2427/*
dea31012005-04-17 16:05:31 -05002428# Some disk devices have a "select ID" or "select Target" capability.
2429# From a protocol standpoint "select ID" usually means select the
2430# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2431# annex" which contains a table that maps a "select ID" (a number
2432# between 0 and 7F) to an ALPA. By default, for compatibility with
2433# older drivers, the lpfc driver scans this table from low ALPA to high
2434# ALPA.
2435#
2436# Turning on the scan-down variable (on = 1, off = 0) will
2437# cause the lpfc driver to use an inverted table, effectively
2438# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2439#
2440# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2441# and will not work across a fabric. Also this parameter will take
2442# effect only in the case when ALPA map is not available.)
2443*/
James Smart3de2a652007-08-02 11:09:59 -04002444LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2445 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002446
2447/*
dea31012005-04-17 16:05:31 -05002448# lpfc_topology: link topology for init link
2449# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002450# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002451# 0x02 = attempt point-to-point mode only
2452# 0x04 = attempt loop mode only
2453# 0x06 = attempt point-to-point mode then loop
2454# Set point-to-point mode if you want to run as an N_Port.
2455# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2456# Default value is 0.
2457*/
James Smarte59058c2008-08-24 21:49:00 -04002458
2459/**
James Smart3621a712009-04-06 18:47:14 -04002460 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002461 * @phba: lpfc_hba pointer.
2462 * @val: topology value.
2463 *
2464 * Description:
2465 * If val is in a valid range then set the adapter's topology field and
2466 * issue a lip; if the lip fails reset the topology to the old value.
2467 *
2468 * If the value is not in range log a kernel error message and return an error.
2469 *
2470 * Returns:
2471 * zero if val is in range and lip okay
2472 * non-zero return value from lpfc_issue_lip()
2473 * -EINVAL val out of range
2474 **/
James Smarta257bf92009-04-06 18:48:10 -04002475static ssize_t
2476lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2477 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002478{
James Smarta257bf92009-04-06 18:48:10 -04002479 struct Scsi_Host *shost = class_to_shost(dev);
2480 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2481 struct lpfc_hba *phba = vport->phba;
2482 int val = 0;
2483 int nolip = 0;
2484 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002485 int err;
2486 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002487
2488 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2489 nolip = 1;
2490 val_buf = &buf[strlen("nolip ")];
2491 }
2492
2493 if (!isdigit(val_buf[0]))
2494 return -EINVAL;
2495 if (sscanf(val_buf, "%i", &val) != 1)
2496 return -EINVAL;
2497
James Smart83108bd2008-01-11 01:53:09 -05002498 if (val >= 0 && val <= 6) {
2499 prev_val = phba->cfg_topology;
2500 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002501 if (nolip)
2502 return strlen(buf);
2503
James Smart83108bd2008-01-11 01:53:09 -05002504 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002505 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002506 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002507 return -EINVAL;
2508 } else
2509 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002510 }
2511 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2512 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2513 "allowed range is [0, 6]\n",
2514 phba->brd_no, val);
2515 return -EINVAL;
2516}
2517static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002518module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002519MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2520lpfc_param_show(topology)
2521lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002522static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002523 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002524
James Smart21e9a0a2009-05-22 14:53:21 -04002525/**
2526 * lpfc_static_vport_show: Read callback function for
2527 * lpfc_static_vport sysfs file.
2528 * @dev: Pointer to class device object.
2529 * @attr: device attribute structure.
2530 * @buf: Data buffer.
2531 *
2532 * This function is the read call back function for
2533 * lpfc_static_vport sysfs file. The lpfc_static_vport
2534 * sysfs file report the mageability of the vport.
2535 **/
2536static ssize_t
2537lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2538 char *buf)
2539{
2540 struct Scsi_Host *shost = class_to_shost(dev);
2541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2542 if (vport->vport_flag & STATIC_VPORT)
2543 sprintf(buf, "1\n");
2544 else
2545 sprintf(buf, "0\n");
2546
2547 return strlen(buf);
2548}
2549
2550/*
2551 * Sysfs attribute to control the statistical data collection.
2552 */
2553static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2554 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002555
2556/**
James Smart3621a712009-04-06 18:47:14 -04002557 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002558 * @dev: Pointer to class device.
2559 * @buf: Data buffer.
2560 * @count: Size of the data buffer.
2561 *
2562 * This function get called when an user write to the lpfc_stat_data_ctrl
2563 * sysfs file. This function parse the command written to the sysfs file
2564 * and take appropriate action. These commands are used for controlling
2565 * driver statistical data collection.
2566 * Following are the command this function handles.
2567 *
2568 * setbucket <bucket_type> <base> <step>
2569 * = Set the latency buckets.
2570 * destroybucket = destroy all the buckets.
2571 * start = start data collection
2572 * stop = stop data collection
2573 * reset = reset the collected data
2574 **/
2575static ssize_t
2576lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2577 const char *buf, size_t count)
2578{
2579 struct Scsi_Host *shost = class_to_shost(dev);
2580 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2581 struct lpfc_hba *phba = vport->phba;
2582#define LPFC_MAX_DATA_CTRL_LEN 1024
2583 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2584 unsigned long i;
2585 char *str_ptr, *token;
2586 struct lpfc_vport **vports;
2587 struct Scsi_Host *v_shost;
2588 char *bucket_type_str, *base_str, *step_str;
2589 unsigned long base, step, bucket_type;
2590
2591 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002592 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002593 return -EINVAL;
2594
2595 strcpy(bucket_data, buf);
2596 str_ptr = &bucket_data[0];
2597 /* Ignore this token - this is command token */
2598 token = strsep(&str_ptr, "\t ");
2599 if (!token)
2600 return -EINVAL;
2601
2602 bucket_type_str = strsep(&str_ptr, "\t ");
2603 if (!bucket_type_str)
2604 return -EINVAL;
2605
2606 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2607 bucket_type = LPFC_LINEAR_BUCKET;
2608 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2609 bucket_type = LPFC_POWER2_BUCKET;
2610 else
2611 return -EINVAL;
2612
2613 base_str = strsep(&str_ptr, "\t ");
2614 if (!base_str)
2615 return -EINVAL;
2616 base = simple_strtoul(base_str, NULL, 0);
2617
2618 step_str = strsep(&str_ptr, "\t ");
2619 if (!step_str)
2620 return -EINVAL;
2621 step = simple_strtoul(step_str, NULL, 0);
2622 if (!step)
2623 return -EINVAL;
2624
2625 /* Block the data collection for every vport */
2626 vports = lpfc_create_vport_work_array(phba);
2627 if (vports == NULL)
2628 return -ENOMEM;
2629
James Smartf4b4c682009-05-22 14:53:12 -04002630 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002631 v_shost = lpfc_shost_from_vport(vports[i]);
2632 spin_lock_irq(v_shost->host_lock);
2633 /* Block and reset data collection */
2634 vports[i]->stat_data_blocked = 1;
2635 if (vports[i]->stat_data_enabled)
2636 lpfc_vport_reset_stat_data(vports[i]);
2637 spin_unlock_irq(v_shost->host_lock);
2638 }
2639
2640 /* Set the bucket attributes */
2641 phba->bucket_type = bucket_type;
2642 phba->bucket_base = base;
2643 phba->bucket_step = step;
2644
James Smartf4b4c682009-05-22 14:53:12 -04002645 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002646 v_shost = lpfc_shost_from_vport(vports[i]);
2647
2648 /* Unblock data collection */
2649 spin_lock_irq(v_shost->host_lock);
2650 vports[i]->stat_data_blocked = 0;
2651 spin_unlock_irq(v_shost->host_lock);
2652 }
2653 lpfc_destroy_vport_work_array(phba, vports);
2654 return strlen(buf);
2655 }
2656
2657 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2658 vports = lpfc_create_vport_work_array(phba);
2659 if (vports == NULL)
2660 return -ENOMEM;
2661
James Smartf4b4c682009-05-22 14:53:12 -04002662 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002663 v_shost = lpfc_shost_from_vport(vports[i]);
2664 spin_lock_irq(shost->host_lock);
2665 vports[i]->stat_data_blocked = 1;
2666 lpfc_free_bucket(vport);
2667 vport->stat_data_enabled = 0;
2668 vports[i]->stat_data_blocked = 0;
2669 spin_unlock_irq(shost->host_lock);
2670 }
2671 lpfc_destroy_vport_work_array(phba, vports);
2672 phba->bucket_type = LPFC_NO_BUCKET;
2673 phba->bucket_base = 0;
2674 phba->bucket_step = 0;
2675 return strlen(buf);
2676 }
2677
2678 if (!strncmp(buf, "start", strlen("start"))) {
2679 /* If no buckets configured return error */
2680 if (phba->bucket_type == LPFC_NO_BUCKET)
2681 return -EINVAL;
2682 spin_lock_irq(shost->host_lock);
2683 if (vport->stat_data_enabled) {
2684 spin_unlock_irq(shost->host_lock);
2685 return strlen(buf);
2686 }
2687 lpfc_alloc_bucket(vport);
2688 vport->stat_data_enabled = 1;
2689 spin_unlock_irq(shost->host_lock);
2690 return strlen(buf);
2691 }
2692
2693 if (!strncmp(buf, "stop", strlen("stop"))) {
2694 spin_lock_irq(shost->host_lock);
2695 if (vport->stat_data_enabled == 0) {
2696 spin_unlock_irq(shost->host_lock);
2697 return strlen(buf);
2698 }
2699 lpfc_free_bucket(vport);
2700 vport->stat_data_enabled = 0;
2701 spin_unlock_irq(shost->host_lock);
2702 return strlen(buf);
2703 }
2704
2705 if (!strncmp(buf, "reset", strlen("reset"))) {
2706 if ((phba->bucket_type == LPFC_NO_BUCKET)
2707 || !vport->stat_data_enabled)
2708 return strlen(buf);
2709 spin_lock_irq(shost->host_lock);
2710 vport->stat_data_blocked = 1;
2711 lpfc_vport_reset_stat_data(vport);
2712 vport->stat_data_blocked = 0;
2713 spin_unlock_irq(shost->host_lock);
2714 return strlen(buf);
2715 }
2716 return -EINVAL;
2717}
2718
2719
2720/**
James Smart3621a712009-04-06 18:47:14 -04002721 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002722 * @dev: Pointer to class device object.
2723 * @buf: Data buffer.
2724 *
2725 * This function is the read call back function for
2726 * lpfc_stat_data_ctrl sysfs file. This function report the
2727 * current statistical data collection state.
2728 **/
2729static ssize_t
2730lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2731 char *buf)
2732{
2733 struct Scsi_Host *shost = class_to_shost(dev);
2734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2735 struct lpfc_hba *phba = vport->phba;
2736 int index = 0;
2737 int i;
2738 char *bucket_type;
2739 unsigned long bucket_value;
2740
2741 switch (phba->bucket_type) {
2742 case LPFC_LINEAR_BUCKET:
2743 bucket_type = "linear";
2744 break;
2745 case LPFC_POWER2_BUCKET:
2746 bucket_type = "power2";
2747 break;
2748 default:
2749 bucket_type = "No Bucket";
2750 break;
2751 }
2752
2753 sprintf(&buf[index], "Statistical Data enabled :%d, "
2754 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2755 " Bucket step :%d\nLatency Ranges :",
2756 vport->stat_data_enabled, vport->stat_data_blocked,
2757 bucket_type, phba->bucket_base, phba->bucket_step);
2758 index = strlen(buf);
2759 if (phba->bucket_type != LPFC_NO_BUCKET) {
2760 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2761 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2762 bucket_value = phba->bucket_base +
2763 phba->bucket_step * i;
2764 else
2765 bucket_value = phba->bucket_base +
2766 (1 << i) * phba->bucket_step;
2767
2768 if (index + 10 > PAGE_SIZE)
2769 break;
2770 sprintf(&buf[index], "%08ld ", bucket_value);
2771 index = strlen(buf);
2772 }
2773 }
2774 sprintf(&buf[index], "\n");
2775 return strlen(buf);
2776}
2777
2778/*
2779 * Sysfs attribute to control the statistical data collection.
2780 */
2781static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2782 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2783
2784/*
2785 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2786 */
2787
2788/*
2789 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2790 * for each target.
2791 */
2792#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2793#define MAX_STAT_DATA_SIZE_PER_TARGET \
2794 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2795
2796
2797/**
James Smart3621a712009-04-06 18:47:14 -04002798 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002799 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002800 * @kobj: Pointer to the kernel object
2801 * @bin_attr: Attribute object
2802 * @buff: Buffer pointer
2803 * @off: File offset
2804 * @count: Buffer size
2805 *
2806 * This function is the read call back function for lpfc_drvr_stat_data
2807 * sysfs file. This function export the statistical data to user
2808 * applications.
2809 **/
2810static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002811sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2812 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002813 char *buf, loff_t off, size_t count)
2814{
2815 struct device *dev = container_of(kobj, struct device,
2816 kobj);
2817 struct Scsi_Host *shost = class_to_shost(dev);
2818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2819 struct lpfc_hba *phba = vport->phba;
2820 int i = 0, index = 0;
2821 unsigned long nport_index;
2822 struct lpfc_nodelist *ndlp = NULL;
2823 nport_index = (unsigned long)off /
2824 MAX_STAT_DATA_SIZE_PER_TARGET;
2825
2826 if (!vport->stat_data_enabled || vport->stat_data_blocked
2827 || (phba->bucket_type == LPFC_NO_BUCKET))
2828 return 0;
2829
2830 spin_lock_irq(shost->host_lock);
2831 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2832 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2833 continue;
2834
2835 if (nport_index > 0) {
2836 nport_index--;
2837 continue;
2838 }
2839
2840 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2841 > count)
2842 break;
2843
2844 if (!ndlp->lat_data)
2845 continue;
2846
2847 /* Print the WWN */
2848 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2849 ndlp->nlp_portname.u.wwn[0],
2850 ndlp->nlp_portname.u.wwn[1],
2851 ndlp->nlp_portname.u.wwn[2],
2852 ndlp->nlp_portname.u.wwn[3],
2853 ndlp->nlp_portname.u.wwn[4],
2854 ndlp->nlp_portname.u.wwn[5],
2855 ndlp->nlp_portname.u.wwn[6],
2856 ndlp->nlp_portname.u.wwn[7]);
2857
2858 index = strlen(buf);
2859
2860 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2861 sprintf(&buf[index], "%010u,",
2862 ndlp->lat_data[i].cmd_count);
2863 index = strlen(buf);
2864 }
2865 sprintf(&buf[index], "\n");
2866 index = strlen(buf);
2867 }
2868 spin_unlock_irq(shost->host_lock);
2869 return index;
2870}
2871
2872static struct bin_attribute sysfs_drvr_stat_data_attr = {
2873 .attr = {
2874 .name = "lpfc_drvr_stat_data",
2875 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04002876 },
2877 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2878 .read = sysfs_drvr_stat_data_read,
2879 .write = NULL,
2880};
2881
dea31012005-04-17 16:05:31 -05002882/*
2883# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2884# connection.
James Smart76a95d72010-11-20 23:11:48 -05002885# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05002886*/
James Smarte59058c2008-08-24 21:49:00 -04002887/**
James Smart3621a712009-04-06 18:47:14 -04002888 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002889 * @phba: lpfc_hba pointer.
2890 * @val: link speed value.
2891 *
2892 * Description:
2893 * If val is in a valid range then set the adapter's link speed field and
2894 * issue a lip; if the lip fails reset the link speed to the old value.
2895 *
2896 * Notes:
2897 * If the value is not in range log a kernel error message and return an error.
2898 *
2899 * Returns:
2900 * zero if val is in range and lip okay.
2901 * non-zero return value from lpfc_issue_lip()
2902 * -EINVAL val out of range
2903 **/
James Smarta257bf92009-04-06 18:48:10 -04002904static ssize_t
2905lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2906 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002907{
James Smarta257bf92009-04-06 18:48:10 -04002908 struct Scsi_Host *shost = class_to_shost(dev);
2909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2910 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05002911 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04002912 int nolip = 0;
2913 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002914 int err;
2915 uint32_t prev_val;
2916
James Smarta257bf92009-04-06 18:48:10 -04002917 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2918 nolip = 1;
2919 val_buf = &buf[strlen("nolip ")];
2920 }
2921
2922 if (!isdigit(val_buf[0]))
2923 return -EINVAL;
2924 if (sscanf(val_buf, "%i", &val) != 1)
2925 return -EINVAL;
2926
James Smart76a95d72010-11-20 23:11:48 -05002927 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2928 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2929 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2930 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2931 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2932 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2934 "2879 lpfc_link_speed attribute cannot be set "
2935 "to %d. Speed is not supported by this port.\n",
2936 val);
James Smart83108bd2008-01-11 01:53:09 -05002937 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05002938 }
2939 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2940 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002941 prev_val = phba->cfg_link_speed;
2942 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002943 if (nolip)
2944 return strlen(buf);
2945
James Smart83108bd2008-01-11 01:53:09 -05002946 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002947 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002948 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002949 return -EINVAL;
2950 } else
2951 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002952 }
James Smart83108bd2008-01-11 01:53:09 -05002953 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05002954 "0469 lpfc_link_speed attribute cannot be set to %d, "
2955 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05002956 return -EINVAL;
2957}
2958
2959static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05002960module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002961MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2962lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002963
2964/**
James Smart3621a712009-04-06 18:47:14 -04002965 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002966 * @phba: lpfc_hba pointer.
2967 * @val: link speed value.
2968 *
2969 * Description:
2970 * If val is in a valid range then set the adapter's link speed field.
2971 *
2972 * Notes:
2973 * If the value is not in range log a kernel error message, clear the link
2974 * speed and return an error.
2975 *
2976 * Returns:
2977 * zero if val saved.
2978 * -EINVAL val out of range
2979 **/
James Smart83108bd2008-01-11 01:53:09 -05002980static int
2981lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2982{
James Smart76a95d72010-11-20 23:11:48 -05002983 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2984 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002985 phba->cfg_link_speed = val;
2986 return 0;
2987 }
2988 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002989 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002990 "be set to %d, allowed values are "
2991 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05002992 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05002993 return -EINVAL;
2994}
2995
Tony Jonesee959b02008-02-22 00:13:36 +01002996static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05002997 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002998
2999/*
James Smart0d878412009-10-02 15:16:56 -04003000# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3001# 0 = aer disabled or not supported
3002# 1 = aer supported and enabled (default)
3003# Value range is [0,1]. Default value is 1.
3004*/
3005
3006/**
3007 * lpfc_aer_support_store - Set the adapter for aer support
3008 *
3009 * @dev: class device that is converted into a Scsi_host.
3010 * @attr: device attribute, not used.
3011 * @buf: containing the string "selective".
3012 * @count: unused variable.
3013 *
3014 * Description:
3015 * If the val is 1 and currently the device's AER capability was not
3016 * enabled, invoke the kernel's enable AER helper routine, trying to
3017 * enable the device's AER capability. If the helper routine enabling
3018 * AER returns success, update the device's cfg_aer_support flag to
3019 * indicate AER is supported by the device; otherwise, if the device
3020 * AER capability is already enabled to support AER, then do nothing.
3021 *
3022 * If the val is 0 and currently the device's AER support was enabled,
3023 * invoke the kernel's disable AER helper routine. After that, update
3024 * the device's cfg_aer_support flag to indicate AER is not supported
3025 * by the device; otherwise, if the device AER capability is already
3026 * disabled from supporting AER, then do nothing.
3027 *
3028 * Returns:
3029 * length of the buf on success if val is in range the intended mode
3030 * is supported.
3031 * -EINVAL if val out of range or intended mode is not supported.
3032 **/
3033static ssize_t
3034lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3035 const char *buf, size_t count)
3036{
3037 struct Scsi_Host *shost = class_to_shost(dev);
3038 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3039 struct lpfc_hba *phba = vport->phba;
3040 int val = 0, rc = -EINVAL;
3041
3042 if (!isdigit(buf[0]))
3043 return -EINVAL;
3044 if (sscanf(buf, "%i", &val) != 1)
3045 return -EINVAL;
3046
3047 switch (val) {
3048 case 0:
3049 if (phba->hba_flag & HBA_AER_ENABLED) {
3050 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3051 if (!rc) {
3052 spin_lock_irq(&phba->hbalock);
3053 phba->hba_flag &= ~HBA_AER_ENABLED;
3054 spin_unlock_irq(&phba->hbalock);
3055 phba->cfg_aer_support = 0;
3056 rc = strlen(buf);
3057 } else
James Smart891478a2009-11-18 15:40:23 -05003058 rc = -EPERM;
3059 } else {
James Smart0d878412009-10-02 15:16:56 -04003060 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003061 rc = strlen(buf);
3062 }
James Smart0d878412009-10-02 15:16:56 -04003063 break;
3064 case 1:
3065 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3066 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3067 if (!rc) {
3068 spin_lock_irq(&phba->hbalock);
3069 phba->hba_flag |= HBA_AER_ENABLED;
3070 spin_unlock_irq(&phba->hbalock);
3071 phba->cfg_aer_support = 1;
3072 rc = strlen(buf);
3073 } else
James Smart891478a2009-11-18 15:40:23 -05003074 rc = -EPERM;
3075 } else {
James Smart0d878412009-10-02 15:16:56 -04003076 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003077 rc = strlen(buf);
3078 }
James Smart0d878412009-10-02 15:16:56 -04003079 break;
3080 default:
3081 rc = -EINVAL;
3082 break;
3083 }
3084 return rc;
3085}
3086
3087static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003088module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003089MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3090lpfc_param_show(aer_support)
3091
3092/**
3093 * lpfc_aer_support_init - Set the initial adapters aer support flag
3094 * @phba: lpfc_hba pointer.
3095 * @val: link speed value.
3096 *
3097 * Description:
3098 * If val is in a valid range [0,1], then set the adapter's initial
3099 * cfg_aer_support field. It will be up to the driver's probe_one
3100 * routine to determine whether the device's AER support can be set
3101 * or not.
3102 *
3103 * Notes:
3104 * If the value is not in range log a kernel error message, and
3105 * choose the default value of setting AER support and return.
3106 *
3107 * Returns:
3108 * zero if val saved.
3109 * -EINVAL val out of range
3110 **/
3111static int
3112lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3113{
3114 if (val == 0 || val == 1) {
3115 phba->cfg_aer_support = val;
3116 return 0;
3117 }
3118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3119 "2712 lpfc_aer_support attribute value %d out "
3120 "of range, allowed values are 0|1, setting it "
3121 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003122 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003123 phba->cfg_aer_support = 1;
3124 return -EINVAL;
3125}
3126
3127static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3128 lpfc_aer_support_show, lpfc_aer_support_store);
3129
3130/**
3131 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3132 * @dev: class device that is converted into a Scsi_host.
3133 * @attr: device attribute, not used.
3134 * @buf: containing the string "selective".
3135 * @count: unused variable.
3136 *
3137 * Description:
3138 * If the @buf contains 1 and the device currently has the AER support
3139 * enabled, then invokes the kernel AER helper routine
3140 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3141 * error status register.
3142 *
3143 * Notes:
3144 *
3145 * Returns:
3146 * -EINVAL if the buf does not contain the 1 or the device is not currently
3147 * enabled with the AER support.
3148 **/
3149static ssize_t
3150lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3151 const char *buf, size_t count)
3152{
3153 struct Scsi_Host *shost = class_to_shost(dev);
3154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3155 struct lpfc_hba *phba = vport->phba;
3156 int val, rc = -1;
3157
3158 if (!isdigit(buf[0]))
3159 return -EINVAL;
3160 if (sscanf(buf, "%i", &val) != 1)
3161 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003162 if (val != 1)
3163 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003164
James Smart891478a2009-11-18 15:40:23 -05003165 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003166 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3167
3168 if (rc == 0)
3169 return strlen(buf);
3170 else
James Smart891478a2009-11-18 15:40:23 -05003171 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003172}
3173
3174static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3175 lpfc_aer_cleanup_state);
3176
3177/*
dea31012005-04-17 16:05:31 -05003178# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3179# Value range is [2,3]. Default value is 3.
3180*/
James Smart3de2a652007-08-02 11:09:59 -04003181LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3182 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003183
3184/*
3185# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3186# is [0,1]. Default value is 0.
3187*/
James Smart3de2a652007-08-02 11:09:59 -04003188LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3189 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003190
3191/*
James Smart977b5a02008-09-07 11:52:04 -04003192# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3193# depth. Default value is 0. When the value of this parameter is zero the
3194# SCSI command completion time is not used for controlling I/O queue depth. When
3195# the parameter is set to a non-zero value, the I/O queue depth is controlled
3196# to limit the I/O completion time to the parameter value.
3197# The value is set in milliseconds.
3198*/
3199static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003200module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003201MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3202 "Use command completion time to control queue depth");
3203lpfc_vport_param_show(max_scsicmpl_time);
3204lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3205static int
3206lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3207{
3208 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3209 struct lpfc_nodelist *ndlp, *next_ndlp;
3210
3211 if (val == vport->cfg_max_scsicmpl_time)
3212 return 0;
3213 if ((val < 0) || (val > 60000))
3214 return -EINVAL;
3215 vport->cfg_max_scsicmpl_time = val;
3216
3217 spin_lock_irq(shost->host_lock);
3218 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3219 if (!NLP_CHK_NODE_ACT(ndlp))
3220 continue;
3221 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3222 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003223 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003224 }
3225 spin_unlock_irq(shost->host_lock);
3226 return 0;
3227}
3228lpfc_vport_param_store(max_scsicmpl_time);
3229static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3230 lpfc_max_scsicmpl_time_show,
3231 lpfc_max_scsicmpl_time_store);
3232
3233/*
dea31012005-04-17 16:05:31 -05003234# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3235# range is [0,1]. Default value is 0.
3236*/
3237LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3238
3239/*
3240# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3241# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003242# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003243# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3244# cr_delay is set to 0.
3245*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003246LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003247 "interrupt response is generated");
3248
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003249LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003250 "interrupt response is generated");
3251
3252/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003253# lpfc_multi_ring_support: Determines how many rings to spread available
3254# cmd/rsp IOCB entries across.
3255# Value range is [1,2]. Default value is 1.
3256*/
3257LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3258 "SLI rings to spread IOCB entries across");
3259
3260/*
James Smarta4bc3372006-12-02 13:34:16 -05003261# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3262# identifies what rctl value to configure the additional ring for.
3263# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3264*/
James Smart6a9c52c2009-10-02 15:16:51 -04003265LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003266 255, "Identifies RCTL for additional ring configuration");
3267
3268/*
3269# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3270# identifies what type value to configure the additional ring for.
3271# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3272*/
James Smart6a9c52c2009-10-02 15:16:51 -04003273LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003274 255, "Identifies TYPE for additional ring configuration");
3275
3276/*
dea31012005-04-17 16:05:31 -05003277# lpfc_fdmi_on: controls FDMI support.
3278# 0 = no FDMI support
3279# 1 = support FDMI without attribute of hostname
3280# 2 = support FDMI with attribute of hostname
3281# Value range [0,2]. Default value is 0.
3282*/
James Smart3de2a652007-08-02 11:09:59 -04003283LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003284
3285/*
3286# Specifies the maximum number of ELS cmds we can have outstanding (for
3287# discovery). Value range is [1,64]. Default value = 32.
3288*/
James Smart3de2a652007-08-02 11:09:59 -04003289LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003290 "during discovery");
3291
3292/*
James Smart65a29c12006-07-06 15:50:50 -04003293# lpfc_max_luns: maximum allowed LUN.
3294# Value range is [0,65535]. Default value is 255.
3295# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003296*/
James Smart3de2a652007-08-02 11:09:59 -04003297LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003298
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003299/*
3300# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3301# Value range is [1,255], default value is 10.
3302*/
3303LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3304 "Milliseconds driver will wait between polling FCP ring");
3305
James Smart4ff43242006-12-02 13:34:56 -05003306/*
3307# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3308# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003309# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003310# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003311# 2 = MSI-X enabled (default)
3312# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003313*/
George Kadianakis8605c462010-01-17 21:19:31 +02003314LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003315 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003316
James Smart13815c82008-01-11 01:52:48 -05003317/*
James Smartda0436e2009-05-22 14:51:39 -04003318# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3319#
3320# Value range is [636,651042]. Default value is 10000.
3321*/
3322LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3323 "Set the maximum number of fast-path FCP interrupts per second");
3324
3325/*
3326# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3327#
3328# Value range is [1,31]. Default value is 4.
3329*/
3330LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3331 "Set the number of fast-path FCP work queues, if possible");
3332
3333/*
3334# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3335#
3336# Value range is [1,7]. Default value is 1.
3337*/
3338LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3339 "Set the number of fast-path FCP event queues, if possible");
3340
3341/*
James Smart13815c82008-01-11 01:52:48 -05003342# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3343# 0 = HBA resets disabled
3344# 1 = HBA resets enabled (default)
3345# Value range is [0,1]. Default value is 1.
3346*/
3347LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003348
James Smart13815c82008-01-11 01:52:48 -05003349/*
James Smarteb7a3392010-11-20 23:12:02 -05003350# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003351# 0 = HBA Heartbeat disabled
3352# 1 = HBA Heartbeat enabled (default)
3353# Value range is [0,1]. Default value is 1.
3354*/
James Smarteb7a3392010-11-20 23:12:02 -05003355LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003356
James Smart83108bd2008-01-11 01:53:09 -05003357/*
James Smart81301a92008-12-04 22:39:46 -05003358# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3359# 0 = BlockGuard disabled (default)
3360# 1 = BlockGuard enabled
3361# Value range is [0,1]. Default value is 0.
3362*/
3363LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3364
James Smart6fb120a2009-05-22 14:52:59 -04003365/*
James Smart81301a92008-12-04 22:39:46 -05003366# lpfc_prot_mask: i
3367# - Bit mask of host protection capabilities used to register with the
3368# SCSI mid-layer
3369# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3370# - Allows you to ultimately specify which profiles to use
3371# - Default will result in registering capabilities for all profiles.
3372#
3373*/
James Smartbc739052010-08-04 16:11:18 -04003374unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003375
James Smartab56dc22011-02-16 12:39:57 -05003376module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003377MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3378
3379/*
3380# lpfc_prot_guard: i
3381# - Bit mask of protection guard types to register with the SCSI mid-layer
3382# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3383# - Allows you to ultimately specify which profiles to use
3384# - Default will result in registering capabilities for all guard types
3385#
3386*/
3387unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003388module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003389MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3390
James Smart92494142011-02-16 12:39:44 -05003391/*
3392 * Delay initial NPort discovery when Clean Address bit is cleared in
3393 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3394 * This parameter can have value 0 or 1.
3395 * When this parameter is set to 0, no delay is added to the initial
3396 * discovery.
3397 * When this parameter is set to non-zero value, initial Nport discovery is
3398 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3399 * accept and FCID/Fabric name/Fabric portname is changed.
3400 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3401 * when Clean Address bit is cleared in FLOGI/FDISC
3402 * accept and FCID/Fabric name/Fabric portname is changed.
3403 * Default value is 0.
3404 */
3405int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003406module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003407MODULE_PARM_DESC(lpfc_delay_discovery,
3408 "Delay NPort discovery when Clean Address bit is cleared. "
3409 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003410
3411/*
James Smart3621a712009-04-06 18:47:14 -04003412 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003413 * This value can be set to values between 64 and 256. The default value is
3414 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3415 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3416 */
3417LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3418 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3419
James Smart81301a92008-12-04 22:39:46 -05003420LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3421 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3422 "Max Protection Scatter Gather Segment Count");
3423
Tony Jonesee959b02008-02-22 00:13:36 +01003424struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003425 &dev_attr_bg_info,
3426 &dev_attr_bg_guard_err,
3427 &dev_attr_bg_apptag_err,
3428 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003429 &dev_attr_info,
3430 &dev_attr_serialnum,
3431 &dev_attr_modeldesc,
3432 &dev_attr_modelname,
3433 &dev_attr_programtype,
3434 &dev_attr_portnum,
3435 &dev_attr_fwrev,
3436 &dev_attr_hdw,
3437 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003438 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003439 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003440 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003441 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003442 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003443 &dev_attr_lpfc_temp_sensor,
3444 &dev_attr_lpfc_log_verbose,
3445 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003446 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003447 &dev_attr_lpfc_hba_queue_depth,
3448 &dev_attr_lpfc_peer_port_login,
3449 &dev_attr_lpfc_nodev_tmo,
3450 &dev_attr_lpfc_devloss_tmo,
3451 &dev_attr_lpfc_fcp_class,
3452 &dev_attr_lpfc_use_adisc,
3453 &dev_attr_lpfc_ack0,
3454 &dev_attr_lpfc_topology,
3455 &dev_attr_lpfc_scan_down,
3456 &dev_attr_lpfc_link_speed,
3457 &dev_attr_lpfc_cr_delay,
3458 &dev_attr_lpfc_cr_count,
3459 &dev_attr_lpfc_multi_ring_support,
3460 &dev_attr_lpfc_multi_ring_rctl,
3461 &dev_attr_lpfc_multi_ring_type,
3462 &dev_attr_lpfc_fdmi_on,
3463 &dev_attr_lpfc_max_luns,
3464 &dev_attr_lpfc_enable_npiv,
James Smart19ca7602010-11-20 23:11:55 -05003465 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003466 &dev_attr_nport_evt_cnt,
3467 &dev_attr_board_mode,
3468 &dev_attr_max_vpi,
3469 &dev_attr_used_vpi,
3470 &dev_attr_max_rpi,
3471 &dev_attr_used_rpi,
3472 &dev_attr_max_xri,
3473 &dev_attr_used_xri,
3474 &dev_attr_npiv_info,
3475 &dev_attr_issue_reset,
3476 &dev_attr_lpfc_poll,
3477 &dev_attr_lpfc_poll_tmo,
3478 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003479 &dev_attr_lpfc_fcp_imax,
3480 &dev_attr_lpfc_fcp_wq_count,
3481 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003482 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003483 &dev_attr_lpfc_soft_wwnn,
3484 &dev_attr_lpfc_soft_wwpn,
3485 &dev_attr_lpfc_soft_wwn_enable,
3486 &dev_attr_lpfc_enable_hba_reset,
3487 &dev_attr_lpfc_enable_hba_heartbeat,
3488 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003489 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003490 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003491 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003492 &dev_attr_lpfc_aer_support,
3493 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003494 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003495 &dev_attr_lpfc_iocb_cnt,
3496 &dev_attr_iocb_hw,
3497 &dev_attr_txq_hw,
3498 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003499 &dev_attr_lpfc_fips_level,
3500 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003501 &dev_attr_lpfc_dss,
dea31012005-04-17 16:05:31 -05003502 NULL,
3503};
3504
Tony Jonesee959b02008-02-22 00:13:36 +01003505struct device_attribute *lpfc_vport_attrs[] = {
3506 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003507 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003508 &dev_attr_num_discovered_ports,
3509 &dev_attr_lpfc_drvr_version,
3510 &dev_attr_lpfc_log_verbose,
3511 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003512 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003513 &dev_attr_lpfc_nodev_tmo,
3514 &dev_attr_lpfc_devloss_tmo,
3515 &dev_attr_lpfc_hba_queue_depth,
3516 &dev_attr_lpfc_peer_port_login,
3517 &dev_attr_lpfc_restrict_login,
3518 &dev_attr_lpfc_fcp_class,
3519 &dev_attr_lpfc_use_adisc,
3520 &dev_attr_lpfc_fdmi_on,
3521 &dev_attr_lpfc_max_luns,
3522 &dev_attr_nport_evt_cnt,
3523 &dev_attr_npiv_info,
3524 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003525 &dev_attr_lpfc_max_scsicmpl_time,
3526 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003527 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003528 &dev_attr_lpfc_fips_level,
3529 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003530 NULL,
3531};
3532
James Smarte59058c2008-08-24 21:49:00 -04003533/**
James Smart3621a712009-04-06 18:47:14 -04003534 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003535 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003536 * @kobj: kernel kobject that contains the kernel class device.
3537 * @bin_attr: kernel attributes passed to us.
3538 * @buf: contains the data to be written to the adapter IOREG space.
3539 * @off: offset into buffer to beginning of data.
3540 * @count: bytes to transfer.
3541 *
3542 * Description:
3543 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3544 * Uses the adapter io control registers to send buf contents to the adapter.
3545 *
3546 * Returns:
3547 * -ERANGE off and count combo out of range
3548 * -EINVAL off, count or buff address invalid
3549 * -EPERM adapter is offline
3550 * value of count, buf contents written
3551 **/
dea31012005-04-17 16:05:31 -05003552static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003553sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3554 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003555 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003556{
3557 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003558 struct device *dev = container_of(kobj, struct device, kobj);
3559 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3561 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003562
James Smartf1126682009-06-10 17:22:44 -04003563 if (phba->sli_rev >= LPFC_SLI_REV4)
3564 return -EPERM;
3565
dea31012005-04-17 16:05:31 -05003566 if ((off + count) > FF_REG_AREA_SIZE)
3567 return -ERANGE;
3568
3569 if (count == 0) return 0;
3570
3571 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3572 return -EINVAL;
3573
James Smart2e0fef82007-06-17 19:56:36 -05003574 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003575 return -EPERM;
3576 }
3577
James Smart2e0fef82007-06-17 19:56:36 -05003578 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003579 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3580 writel(*((uint32_t *)(buf + buf_off)),
3581 phba->ctrl_regs_memmap_p + off + buf_off);
3582
James Smart2e0fef82007-06-17 19:56:36 -05003583 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003584
3585 return count;
3586}
3587
James Smarte59058c2008-08-24 21:49:00 -04003588/**
James Smart3621a712009-04-06 18:47:14 -04003589 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003590 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003591 * @kobj: kernel kobject that contains the kernel class device.
3592 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003593 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003594 * @off: offset into buffer to beginning of data.
3595 * @count: bytes to transfer.
3596 *
3597 * Description:
3598 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3599 * Uses the adapter io control registers to read data into buf.
3600 *
3601 * Returns:
3602 * -ERANGE off and count combo out of range
3603 * -EINVAL off, count or buff address invalid
3604 * value of count, buf contents read
3605 **/
dea31012005-04-17 16:05:31 -05003606static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003607sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3608 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003609 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003610{
3611 size_t buf_off;
3612 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003613 struct device *dev = container_of(kobj, struct device, kobj);
3614 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3616 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003617
James Smartf1126682009-06-10 17:22:44 -04003618 if (phba->sli_rev >= LPFC_SLI_REV4)
3619 return -EPERM;
3620
dea31012005-04-17 16:05:31 -05003621 if (off > FF_REG_AREA_SIZE)
3622 return -ERANGE;
3623
3624 if ((off + count) > FF_REG_AREA_SIZE)
3625 count = FF_REG_AREA_SIZE - off;
3626
3627 if (count == 0) return 0;
3628
3629 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3630 return -EINVAL;
3631
James Smart2e0fef82007-06-17 19:56:36 -05003632 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003633
3634 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3635 tmp_ptr = (uint32_t *)(buf + buf_off);
3636 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3637 }
3638
James Smart2e0fef82007-06-17 19:56:36 -05003639 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003640
3641 return count;
3642}
3643
3644static struct bin_attribute sysfs_ctlreg_attr = {
3645 .attr = {
3646 .name = "ctlreg",
3647 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003648 },
3649 .size = 256,
3650 .read = sysfs_ctlreg_read,
3651 .write = sysfs_ctlreg_write,
3652};
3653
James Smarte59058c2008-08-24 21:49:00 -04003654/**
James Smart3621a712009-04-06 18:47:14 -04003655 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003656 * @phba: lpfc_hba pointer
3657 **/
dea31012005-04-17 16:05:31 -05003658static void
James Smart2e0fef82007-06-17 19:56:36 -05003659sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003660{
3661 phba->sysfs_mbox.state = SMBOX_IDLE;
3662 phba->sysfs_mbox.offset = 0;
3663
3664 if (phba->sysfs_mbox.mbox) {
3665 mempool_free(phba->sysfs_mbox.mbox,
3666 phba->mbox_mem_pool);
3667 phba->sysfs_mbox.mbox = NULL;
3668 }
3669}
3670
James Smarte59058c2008-08-24 21:49:00 -04003671/**
James Smart3621a712009-04-06 18:47:14 -04003672 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003673 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003674 * @kobj: kernel kobject that contains the kernel class device.
3675 * @bin_attr: kernel attributes passed to us.
3676 * @buf: contains the data to be written to sysfs mbox.
3677 * @off: offset into buffer to beginning of data.
3678 * @count: bytes to transfer.
3679 *
3680 * Description:
3681 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3682 * Uses the sysfs mbox to send buf contents to the adapter.
3683 *
3684 * Returns:
3685 * -ERANGE off and count combo out of range
3686 * -EINVAL off, count or buff address invalid
3687 * zero if count is zero
3688 * -EPERM adapter is offline
3689 * -ENOMEM failed to allocate memory for the mail box
3690 * -EAGAIN offset, state or mbox is NULL
3691 * count number of bytes transferred
3692 **/
dea31012005-04-17 16:05:31 -05003693static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003694sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3695 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003696 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003697{
Tony Jonesee959b02008-02-22 00:13:36 +01003698 struct device *dev = container_of(kobj, struct device, kobj);
3699 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003700 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3701 struct lpfc_hba *phba = vport->phba;
3702 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003703
3704 if ((count + off) > MAILBOX_CMD_SIZE)
3705 return -ERANGE;
3706
3707 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3708 return -EINVAL;
3709
3710 if (count == 0)
3711 return 0;
3712
3713 if (off == 0) {
3714 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3715 if (!mbox)
3716 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003717 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003718 }
3719
James Smart2e0fef82007-06-17 19:56:36 -05003720 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003721
3722 if (off == 0) {
3723 if (phba->sysfs_mbox.mbox)
3724 mempool_free(mbox, phba->mbox_mem_pool);
3725 else
3726 phba->sysfs_mbox.mbox = mbox;
3727 phba->sysfs_mbox.state = SMBOX_WRITING;
3728 } else {
3729 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3730 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003731 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003732 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003733 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003734 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003735 }
3736 }
3737
James Smart04c68492009-05-22 14:52:52 -04003738 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003739 buf, count);
3740
3741 phba->sysfs_mbox.offset = off + count;
3742
James Smart2e0fef82007-06-17 19:56:36 -05003743 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003744
3745 return count;
3746}
3747
James Smarte59058c2008-08-24 21:49:00 -04003748/**
James Smart3621a712009-04-06 18:47:14 -04003749 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003750 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003751 * @kobj: kernel kobject that contains the kernel class device.
3752 * @bin_attr: kernel attributes passed to us.
3753 * @buf: contains the data to be read from sysfs mbox.
3754 * @off: offset into buffer to beginning of data.
3755 * @count: bytes to transfer.
3756 *
3757 * Description:
3758 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3759 * Uses the sysfs mbox to receive data from to the adapter.
3760 *
3761 * Returns:
3762 * -ERANGE off greater than mailbox command size
3763 * -EINVAL off, count or buff address invalid
3764 * zero if off and count are zero
3765 * -EACCES adapter over temp
3766 * -EPERM garbage can value to catch a multitude of errors
3767 * -EAGAIN management IO not permitted, state or off error
3768 * -ETIME mailbox timeout
3769 * -ENODEV mailbox error
3770 * count number of bytes transferred
3771 **/
dea31012005-04-17 16:05:31 -05003772static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003773sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3774 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003775 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003776{
Tony Jonesee959b02008-02-22 00:13:36 +01003777 struct device *dev = container_of(kobj, struct device, kobj);
3778 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003779 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3780 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003781 int rc;
James Smart04c68492009-05-22 14:52:52 -04003782 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003783
James Smart1dcb58e2007-04-25 09:51:30 -04003784 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003785 return -ERANGE;
3786
James Smart1dcb58e2007-04-25 09:51:30 -04003787 if ((count + off) > MAILBOX_CMD_SIZE)
3788 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003789
3790 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3791 return -EINVAL;
3792
3793 if (off && count == 0)
3794 return 0;
3795
James Smart2e0fef82007-06-17 19:56:36 -05003796 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003797
James Smart7af67052007-10-27 13:38:11 -04003798 if (phba->over_temp_state == HBA_OVER_TEMP) {
3799 sysfs_mbox_idle(phba);
3800 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003801 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003802 }
3803
dea31012005-04-17 16:05:31 -05003804 if (off == 0 &&
3805 phba->sysfs_mbox.state == SMBOX_WRITING &&
3806 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003807 pmb = &phba->sysfs_mbox.mbox->u.mb;
3808 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003809 /* Offline only */
dea31012005-04-17 16:05:31 -05003810 case MBX_INIT_LINK:
3811 case MBX_DOWN_LINK:
3812 case MBX_CONFIG_LINK:
3813 case MBX_CONFIG_RING:
3814 case MBX_RESET_RING:
3815 case MBX_UNREG_LOGIN:
3816 case MBX_CLEAR_LA:
3817 case MBX_DUMP_CONTEXT:
3818 case MBX_RUN_DIAGS:
3819 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003820 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003821 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003822 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003823 printk(KERN_WARNING "mbox_read:Command 0x%x "
3824 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003825 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003826 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003827 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003828 return -EPERM;
3829 }
James Smarta8adb832007-10-27 13:37:53 -04003830 case MBX_WRITE_NV:
3831 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003832 case MBX_LOAD_SM:
3833 case MBX_READ_NV:
3834 case MBX_READ_CONFIG:
3835 case MBX_READ_RCONFIG:
3836 case MBX_READ_STATUS:
3837 case MBX_READ_XRI:
3838 case MBX_READ_REV:
3839 case MBX_READ_LNK_STAT:
3840 case MBX_DUMP_MEMORY:
3841 case MBX_DOWN_LOAD:
3842 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003843 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003844 case MBX_LOAD_AREA:
3845 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003846 case MBX_BEACON:
3847 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003848 case MBX_SET_VARIABLE:
3849 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003850 case MBX_PORT_CAPABILITIES:
3851 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003852 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04003853 case MBX_SECURITY_MGMT:
3854 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04003855 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3856 printk(KERN_WARNING "mbox_read:Command 0x%x "
3857 "is not permitted\n", pmb->mbxCommand);
3858 sysfs_mbox_idle(phba);
3859 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04003860 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04003861 }
James Smartdcf2a4e2010-09-29 11:18:53 -04003862 break;
dea31012005-04-17 16:05:31 -05003863 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05003864 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05003865 case MBX_REG_LOGIN:
3866 case MBX_REG_LOGIN64:
3867 case MBX_CONFIG_PORT:
3868 case MBX_RUN_BIU_DIAG:
3869 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003870 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003871 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003872 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003873 return -EPERM;
3874 default:
3875 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003876 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003877 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003878 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003879 return -EPERM;
3880 }
3881
James Smart09372822008-01-11 01:52:54 -05003882 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003883 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003884 */
James Smartd7c255b2008-08-24 21:50:00 -04003885 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003886 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3887 pmb->mbxCommand != MBX_RESTART &&
3888 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3889 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003890 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3891 "1259 mbox: Issued mailbox cmd "
3892 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003893 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003894
James Smart92d7f7b2007-06-17 19:56:38 -05003895 phba->sysfs_mbox.mbox->vport = vport;
3896
James Smart58da1ff2008-04-07 10:15:56 -04003897 /* Don't allow mailbox commands to be sent when blocked
3898 * or when in the middle of discovery
3899 */
James Smart495a7142008-06-14 22:52:59 -04003900 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003901 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003902 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003903 return -EAGAIN;
3904 }
3905
James Smart2e0fef82007-06-17 19:56:36 -05003906 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003907 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003908
James Smart2e0fef82007-06-17 19:56:36 -05003909 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003910 rc = lpfc_sli_issue_mbox (phba,
3911 phba->sysfs_mbox.mbox,
3912 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003913 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003914
3915 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003916 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003917 rc = lpfc_sli_issue_mbox_wait (phba,
3918 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003919 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003920 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003921 }
3922
3923 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003924 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003925 phba->sysfs_mbox.mbox = NULL;
3926 }
dea31012005-04-17 16:05:31 -05003927 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003928 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003929 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003930 }
3931 phba->sysfs_mbox.state = SMBOX_READING;
3932 }
3933 else if (phba->sysfs_mbox.offset != off ||
3934 phba->sysfs_mbox.state != SMBOX_READING) {
3935 printk(KERN_WARNING "mbox_read: Bad State\n");
3936 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003937 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003938 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003939 }
3940
James Smart04c68492009-05-22 14:52:52 -04003941 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003942
3943 phba->sysfs_mbox.offset = off + count;
3944
James Smart1dcb58e2007-04-25 09:51:30 -04003945 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003946 sysfs_mbox_idle(phba);
3947
James Smart2e0fef82007-06-17 19:56:36 -05003948 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003949
3950 return count;
3951}
3952
3953static struct bin_attribute sysfs_mbox_attr = {
3954 .attr = {
3955 .name = "mbox",
3956 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003957 },
James Smart1dcb58e2007-04-25 09:51:30 -04003958 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003959 .read = sysfs_mbox_read,
3960 .write = sysfs_mbox_write,
3961};
3962
James Smarte59058c2008-08-24 21:49:00 -04003963/**
James Smart3621a712009-04-06 18:47:14 -04003964 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003965 * @vport: address of lpfc vport structure.
3966 *
3967 * Return codes:
3968 * zero on success
3969 * error return code from sysfs_create_bin_file()
3970 **/
dea31012005-04-17 16:05:31 -05003971int
James Smart2e0fef82007-06-17 19:56:36 -05003972lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003973{
James Smart2e0fef82007-06-17 19:56:36 -05003974 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003975 int error;
3976
Tony Jonesee959b02008-02-22 00:13:36 +01003977 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003978 &sysfs_drvr_stat_data_attr);
3979
3980 /* Virtual ports do not need ctrl_reg and mbox */
3981 if (error || vport->port_type == LPFC_NPIV_PORT)
3982 goto out;
3983
3984 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003985 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003986 if (error)
James Smarteada2722008-12-04 22:39:13 -05003987 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003988
Tony Jonesee959b02008-02-22 00:13:36 +01003989 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003990 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003991 if (error)
3992 goto out_remove_ctlreg_attr;
3993
3994 return 0;
3995out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003996 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003997out_remove_stat_attr:
3998 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3999 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004000out:
4001 return error;
4002}
4003
James Smarte59058c2008-08-24 21:49:00 -04004004/**
James Smart3621a712009-04-06 18:47:14 -04004005 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004006 * @vport: address of lpfc vport structure.
4007 **/
dea31012005-04-17 16:05:31 -05004008void
James Smart2e0fef82007-06-17 19:56:36 -05004009lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004010{
James Smart2e0fef82007-06-17 19:56:36 -05004011 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004012 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4013 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004014 /* Virtual ports do not need ctrl_reg and mbox */
4015 if (vport->port_type == LPFC_NPIV_PORT)
4016 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004017 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4018 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004019}
4020
4021
4022/*
4023 * Dynamic FC Host Attributes Support
4024 */
4025
James Smarte59058c2008-08-24 21:49:00 -04004026/**
James Smart3621a712009-04-06 18:47:14 -04004027 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004028 * @shost: kernel scsi host pointer.
4029 **/
dea31012005-04-17 16:05:31 -05004030static void
4031lpfc_get_host_port_id(struct Scsi_Host *shost)
4032{
James Smart2e0fef82007-06-17 19:56:36 -05004033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4034
dea31012005-04-17 16:05:31 -05004035 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004036 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004037}
4038
James Smarte59058c2008-08-24 21:49:00 -04004039/**
James Smart3621a712009-04-06 18:47:14 -04004040 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004041 * @shost: kernel scsi host pointer.
4042 **/
dea31012005-04-17 16:05:31 -05004043static void
4044lpfc_get_host_port_type(struct Scsi_Host *shost)
4045{
James Smart2e0fef82007-06-17 19:56:36 -05004046 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4047 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004048
4049 spin_lock_irq(shost->host_lock);
4050
James Smart92d7f7b2007-06-17 19:56:38 -05004051 if (vport->port_type == LPFC_NPIV_PORT) {
4052 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4053 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004054 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004055 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004056 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4057 else
4058 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4059 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004060 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004061 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4062 else
4063 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4064 }
4065 } else
4066 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4067
4068 spin_unlock_irq(shost->host_lock);
4069}
4070
James Smarte59058c2008-08-24 21:49:00 -04004071/**
James Smart3621a712009-04-06 18:47:14 -04004072 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004073 * @shost: kernel scsi host pointer.
4074 **/
dea31012005-04-17 16:05:31 -05004075static void
4076lpfc_get_host_port_state(struct Scsi_Host *shost)
4077{
James Smart2e0fef82007-06-17 19:56:36 -05004078 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4079 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004080
4081 spin_lock_irq(shost->host_lock);
4082
James Smart2e0fef82007-06-17 19:56:36 -05004083 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004084 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4085 else {
James Smart2e0fef82007-06-17 19:56:36 -05004086 switch (phba->link_state) {
4087 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004088 case LPFC_LINK_DOWN:
4089 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4090 break;
4091 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004092 case LPFC_CLEAR_LA:
4093 case LPFC_HBA_READY:
4094 /* Links up, beyond this port_type reports state */
4095 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4096 break;
4097 case LPFC_HBA_ERROR:
4098 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4099 break;
4100 default:
4101 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4102 break;
4103 }
4104 }
4105
4106 spin_unlock_irq(shost->host_lock);
4107}
4108
James Smarte59058c2008-08-24 21:49:00 -04004109/**
James Smart3621a712009-04-06 18:47:14 -04004110 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004111 * @shost: kernel scsi host pointer.
4112 **/
dea31012005-04-17 16:05:31 -05004113static void
4114lpfc_get_host_speed(struct Scsi_Host *shost)
4115{
James Smart2e0fef82007-06-17 19:56:36 -05004116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4117 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004118
4119 spin_lock_irq(shost->host_lock);
4120
James Smart2e0fef82007-06-17 19:56:36 -05004121 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004122 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004123 case LPFC_LINK_SPEED_1GHZ:
4124 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004125 break;
James Smart76a95d72010-11-20 23:11:48 -05004126 case LPFC_LINK_SPEED_2GHZ:
4127 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004128 break;
James Smart76a95d72010-11-20 23:11:48 -05004129 case LPFC_LINK_SPEED_4GHZ:
4130 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004131 break;
James Smart76a95d72010-11-20 23:11:48 -05004132 case LPFC_LINK_SPEED_8GHZ:
4133 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004134 break;
James Smart76a95d72010-11-20 23:11:48 -05004135 case LPFC_LINK_SPEED_10GHZ:
4136 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004137 break;
James Smart76a95d72010-11-20 23:11:48 -05004138 case LPFC_LINK_SPEED_16GHZ:
4139 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4140 break;
4141 default:
4142 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004143 break;
4144 }
James Smart09372822008-01-11 01:52:54 -05004145 } else
4146 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004147
4148 spin_unlock_irq(shost->host_lock);
4149}
4150
James Smarte59058c2008-08-24 21:49:00 -04004151/**
James Smart3621a712009-04-06 18:47:14 -04004152 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004153 * @shost: kernel scsi host pointer.
4154 **/
dea31012005-04-17 16:05:31 -05004155static void
4156lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4157{
James Smart2e0fef82007-06-17 19:56:36 -05004158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4159 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004160 u64 node_name;
dea31012005-04-17 16:05:31 -05004161
4162 spin_lock_irq(shost->host_lock);
4163
James Smart2e0fef82007-06-17 19:56:36 -05004164 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004165 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004166 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004167 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004168 else
4169 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004170 node_name = 0;
dea31012005-04-17 16:05:31 -05004171
4172 spin_unlock_irq(shost->host_lock);
4173
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004174 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004175}
4176
James Smarte59058c2008-08-24 21:49:00 -04004177/**
James Smart3621a712009-04-06 18:47:14 -04004178 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004179 * @shost: kernel scsi host pointer.
4180 *
4181 * Notes:
4182 * NULL on error for link down, no mbox pool, sli2 active,
4183 * management not allowed, memory allocation error, or mbox error.
4184 *
4185 * Returns:
4186 * NULL for error
4187 * address of the adapter host statistics
4188 **/
dea31012005-04-17 16:05:31 -05004189static struct fc_host_statistics *
4190lpfc_get_stats(struct Scsi_Host *shost)
4191{
James Smart2e0fef82007-06-17 19:56:36 -05004192 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4193 struct lpfc_hba *phba = vport->phba;
4194 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004195 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004196 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004197 LPFC_MBOXQ_t *pmboxq;
4198 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004199 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004200 int rc = 0;
dea31012005-04-17 16:05:31 -05004201
James Smart92d7f7b2007-06-17 19:56:38 -05004202 /*
4203 * prevent udev from issuing mailbox commands until the port is
4204 * configured.
4205 */
James Smart2e0fef82007-06-17 19:56:36 -05004206 if (phba->link_state < LPFC_LINK_DOWN ||
4207 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004208 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004209 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004210
4211 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004212 return NULL;
4213
dea31012005-04-17 16:05:31 -05004214 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4215 if (!pmboxq)
4216 return NULL;
4217 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4218
James Smart04c68492009-05-22 14:52:52 -04004219 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004220 pmb->mbxCommand = MBX_READ_STATUS;
4221 pmb->mbxOwner = OWN_HOST;
4222 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004223 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004224
James Smart75baf692010-06-08 18:31:21 -04004225 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004226 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004227 else
dea31012005-04-17 16:05:31 -05004228 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4229
4230 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004231 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004232 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004233 return NULL;
4234 }
4235
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004236 memset(hs, 0, sizeof (struct fc_host_statistics));
4237
dea31012005-04-17 16:05:31 -05004238 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4239 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4240 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4241 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4242
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004243 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004244 pmb->mbxCommand = MBX_READ_LNK_STAT;
4245 pmb->mbxOwner = OWN_HOST;
4246 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004247 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004248
James Smart75baf692010-06-08 18:31:21 -04004249 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004250 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004251 else
dea31012005-04-17 16:05:31 -05004252 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4253
4254 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004255 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004256 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004257 return NULL;
4258 }
4259
4260 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4261 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4262 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4263 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4264 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4265 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4266 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4267
James Smart64ba8812006-08-02 15:24:34 -04004268 hs->link_failure_count -= lso->link_failure_count;
4269 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4270 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4271 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4272 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4273 hs->invalid_crc_count -= lso->invalid_crc_count;
4274 hs->error_frames -= lso->error_frames;
4275
James Smart76a95d72010-11-20 23:11:48 -05004276 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004277 hs->lip_count = -1;
4278 hs->nos_count = (phba->link_events >> 1);
4279 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004280 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004281 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004282 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004283 hs->nos_count = -1;
4284 } else {
4285 hs->lip_count = -1;
4286 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004287 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004288 }
4289
4290 hs->dumped_frames = -1;
4291
James Smart64ba8812006-08-02 15:24:34 -04004292 seconds = get_seconds();
4293 if (seconds < psli->stats_start)
4294 hs->seconds_since_last_reset = seconds +
4295 ((unsigned long)-1 - psli->stats_start);
4296 else
4297 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004298
James Smart1dcb58e2007-04-25 09:51:30 -04004299 mempool_free(pmboxq, phba->mbox_mem_pool);
4300
dea31012005-04-17 16:05:31 -05004301 return hs;
4302}
4303
James Smarte59058c2008-08-24 21:49:00 -04004304/**
James Smart3621a712009-04-06 18:47:14 -04004305 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004306 * @shost: kernel scsi host pointer.
4307 **/
James Smart64ba8812006-08-02 15:24:34 -04004308static void
4309lpfc_reset_stats(struct Scsi_Host *shost)
4310{
James Smart2e0fef82007-06-17 19:56:36 -05004311 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4312 struct lpfc_hba *phba = vport->phba;
4313 struct lpfc_sli *psli = &phba->sli;
4314 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004315 LPFC_MBOXQ_t *pmboxq;
4316 MAILBOX_t *pmb;
4317 int rc = 0;
4318
James Smart2e0fef82007-06-17 19:56:36 -05004319 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004320 return;
4321
James Smart64ba8812006-08-02 15:24:34 -04004322 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4323 if (!pmboxq)
4324 return;
4325 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4326
James Smart04c68492009-05-22 14:52:52 -04004327 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004328 pmb->mbxCommand = MBX_READ_STATUS;
4329 pmb->mbxOwner = OWN_HOST;
4330 pmb->un.varWords[0] = 0x1; /* reset request */
4331 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004332 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004333
James Smart2e0fef82007-06-17 19:56:36 -05004334 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004335 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004336 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4337 else
4338 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4339
4340 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004341 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004342 mempool_free(pmboxq, phba->mbox_mem_pool);
4343 return;
4344 }
4345
4346 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4347 pmb->mbxCommand = MBX_READ_LNK_STAT;
4348 pmb->mbxOwner = OWN_HOST;
4349 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004350 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004351
James Smart2e0fef82007-06-17 19:56:36 -05004352 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004353 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004354 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4355 else
4356 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4357
4358 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004359 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004360 mempool_free( pmboxq, phba->mbox_mem_pool);
4361 return;
4362 }
4363
4364 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4365 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4366 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4367 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4368 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4369 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4370 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004371 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004372 lso->link_events = (phba->link_events >> 1);
4373 else
4374 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004375
4376 psli->stats_start = get_seconds();
4377
James Smart1dcb58e2007-04-25 09:51:30 -04004378 mempool_free(pmboxq, phba->mbox_mem_pool);
4379
James Smart64ba8812006-08-02 15:24:34 -04004380 return;
4381}
dea31012005-04-17 16:05:31 -05004382
4383/*
4384 * The LPFC driver treats linkdown handling as target loss events so there
4385 * are no sysfs handlers for link_down_tmo.
4386 */
James Smart685f0bf2007-04-25 09:53:08 -04004387
James Smarte59058c2008-08-24 21:49:00 -04004388/**
James Smart3621a712009-04-06 18:47:14 -04004389 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004390 * @starget: kernel scsi target pointer.
4391 *
4392 * Returns:
4393 * address of the node list if found
4394 * NULL target not found
4395 **/
James Smart685f0bf2007-04-25 09:53:08 -04004396static struct lpfc_nodelist *
4397lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004398{
James Smart2e0fef82007-06-17 19:56:36 -05004399 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4400 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004401 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004402
4403 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004404 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004405 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004406 if (NLP_CHK_NODE_ACT(ndlp) &&
4407 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004408 starget->id == ndlp->nlp_sid) {
4409 spin_unlock_irq(shost->host_lock);
4410 return ndlp;
dea31012005-04-17 16:05:31 -05004411 }
4412 }
4413 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004414 return NULL;
4415}
dea31012005-04-17 16:05:31 -05004416
James Smarte59058c2008-08-24 21:49:00 -04004417/**
James Smart3621a712009-04-06 18:47:14 -04004418 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004419 * @starget: kernel scsi target pointer.
4420 **/
James Smart685f0bf2007-04-25 09:53:08 -04004421static void
4422lpfc_get_starget_port_id(struct scsi_target *starget)
4423{
4424 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4425
4426 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004427}
4428
James Smarte59058c2008-08-24 21:49:00 -04004429/**
James Smart3621a712009-04-06 18:47:14 -04004430 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004431 * @starget: kernel scsi target pointer.
4432 *
4433 * Description: Set the target node name to the ndlp node name wwn or zero.
4434 **/
dea31012005-04-17 16:05:31 -05004435static void
4436lpfc_get_starget_node_name(struct scsi_target *starget)
4437{
James Smart685f0bf2007-04-25 09:53:08 -04004438 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004439
James Smart685f0bf2007-04-25 09:53:08 -04004440 fc_starget_node_name(starget) =
4441 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004442}
4443
James Smarte59058c2008-08-24 21:49:00 -04004444/**
James Smart3621a712009-04-06 18:47:14 -04004445 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004446 * @starget: kernel scsi target pointer.
4447 *
4448 * Description: set the target port name to the ndlp port name wwn or zero.
4449 **/
dea31012005-04-17 16:05:31 -05004450static void
4451lpfc_get_starget_port_name(struct scsi_target *starget)
4452{
James Smart685f0bf2007-04-25 09:53:08 -04004453 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004454
James Smart685f0bf2007-04-25 09:53:08 -04004455 fc_starget_port_name(starget) =
4456 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004457}
4458
James Smarte59058c2008-08-24 21:49:00 -04004459/**
James Smart3621a712009-04-06 18:47:14 -04004460 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004461 * @rport: fc rport address.
4462 * @timeout: new value for dev loss tmo.
4463 *
4464 * Description:
4465 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4466 * dev_loss_tmo to one.
4467 **/
dea31012005-04-17 16:05:31 -05004468static void
dea31012005-04-17 16:05:31 -05004469lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4470{
dea31012005-04-17 16:05:31 -05004471 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004472 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004473 else
James Smartc01f3202006-08-18 17:47:08 -04004474 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004475}
4476
James Smarte59058c2008-08-24 21:49:00 -04004477/**
James Smart3621a712009-04-06 18:47:14 -04004478 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004479 *
4480 * Description:
4481 * Macro that uses field to generate a function with the name lpfc_show_rport_
4482 *
4483 * lpfc_show_rport_##field: returns the bytes formatted in buf
4484 * @cdev: class converted to an fc_rport.
4485 * @buf: on return contains the target_field or zero.
4486 *
4487 * Returns: size of formatted string.
4488 **/
dea31012005-04-17 16:05:31 -05004489#define lpfc_rport_show_function(field, format_string, sz, cast) \
4490static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004491lpfc_show_rport_##field (struct device *dev, \
4492 struct device_attribute *attr, \
4493 char *buf) \
dea31012005-04-17 16:05:31 -05004494{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004495 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004496 struct lpfc_rport_data *rdata = rport->hostdata; \
4497 return snprintf(buf, sz, format_string, \
4498 (rdata->target) ? cast rdata->target->field : 0); \
4499}
4500
4501#define lpfc_rport_rd_attr(field, format_string, sz) \
4502 lpfc_rport_show_function(field, format_string, sz, ) \
4503static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4504
James Smarteada2722008-12-04 22:39:13 -05004505/**
James Smart3621a712009-04-06 18:47:14 -04004506 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004507 * @fc_vport: The fc_vport who's symbolic name has been changed.
4508 *
4509 * Description:
4510 * This function is called by the transport after the @fc_vport's symbolic name
4511 * has been changed. This function re-registers the symbolic name with the
4512 * switch to propogate the change into the fabric if the vport is active.
4513 **/
4514static void
4515lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4516{
4517 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4518
4519 if (vport->port_state == LPFC_VPORT_READY)
4520 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4521}
dea31012005-04-17 16:05:31 -05004522
James Smartf4b4c682009-05-22 14:53:12 -04004523/**
4524 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4525 * @phba: Pointer to lpfc_hba struct.
4526 *
4527 * This function is called by the lpfc_get_cfgparam() routine to set the
4528 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4529 * log messsage according to the module's lpfc_log_verbose parameter setting
4530 * before hba port or vport created.
4531 **/
4532static void
4533lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4534{
4535 phba->cfg_log_verbose = verbose;
4536}
4537
dea31012005-04-17 16:05:31 -05004538struct fc_function_template lpfc_transport_functions = {
4539 /* fixed attributes the driver supports */
4540 .show_host_node_name = 1,
4541 .show_host_port_name = 1,
4542 .show_host_supported_classes = 1,
4543 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004544 .show_host_supported_speeds = 1,
4545 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004546 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004547
4548 /* dynamic attributes the driver supports */
4549 .get_host_port_id = lpfc_get_host_port_id,
4550 .show_host_port_id = 1,
4551
4552 .get_host_port_type = lpfc_get_host_port_type,
4553 .show_host_port_type = 1,
4554
4555 .get_host_port_state = lpfc_get_host_port_state,
4556 .show_host_port_state = 1,
4557
4558 /* active_fc4s is shown but doesn't change (thus no get function) */
4559 .show_host_active_fc4s = 1,
4560
4561 .get_host_speed = lpfc_get_host_speed,
4562 .show_host_speed = 1,
4563
4564 .get_host_fabric_name = lpfc_get_host_fabric_name,
4565 .show_host_fabric_name = 1,
4566
4567 /*
4568 * The LPFC driver treats linkdown handling as target loss events
4569 * so there are no sysfs handlers for link_down_tmo.
4570 */
4571
4572 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004573 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004574
4575 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4576 .show_rport_maxframe_size = 1,
4577 .show_rport_supported_classes = 1,
4578
dea31012005-04-17 16:05:31 -05004579 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4580 .show_rport_dev_loss_tmo = 1,
4581
4582 .get_starget_port_id = lpfc_get_starget_port_id,
4583 .show_starget_port_id = 1,
4584
4585 .get_starget_node_name = lpfc_get_starget_node_name,
4586 .show_starget_node_name = 1,
4587
4588 .get_starget_port_name = lpfc_get_starget_port_name,
4589 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004590
4591 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004592 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4593 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004594
James Smart92d7f7b2007-06-17 19:56:38 -05004595 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004596
4597 .vport_disable = lpfc_vport_disable,
4598
4599 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004600
4601 .bsg_request = lpfc_bsg_request,
4602 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004603};
4604
James Smart98c9ea52007-10-27 13:37:33 -04004605struct fc_function_template lpfc_vport_transport_functions = {
4606 /* fixed attributes the driver supports */
4607 .show_host_node_name = 1,
4608 .show_host_port_name = 1,
4609 .show_host_supported_classes = 1,
4610 .show_host_supported_fc4s = 1,
4611 .show_host_supported_speeds = 1,
4612 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004613 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004614
4615 /* dynamic attributes the driver supports */
4616 .get_host_port_id = lpfc_get_host_port_id,
4617 .show_host_port_id = 1,
4618
4619 .get_host_port_type = lpfc_get_host_port_type,
4620 .show_host_port_type = 1,
4621
4622 .get_host_port_state = lpfc_get_host_port_state,
4623 .show_host_port_state = 1,
4624
4625 /* active_fc4s is shown but doesn't change (thus no get function) */
4626 .show_host_active_fc4s = 1,
4627
4628 .get_host_speed = lpfc_get_host_speed,
4629 .show_host_speed = 1,
4630
4631 .get_host_fabric_name = lpfc_get_host_fabric_name,
4632 .show_host_fabric_name = 1,
4633
4634 /*
4635 * The LPFC driver treats linkdown handling as target loss events
4636 * so there are no sysfs handlers for link_down_tmo.
4637 */
4638
4639 .get_fc_host_stats = lpfc_get_stats,
4640 .reset_fc_host_stats = lpfc_reset_stats,
4641
4642 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4643 .show_rport_maxframe_size = 1,
4644 .show_rport_supported_classes = 1,
4645
4646 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4647 .show_rport_dev_loss_tmo = 1,
4648
4649 .get_starget_port_id = lpfc_get_starget_port_id,
4650 .show_starget_port_id = 1,
4651
4652 .get_starget_node_name = lpfc_get_starget_node_name,
4653 .show_starget_node_name = 1,
4654
4655 .get_starget_port_name = lpfc_get_starget_port_name,
4656 .show_starget_port_name = 1,
4657
4658 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4659 .terminate_rport_io = lpfc_terminate_rport_io,
4660
4661 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004662
4663 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004664};
4665
James Smarte59058c2008-08-24 21:49:00 -04004666/**
James Smart3621a712009-04-06 18:47:14 -04004667 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004668 * @phba: lpfc_hba pointer.
4669 **/
dea31012005-04-17 16:05:31 -05004670void
4671lpfc_get_cfgparam(struct lpfc_hba *phba)
4672{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004673 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4674 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004675 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004676 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4677 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004678 lpfc_ack0_init(phba, lpfc_ack0);
4679 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004680 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004681 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004682 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart19ca7602010-11-20 23:11:55 -05004683 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05004684 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004685 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4686 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4687 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004688 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4689 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004690 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004691 if (phba->sli_rev == LPFC_SLI_REV4)
4692 phba->cfg_poll = 0;
4693 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004694 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004695 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004696 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004697 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004698 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004699 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004700 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004701 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004702 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004703 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05004704 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04004705 return;
4706}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004707
James Smarte59058c2008-08-24 21:49:00 -04004708/**
James Smart3621a712009-04-06 18:47:14 -04004709 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004710 * @vport: lpfc_vport pointer.
4711 **/
James Smart3de2a652007-08-02 11:09:59 -04004712void
4713lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4714{
James Smarte8b62012007-08-02 11:10:09 -04004715 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004716 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004717 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004718 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4719 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4720 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4721 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4722 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4723 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004724 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004725 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4726 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4727 lpfc_max_luns_init(vport, lpfc_max_luns);
4728 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004729 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004730 return;
4731}