blob: 72cb750860d69e297e5402945d900a4c8bd31e11 [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 Smartf7a919b2011-08-21 21:49:16 -040055/*
56 * Write key size should be multiple of 4. If write key is changed
57 * make sure that library write key is also changed.
58 */
59#define LPFC_REG_WRITE_KEY_SIZE 4
60#define LPFC_REG_WRITE_KEY "EMLX"
61
James Smarte59058c2008-08-24 21:49:00 -040062/**
James Smart3621a712009-04-06 18:47:14 -040063 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040064 * @incr: integer to convert.
65 * @hdw: ascii string holding converted integer plus a string terminator.
66 *
67 * Description:
68 * JEDEC Joint Electron Device Engineering Council.
69 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
70 * character string. The string is then terminated with a NULL in byte 9.
71 * Hex 0-9 becomes ascii '0' to '9'.
72 * Hex a-f becomes ascii '=' to 'B' capital B.
73 *
74 * Notes:
75 * Coded for 32 bit integers only.
76 **/
dea31012005-04-17 16:05:31 -050077static void
78lpfc_jedec_to_ascii(int incr, char hdw[])
79{
80 int i, j;
81 for (i = 0; i < 8; i++) {
82 j = (incr & 0xf);
83 if (j <= 9)
84 hdw[7 - i] = 0x30 + j;
85 else
86 hdw[7 - i] = 0x61 + j - 10;
87 incr = (incr >> 4);
88 }
89 hdw[8] = 0;
90 return;
91}
92
James Smarte59058c2008-08-24 21:49:00 -040093/**
James Smart3621a712009-04-06 18:47:14 -040094 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040095 * @dev: class unused variable.
96 * @attr: device attribute, not used.
97 * @buf: on return contains the module description text.
98 *
99 * Returns: size of formatted string.
100 **/
dea31012005-04-17 16:05:31 -0500101static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100102lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
103 char *buf)
dea31012005-04-17 16:05:31 -0500104{
105 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
106}
107
James Smart45ed1192009-10-02 15:17:02 -0400108/**
109 * lpfc_enable_fip_show - Return the fip mode of the HBA
110 * @dev: class unused variable.
111 * @attr: device attribute, not used.
112 * @buf: on return contains the module description text.
113 *
114 * Returns: size of formatted string.
115 **/
116static ssize_t
117lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
118 char *buf)
119{
120 struct Scsi_Host *shost = class_to_shost(dev);
121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
122 struct lpfc_hba *phba = vport->phba;
123
124 if (phba->hba_flag & HBA_FIP_SUPPORT)
125 return snprintf(buf, PAGE_SIZE, "1\n");
126 else
127 return snprintf(buf, PAGE_SIZE, "0\n");
128}
129
James Smart81301a92008-12-04 22:39:46 -0500130static ssize_t
131lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
132 char *buf)
133{
134 struct Scsi_Host *shost = class_to_shost(dev);
135 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
136 struct lpfc_hba *phba = vport->phba;
137
138 if (phba->cfg_enable_bg)
139 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
140 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
141 else
142 return snprintf(buf, PAGE_SIZE,
143 "BlockGuard Not Supported\n");
144 else
145 return snprintf(buf, PAGE_SIZE,
146 "BlockGuard Disabled\n");
147}
148
149static ssize_t
150lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
151 char *buf)
152{
153 struct Scsi_Host *shost = class_to_shost(dev);
154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
155 struct lpfc_hba *phba = vport->phba;
156
James Smart87b5c322008-12-16 10:34:09 -0500157 return snprintf(buf, PAGE_SIZE, "%llu\n",
158 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500159}
160
161static ssize_t
162lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
163 char *buf)
164{
165 struct Scsi_Host *shost = class_to_shost(dev);
166 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
167 struct lpfc_hba *phba = vport->phba;
168
James Smart87b5c322008-12-16 10:34:09 -0500169 return snprintf(buf, PAGE_SIZE, "%llu\n",
170 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500171}
172
173static ssize_t
174lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
175 char *buf)
176{
177 struct Scsi_Host *shost = class_to_shost(dev);
178 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
179 struct lpfc_hba *phba = vport->phba;
180
James Smart87b5c322008-12-16 10:34:09 -0500181 return snprintf(buf, PAGE_SIZE, "%llu\n",
182 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500183}
184
James Smarte59058c2008-08-24 21:49:00 -0400185/**
James Smart3621a712009-04-06 18:47:14 -0400186 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400187 * @dev: class converted to a Scsi_host structure.
188 * @attr: device attribute, not used.
189 * @buf: on return contains the formatted text from lpfc_info().
190 *
191 * Returns: size of formatted string.
192 **/
dea31012005-04-17 16:05:31 -0500193static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100194lpfc_info_show(struct device *dev, struct device_attribute *attr,
195 char *buf)
dea31012005-04-17 16:05:31 -0500196{
Tony Jonesee959b02008-02-22 00:13:36 +0100197 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500198
dea31012005-04-17 16:05:31 -0500199 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
200}
201
James Smarte59058c2008-08-24 21:49:00 -0400202/**
James Smart3621a712009-04-06 18:47:14 -0400203 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400204 * @dev: class converted to a Scsi_host structure.
205 * @attr: device attribute, not used.
206 * @buf: on return contains the formatted text serial number.
207 *
208 * Returns: size of formatted string.
209 **/
dea31012005-04-17 16:05:31 -0500210static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100211lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
212 char *buf)
dea31012005-04-17 16:05:31 -0500213{
Tony Jonesee959b02008-02-22 00:13:36 +0100214 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500215 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
216 struct lpfc_hba *phba = vport->phba;
217
dea31012005-04-17 16:05:31 -0500218 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
219}
220
James Smarte59058c2008-08-24 21:49:00 -0400221/**
James Smart3621a712009-04-06 18:47:14 -0400222 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400223 * @dev: class converted to a Scsi_host structure.
224 * @attr: device attribute, not used.
225 * @buf: on return contains the formatted support level.
226 *
227 * Description:
228 * Returns a number indicating the temperature sensor level currently
229 * supported, zero or one in ascii.
230 *
231 * Returns: size of formatted string.
232 **/
dea31012005-04-17 16:05:31 -0500233static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100234lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
235 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400236{
Tony Jonesee959b02008-02-22 00:13:36 +0100237 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
239 struct lpfc_hba *phba = vport->phba;
240 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
241}
242
James Smarte59058c2008-08-24 21:49:00 -0400243/**
James Smart3621a712009-04-06 18:47:14 -0400244 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400245 * @dev: class converted to a Scsi_host structure.
246 * @attr: device attribute, not used.
247 * @buf: on return contains the scsi vpd model description.
248 *
249 * Returns: size of formatted string.
250 **/
James Smart57127f12007-10-27 13:37:05 -0400251static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100252lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
253 char *buf)
dea31012005-04-17 16:05:31 -0500254{
Tony Jonesee959b02008-02-22 00:13:36 +0100255 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500256 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
257 struct lpfc_hba *phba = vport->phba;
258
dea31012005-04-17 16:05:31 -0500259 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
260}
261
James Smarte59058c2008-08-24 21:49:00 -0400262/**
James Smart3621a712009-04-06 18:47:14 -0400263 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400264 * @dev: class converted to a Scsi_host structure.
265 * @attr: device attribute, not used.
266 * @buf: on return contains the scsi vpd model name.
267 *
268 * Returns: size of formatted string.
269 **/
dea31012005-04-17 16:05:31 -0500270static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100271lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
272 char *buf)
dea31012005-04-17 16:05:31 -0500273{
Tony Jonesee959b02008-02-22 00:13:36 +0100274 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500275 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
276 struct lpfc_hba *phba = vport->phba;
277
dea31012005-04-17 16:05:31 -0500278 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
279}
280
James Smarte59058c2008-08-24 21:49:00 -0400281/**
James Smart3621a712009-04-06 18:47:14 -0400282 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400283 * @dev: class converted to a Scsi_host structure.
284 * @attr: device attribute, not used.
285 * @buf: on return contains the scsi vpd program type.
286 *
287 * Returns: size of formatted string.
288 **/
dea31012005-04-17 16:05:31 -0500289static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100290lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
291 char *buf)
dea31012005-04-17 16:05:31 -0500292{
Tony Jonesee959b02008-02-22 00:13:36 +0100293 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500294 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
295 struct lpfc_hba *phba = vport->phba;
296
dea31012005-04-17 16:05:31 -0500297 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
298}
299
James Smarte59058c2008-08-24 21:49:00 -0400300/**
James Smart3621a712009-04-06 18:47:14 -0400301 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400302 * @dev: class converted to a Scsi_host structure.
303 * @attr: device attribute, not used.
304 * @buf: on return contains the Menlo Maintenance sli flag.
305 *
306 * Returns: size of formatted string.
307 **/
308static ssize_t
309lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
310{
311 struct Scsi_Host *shost = class_to_shost(dev);
312 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
313 struct lpfc_hba *phba = vport->phba;
314
315 return snprintf(buf, PAGE_SIZE, "%d\n",
316 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
317}
318
319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400321 * @dev: class converted to a Scsi_host structure.
322 * @attr: device attribute, not used.
323 * @buf: on return contains scsi vpd program type.
324 *
325 * Returns: size of formatted string.
326 **/
dea31012005-04-17 16:05:31 -0500327static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100328lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
329 char *buf)
dea31012005-04-17 16:05:31 -0500330{
Tony Jonesee959b02008-02-22 00:13:36 +0100331 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500332 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
333 struct lpfc_hba *phba = vport->phba;
334
dea31012005-04-17 16:05:31 -0500335 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
336}
337
James Smarte59058c2008-08-24 21:49:00 -0400338/**
James Smart3621a712009-04-06 18:47:14 -0400339 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400340 * @dev: class converted to a Scsi_host structure.
341 * @attr: device attribute, not used.
342 * @buf: on return contains the scsi vpd program type.
343 *
344 * Returns: size of formatted string.
345 **/
dea31012005-04-17 16:05:31 -0500346static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100347lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
348 char *buf)
dea31012005-04-17 16:05:31 -0500349{
Tony Jonesee959b02008-02-22 00:13:36 +0100350 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
352 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500353 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500354
dea31012005-04-17 16:05:31 -0500355 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500356 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500357}
358
James Smarte59058c2008-08-24 21:49:00 -0400359/**
James Smart3621a712009-04-06 18:47:14 -0400360 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400361 * @dev: class converted to a Scsi_host structure.
362 * @attr: device attribute, not used.
363 * @buf: on return contains the scsi vpd program type.
364 *
365 * Returns: size of formatted string.
366 **/
dea31012005-04-17 16:05:31 -0500367static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100368lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500369{
370 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100371 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
373 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500374 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500375
dea31012005-04-17 16:05:31 -0500376 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
377 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
378}
James Smarte59058c2008-08-24 21:49:00 -0400379
380/**
James Smart3621a712009-04-06 18:47:14 -0400381 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400382 * @dev: class converted to a Scsi_host structure.
383 * @attr: device attribute, not used.
384 * @buf: on return contains the ROM and FCode ascii strings.
385 *
386 * Returns: size of formatted string.
387 **/
dea31012005-04-17 16:05:31 -0500388static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100389lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
390 char *buf)
dea31012005-04-17 16:05:31 -0500391{
Tony Jonesee959b02008-02-22 00:13:36 +0100392 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
395
dea31012005-04-17 16:05:31 -0500396 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
397}
James Smarte59058c2008-08-24 21:49:00 -0400398
399/**
James Smart3621a712009-04-06 18:47:14 -0400400 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400401 * @dev: class converted to a Scsi_host structure.
402 * @attr: device attribute, not used.
403 * @buf: on return contains text describing the state of the link.
404 *
405 * Notes:
406 * The switch statement has no default so zero will be returned.
407 *
408 * Returns: size of formatted string.
409 **/
dea31012005-04-17 16:05:31 -0500410static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100411lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
412 char *buf)
dea31012005-04-17 16:05:31 -0500413{
Tony Jonesee959b02008-02-22 00:13:36 +0100414 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
416 struct lpfc_hba *phba = vport->phba;
417 int len = 0;
418
419 switch (phba->link_state) {
420 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500421 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500422 case LPFC_INIT_START:
423 case LPFC_INIT_MBX_CMDS:
424 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500425 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400426 if (phba->hba_flag & LINK_DISABLED)
427 len += snprintf(buf + len, PAGE_SIZE-len,
428 "Link Down - User disabled\n");
429 else
430 len += snprintf(buf + len, PAGE_SIZE-len,
431 "Link Down\n");
dea31012005-04-17 16:05:31 -0500432 break;
433 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500434 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500435 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400436 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500437
438 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500439 case LPFC_LOCAL_CFG_LINK:
440 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500441 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500442 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500443 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500444 case LPFC_FLOGI:
445 case LPFC_FABRIC_CFG_LINK:
446 case LPFC_NS_REG:
447 case LPFC_NS_QRY:
448 case LPFC_BUILD_DISC_LIST:
449 case LPFC_DISC_AUTH:
450 len += snprintf(buf + len, PAGE_SIZE - len,
451 "Discovery\n");
452 break;
453 case LPFC_VPORT_READY:
454 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
455 break;
456
James Smart92d7f7b2007-06-17 19:56:38 -0500457 case LPFC_VPORT_FAILED:
458 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
459 break;
460
461 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500462 len += snprintf(buf + len, PAGE_SIZE - len,
463 "Unknown\n");
464 break;
465 }
James Smart84774a42008-08-24 21:50:06 -0400466 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500469 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500470 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Public Loop\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Private Loop\n");
476 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500477 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500478 len += snprintf(buf + len, PAGE_SIZE-len,
479 " Fabric\n");
480 else
481 len += snprintf(buf + len, PAGE_SIZE-len,
482 " Point-2-Point\n");
483 }
484 }
James Smart2e0fef82007-06-17 19:56:36 -0500485
dea31012005-04-17 16:05:31 -0500486 return len;
487}
488
James Smarte59058c2008-08-24 21:49:00 -0400489/**
James Smart84d1b002010-02-12 14:42:33 -0500490 * lpfc_link_state_store - Transition the link_state on an HBA port
491 * @dev: class device that is converted into a Scsi_host.
492 * @attr: device attribute, not used.
493 * @buf: one or more lpfc_polling_flags values.
494 * @count: not used.
495 *
496 * Returns:
497 * -EINVAL if the buffer is not "up" or "down"
498 * return from link state change function if non-zero
499 * length of the buf on success
500 **/
501static ssize_t
502lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
503 const char *buf, size_t count)
504{
505 struct Scsi_Host *shost = class_to_shost(dev);
506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
507 struct lpfc_hba *phba = vport->phba;
508
509 int status = -EINVAL;
510
511 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
512 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400513 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500514 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
515 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400516 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500517
518 if (status == 0)
519 return strlen(buf);
520 else
521 return status;
522}
523
524/**
James Smart3621a712009-04-06 18:47:14 -0400525 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400526 * @dev: class device that is converted into a Scsi_host.
527 * @attr: device attribute, not used.
528 * @buf: on return contains the sum of fc mapped and unmapped.
529 *
530 * Description:
531 * Returns the ascii text number of the sum of the fc mapped and unmapped
532 * vport counts.
533 *
534 * Returns: size of formatted string.
535 **/
dea31012005-04-17 16:05:31 -0500536static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100537lpfc_num_discovered_ports_show(struct device *dev,
538 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500539{
Tony Jonesee959b02008-02-22 00:13:36 +0100540 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
542
543 return snprintf(buf, PAGE_SIZE, "%d\n",
544 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500545}
546
James Smarte59058c2008-08-24 21:49:00 -0400547/**
James Smart3621a712009-04-06 18:47:14 -0400548 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400549 * @shost: Scsi_Host pointer.
550 *
551 * Description:
552 * Bring the link down gracefully then re-init the link. The firmware will
553 * re-init the fiber channel interface as required. Does not issue a LIP.
554 *
555 * Returns:
556 * -EPERM port offline or management commands are being blocked
557 * -ENOMEM cannot allocate memory for the mailbox command
558 * -EIO error sending the mailbox command
559 * zero for success
560 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700561static int
James Smart2e0fef82007-06-17 19:56:36 -0500562lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500563{
James Smart2e0fef82007-06-17 19:56:36 -0500564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
565 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500566 LPFC_MBOXQ_t *pmboxq;
567 int mbxstatus = MBXERR_ERROR;
568
James Smart2e0fef82007-06-17 19:56:36 -0500569 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500570 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500571 return -EPERM;
572
573 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
574
575 if (!pmboxq)
576 return -ENOMEM;
577
578 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400579 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
580 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400581
James Smart33ccf8d2006-08-17 11:57:58 -0400582 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500583
James Smart04c68492009-05-22 14:52:52 -0400584 if ((mbxstatus == MBX_SUCCESS) &&
585 (pmboxq->u.mb.mbxStatus == 0 ||
586 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400587 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
588 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
589 phba->cfg_link_speed);
590 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
591 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400592 if ((mbxstatus == MBX_SUCCESS) &&
593 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
594 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
595 "2859 SLI authentication is required "
596 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400597 }
598
James Smart5b8bd0c2007-04-25 09:52:49 -0400599 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500600 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400601 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500602
603 if (mbxstatus == MBXERR_ERROR)
604 return -EIO;
605
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700606 return 0;
dea31012005-04-17 16:05:31 -0500607}
608
James Smarte59058c2008-08-24 21:49:00 -0400609/**
James Smart3621a712009-04-06 18:47:14 -0400610 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400611 * @phba: lpfc_hba pointer.
612 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
613 *
614 * Notes:
615 * Assumes any error from lpfc_do_offline() will be negative.
616 * Can wait up to 5 seconds for the port ring buffers count
617 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400618 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400619 *
620 * Returns:
621 * -EIO error posting the event
622 * zero for success
623 **/
James Smart40496f02006-07-06 15:50:22 -0400624static int
James Smart46fa3112007-04-25 09:51:45 -0400625lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
626{
627 struct completion online_compl;
628 struct lpfc_sli_ring *pring;
629 struct lpfc_sli *psli;
630 int status = 0;
631 int cnt = 0;
632 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500633 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400634
635 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500636 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400637 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500638 if (rc == 0)
639 return -ENOMEM;
640
James Smart46fa3112007-04-25 09:51:45 -0400641 wait_for_completion(&online_compl);
642
643 if (status != 0)
644 return -EIO;
645
646 psli = &phba->sli;
647
James Smart09372822008-01-11 01:52:54 -0500648 /* Wait a little for things to settle down, but not
649 * long enough for dev loss timeout to expire.
650 */
James Smart46fa3112007-04-25 09:51:45 -0400651 for (i = 0; i < psli->num_rings; i++) {
652 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400653 while (pring->txcmplq_cnt) {
654 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500655 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400656 lpfc_printf_log(phba,
657 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400658 "0466 Outstanding IO when "
659 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400660 break;
661 }
662 }
663 }
664
665 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500666 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
667 if (rc == 0)
668 return -ENOMEM;
669
James Smart46fa3112007-04-25 09:51:45 -0400670 wait_for_completion(&online_compl);
671
672 if (status != 0)
673 return -EIO;
674
675 return 0;
676}
677
James Smarte59058c2008-08-24 21:49:00 -0400678/**
James Smart3621a712009-04-06 18:47:14 -0400679 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400680 * @phba: lpfc_hba pointer.
681 *
682 * Description:
683 * If the port is configured to allow a reset then the hba is brought
684 * offline then online.
685 *
686 * Notes:
687 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500688 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400689 *
690 * Returns:
691 * lpfc_do_offline() return code if not zero
692 * -EIO reset not configured or error posting the event
693 * zero for success
694 **/
James Smart7f860592011-03-11 16:05:52 -0500695int
James Smart40496f02006-07-06 15:50:22 -0400696lpfc_selective_reset(struct lpfc_hba *phba)
697{
698 struct completion online_compl;
699 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500700 int rc;
James Smart40496f02006-07-06 15:50:22 -0400701
James Smart13815c82008-01-11 01:52:48 -0500702 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400703 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500704
James Smart46fa3112007-04-25 09:51:45 -0400705 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400706
707 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400708 return status;
James Smart40496f02006-07-06 15:50:22 -0400709
710 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500711 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400712 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500713 if (rc == 0)
714 return -ENOMEM;
715
James Smart40496f02006-07-06 15:50:22 -0400716 wait_for_completion(&online_compl);
717
718 if (status != 0)
719 return -EIO;
720
721 return 0;
722}
723
James Smarte59058c2008-08-24 21:49:00 -0400724/**
James Smart3621a712009-04-06 18:47:14 -0400725 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400726 * @dev: class device that is converted into a Scsi_host.
727 * @attr: device attribute, not used.
728 * @buf: containing the string "selective".
729 * @count: unused variable.
730 *
731 * Description:
732 * If the buf contains the string "selective" then lpfc_selective_reset()
733 * is called to perform the reset.
734 *
735 * Notes:
736 * Assumes any error from lpfc_selective_reset() will be negative.
737 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200738 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400739 *
740 * Returns:
741 * -EINVAL if the buffer does not contain the string "selective"
742 * length of buf if lpfc-selective_reset() if the call succeeds
743 * return value of lpfc_selective_reset() if the call fails
744**/
James Smart40496f02006-07-06 15:50:22 -0400745static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100746lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
747 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400748{
Tony Jonesee959b02008-02-22 00:13:36 +0100749 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500750 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
751 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400752 int status = -EINVAL;
753
James Smart73d91e52011-10-10 21:32:10 -0400754 if (!phba->cfg_enable_hba_reset)
755 return -EACCES;
756
James Smart40496f02006-07-06 15:50:22 -0400757 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500758 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400759
760 if (status == 0)
761 return strlen(buf);
762 else
763 return status;
764}
765
James Smarte59058c2008-08-24 21:49:00 -0400766/**
James Smart88a2cfb2011-07-22 18:36:33 -0400767 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
768 * @phba: lpfc_hba pointer.
769 *
770 * Description:
771 * SLI4 interface type-2 device to wait on the sliport status register for
772 * the readyness after performing a firmware reset.
773 *
774 * Returns:
775 * zero for success
776 **/
James Smart73d91e52011-10-10 21:32:10 -0400777int
James Smart88a2cfb2011-07-22 18:36:33 -0400778lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
779{
James Smartf7a919b2011-08-21 21:49:16 -0400780 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400781 int i;
782
James Smartf7a919b2011-08-21 21:49:16 -0400783 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400784 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
785 &portstat_reg.word0);
786
James Smartf7a919b2011-08-21 21:49:16 -0400787 /* verify if privilaged for the request operation */
788 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
789 !bf_get(lpfc_sliport_status_err, &portstat_reg))
790 return -EPERM;
791
James Smart88a2cfb2011-07-22 18:36:33 -0400792 /* wait for the SLI port firmware ready after firmware reset */
793 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
794 msleep(10);
795 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
796 &portstat_reg.word0);
797 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
798 continue;
799 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
800 continue;
801 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
802 continue;
803 break;
804 }
805
806 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
807 return 0;
808 else
809 return -EIO;
810}
811
812/**
James Smart52d52442011-05-24 11:42:45 -0400813 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400814 * @phba: lpfc_hba pointer.
815 *
816 * Description:
James Smart52d52442011-05-24 11:42:45 -0400817 * Request SLI4 interface type-2 device to perform a physical register set
818 * access.
James Smartc0c11512011-05-24 11:41:34 -0400819 *
820 * Returns:
821 * zero for success
822 **/
823static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400824lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400825{
826 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400827 struct pci_dev *pdev = phba->pcidev;
James Smartc0c11512011-05-24 11:41:34 -0400828 uint32_t reg_val;
829 int status = 0;
830 int rc;
831
832 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400833 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400834
James Smart52d52442011-05-24 11:42:45 -0400835 if ((phba->sli_rev < LPFC_SLI_REV4) ||
836 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
837 LPFC_SLI_INTF_IF_TYPE_2))
838 return -EPERM;
839
James Smartb76f2dc2011-07-22 18:37:42 -0400840 /* Disable SR-IOV virtual functions if enabled */
841 if (phba->cfg_sriov_nr_virtfn) {
842 pci_disable_sriov(pdev);
843 phba->cfg_sriov_nr_virtfn = 0;
844 }
James Smartc0c11512011-05-24 11:41:34 -0400845 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
846
847 if (status != 0)
848 return status;
849
850 /* wait for the device to be quiesced before firmware reset */
851 msleep(100);
852
853 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
854 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400855
856 if (opcode == LPFC_FW_DUMP)
857 reg_val |= LPFC_FW_DUMP_REQUEST;
858 else if (opcode == LPFC_FW_RESET)
859 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
860 else if (opcode == LPFC_DV_RESET)
861 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
862
James Smartc0c11512011-05-24 11:41:34 -0400863 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
864 LPFC_CTL_PDEV_CTL_OFFSET);
865 /* flush */
866 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
867
868 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400869 rc = lpfc_sli4_pdev_status_reg_wait(phba);
870
871 if (rc)
James Smartf7a919b2011-08-21 21:49:16 -0400872 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400873
874 init_completion(&online_compl);
875 rc = lpfc_workq_post_event(phba, &status, &online_compl,
876 LPFC_EVT_ONLINE);
877 if (rc == 0)
878 return -ENOMEM;
879
880 wait_for_completion(&online_compl);
881
882 if (status != 0)
883 return -EIO;
884
885 return 0;
886}
887
888/**
James Smart3621a712009-04-06 18:47:14 -0400889 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400890 * @dev: class device that is converted into a Scsi_host.
891 * @attr: device attribute, not used.
892 * @buf: on return contains the ascii number of nport events.
893 *
894 * Returns: size of formatted string.
895 **/
dea31012005-04-17 16:05:31 -0500896static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100897lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
898 char *buf)
dea31012005-04-17 16:05:31 -0500899{
Tony Jonesee959b02008-02-22 00:13:36 +0100900 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500901 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
902 struct lpfc_hba *phba = vport->phba;
903
dea31012005-04-17 16:05:31 -0500904 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
905}
906
James Smarte59058c2008-08-24 21:49:00 -0400907/**
James Smart3621a712009-04-06 18:47:14 -0400908 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400909 * @dev: class device that is converted into a Scsi_host.
910 * @attr: device attribute, not used.
911 * @buf: on return contains the state of the adapter.
912 *
913 * Returns: size of formatted string.
914 **/
dea31012005-04-17 16:05:31 -0500915static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100916lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
917 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500918{
Tony Jonesee959b02008-02-22 00:13:36 +0100919 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
921 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500922 char * state;
923
James Smart2e0fef82007-06-17 19:56:36 -0500924 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500925 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500926 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500927 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500928 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500929 state = "offline";
930 else
931 state = "online";
932
933 return snprintf(buf, PAGE_SIZE, "%s\n", state);
934}
935
James Smarte59058c2008-08-24 21:49:00 -0400936/**
James Smart3621a712009-04-06 18:47:14 -0400937 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400938 * @dev: class device that is converted into a Scsi_host.
939 * @attr: device attribute, not used.
940 * @buf: containing one of the strings "online", "offline", "warm" or "error".
941 * @count: unused variable.
942 *
943 * Returns:
944 * -EACCES if enable hba reset not enabled
945 * -EINVAL if the buffer does not contain a valid string (see above)
946 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
947 * buf length greater than zero indicates success
948 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500949static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100950lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
951 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500952{
Tony Jonesee959b02008-02-22 00:13:36 +0100953 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500954 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
955 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500956 struct completion online_compl;
957 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500958 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500959
James Smart13815c82008-01-11 01:52:48 -0500960 if (!phba->cfg_enable_hba_reset)
961 return -EACCES;
James Smart88a2cfb2011-07-22 18:36:33 -0400962
963 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
964 "3050 lpfc_board_mode set to %s\n", buf);
965
Jamie Wellnitz41415862006-02-28 19:25:27 -0500966 init_completion(&online_compl);
967
James Smart46fa3112007-04-25 09:51:45 -0400968 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500969 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500970 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500971 if (rc == 0)
972 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400973 wait_for_completion(&online_compl);
974 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
975 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500976 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400977 if (phba->sli_rev == LPFC_SLI_REV4)
978 return -EINVAL;
979 else
980 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400981 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400982 if (phba->sli_rev == LPFC_SLI_REV4)
983 return -EINVAL;
984 else
985 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -0400986 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -0400987 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
988 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
989 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
990 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
991 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500992 else
993 return -EINVAL;
994
Jamie Wellnitz41415862006-02-28 19:25:27 -0500995 if (!status)
996 return strlen(buf);
997 else
James Smartf7a919b2011-08-21 21:49:16 -0400998 return status;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500999}
1000
James Smarte59058c2008-08-24 21:49:00 -04001001/**
James Smart3621a712009-04-06 18:47:14 -04001002 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001003 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001004 * @mxri: max xri count.
1005 * @axri: available xri count.
1006 * @mrpi: max rpi count.
1007 * @arpi: available rpi count.
1008 * @mvpi: max vpi count.
1009 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001010 *
1011 * Description:
1012 * If an integer pointer for an count is not null then the value for the
1013 * count is returned.
1014 *
1015 * Returns:
1016 * zero on error
1017 * one for success
1018 **/
James Smart311464e2007-08-02 11:10:37 -04001019static int
James Smart858c9f62007-06-17 19:56:39 -05001020lpfc_get_hba_info(struct lpfc_hba *phba,
1021 uint32_t *mxri, uint32_t *axri,
1022 uint32_t *mrpi, uint32_t *arpi,
1023 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001024{
James Smart04c68492009-05-22 14:52:52 -04001025 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001026 LPFC_MBOXQ_t *pmboxq;
1027 MAILBOX_t *pmb;
1028 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001029 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001030
1031 /*
1032 * prevent udev from issuing mailbox commands until the port is
1033 * configured.
1034 */
1035 if (phba->link_state < LPFC_LINK_DOWN ||
1036 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001037 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001038 return 0;
1039
1040 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1041 return 0;
1042
1043 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1044 if (!pmboxq)
1045 return 0;
1046 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1047
James Smart04c68492009-05-22 14:52:52 -04001048 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001049 pmb->mbxCommand = MBX_READ_CONFIG;
1050 pmb->mbxOwner = OWN_HOST;
1051 pmboxq->context1 = NULL;
1052
James Smart75baf692010-06-08 18:31:21 -04001053 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001054 rc = MBX_NOT_FINISHED;
1055 else
1056 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1057
1058 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001059 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001060 mempool_free(pmboxq, phba->mbox_mem_pool);
1061 return 0;
1062 }
1063
James Smartda0436e2009-05-22 14:51:39 -04001064 if (phba->sli_rev == LPFC_SLI_REV4) {
1065 rd_config = &pmboxq->u.mqe.un.rd_config;
1066 if (mrpi)
1067 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1068 if (arpi)
1069 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1070 phba->sli4_hba.max_cfg_param.rpi_used;
1071 if (mxri)
1072 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1073 if (axri)
1074 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1075 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001076
1077 /* Account for differences with SLI-3. Get vpi count from
1078 * mailbox data and subtract one for max vpi value.
1079 */
1080 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1081 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1082
James Smartda0436e2009-05-22 14:51:39 -04001083 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001084 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001085 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001086 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001087 } else {
1088 if (mrpi)
1089 *mrpi = pmb->un.varRdConfig.max_rpi;
1090 if (arpi)
1091 *arpi = pmb->un.varRdConfig.avail_rpi;
1092 if (mxri)
1093 *mxri = pmb->un.varRdConfig.max_xri;
1094 if (axri)
1095 *axri = pmb->un.varRdConfig.avail_xri;
1096 if (mvpi)
1097 *mvpi = pmb->un.varRdConfig.max_vpi;
1098 if (avpi)
1099 *avpi = pmb->un.varRdConfig.avail_vpi;
1100 }
James Smart92d7f7b2007-06-17 19:56:38 -05001101
1102 mempool_free(pmboxq, phba->mbox_mem_pool);
1103 return 1;
1104}
1105
James Smarte59058c2008-08-24 21:49:00 -04001106/**
James Smart3621a712009-04-06 18:47:14 -04001107 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001108 * @dev: class device that is converted into a Scsi_host.
1109 * @attr: device attribute, not used.
1110 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1111 *
1112 * Description:
1113 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1114 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1115 * to "Unknown" and the buffer length is returned, therefore the caller
1116 * must check for "Unknown" in the buffer to detect a failure.
1117 *
1118 * Returns: size of formatted string.
1119 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001120static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001121lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1122 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001123{
Tony Jonesee959b02008-02-22 00:13:36 +01001124 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1126 struct lpfc_hba *phba = vport->phba;
1127 uint32_t cnt;
1128
James Smart858c9f62007-06-17 19:56:39 -05001129 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001130 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1131 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1132}
1133
James Smarte59058c2008-08-24 21:49:00 -04001134/**
James Smart3621a712009-04-06 18:47:14 -04001135 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001136 * @dev: class device that is converted into a Scsi_host.
1137 * @attr: device attribute, not used.
1138 * @buf: containing the used rpi count in decimal or "Unknown".
1139 *
1140 * Description:
1141 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1142 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1143 * to "Unknown" and the buffer length is returned, therefore the caller
1144 * must check for "Unknown" in the buffer to detect a failure.
1145 *
1146 * Returns: size of formatted string.
1147 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001148static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001149lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1150 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001151{
Tony Jonesee959b02008-02-22 00:13:36 +01001152 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001153 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1154 struct lpfc_hba *phba = vport->phba;
1155 uint32_t cnt, acnt;
1156
James Smart858c9f62007-06-17 19:56:39 -05001157 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001158 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1159 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1160}
1161
James Smarte59058c2008-08-24 21:49:00 -04001162/**
James Smart3621a712009-04-06 18:47:14 -04001163 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001164 * @dev: class device that is converted into a Scsi_host.
1165 * @attr: device attribute, not used.
1166 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1167 *
1168 * Description:
1169 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1170 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1171 * to "Unknown" and the buffer length is returned, therefore the caller
1172 * must check for "Unknown" in the buffer to detect a failure.
1173 *
1174 * Returns: size of formatted string.
1175 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001176static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001177lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1178 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001179{
Tony Jonesee959b02008-02-22 00:13:36 +01001180 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001181 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1182 struct lpfc_hba *phba = vport->phba;
1183 uint32_t cnt;
1184
James Smart858c9f62007-06-17 19:56:39 -05001185 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001186 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1187 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1188}
1189
James Smarte59058c2008-08-24 21:49:00 -04001190/**
James Smart3621a712009-04-06 18:47:14 -04001191 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001192 * @dev: class device that is converted into a Scsi_host.
1193 * @attr: device attribute, not used.
1194 * @buf: on return contains the used xri count in decimal or "Unknown".
1195 *
1196 * Description:
1197 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1198 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1199 * to "Unknown" and the buffer length is returned, therefore the caller
1200 * must check for "Unknown" in the buffer to detect a failure.
1201 *
1202 * Returns: size of formatted string.
1203 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001204static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001205lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1206 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001207{
Tony Jonesee959b02008-02-22 00:13:36 +01001208 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1210 struct lpfc_hba *phba = vport->phba;
1211 uint32_t cnt, acnt;
1212
James Smart858c9f62007-06-17 19:56:39 -05001213 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1214 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1215 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1216}
1217
James Smarte59058c2008-08-24 21:49:00 -04001218/**
James Smart3621a712009-04-06 18:47:14 -04001219 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001220 * @dev: class device that is converted into a Scsi_host.
1221 * @attr: device attribute, not used.
1222 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1223 *
1224 * Description:
1225 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1226 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1227 * to "Unknown" and the buffer length is returned, therefore the caller
1228 * must check for "Unknown" in the buffer to detect a failure.
1229 *
1230 * Returns: size of formatted string.
1231 **/
James Smart858c9f62007-06-17 19:56:39 -05001232static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001233lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1234 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001235{
Tony Jonesee959b02008-02-22 00:13:36 +01001236 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001237 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1238 struct lpfc_hba *phba = vport->phba;
1239 uint32_t cnt;
1240
1241 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1242 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1243 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1244}
1245
James Smarte59058c2008-08-24 21:49:00 -04001246/**
James Smart3621a712009-04-06 18:47:14 -04001247 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001248 * @dev: class device that is converted into a Scsi_host.
1249 * @attr: device attribute, not used.
1250 * @buf: on return contains the used vpi count in decimal or "Unknown".
1251 *
1252 * Description:
1253 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1254 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1255 * to "Unknown" and the buffer length is returned, therefore the caller
1256 * must check for "Unknown" in the buffer to detect a failure.
1257 *
1258 * Returns: size of formatted string.
1259 **/
James Smart858c9f62007-06-17 19:56:39 -05001260static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001261lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1262 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001263{
Tony Jonesee959b02008-02-22 00:13:36 +01001264 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001265 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1266 struct lpfc_hba *phba = vport->phba;
1267 uint32_t cnt, acnt;
1268
1269 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001270 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1271 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1272}
1273
James Smarte59058c2008-08-24 21:49:00 -04001274/**
James Smart3621a712009-04-06 18:47:14 -04001275 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001276 * @dev: class device that is converted into a Scsi_host.
1277 * @attr: device attribute, not used.
1278 * @buf: text that must be interpreted to determine if npiv is supported.
1279 *
1280 * Description:
1281 * Buffer will contain text indicating npiv is not suppoerted on the port,
1282 * the port is an NPIV physical port, or it is an npiv virtual port with
1283 * the id of the vport.
1284 *
1285 * Returns: size of formatted string.
1286 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001287static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001288lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1289 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001290{
Tony Jonesee959b02008-02-22 00:13:36 +01001291 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001292 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1293 struct lpfc_hba *phba = vport->phba;
1294
1295 if (!(phba->max_vpi))
1296 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1297 if (vport->port_type == LPFC_PHYSICAL_PORT)
1298 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1299 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1300}
1301
James Smarte59058c2008-08-24 21:49:00 -04001302/**
James Smart3621a712009-04-06 18:47:14 -04001303 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001304 * @dev: class device that is converted into a Scsi_host.
1305 * @attr: device attribute, not used.
1306 * @buf: on return contains the cfg_poll in hex.
1307 *
1308 * Notes:
1309 * cfg_poll should be a lpfc_polling_flags type.
1310 *
1311 * Returns: size of formatted string.
1312 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001313static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001314lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1315 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001316{
Tony Jonesee959b02008-02-22 00:13:36 +01001317 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001318 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1319 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001320
1321 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1322}
1323
James Smarte59058c2008-08-24 21:49:00 -04001324/**
James Smart3621a712009-04-06 18:47:14 -04001325 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001326 * @dev: class device that is converted into a Scsi_host.
1327 * @attr: device attribute, not used.
1328 * @buf: one or more lpfc_polling_flags values.
1329 * @count: not used.
1330 *
1331 * Notes:
1332 * buf contents converted to integer and checked for a valid value.
1333 *
1334 * Returns:
1335 * -EINVAL if the buffer connot be converted or is out of range
1336 * length of the buf on success
1337 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001338static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001339lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1340 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001341{
Tony Jonesee959b02008-02-22 00:13:36 +01001342 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1344 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001345 uint32_t creg_val;
1346 uint32_t old_val;
1347 int val=0;
1348
1349 if (!isdigit(buf[0]))
1350 return -EINVAL;
1351
1352 if (sscanf(buf, "%i", &val) != 1)
1353 return -EINVAL;
1354
1355 if ((val & 0x3) != val)
1356 return -EINVAL;
1357
James Smart45ed1192009-10-02 15:17:02 -04001358 if (phba->sli_rev == LPFC_SLI_REV4)
1359 val = 0;
1360
James Smart88a2cfb2011-07-22 18:36:33 -04001361 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1362 "3051 lpfc_poll changed from %d to %d\n",
1363 phba->cfg_poll, val);
1364
James Smart2e0fef82007-06-17 19:56:36 -05001365 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001366
1367 old_val = phba->cfg_poll;
1368
1369 if (val & ENABLE_FCP_RING_POLLING) {
1370 if ((val & DISABLE_FCP_RING_INT) &&
1371 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001372 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1373 spin_unlock_irq(&phba->hbalock);
1374 return -EINVAL;
1375 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001376 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1377 writel(creg_val, phba->HCregaddr);
1378 readl(phba->HCregaddr); /* flush */
1379
1380 lpfc_poll_start_timer(phba);
1381 }
1382 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001383 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001384 return -EINVAL;
1385 }
1386
1387 if (!(val & DISABLE_FCP_RING_INT) &&
1388 (old_val & DISABLE_FCP_RING_INT))
1389 {
James Smart2e0fef82007-06-17 19:56:36 -05001390 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001391 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001392 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001393 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1394 spin_unlock_irq(&phba->hbalock);
1395 return -EINVAL;
1396 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001397 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1398 writel(creg_val, phba->HCregaddr);
1399 readl(phba->HCregaddr); /* flush */
1400 }
1401
1402 phba->cfg_poll = val;
1403
James Smart2e0fef82007-06-17 19:56:36 -05001404 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001405
1406 return strlen(buf);
1407}
dea31012005-04-17 16:05:31 -05001408
James Smarte59058c2008-08-24 21:49:00 -04001409/**
James Smartbc739052010-08-04 16:11:18 -04001410 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1411 * @dev: class unused variable.
1412 * @attr: device attribute, not used.
1413 * @buf: on return contains the module description text.
1414 *
1415 * Returns: size of formatted string.
1416 **/
1417static ssize_t
1418lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1419 char *buf)
1420{
1421 struct Scsi_Host *shost = class_to_shost(dev);
1422 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1423 struct lpfc_hba *phba = vport->phba;
1424
1425 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1426}
1427
1428/**
1429 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1430 * @dev: class unused variable.
1431 * @attr: device attribute, not used.
1432 * @buf: on return contains the module description text.
1433 *
1434 * Returns: size of formatted string.
1435 **/
1436static ssize_t
1437lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1438 char *buf)
1439{
1440 struct Scsi_Host *shost = class_to_shost(dev);
1441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1442 struct lpfc_hba *phba = vport->phba;
1443
1444 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1445}
1446
1447/**
James Smartab56dc22011-02-16 12:39:57 -05001448 * lpfc_dss_show - Return the current state of dss and the configured state
1449 * @dev: class converted to a Scsi_host structure.
1450 * @attr: device attribute, not used.
1451 * @buf: on return contains the formatted text.
1452 *
1453 * Returns: size of formatted string.
1454 **/
1455static ssize_t
1456lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1457 char *buf)
1458{
1459 struct Scsi_Host *shost = class_to_shost(dev);
1460 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1461 struct lpfc_hba *phba = vport->phba;
1462
1463 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1464 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1465 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1466 "" : "Not ");
1467}
1468
1469/**
James Smart912e3ac2011-05-24 11:42:11 -04001470 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1471 * @dev: class converted to a Scsi_host structure.
1472 * @attr: device attribute, not used.
1473 * @buf: on return contains the formatted support level.
1474 *
1475 * Description:
1476 * Returns the maximum number of virtual functions a physical function can
1477 * support, 0 will be returned if called on virtual function.
1478 *
1479 * Returns: size of formatted string.
1480 **/
1481static ssize_t
1482lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1483 struct device_attribute *attr,
1484 char *buf)
1485{
1486 struct Scsi_Host *shost = class_to_shost(dev);
1487 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1488 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001489 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001490
James Smart0a96e972011-07-22 18:37:28 -04001491 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1492 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001493}
1494
1495/**
James Smart3621a712009-04-06 18:47:14 -04001496 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001497 *
1498 * Description:
1499 * Macro that given an attr e.g. hba_queue_depth expands
1500 * into a function with the name lpfc_hba_queue_depth_show.
1501 *
1502 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1503 * @dev: class device that is converted into a Scsi_host.
1504 * @attr: device attribute, not used.
1505 * @buf: on return contains the attribute value in decimal.
1506 *
1507 * Returns: size of formatted string.
1508 **/
dea31012005-04-17 16:05:31 -05001509#define lpfc_param_show(attr) \
1510static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001511lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1512 char *buf) \
dea31012005-04-17 16:05:31 -05001513{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001514 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001515 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1516 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001517 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001518 val = phba->cfg_##attr;\
1519 return snprintf(buf, PAGE_SIZE, "%d\n",\
1520 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001521}
1522
James Smarte59058c2008-08-24 21:49:00 -04001523/**
James Smart3621a712009-04-06 18:47:14 -04001524 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001525 *
1526 * Description:
1527 * Macro that given an attr e.g. hba_queue_depth expands
1528 * into a function with the name lpfc_hba_queue_depth_show
1529 *
1530 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1531 * @dev: class device that is converted into a Scsi_host.
1532 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001533 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001534 *
1535 * Returns: size of formatted string.
1536 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001537#define lpfc_param_hex_show(attr) \
1538static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001539lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1540 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001541{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001542 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001543 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1544 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001545 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001546 val = phba->cfg_##attr;\
1547 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1548 phba->cfg_##attr);\
1549}
1550
James Smarte59058c2008-08-24 21:49:00 -04001551/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001552 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001553 *
1554 * Description:
1555 * Macro that given an attr e.g. hba_queue_depth expands
1556 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1557 * takes a default argument, a minimum and maximum argument.
1558 *
1559 * lpfc_##attr##_init: Initializes an attribute.
1560 * @phba: pointer the the adapter structure.
1561 * @val: integer attribute value.
1562 *
1563 * Validates the min and max values then sets the adapter config field
1564 * accordingly, or uses the default if out of range and prints an error message.
1565 *
1566 * Returns:
1567 * zero on success
1568 * -EINVAL if default used
1569 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001570#define lpfc_param_init(attr, default, minval, maxval) \
1571static int \
James Smart84d1b002010-02-12 14:42:33 -05001572lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001573{ \
1574 if (val >= minval && val <= maxval) {\
1575 phba->cfg_##attr = val;\
1576 return 0;\
1577 }\
1578 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001579 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1580 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001581 phba->cfg_##attr = default;\
1582 return -EINVAL;\
1583}
1584
James Smarte59058c2008-08-24 21:49:00 -04001585/**
James Smart3621a712009-04-06 18:47:14 -04001586 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001587 *
1588 * Description:
1589 * Macro that given an attr e.g. hba_queue_depth expands
1590 * into a function with the name lpfc_hba_queue_depth_set
1591 *
1592 * lpfc_##attr##_set: Sets an attribute value.
1593 * @phba: pointer the the adapter structure.
1594 * @val: integer attribute value.
1595 *
1596 * Description:
1597 * Validates the min and max values then sets the
1598 * adapter config field if in the valid range. prints error message
1599 * and does not set the parameter if invalid.
1600 *
1601 * Returns:
1602 * zero on success
1603 * -EINVAL if val is invalid
1604 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001605#define lpfc_param_set(attr, default, minval, maxval) \
1606static int \
James Smart84d1b002010-02-12 14:42:33 -05001607lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001608{ \
1609 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1611 "3052 lpfc_" #attr " changed from %d to %d\n", \
1612 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001613 phba->cfg_##attr = val;\
1614 return 0;\
1615 }\
1616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001617 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1618 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001619 return -EINVAL;\
1620}
1621
James Smarte59058c2008-08-24 21:49:00 -04001622/**
James Smart3621a712009-04-06 18:47:14 -04001623 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001624 *
1625 * Description:
1626 * Macro that given an attr e.g. hba_queue_depth expands
1627 * into a function with the name lpfc_hba_queue_depth_store.
1628 *
1629 * lpfc_##attr##_store: Set an sttribute value.
1630 * @dev: class device that is converted into a Scsi_host.
1631 * @attr: device attribute, not used.
1632 * @buf: contains the attribute value in ascii.
1633 * @count: not used.
1634 *
1635 * Description:
1636 * Convert the ascii text number to an integer, then
1637 * use the lpfc_##attr##_set function to set the value.
1638 *
1639 * Returns:
1640 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1641 * length of buffer upon success.
1642 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001643#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001644static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001645lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1646 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001647{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001648 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001649 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1650 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001651 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001652 if (!isdigit(buf[0]))\
1653 return -EINVAL;\
1654 if (sscanf(buf, "%i", &val) != 1)\
1655 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001656 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001657 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001658 else \
1659 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001660}
1661
James Smarte59058c2008-08-24 21:49:00 -04001662/**
James Smart3621a712009-04-06 18:47:14 -04001663 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001664 *
1665 * Description:
1666 * Macro that given an attr e.g. hba_queue_depth expands
1667 * into a function with the name lpfc_hba_queue_depth_show
1668 *
1669 * lpfc_##attr##_show: prints the attribute value in decimal.
1670 * @dev: class device that is converted into a Scsi_host.
1671 * @attr: device attribute, not used.
1672 * @buf: on return contains the attribute value in decimal.
1673 *
1674 * Returns: length of formatted string.
1675 **/
James Smart3de2a652007-08-02 11:09:59 -04001676#define lpfc_vport_param_show(attr) \
1677static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001678lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1679 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001680{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001681 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001683 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001684 val = vport->cfg_##attr;\
1685 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1686}
1687
James Smarte59058c2008-08-24 21:49:00 -04001688/**
James Smart3621a712009-04-06 18:47:14 -04001689 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001690 *
1691 * Description:
1692 * Macro that given an attr e.g.
1693 * hba_queue_depth expands into a function with the name
1694 * lpfc_hba_queue_depth_show
1695 *
James Smart3621a712009-04-06 18:47:14 -04001696 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001697 * @dev: class device that is converted into a Scsi_host.
1698 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001699 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001700 *
1701 * Returns: length of formatted string.
1702 **/
James Smart3de2a652007-08-02 11:09:59 -04001703#define lpfc_vport_param_hex_show(attr) \
1704static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001705lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1706 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001707{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001708 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001709 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001710 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001711 val = vport->cfg_##attr;\
1712 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1713}
1714
James Smarte59058c2008-08-24 21:49:00 -04001715/**
James Smart3621a712009-04-06 18:47:14 -04001716 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001717 *
1718 * Description:
1719 * Macro that given an attr e.g. hba_queue_depth expands
1720 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1721 * takes a default argument, a minimum and maximum argument.
1722 *
1723 * lpfc_##attr##_init: validates the min and max values then sets the
1724 * adapter config field accordingly, or uses the default if out of range
1725 * and prints an error message.
1726 * @phba: pointer the the adapter structure.
1727 * @val: integer attribute value.
1728 *
1729 * Returns:
1730 * zero on success
1731 * -EINVAL if default used
1732 **/
James Smart3de2a652007-08-02 11:09:59 -04001733#define lpfc_vport_param_init(attr, default, minval, maxval) \
1734static int \
James Smart84d1b002010-02-12 14:42:33 -05001735lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001736{ \
1737 if (val >= minval && val <= maxval) {\
1738 vport->cfg_##attr = val;\
1739 return 0;\
1740 }\
James Smarte8b62012007-08-02 11:10:09 -04001741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001742 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001743 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001744 vport->cfg_##attr = default;\
1745 return -EINVAL;\
1746}
1747
James Smarte59058c2008-08-24 21:49:00 -04001748/**
James Smart3621a712009-04-06 18:47:14 -04001749 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001750 *
1751 * Description:
1752 * Macro that given an attr e.g. hba_queue_depth expands
1753 * into a function with the name lpfc_hba_queue_depth_set
1754 *
1755 * lpfc_##attr##_set: validates the min and max values then sets the
1756 * adapter config field if in the valid range. prints error message
1757 * and does not set the parameter if invalid.
1758 * @phba: pointer the the adapter structure.
1759 * @val: integer attribute value.
1760 *
1761 * Returns:
1762 * zero on success
1763 * -EINVAL if val is invalid
1764 **/
James Smart3de2a652007-08-02 11:09:59 -04001765#define lpfc_vport_param_set(attr, default, minval, maxval) \
1766static int \
James Smart84d1b002010-02-12 14:42:33 -05001767lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001768{ \
1769 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001770 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1771 "3053 lpfc_" #attr " changed from %d to %d\n", \
1772 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001773 vport->cfg_##attr = val;\
1774 return 0;\
1775 }\
James Smarte8b62012007-08-02 11:10:09 -04001776 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001777 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001778 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001779 return -EINVAL;\
1780}
1781
James Smarte59058c2008-08-24 21:49:00 -04001782/**
James Smart3621a712009-04-06 18:47:14 -04001783 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001784 *
1785 * Description:
1786 * Macro that given an attr e.g. hba_queue_depth
1787 * expands into a function with the name lpfc_hba_queue_depth_store
1788 *
1789 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1790 * use the lpfc_##attr##_set function to set the value.
1791 * @cdev: class device that is converted into a Scsi_host.
1792 * @buf: contains the attribute value in decimal.
1793 * @count: not used.
1794 *
1795 * Returns:
1796 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1797 * length of buffer upon success.
1798 **/
James Smart3de2a652007-08-02 11:09:59 -04001799#define lpfc_vport_param_store(attr) \
1800static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001801lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1802 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001803{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001804 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001806 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001807 if (!isdigit(buf[0]))\
1808 return -EINVAL;\
1809 if (sscanf(buf, "%i", &val) != 1)\
1810 return -EINVAL;\
1811 if (lpfc_##attr##_set(vport, val) == 0) \
1812 return strlen(buf);\
1813 else \
1814 return -EINVAL;\
1815}
1816
1817
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001818#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001819static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001820module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001821MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001822lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001823
1824#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001825static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001826module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001827MODULE_PARM_DESC(lpfc_##name, desc);\
1828lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001829lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001830static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001831
1832#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001833static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001834module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001835MODULE_PARM_DESC(lpfc_##name, desc);\
1836lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001837lpfc_param_init(name, defval, minval, maxval)\
1838lpfc_param_set(name, defval, minval, maxval)\
1839lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001840static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1841 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001842
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001843#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001844static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001845module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001846MODULE_PARM_DESC(lpfc_##name, desc);\
1847lpfc_param_hex_show(name)\
1848lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001849static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001850
1851#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001852static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001853module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001854MODULE_PARM_DESC(lpfc_##name, desc);\
1855lpfc_param_hex_show(name)\
1856lpfc_param_init(name, defval, minval, maxval)\
1857lpfc_param_set(name, defval, minval, maxval)\
1858lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001859static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1860 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001861
James Smart3de2a652007-08-02 11:09:59 -04001862#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001863static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001864module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001865MODULE_PARM_DESC(lpfc_##name, desc);\
1866lpfc_vport_param_init(name, defval, minval, maxval)
1867
1868#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001869static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001870module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001871MODULE_PARM_DESC(lpfc_##name, desc);\
1872lpfc_vport_param_show(name)\
1873lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001874static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001875
1876#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001877static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001878module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001879MODULE_PARM_DESC(lpfc_##name, desc);\
1880lpfc_vport_param_show(name)\
1881lpfc_vport_param_init(name, defval, minval, maxval)\
1882lpfc_vport_param_set(name, defval, minval, maxval)\
1883lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001884static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1885 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001886
1887#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001888static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001889module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001890MODULE_PARM_DESC(lpfc_##name, desc);\
1891lpfc_vport_param_hex_show(name)\
1892lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001893static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001894
1895#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001896static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001897module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001898MODULE_PARM_DESC(lpfc_##name, desc);\
1899lpfc_vport_param_hex_show(name)\
1900lpfc_vport_param_init(name, defval, minval, maxval)\
1901lpfc_vport_param_set(name, defval, minval, maxval)\
1902lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001903static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1904 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001905
James Smart81301a92008-12-04 22:39:46 -05001906static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1907static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1908static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1909static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001910static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1911static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1912static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1913static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1914static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1915static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1916static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1917static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001918static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1919 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001920static DEVICE_ATTR(option_rom_version, S_IRUGO,
1921 lpfc_option_rom_version_show, NULL);
1922static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1923 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001924static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001925static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1926static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001927static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001928static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1929 lpfc_board_mode_show, lpfc_board_mode_store);
1930static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1931static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1932static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1933static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1934static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1935static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1936static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1937static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1938static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001939static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1940static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001941static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001942static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1943 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001944
James Smarta12e07b2006-12-02 13:35:30 -05001945static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001946
James Smarte59058c2008-08-24 21:49:00 -04001947/**
James Smart3621a712009-04-06 18:47:14 -04001948 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001949 * @dev: class device that is converted into a Scsi_host.
1950 * @attr: device attribute, not used.
1951 * @buf: containing the string lpfc_soft_wwn_key.
1952 * @count: must be size of lpfc_soft_wwn_key.
1953 *
1954 * Returns:
1955 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1956 * length of buf indicates success
1957 **/
James Smartc3f28af2006-08-18 17:47:18 -04001958static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001959lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1960 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001961{
Tony Jonesee959b02008-02-22 00:13:36 +01001962 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1964 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001965 unsigned int cnt = count;
1966
1967 /*
1968 * We're doing a simple sanity check for soft_wwpn setting.
1969 * We require that the user write a specific key to enable
1970 * the soft_wwpn attribute to be settable. Once the attribute
1971 * is written, the enable key resets. If further updates are
1972 * desired, the key must be written again to re-enable the
1973 * attribute.
1974 *
1975 * The "key" is not secret - it is a hardcoded string shown
1976 * here. The intent is to protect against the random user or
1977 * application that is just writing attributes.
1978 */
1979
1980 /* count may include a LF at end of string */
1981 if (buf[cnt-1] == '\n')
1982 cnt--;
1983
James Smarta12e07b2006-12-02 13:35:30 -05001984 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1985 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001986 return -EINVAL;
1987
James Smarta12e07b2006-12-02 13:35:30 -05001988 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001989 return count;
1990}
Tony Jonesee959b02008-02-22 00:13:36 +01001991static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1992 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001993
James Smarte59058c2008-08-24 21:49:00 -04001994/**
James Smart3621a712009-04-06 18:47:14 -04001995 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001996 * @dev: class device that is converted into a Scsi_host.
1997 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001998 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001999 *
2000 * Returns: size of formatted string.
2001 **/
James Smartc3f28af2006-08-18 17:47:18 -04002002static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002003lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2004 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002005{
Tony Jonesee959b02008-02-22 00:13:36 +01002006 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002007 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2008 struct lpfc_hba *phba = vport->phba;
2009
Randy Dunlapafc071e2006-10-23 21:47:13 -07002010 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2011 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002012}
2013
James Smarte59058c2008-08-24 21:49:00 -04002014/**
James Smart3621a712009-04-06 18:47:14 -04002015 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002016 * @dev class device that is converted into a Scsi_host.
2017 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002018 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002019 * @count: number of wwpn bytes in buf
2020 *
2021 * Returns:
2022 * -EACCES hba reset not enabled, adapter over temp
2023 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2024 * -EIO error taking adapter offline or online
2025 * value of count on success
2026 **/
James Smartc3f28af2006-08-18 17:47:18 -04002027static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002028lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2029 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002030{
Tony Jonesee959b02008-02-22 00:13:36 +01002031 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002032 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2033 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002034 struct completion online_compl;
2035 int stat1=0, stat2=0;
2036 unsigned int i, j, cnt=count;
2037 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002038 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002039
James Smart13815c82008-01-11 01:52:48 -05002040 if (!phba->cfg_enable_hba_reset)
2041 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002042 spin_lock_irq(&phba->hbalock);
2043 if (phba->over_temp_state == HBA_OVER_TEMP) {
2044 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002045 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002046 }
2047 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002048 /* count may include a LF at end of string */
2049 if (buf[cnt-1] == '\n')
2050 cnt--;
2051
James Smarta12e07b2006-12-02 13:35:30 -05002052 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002053 ((cnt == 17) && (*buf++ != 'x')) ||
2054 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2055 return -EINVAL;
2056
James Smarta12e07b2006-12-02 13:35:30 -05002057 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002058
2059 memset(wwpn, 0, sizeof(wwpn));
2060
2061 /* Validate and store the new name */
2062 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002063 int value;
2064
2065 value = hex_to_bin(*buf++);
2066 if (value >= 0)
2067 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002068 else
2069 return -EINVAL;
2070 if (i % 2) {
2071 wwpn[i/2] = j & 0xff;
2072 j = 0;
2073 }
2074 }
2075 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002076 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002077 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002078 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002079
2080 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2081 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2082
James Smart46fa3112007-04-25 09:51:45 -04002083 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002084 if (stat1)
2085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002086 "0463 lpfc_soft_wwpn attribute set failed to "
2087 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002088 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002089 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2090 LPFC_EVT_ONLINE);
2091 if (rc == 0)
2092 return -ENOMEM;
2093
James Smartc3f28af2006-08-18 17:47:18 -04002094 wait_for_completion(&online_compl);
2095 if (stat2)
2096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002097 "0464 lpfc_soft_wwpn attribute set failed to "
2098 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002099 return (stat1 || stat2) ? -EIO : count;
2100}
Tony Jonesee959b02008-02-22 00:13:36 +01002101static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2102 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002103
James Smarte59058c2008-08-24 21:49:00 -04002104/**
James Smart3621a712009-04-06 18:47:14 -04002105 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002106 * @dev: class device that is converted into a Scsi_host.
2107 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002108 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002109 *
2110 * Returns: size of formatted string.
2111 **/
James Smarta12e07b2006-12-02 13:35:30 -05002112static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002113lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2114 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002115{
Tony Jonesee959b02008-02-22 00:13:36 +01002116 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002117 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002118 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2119 (unsigned long long)phba->cfg_soft_wwnn);
2120}
2121
James Smarte59058c2008-08-24 21:49:00 -04002122/**
James Smart3621a712009-04-06 18:47:14 -04002123 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002124 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002125 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002126 * @count: number of wwnn bytes in buf.
2127 *
2128 * Returns:
2129 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2130 * value of count on success
2131 **/
James Smarta12e07b2006-12-02 13:35:30 -05002132static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002133lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2134 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002135{
Tony Jonesee959b02008-02-22 00:13:36 +01002136 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002137 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002138 unsigned int i, j, cnt=count;
2139 u8 wwnn[8];
2140
2141 /* count may include a LF at end of string */
2142 if (buf[cnt-1] == '\n')
2143 cnt--;
2144
2145 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2146 ((cnt == 17) && (*buf++ != 'x')) ||
2147 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2148 return -EINVAL;
2149
2150 /*
2151 * Allow wwnn to be set many times, as long as the enable is set.
2152 * However, once the wwpn is set, everything locks.
2153 */
2154
2155 memset(wwnn, 0, sizeof(wwnn));
2156
2157 /* Validate and store the new name */
2158 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002159 int value;
2160
2161 value = hex_to_bin(*buf++);
2162 if (value >= 0)
2163 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002164 else
2165 return -EINVAL;
2166 if (i % 2) {
2167 wwnn[i/2] = j & 0xff;
2168 j = 0;
2169 }
2170 }
2171 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2172
2173 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2174 "lpfc%d: soft_wwnn set. Value will take effect upon "
2175 "setting of the soft_wwpn\n", phba->brd_no);
2176
2177 return count;
2178}
Tony Jonesee959b02008-02-22 00:13:36 +01002179static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2180 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002181
James Smartc3f28af2006-08-18 17:47:18 -04002182
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002183static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002184module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002185MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2186 " 0 - none,"
2187 " 1 - poll with interrupts enabled"
2188 " 3 - poll and disable FCP ring interrupts");
2189
Tony Jonesee959b02008-02-22 00:13:36 +01002190static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2191 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002192
James Smart92d7f7b2007-06-17 19:56:38 -05002193int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002194module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002195MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2196 " 0 - auto (SLI-3 if supported),"
2197 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2198 " 3 - select SLI-3");
2199
James Smart15672312010-04-06 14:49:03 -04002200int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002201module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002202MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2203lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002204lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002205static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002206
James Smart7d791df2011-07-22 18:37:52 -04002207LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2208 "FCF Fast failover=1 Priority failover=2");
2209
James Smart19ca7602010-11-20 23:11:55 -05002210int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002211module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002212MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2213lpfc_param_show(enable_rrq);
2214lpfc_param_init(enable_rrq, 0, 0, 1);
2215static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2216
dea31012005-04-17 16:05:31 -05002217/*
James Smart84d1b002010-02-12 14:42:33 -05002218# lpfc_suppress_link_up: Bring link up at initialization
2219# 0x0 = bring link up (issue MBX_INIT_LINK)
2220# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2221# 0x2 = never bring up link
2222# Default value is 0.
2223*/
James Smarte40a02c2010-02-26 14:13:54 -05002224LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2225 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2226 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002227/*
2228# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2229# 1 - (1024)
2230# 2 - (2048)
2231# 3 - (3072)
2232# 4 - (4096)
2233# 5 - (5120)
2234*/
2235static ssize_t
2236lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2237{
2238 struct Scsi_Host *shost = class_to_shost(dev);
2239 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2240
2241 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2242}
2243
2244static DEVICE_ATTR(iocb_hw, S_IRUGO,
2245 lpfc_iocb_hw_show, NULL);
2246static ssize_t
2247lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2248{
2249 struct Scsi_Host *shost = class_to_shost(dev);
2250 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2251
2252 return snprintf(buf, PAGE_SIZE, "%d\n",
2253 phba->sli.ring[LPFC_ELS_RING].txq_max);
2254}
2255
2256static DEVICE_ATTR(txq_hw, S_IRUGO,
2257 lpfc_txq_hw_show, NULL);
2258static ssize_t
2259lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2260 char *buf)
2261{
2262 struct Scsi_Host *shost = class_to_shost(dev);
2263 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2264
2265 return snprintf(buf, PAGE_SIZE, "%d\n",
2266 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2267}
2268
2269static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2270 lpfc_txcmplq_hw_show, NULL);
2271
2272int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002273module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002274MODULE_PARM_DESC(lpfc_iocb_cnt,
2275 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2276lpfc_param_show(iocb_cnt);
2277lpfc_param_init(iocb_cnt, 2, 1, 5);
2278static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2279 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002280
2281/*
James Smartc01f3202006-08-18 17:47:08 -04002282# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2283# until the timer expires. Value range is [0,255]. Default value is 30.
2284*/
2285static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2286static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2287module_param(lpfc_nodev_tmo, int, 0);
2288MODULE_PARM_DESC(lpfc_nodev_tmo,
2289 "Seconds driver will hold I/O waiting "
2290 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002291
2292/**
James Smart3621a712009-04-06 18:47:14 -04002293 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002294 * @dev: class converted to a Scsi_host structure.
2295 * @attr: device attribute, not used.
2296 * @buf: on return contains the dev loss timeout in decimal.
2297 *
2298 * Returns: size of formatted string.
2299 **/
James Smartc01f3202006-08-18 17:47:08 -04002300static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002301lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2302 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002303{
Tony Jonesee959b02008-02-22 00:13:36 +01002304 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002305 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002306
James Smart3de2a652007-08-02 11:09:59 -04002307 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002308}
2309
James Smarte59058c2008-08-24 21:49:00 -04002310/**
James Smart3621a712009-04-06 18:47:14 -04002311 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002312 * @vport: lpfc vport structure pointer.
2313 * @val: contains the nodev timeout value.
2314 *
2315 * Description:
2316 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2317 * a kernel error message is printed and zero is returned.
2318 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2319 * Otherwise nodev tmo is set to the default value.
2320 *
2321 * Returns:
2322 * zero if already set or if val is in range
2323 * -EINVAL val out of range
2324 **/
James Smartc01f3202006-08-18 17:47:08 -04002325static int
James Smart3de2a652007-08-02 11:09:59 -04002326lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002327{
James Smart3de2a652007-08-02 11:09:59 -04002328 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2329 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2330 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002331 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002332 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002333 "parameter because devloss_tmo is "
2334 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002335 return 0;
2336 }
2337
2338 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002339 vport->cfg_nodev_tmo = val;
2340 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002341 return 0;
2342 }
James Smarte8b62012007-08-02 11:10:09 -04002343 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2344 "0400 lpfc_nodev_tmo attribute cannot be set to"
2345 " %d, allowed range is [%d, %d]\n",
2346 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002347 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002348 return -EINVAL;
2349}
2350
James Smarte59058c2008-08-24 21:49:00 -04002351/**
James Smart3621a712009-04-06 18:47:14 -04002352 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002353 * @vport: lpfc vport structure pointer.
2354 *
2355 * Description:
2356 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2357 **/
James Smart7054a602007-04-25 09:52:34 -04002358static void
James Smart3de2a652007-08-02 11:09:59 -04002359lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002360{
James Smart858c9f62007-06-17 19:56:39 -05002361 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002362 struct lpfc_nodelist *ndlp;
2363
James Smart51ef4c22007-08-02 11:10:31 -04002364 shost = lpfc_shost_from_vport(vport);
2365 spin_lock_irq(shost->host_lock);
2366 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002367 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002368 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2369 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002370}
2371
James Smarte59058c2008-08-24 21:49:00 -04002372/**
James Smart3621a712009-04-06 18:47:14 -04002373 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002374 * @vport: lpfc vport structure pointer.
2375 * @val: contains the tmo value.
2376 *
2377 * Description:
2378 * If the devloss tmo is already set or the vport dev loss tmo has changed
2379 * then a kernel error message is printed and zero is returned.
2380 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2381 * Otherwise nodev tmo is set to the default value.
2382 *
2383 * Returns:
2384 * zero if already set or if val is in range
2385 * -EINVAL val out of range
2386 **/
James Smartc01f3202006-08-18 17:47:08 -04002387static int
James Smart3de2a652007-08-02 11:09:59 -04002388lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002389{
James Smart3de2a652007-08-02 11:09:59 -04002390 if (vport->dev_loss_tmo_changed ||
2391 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002392 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2393 "0401 Ignoring change to nodev_tmo "
2394 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002395 return 0;
2396 }
James Smartc01f3202006-08-18 17:47:08 -04002397 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002398 vport->cfg_nodev_tmo = val;
2399 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002400 /*
2401 * For compat: set the fc_host dev loss so new rports
2402 * will get the value.
2403 */
2404 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002405 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002406 return 0;
2407 }
James Smarte8b62012007-08-02 11:10:09 -04002408 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2409 "0403 lpfc_nodev_tmo attribute cannot be set to"
2410 "%d, allowed range is [%d, %d]\n",
2411 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002412 return -EINVAL;
2413}
2414
James Smart3de2a652007-08-02 11:09:59 -04002415lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002416
Tony Jonesee959b02008-02-22 00:13:36 +01002417static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2418 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002419
2420/*
2421# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2422# disappear until the timer expires. Value range is [0,255]. Default
2423# value is 30.
2424*/
James Smartab56dc22011-02-16 12:39:57 -05002425module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002426MODULE_PARM_DESC(lpfc_devloss_tmo,
2427 "Seconds driver will hold I/O waiting "
2428 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002429lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2430 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2431lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002432
2433/**
James Smart3621a712009-04-06 18:47:14 -04002434 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002435 * @vport: lpfc vport structure pointer.
2436 * @val: contains the tmo value.
2437 *
2438 * Description:
2439 * If val is in a valid range then set the vport nodev tmo,
2440 * devloss tmo, also set the vport dev loss tmo changed flag.
2441 * Else a kernel error message is printed.
2442 *
2443 * Returns:
2444 * zero if val is in range
2445 * -EINVAL val out of range
2446 **/
James Smartc01f3202006-08-18 17:47:08 -04002447static int
James Smart3de2a652007-08-02 11:09:59 -04002448lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002449{
2450 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002451 vport->cfg_nodev_tmo = val;
2452 vport->cfg_devloss_tmo = val;
2453 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002454 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002455 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002456 return 0;
2457 }
2458
James Smarte8b62012007-08-02 11:10:09 -04002459 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2460 "0404 lpfc_devloss_tmo attribute cannot be set to"
2461 " %d, allowed range is [%d, %d]\n",
2462 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002463 return -EINVAL;
2464}
2465
James Smart3de2a652007-08-02 11:09:59 -04002466lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002467static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2468 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002469
2470/*
dea31012005-04-17 16:05:31 -05002471# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2472# deluged with LOTS of information.
2473# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002474# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002475*/
James Smartf4b4c682009-05-22 14:53:12 -04002476LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002477 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002478
2479/*
James Smart7ee5d432007-10-27 13:37:17 -04002480# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2481# objects that have been registered with the nameserver after login.
2482*/
2483LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2484 "Deregister nameserver objects before LOGO");
2485
2486/*
dea31012005-04-17 16:05:31 -05002487# lun_queue_depth: This parameter is used to limit the number of outstanding
2488# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2489*/
James Smart3de2a652007-08-02 11:09:59 -04002490LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2491 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002492
2493/*
James Smart7dc517d2010-07-14 15:32:10 -04002494# tgt_queue_depth: This parameter is used to limit the number of outstanding
2495# commands per target port. Value range is [10,65535]. Default value is 65535.
2496*/
2497LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2498 "Max number of FCP commands we can queue to a specific target port");
2499
2500/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002501# hba_queue_depth: This parameter is used to limit the number of outstanding
2502# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2503# value is greater than the maximum number of exchanges supported by the HBA,
2504# then maximum number of exchanges supported by the HBA is used to determine
2505# the hba_queue_depth.
2506*/
2507LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2508 "Max number of FCP commands we can queue to a lpfc HBA");
2509
2510/*
James Smart92d7f7b2007-06-17 19:56:38 -05002511# peer_port_login: This parameter allows/prevents logins
2512# between peer ports hosted on the same physical port.
2513# When this parameter is set 0 peer ports of same physical port
2514# are not allowed to login to each other.
2515# When this parameter is set 1 peer ports of same physical port
2516# are allowed to login to each other.
2517# Default value of this parameter is 0.
2518*/
James Smart3de2a652007-08-02 11:09:59 -04002519LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2520 "Allow peer ports on the same physical port to login to each "
2521 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002522
2523/*
James Smart3de2a652007-08-02 11:09:59 -04002524# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002525# between Virtual Ports and remote initiators.
2526# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2527# other initiators and will attempt to PLOGI all remote ports.
2528# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2529# remote ports and will not attempt to PLOGI to other initiators.
2530# This parameter does not restrict to the physical port.
2531# This parameter does not restrict logins to Fabric resident remote ports.
2532# Default value of this parameter is 1.
2533*/
James Smart3de2a652007-08-02 11:09:59 -04002534static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002535module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002536MODULE_PARM_DESC(lpfc_restrict_login,
2537 "Restrict virtual ports login to remote initiators.");
2538lpfc_vport_param_show(restrict_login);
2539
James Smarte59058c2008-08-24 21:49:00 -04002540/**
James Smart3621a712009-04-06 18:47:14 -04002541 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002542 * @vport: lpfc vport structure pointer.
2543 * @val: contains the restrict login value.
2544 *
2545 * Description:
2546 * If val is not in a valid range then log a kernel error message and set
2547 * the vport restrict login to one.
2548 * If the port type is physical clear the restrict login flag and return.
2549 * Else set the restrict login flag to val.
2550 *
2551 * Returns:
2552 * zero if val is in range
2553 * -EINVAL val out of range
2554 **/
James Smart3de2a652007-08-02 11:09:59 -04002555static int
2556lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2557{
2558 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002559 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002560 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002561 "be set to %d, allowed range is [0, 1]\n",
2562 val);
James Smart3de2a652007-08-02 11:09:59 -04002563 vport->cfg_restrict_login = 1;
2564 return -EINVAL;
2565 }
2566 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2567 vport->cfg_restrict_login = 0;
2568 return 0;
2569 }
2570 vport->cfg_restrict_login = val;
2571 return 0;
2572}
2573
James Smarte59058c2008-08-24 21:49:00 -04002574/**
James Smart3621a712009-04-06 18:47:14 -04002575 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002576 * @vport: lpfc vport structure pointer.
2577 * @val: contains the restrict login value.
2578 *
2579 * Description:
2580 * If val is not in a valid range then log a kernel error message and set
2581 * the vport restrict login to one.
2582 * If the port type is physical and the val is not zero log a kernel
2583 * error message, clear the restrict login flag and return zero.
2584 * Else set the restrict login flag to val.
2585 *
2586 * Returns:
2587 * zero if val is in range
2588 * -EINVAL val out of range
2589 **/
James Smart3de2a652007-08-02 11:09:59 -04002590static int
2591lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2592{
2593 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002594 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002595 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002596 "be set to %d, allowed range is [0, 1]\n",
2597 val);
James Smart3de2a652007-08-02 11:09:59 -04002598 vport->cfg_restrict_login = 1;
2599 return -EINVAL;
2600 }
2601 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002602 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2603 "0468 lpfc_restrict_login must be 0 for "
2604 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002605 vport->cfg_restrict_login = 0;
2606 return 0;
2607 }
2608 vport->cfg_restrict_login = val;
2609 return 0;
2610}
2611lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002612static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2613 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002614
2615/*
dea31012005-04-17 16:05:31 -05002616# Some disk devices have a "select ID" or "select Target" capability.
2617# From a protocol standpoint "select ID" usually means select the
2618# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2619# annex" which contains a table that maps a "select ID" (a number
2620# between 0 and 7F) to an ALPA. By default, for compatibility with
2621# older drivers, the lpfc driver scans this table from low ALPA to high
2622# ALPA.
2623#
2624# Turning on the scan-down variable (on = 1, off = 0) will
2625# cause the lpfc driver to use an inverted table, effectively
2626# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2627#
2628# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2629# and will not work across a fabric. Also this parameter will take
2630# effect only in the case when ALPA map is not available.)
2631*/
James Smart3de2a652007-08-02 11:09:59 -04002632LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2633 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002634
2635/*
dea31012005-04-17 16:05:31 -05002636# lpfc_topology: link topology for init link
2637# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002638# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002639# 0x02 = attempt point-to-point mode only
2640# 0x04 = attempt loop mode only
2641# 0x06 = attempt point-to-point mode then loop
2642# Set point-to-point mode if you want to run as an N_Port.
2643# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2644# Default value is 0.
2645*/
James Smarte59058c2008-08-24 21:49:00 -04002646
2647/**
James Smart3621a712009-04-06 18:47:14 -04002648 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002649 * @phba: lpfc_hba pointer.
2650 * @val: topology value.
2651 *
2652 * Description:
2653 * If val is in a valid range then set the adapter's topology field and
2654 * issue a lip; if the lip fails reset the topology to the old value.
2655 *
2656 * If the value is not in range log a kernel error message and return an error.
2657 *
2658 * Returns:
2659 * zero if val is in range and lip okay
2660 * non-zero return value from lpfc_issue_lip()
2661 * -EINVAL val out of range
2662 **/
James Smarta257bf92009-04-06 18:48:10 -04002663static ssize_t
2664lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2665 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002666{
James Smarta257bf92009-04-06 18:48:10 -04002667 struct Scsi_Host *shost = class_to_shost(dev);
2668 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2669 struct lpfc_hba *phba = vport->phba;
2670 int val = 0;
2671 int nolip = 0;
2672 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002673 int err;
2674 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002675
2676 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2677 nolip = 1;
2678 val_buf = &buf[strlen("nolip ")];
2679 }
2680
2681 if (!isdigit(val_buf[0]))
2682 return -EINVAL;
2683 if (sscanf(val_buf, "%i", &val) != 1)
2684 return -EINVAL;
2685
James Smart83108bd2008-01-11 01:53:09 -05002686 if (val >= 0 && val <= 6) {
2687 prev_val = phba->cfg_topology;
2688 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002689 if (nolip)
2690 return strlen(buf);
2691
James Smart88a2cfb2011-07-22 18:36:33 -04002692 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2693 "3054 lpfc_topology changed from %d to %d\n",
2694 prev_val, val);
James Smart83108bd2008-01-11 01:53:09 -05002695 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002696 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002697 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002698 return -EINVAL;
2699 } else
2700 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002701 }
2702 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2703 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2704 "allowed range is [0, 6]\n",
2705 phba->brd_no, val);
2706 return -EINVAL;
2707}
2708static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002709module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002710MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2711lpfc_param_show(topology)
2712lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002713static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002714 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002715
James Smart21e9a0a2009-05-22 14:53:21 -04002716/**
2717 * lpfc_static_vport_show: Read callback function for
2718 * lpfc_static_vport sysfs file.
2719 * @dev: Pointer to class device object.
2720 * @attr: device attribute structure.
2721 * @buf: Data buffer.
2722 *
2723 * This function is the read call back function for
2724 * lpfc_static_vport sysfs file. The lpfc_static_vport
2725 * sysfs file report the mageability of the vport.
2726 **/
2727static ssize_t
2728lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2729 char *buf)
2730{
2731 struct Scsi_Host *shost = class_to_shost(dev);
2732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2733 if (vport->vport_flag & STATIC_VPORT)
2734 sprintf(buf, "1\n");
2735 else
2736 sprintf(buf, "0\n");
2737
2738 return strlen(buf);
2739}
2740
2741/*
2742 * Sysfs attribute to control the statistical data collection.
2743 */
2744static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2745 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002746
2747/**
James Smart3621a712009-04-06 18:47:14 -04002748 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002749 * @dev: Pointer to class device.
2750 * @buf: Data buffer.
2751 * @count: Size of the data buffer.
2752 *
2753 * This function get called when an user write to the lpfc_stat_data_ctrl
2754 * sysfs file. This function parse the command written to the sysfs file
2755 * and take appropriate action. These commands are used for controlling
2756 * driver statistical data collection.
2757 * Following are the command this function handles.
2758 *
2759 * setbucket <bucket_type> <base> <step>
2760 * = Set the latency buckets.
2761 * destroybucket = destroy all the buckets.
2762 * start = start data collection
2763 * stop = stop data collection
2764 * reset = reset the collected data
2765 **/
2766static ssize_t
2767lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2768 const char *buf, size_t count)
2769{
2770 struct Scsi_Host *shost = class_to_shost(dev);
2771 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2772 struct lpfc_hba *phba = vport->phba;
2773#define LPFC_MAX_DATA_CTRL_LEN 1024
2774 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2775 unsigned long i;
2776 char *str_ptr, *token;
2777 struct lpfc_vport **vports;
2778 struct Scsi_Host *v_shost;
2779 char *bucket_type_str, *base_str, *step_str;
2780 unsigned long base, step, bucket_type;
2781
2782 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002783 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002784 return -EINVAL;
2785
2786 strcpy(bucket_data, buf);
2787 str_ptr = &bucket_data[0];
2788 /* Ignore this token - this is command token */
2789 token = strsep(&str_ptr, "\t ");
2790 if (!token)
2791 return -EINVAL;
2792
2793 bucket_type_str = strsep(&str_ptr, "\t ");
2794 if (!bucket_type_str)
2795 return -EINVAL;
2796
2797 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2798 bucket_type = LPFC_LINEAR_BUCKET;
2799 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2800 bucket_type = LPFC_POWER2_BUCKET;
2801 else
2802 return -EINVAL;
2803
2804 base_str = strsep(&str_ptr, "\t ");
2805 if (!base_str)
2806 return -EINVAL;
2807 base = simple_strtoul(base_str, NULL, 0);
2808
2809 step_str = strsep(&str_ptr, "\t ");
2810 if (!step_str)
2811 return -EINVAL;
2812 step = simple_strtoul(step_str, NULL, 0);
2813 if (!step)
2814 return -EINVAL;
2815
2816 /* Block the data collection for every vport */
2817 vports = lpfc_create_vport_work_array(phba);
2818 if (vports == NULL)
2819 return -ENOMEM;
2820
James Smartf4b4c682009-05-22 14:53:12 -04002821 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002822 v_shost = lpfc_shost_from_vport(vports[i]);
2823 spin_lock_irq(v_shost->host_lock);
2824 /* Block and reset data collection */
2825 vports[i]->stat_data_blocked = 1;
2826 if (vports[i]->stat_data_enabled)
2827 lpfc_vport_reset_stat_data(vports[i]);
2828 spin_unlock_irq(v_shost->host_lock);
2829 }
2830
2831 /* Set the bucket attributes */
2832 phba->bucket_type = bucket_type;
2833 phba->bucket_base = base;
2834 phba->bucket_step = step;
2835
James Smartf4b4c682009-05-22 14:53:12 -04002836 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002837 v_shost = lpfc_shost_from_vport(vports[i]);
2838
2839 /* Unblock data collection */
2840 spin_lock_irq(v_shost->host_lock);
2841 vports[i]->stat_data_blocked = 0;
2842 spin_unlock_irq(v_shost->host_lock);
2843 }
2844 lpfc_destroy_vport_work_array(phba, vports);
2845 return strlen(buf);
2846 }
2847
2848 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2849 vports = lpfc_create_vport_work_array(phba);
2850 if (vports == NULL)
2851 return -ENOMEM;
2852
James Smartf4b4c682009-05-22 14:53:12 -04002853 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002854 v_shost = lpfc_shost_from_vport(vports[i]);
2855 spin_lock_irq(shost->host_lock);
2856 vports[i]->stat_data_blocked = 1;
2857 lpfc_free_bucket(vport);
2858 vport->stat_data_enabled = 0;
2859 vports[i]->stat_data_blocked = 0;
2860 spin_unlock_irq(shost->host_lock);
2861 }
2862 lpfc_destroy_vport_work_array(phba, vports);
2863 phba->bucket_type = LPFC_NO_BUCKET;
2864 phba->bucket_base = 0;
2865 phba->bucket_step = 0;
2866 return strlen(buf);
2867 }
2868
2869 if (!strncmp(buf, "start", strlen("start"))) {
2870 /* If no buckets configured return error */
2871 if (phba->bucket_type == LPFC_NO_BUCKET)
2872 return -EINVAL;
2873 spin_lock_irq(shost->host_lock);
2874 if (vport->stat_data_enabled) {
2875 spin_unlock_irq(shost->host_lock);
2876 return strlen(buf);
2877 }
2878 lpfc_alloc_bucket(vport);
2879 vport->stat_data_enabled = 1;
2880 spin_unlock_irq(shost->host_lock);
2881 return strlen(buf);
2882 }
2883
2884 if (!strncmp(buf, "stop", strlen("stop"))) {
2885 spin_lock_irq(shost->host_lock);
2886 if (vport->stat_data_enabled == 0) {
2887 spin_unlock_irq(shost->host_lock);
2888 return strlen(buf);
2889 }
2890 lpfc_free_bucket(vport);
2891 vport->stat_data_enabled = 0;
2892 spin_unlock_irq(shost->host_lock);
2893 return strlen(buf);
2894 }
2895
2896 if (!strncmp(buf, "reset", strlen("reset"))) {
2897 if ((phba->bucket_type == LPFC_NO_BUCKET)
2898 || !vport->stat_data_enabled)
2899 return strlen(buf);
2900 spin_lock_irq(shost->host_lock);
2901 vport->stat_data_blocked = 1;
2902 lpfc_vport_reset_stat_data(vport);
2903 vport->stat_data_blocked = 0;
2904 spin_unlock_irq(shost->host_lock);
2905 return strlen(buf);
2906 }
2907 return -EINVAL;
2908}
2909
2910
2911/**
James Smart3621a712009-04-06 18:47:14 -04002912 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002913 * @dev: Pointer to class device object.
2914 * @buf: Data buffer.
2915 *
2916 * This function is the read call back function for
2917 * lpfc_stat_data_ctrl sysfs file. This function report the
2918 * current statistical data collection state.
2919 **/
2920static ssize_t
2921lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2922 char *buf)
2923{
2924 struct Scsi_Host *shost = class_to_shost(dev);
2925 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2926 struct lpfc_hba *phba = vport->phba;
2927 int index = 0;
2928 int i;
2929 char *bucket_type;
2930 unsigned long bucket_value;
2931
2932 switch (phba->bucket_type) {
2933 case LPFC_LINEAR_BUCKET:
2934 bucket_type = "linear";
2935 break;
2936 case LPFC_POWER2_BUCKET:
2937 bucket_type = "power2";
2938 break;
2939 default:
2940 bucket_type = "No Bucket";
2941 break;
2942 }
2943
2944 sprintf(&buf[index], "Statistical Data enabled :%d, "
2945 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2946 " Bucket step :%d\nLatency Ranges :",
2947 vport->stat_data_enabled, vport->stat_data_blocked,
2948 bucket_type, phba->bucket_base, phba->bucket_step);
2949 index = strlen(buf);
2950 if (phba->bucket_type != LPFC_NO_BUCKET) {
2951 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2952 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2953 bucket_value = phba->bucket_base +
2954 phba->bucket_step * i;
2955 else
2956 bucket_value = phba->bucket_base +
2957 (1 << i) * phba->bucket_step;
2958
2959 if (index + 10 > PAGE_SIZE)
2960 break;
2961 sprintf(&buf[index], "%08ld ", bucket_value);
2962 index = strlen(buf);
2963 }
2964 }
2965 sprintf(&buf[index], "\n");
2966 return strlen(buf);
2967}
2968
2969/*
2970 * Sysfs attribute to control the statistical data collection.
2971 */
2972static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2973 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2974
2975/*
2976 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2977 */
2978
2979/*
2980 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2981 * for each target.
2982 */
2983#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2984#define MAX_STAT_DATA_SIZE_PER_TARGET \
2985 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2986
2987
2988/**
James Smart3621a712009-04-06 18:47:14 -04002989 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002990 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002991 * @kobj: Pointer to the kernel object
2992 * @bin_attr: Attribute object
2993 * @buff: Buffer pointer
2994 * @off: File offset
2995 * @count: Buffer size
2996 *
2997 * This function is the read call back function for lpfc_drvr_stat_data
2998 * sysfs file. This function export the statistical data to user
2999 * applications.
3000 **/
3001static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003002sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3003 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003004 char *buf, loff_t off, size_t count)
3005{
3006 struct device *dev = container_of(kobj, struct device,
3007 kobj);
3008 struct Scsi_Host *shost = class_to_shost(dev);
3009 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3010 struct lpfc_hba *phba = vport->phba;
3011 int i = 0, index = 0;
3012 unsigned long nport_index;
3013 struct lpfc_nodelist *ndlp = NULL;
3014 nport_index = (unsigned long)off /
3015 MAX_STAT_DATA_SIZE_PER_TARGET;
3016
3017 if (!vport->stat_data_enabled || vport->stat_data_blocked
3018 || (phba->bucket_type == LPFC_NO_BUCKET))
3019 return 0;
3020
3021 spin_lock_irq(shost->host_lock);
3022 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3023 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3024 continue;
3025
3026 if (nport_index > 0) {
3027 nport_index--;
3028 continue;
3029 }
3030
3031 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3032 > count)
3033 break;
3034
3035 if (!ndlp->lat_data)
3036 continue;
3037
3038 /* Print the WWN */
3039 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3040 ndlp->nlp_portname.u.wwn[0],
3041 ndlp->nlp_portname.u.wwn[1],
3042 ndlp->nlp_portname.u.wwn[2],
3043 ndlp->nlp_portname.u.wwn[3],
3044 ndlp->nlp_portname.u.wwn[4],
3045 ndlp->nlp_portname.u.wwn[5],
3046 ndlp->nlp_portname.u.wwn[6],
3047 ndlp->nlp_portname.u.wwn[7]);
3048
3049 index = strlen(buf);
3050
3051 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3052 sprintf(&buf[index], "%010u,",
3053 ndlp->lat_data[i].cmd_count);
3054 index = strlen(buf);
3055 }
3056 sprintf(&buf[index], "\n");
3057 index = strlen(buf);
3058 }
3059 spin_unlock_irq(shost->host_lock);
3060 return index;
3061}
3062
3063static struct bin_attribute sysfs_drvr_stat_data_attr = {
3064 .attr = {
3065 .name = "lpfc_drvr_stat_data",
3066 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003067 },
3068 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3069 .read = sysfs_drvr_stat_data_read,
3070 .write = NULL,
3071};
3072
dea31012005-04-17 16:05:31 -05003073/*
3074# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3075# connection.
James Smart76a95d72010-11-20 23:11:48 -05003076# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003077*/
James Smarte59058c2008-08-24 21:49:00 -04003078/**
James Smart3621a712009-04-06 18:47:14 -04003079 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003080 * @phba: lpfc_hba pointer.
3081 * @val: link speed value.
3082 *
3083 * Description:
3084 * If val is in a valid range then set the adapter's link speed field and
3085 * issue a lip; if the lip fails reset the link speed to the old value.
3086 *
3087 * Notes:
3088 * If the value is not in range log a kernel error message and return an error.
3089 *
3090 * Returns:
3091 * zero if val is in range and lip okay.
3092 * non-zero return value from lpfc_issue_lip()
3093 * -EINVAL val out of range
3094 **/
James Smarta257bf92009-04-06 18:48:10 -04003095static ssize_t
3096lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3097 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003098{
James Smarta257bf92009-04-06 18:48:10 -04003099 struct Scsi_Host *shost = class_to_shost(dev);
3100 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3101 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003102 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003103 int nolip = 0;
3104 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003105 int err;
3106 uint32_t prev_val;
3107
James Smarta257bf92009-04-06 18:48:10 -04003108 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3109 nolip = 1;
3110 val_buf = &buf[strlen("nolip ")];
3111 }
3112
3113 if (!isdigit(val_buf[0]))
3114 return -EINVAL;
3115 if (sscanf(val_buf, "%i", &val) != 1)
3116 return -EINVAL;
3117
James Smart88a2cfb2011-07-22 18:36:33 -04003118 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3119 "3055 lpfc_link_speed changed from %d to %d %s\n",
3120 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3121
James Smart76a95d72010-11-20 23:11:48 -05003122 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3123 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3124 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3125 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3126 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3127 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3128 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3129 "2879 lpfc_link_speed attribute cannot be set "
3130 "to %d. Speed is not supported by this port.\n",
3131 val);
James Smart83108bd2008-01-11 01:53:09 -05003132 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003133 }
3134 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3135 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003136 prev_val = phba->cfg_link_speed;
3137 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003138 if (nolip)
3139 return strlen(buf);
3140
James Smart83108bd2008-01-11 01:53:09 -05003141 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003142 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003143 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003144 return -EINVAL;
3145 } else
3146 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003147 }
James Smart83108bd2008-01-11 01:53:09 -05003148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003149 "0469 lpfc_link_speed attribute cannot be set to %d, "
3150 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003151 return -EINVAL;
3152}
3153
3154static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003155module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003156MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3157lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003158
3159/**
James Smart3621a712009-04-06 18:47:14 -04003160 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003161 * @phba: lpfc_hba pointer.
3162 * @val: link speed value.
3163 *
3164 * Description:
3165 * If val is in a valid range then set the adapter's link speed field.
3166 *
3167 * Notes:
3168 * If the value is not in range log a kernel error message, clear the link
3169 * speed and return an error.
3170 *
3171 * Returns:
3172 * zero if val saved.
3173 * -EINVAL val out of range
3174 **/
James Smart83108bd2008-01-11 01:53:09 -05003175static int
3176lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3177{
James Smart76a95d72010-11-20 23:11:48 -05003178 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3179 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003180 phba->cfg_link_speed = val;
3181 return 0;
3182 }
3183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003184 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003185 "be set to %d, allowed values are "
3186 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003187 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003188 return -EINVAL;
3189}
3190
Tony Jonesee959b02008-02-22 00:13:36 +01003191static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003192 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003193
3194/*
James Smart0d878412009-10-02 15:16:56 -04003195# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3196# 0 = aer disabled or not supported
3197# 1 = aer supported and enabled (default)
3198# Value range is [0,1]. Default value is 1.
3199*/
3200
3201/**
3202 * lpfc_aer_support_store - Set the adapter for aer support
3203 *
3204 * @dev: class device that is converted into a Scsi_host.
3205 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003206 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003207 * @count: unused variable.
3208 *
3209 * Description:
3210 * If the val is 1 and currently the device's AER capability was not
3211 * enabled, invoke the kernel's enable AER helper routine, trying to
3212 * enable the device's AER capability. If the helper routine enabling
3213 * AER returns success, update the device's cfg_aer_support flag to
3214 * indicate AER is supported by the device; otherwise, if the device
3215 * AER capability is already enabled to support AER, then do nothing.
3216 *
3217 * If the val is 0 and currently the device's AER support was enabled,
3218 * invoke the kernel's disable AER helper routine. After that, update
3219 * the device's cfg_aer_support flag to indicate AER is not supported
3220 * by the device; otherwise, if the device AER capability is already
3221 * disabled from supporting AER, then do nothing.
3222 *
3223 * Returns:
3224 * length of the buf on success if val is in range the intended mode
3225 * is supported.
3226 * -EINVAL if val out of range or intended mode is not supported.
3227 **/
3228static ssize_t
3229lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3230 const char *buf, size_t count)
3231{
3232 struct Scsi_Host *shost = class_to_shost(dev);
3233 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3234 struct lpfc_hba *phba = vport->phba;
3235 int val = 0, rc = -EINVAL;
3236
3237 if (!isdigit(buf[0]))
3238 return -EINVAL;
3239 if (sscanf(buf, "%i", &val) != 1)
3240 return -EINVAL;
3241
3242 switch (val) {
3243 case 0:
3244 if (phba->hba_flag & HBA_AER_ENABLED) {
3245 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3246 if (!rc) {
3247 spin_lock_irq(&phba->hbalock);
3248 phba->hba_flag &= ~HBA_AER_ENABLED;
3249 spin_unlock_irq(&phba->hbalock);
3250 phba->cfg_aer_support = 0;
3251 rc = strlen(buf);
3252 } else
James Smart891478a2009-11-18 15:40:23 -05003253 rc = -EPERM;
3254 } else {
James Smart0d878412009-10-02 15:16:56 -04003255 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003256 rc = strlen(buf);
3257 }
James Smart0d878412009-10-02 15:16:56 -04003258 break;
3259 case 1:
3260 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3261 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3262 if (!rc) {
3263 spin_lock_irq(&phba->hbalock);
3264 phba->hba_flag |= HBA_AER_ENABLED;
3265 spin_unlock_irq(&phba->hbalock);
3266 phba->cfg_aer_support = 1;
3267 rc = strlen(buf);
3268 } else
James Smart891478a2009-11-18 15:40:23 -05003269 rc = -EPERM;
3270 } else {
James Smart0d878412009-10-02 15:16:56 -04003271 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003272 rc = strlen(buf);
3273 }
James Smart0d878412009-10-02 15:16:56 -04003274 break;
3275 default:
3276 rc = -EINVAL;
3277 break;
3278 }
3279 return rc;
3280}
3281
3282static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003283module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003284MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3285lpfc_param_show(aer_support)
3286
3287/**
3288 * lpfc_aer_support_init - Set the initial adapters aer support flag
3289 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003290 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003291 *
3292 * Description:
3293 * If val is in a valid range [0,1], then set the adapter's initial
3294 * cfg_aer_support field. It will be up to the driver's probe_one
3295 * routine to determine whether the device's AER support can be set
3296 * or not.
3297 *
3298 * Notes:
3299 * If the value is not in range log a kernel error message, and
3300 * choose the default value of setting AER support and return.
3301 *
3302 * Returns:
3303 * zero if val saved.
3304 * -EINVAL val out of range
3305 **/
3306static int
3307lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3308{
3309 if (val == 0 || val == 1) {
3310 phba->cfg_aer_support = val;
3311 return 0;
3312 }
3313 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3314 "2712 lpfc_aer_support attribute value %d out "
3315 "of range, allowed values are 0|1, setting it "
3316 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003317 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003318 phba->cfg_aer_support = 1;
3319 return -EINVAL;
3320}
3321
3322static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3323 lpfc_aer_support_show, lpfc_aer_support_store);
3324
3325/**
3326 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3327 * @dev: class device that is converted into a Scsi_host.
3328 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003329 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003330 * @count: unused variable.
3331 *
3332 * Description:
3333 * If the @buf contains 1 and the device currently has the AER support
3334 * enabled, then invokes the kernel AER helper routine
3335 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3336 * error status register.
3337 *
3338 * Notes:
3339 *
3340 * Returns:
3341 * -EINVAL if the buf does not contain the 1 or the device is not currently
3342 * enabled with the AER support.
3343 **/
3344static ssize_t
3345lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3346 const char *buf, size_t count)
3347{
3348 struct Scsi_Host *shost = class_to_shost(dev);
3349 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3350 struct lpfc_hba *phba = vport->phba;
3351 int val, rc = -1;
3352
3353 if (!isdigit(buf[0]))
3354 return -EINVAL;
3355 if (sscanf(buf, "%i", &val) != 1)
3356 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003357 if (val != 1)
3358 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003359
James Smart891478a2009-11-18 15:40:23 -05003360 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003361 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3362
3363 if (rc == 0)
3364 return strlen(buf);
3365 else
James Smart891478a2009-11-18 15:40:23 -05003366 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003367}
3368
3369static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3370 lpfc_aer_cleanup_state);
3371
James Smart912e3ac2011-05-24 11:42:11 -04003372/**
3373 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3374 *
3375 * @dev: class device that is converted into a Scsi_host.
3376 * @attr: device attribute, not used.
3377 * @buf: containing the string the number of vfs to be enabled.
3378 * @count: unused variable.
3379 *
3380 * Description:
3381 * When this api is called either through user sysfs, the driver shall
3382 * try to enable or disable SR-IOV virtual functions according to the
3383 * following:
3384 *
3385 * If zero virtual function has been enabled to the physical function,
3386 * the driver shall invoke the pci enable virtual function api trying
3387 * to enable the virtual functions. If the nr_vfn provided is greater
3388 * than the maximum supported, the maximum virtual function number will
3389 * be used for invoking the api; otherwise, the nr_vfn provided shall
3390 * be used for invoking the api. If the api call returned success, the
3391 * actual number of virtual functions enabled will be set to the driver
3392 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3393 * cfg_sriov_nr_virtfn remains zero.
3394 *
3395 * If none-zero virtual functions have already been enabled to the
3396 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3397 * -EINVAL will be returned and the driver does nothing;
3398 *
3399 * If the nr_vfn provided is zero and none-zero virtual functions have
3400 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3401 * disabling virtual function api shall be invoded to disable all the
3402 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3403 * zero. Otherwise, if zero virtual function has been enabled, do
3404 * nothing.
3405 *
3406 * Returns:
3407 * length of the buf on success if val is in range the intended mode
3408 * is supported.
3409 * -EINVAL if val out of range or intended mode is not supported.
3410 **/
3411static ssize_t
3412lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3413 const char *buf, size_t count)
3414{
3415 struct Scsi_Host *shost = class_to_shost(dev);
3416 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3417 struct lpfc_hba *phba = vport->phba;
3418 struct pci_dev *pdev = phba->pcidev;
3419 int val = 0, rc = -EINVAL;
3420
3421 /* Sanity check on user data */
3422 if (!isdigit(buf[0]))
3423 return -EINVAL;
3424 if (sscanf(buf, "%i", &val) != 1)
3425 return -EINVAL;
3426 if (val < 0)
3427 return -EINVAL;
3428
3429 /* Request disabling virtual functions */
3430 if (val == 0) {
3431 if (phba->cfg_sriov_nr_virtfn > 0) {
3432 pci_disable_sriov(pdev);
3433 phba->cfg_sriov_nr_virtfn = 0;
3434 }
3435 return strlen(buf);
3436 }
3437
3438 /* Request enabling virtual functions */
3439 if (phba->cfg_sriov_nr_virtfn > 0) {
3440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3441 "3018 There are %d virtual functions "
3442 "enabled on physical function.\n",
3443 phba->cfg_sriov_nr_virtfn);
3444 return -EEXIST;
3445 }
3446
3447 if (val <= LPFC_MAX_VFN_PER_PFN)
3448 phba->cfg_sriov_nr_virtfn = val;
3449 else {
3450 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3451 "3019 Enabling %d virtual functions is not "
3452 "allowed.\n", val);
3453 return -EINVAL;
3454 }
3455
3456 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3457 if (rc) {
3458 phba->cfg_sriov_nr_virtfn = 0;
3459 rc = -EPERM;
3460 } else
3461 rc = strlen(buf);
3462
3463 return rc;
3464}
3465
3466static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3467module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3468MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3469lpfc_param_show(sriov_nr_virtfn)
3470
3471/**
3472 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3473 * @phba: lpfc_hba pointer.
3474 * @val: link speed value.
3475 *
3476 * Description:
3477 * If val is in a valid range [0,255], then set the adapter's initial
3478 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3479 * number shall be used instead. It will be up to the driver's probe_one
3480 * routine to determine whether the device's SR-IOV is supported or not.
3481 *
3482 * Returns:
3483 * zero if val saved.
3484 * -EINVAL val out of range
3485 **/
3486static int
3487lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3488{
3489 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3490 phba->cfg_sriov_nr_virtfn = val;
3491 return 0;
3492 }
3493
3494 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3495 "3017 Enabling %d virtual functions is not "
3496 "allowed.\n", val);
3497 return -EINVAL;
3498}
3499static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3500 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3501
James Smart0d878412009-10-02 15:16:56 -04003502/*
dea31012005-04-17 16:05:31 -05003503# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3504# Value range is [2,3]. Default value is 3.
3505*/
James Smart3de2a652007-08-02 11:09:59 -04003506LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3507 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003508
3509/*
3510# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3511# is [0,1]. Default value is 0.
3512*/
James Smart3de2a652007-08-02 11:09:59 -04003513LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3514 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003515
3516/*
James Smart977b5a02008-09-07 11:52:04 -04003517# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3518# depth. Default value is 0. When the value of this parameter is zero the
3519# SCSI command completion time is not used for controlling I/O queue depth. When
3520# the parameter is set to a non-zero value, the I/O queue depth is controlled
3521# to limit the I/O completion time to the parameter value.
3522# The value is set in milliseconds.
3523*/
3524static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003525module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003526MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3527 "Use command completion time to control queue depth");
3528lpfc_vport_param_show(max_scsicmpl_time);
3529lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3530static int
3531lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3532{
3533 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3534 struct lpfc_nodelist *ndlp, *next_ndlp;
3535
3536 if (val == vport->cfg_max_scsicmpl_time)
3537 return 0;
3538 if ((val < 0) || (val > 60000))
3539 return -EINVAL;
3540 vport->cfg_max_scsicmpl_time = val;
3541
3542 spin_lock_irq(shost->host_lock);
3543 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3544 if (!NLP_CHK_NODE_ACT(ndlp))
3545 continue;
3546 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3547 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003548 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003549 }
3550 spin_unlock_irq(shost->host_lock);
3551 return 0;
3552}
3553lpfc_vport_param_store(max_scsicmpl_time);
3554static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3555 lpfc_max_scsicmpl_time_show,
3556 lpfc_max_scsicmpl_time_store);
3557
3558/*
dea31012005-04-17 16:05:31 -05003559# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3560# range is [0,1]. Default value is 0.
3561*/
3562LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3563
3564/*
3565# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3566# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003567# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003568# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3569# cr_delay is set to 0.
3570*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003571LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003572 "interrupt response is generated");
3573
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003574LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003575 "interrupt response is generated");
3576
3577/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003578# lpfc_multi_ring_support: Determines how many rings to spread available
3579# cmd/rsp IOCB entries across.
3580# Value range is [1,2]. Default value is 1.
3581*/
3582LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3583 "SLI rings to spread IOCB entries across");
3584
3585/*
James Smarta4bc3372006-12-02 13:34:16 -05003586# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3587# identifies what rctl value to configure the additional ring for.
3588# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3589*/
James Smart6a9c52c2009-10-02 15:16:51 -04003590LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003591 255, "Identifies RCTL for additional ring configuration");
3592
3593/*
3594# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3595# identifies what type value to configure the additional ring for.
3596# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3597*/
James Smart6a9c52c2009-10-02 15:16:51 -04003598LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003599 255, "Identifies TYPE for additional ring configuration");
3600
3601/*
dea31012005-04-17 16:05:31 -05003602# lpfc_fdmi_on: controls FDMI support.
3603# 0 = no FDMI support
3604# 1 = support FDMI without attribute of hostname
3605# 2 = support FDMI with attribute of hostname
3606# Value range [0,2]. Default value is 0.
3607*/
James Smart3de2a652007-08-02 11:09:59 -04003608LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003609
3610/*
3611# Specifies the maximum number of ELS cmds we can have outstanding (for
3612# discovery). Value range is [1,64]. Default value = 32.
3613*/
James Smart3de2a652007-08-02 11:09:59 -04003614LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003615 "during discovery");
3616
3617/*
James Smart65a29c12006-07-06 15:50:50 -04003618# lpfc_max_luns: maximum allowed LUN.
3619# Value range is [0,65535]. Default value is 255.
3620# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003621*/
James Smart3de2a652007-08-02 11:09:59 -04003622LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003623
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003624/*
3625# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3626# Value range is [1,255], default value is 10.
3627*/
3628LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3629 "Milliseconds driver will wait between polling FCP ring");
3630
James Smart4ff43242006-12-02 13:34:56 -05003631/*
3632# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3633# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003634# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003635# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003636# 2 = MSI-X enabled (default)
3637# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003638*/
George Kadianakis8605c462010-01-17 21:19:31 +02003639LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003640 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003641
James Smart13815c82008-01-11 01:52:48 -05003642/*
James Smartda0436e2009-05-22 14:51:39 -04003643# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3644#
3645# Value range is [636,651042]. Default value is 10000.
3646*/
3647LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3648 "Set the maximum number of fast-path FCP interrupts per second");
3649
3650/*
3651# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3652#
3653# Value range is [1,31]. Default value is 4.
3654*/
3655LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3656 "Set the number of fast-path FCP work queues, if possible");
3657
3658/*
3659# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3660#
3661# Value range is [1,7]. Default value is 1.
3662*/
3663LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3664 "Set the number of fast-path FCP event queues, if possible");
3665
3666/*
James Smart13815c82008-01-11 01:52:48 -05003667# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3668# 0 = HBA resets disabled
3669# 1 = HBA resets enabled (default)
3670# Value range is [0,1]. Default value is 1.
3671*/
3672LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003673
James Smart13815c82008-01-11 01:52:48 -05003674/*
James Smarteb7a3392010-11-20 23:12:02 -05003675# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003676# 0 = HBA Heartbeat disabled
3677# 1 = HBA Heartbeat enabled (default)
3678# Value range is [0,1]. Default value is 1.
3679*/
James Smarteb7a3392010-11-20 23:12:02 -05003680LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003681
James Smart83108bd2008-01-11 01:53:09 -05003682/*
James Smart81301a92008-12-04 22:39:46 -05003683# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3684# 0 = BlockGuard disabled (default)
3685# 1 = BlockGuard enabled
3686# Value range is [0,1]. Default value is 0.
3687*/
3688LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3689
James Smart6fb120a2009-05-22 14:52:59 -04003690/*
James Smart81301a92008-12-04 22:39:46 -05003691# lpfc_prot_mask: i
3692# - Bit mask of host protection capabilities used to register with the
3693# SCSI mid-layer
3694# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3695# - Allows you to ultimately specify which profiles to use
3696# - Default will result in registering capabilities for all profiles.
3697#
3698*/
James Smart7c56b9f2011-07-22 18:36:25 -04003699unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3700 SHOST_DIX_TYPE0_PROTECTION |
3701 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003702
James Smartab56dc22011-02-16 12:39:57 -05003703module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003704MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3705
3706/*
3707# lpfc_prot_guard: i
3708# - Bit mask of protection guard types to register with the SCSI mid-layer
3709# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3710# - Allows you to ultimately specify which profiles to use
3711# - Default will result in registering capabilities for all guard types
3712#
3713*/
3714unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003715module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003716MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3717
James Smart92494142011-02-16 12:39:44 -05003718/*
3719 * Delay initial NPort discovery when Clean Address bit is cleared in
3720 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3721 * This parameter can have value 0 or 1.
3722 * When this parameter is set to 0, no delay is added to the initial
3723 * discovery.
3724 * When this parameter is set to non-zero value, initial Nport discovery is
3725 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3726 * accept and FCID/Fabric name/Fabric portname is changed.
3727 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3728 * when Clean Address bit is cleared in FLOGI/FDISC
3729 * accept and FCID/Fabric name/Fabric portname is changed.
3730 * Default value is 0.
3731 */
3732int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003733module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003734MODULE_PARM_DESC(lpfc_delay_discovery,
3735 "Delay NPort discovery when Clean Address bit is cleared. "
3736 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003737
3738/*
James Smart3621a712009-04-06 18:47:14 -04003739 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003740 * This value can be set to values between 64 and 256. The default value is
3741 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3742 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3743 */
3744LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3745 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3746
James Smart81301a92008-12-04 22:39:46 -05003747LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3748 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3749 "Max Protection Scatter Gather Segment Count");
3750
Tony Jonesee959b02008-02-22 00:13:36 +01003751struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003752 &dev_attr_bg_info,
3753 &dev_attr_bg_guard_err,
3754 &dev_attr_bg_apptag_err,
3755 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003756 &dev_attr_info,
3757 &dev_attr_serialnum,
3758 &dev_attr_modeldesc,
3759 &dev_attr_modelname,
3760 &dev_attr_programtype,
3761 &dev_attr_portnum,
3762 &dev_attr_fwrev,
3763 &dev_attr_hdw,
3764 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003765 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003766 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003767 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003768 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003769 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003770 &dev_attr_lpfc_temp_sensor,
3771 &dev_attr_lpfc_log_verbose,
3772 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003773 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003774 &dev_attr_lpfc_hba_queue_depth,
3775 &dev_attr_lpfc_peer_port_login,
3776 &dev_attr_lpfc_nodev_tmo,
3777 &dev_attr_lpfc_devloss_tmo,
3778 &dev_attr_lpfc_fcp_class,
3779 &dev_attr_lpfc_use_adisc,
3780 &dev_attr_lpfc_ack0,
3781 &dev_attr_lpfc_topology,
3782 &dev_attr_lpfc_scan_down,
3783 &dev_attr_lpfc_link_speed,
3784 &dev_attr_lpfc_cr_delay,
3785 &dev_attr_lpfc_cr_count,
3786 &dev_attr_lpfc_multi_ring_support,
3787 &dev_attr_lpfc_multi_ring_rctl,
3788 &dev_attr_lpfc_multi_ring_type,
3789 &dev_attr_lpfc_fdmi_on,
3790 &dev_attr_lpfc_max_luns,
3791 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04003792 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05003793 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003794 &dev_attr_nport_evt_cnt,
3795 &dev_attr_board_mode,
3796 &dev_attr_max_vpi,
3797 &dev_attr_used_vpi,
3798 &dev_attr_max_rpi,
3799 &dev_attr_used_rpi,
3800 &dev_attr_max_xri,
3801 &dev_attr_used_xri,
3802 &dev_attr_npiv_info,
3803 &dev_attr_issue_reset,
3804 &dev_attr_lpfc_poll,
3805 &dev_attr_lpfc_poll_tmo,
3806 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003807 &dev_attr_lpfc_fcp_imax,
3808 &dev_attr_lpfc_fcp_wq_count,
3809 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003810 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003811 &dev_attr_lpfc_soft_wwnn,
3812 &dev_attr_lpfc_soft_wwpn,
3813 &dev_attr_lpfc_soft_wwn_enable,
3814 &dev_attr_lpfc_enable_hba_reset,
3815 &dev_attr_lpfc_enable_hba_heartbeat,
3816 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003817 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003818 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003819 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003820 &dev_attr_lpfc_aer_support,
3821 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04003822 &dev_attr_lpfc_sriov_nr_virtfn,
James Smart84d1b002010-02-12 14:42:33 -05003823 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003824 &dev_attr_lpfc_iocb_cnt,
3825 &dev_attr_iocb_hw,
3826 &dev_attr_txq_hw,
3827 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003828 &dev_attr_lpfc_fips_level,
3829 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003830 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04003831 &dev_attr_lpfc_sriov_hw_max_virtfn,
dea31012005-04-17 16:05:31 -05003832 NULL,
3833};
3834
Tony Jonesee959b02008-02-22 00:13:36 +01003835struct device_attribute *lpfc_vport_attrs[] = {
3836 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003837 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003838 &dev_attr_num_discovered_ports,
3839 &dev_attr_lpfc_drvr_version,
3840 &dev_attr_lpfc_log_verbose,
3841 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003842 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003843 &dev_attr_lpfc_nodev_tmo,
3844 &dev_attr_lpfc_devloss_tmo,
3845 &dev_attr_lpfc_hba_queue_depth,
3846 &dev_attr_lpfc_peer_port_login,
3847 &dev_attr_lpfc_restrict_login,
3848 &dev_attr_lpfc_fcp_class,
3849 &dev_attr_lpfc_use_adisc,
3850 &dev_attr_lpfc_fdmi_on,
3851 &dev_attr_lpfc_max_luns,
3852 &dev_attr_nport_evt_cnt,
3853 &dev_attr_npiv_info,
3854 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003855 &dev_attr_lpfc_max_scsicmpl_time,
3856 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003857 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003858 &dev_attr_lpfc_fips_level,
3859 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003860 NULL,
3861};
3862
James Smarte59058c2008-08-24 21:49:00 -04003863/**
James Smart3621a712009-04-06 18:47:14 -04003864 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003865 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003866 * @kobj: kernel kobject that contains the kernel class device.
3867 * @bin_attr: kernel attributes passed to us.
3868 * @buf: contains the data to be written to the adapter IOREG space.
3869 * @off: offset into buffer to beginning of data.
3870 * @count: bytes to transfer.
3871 *
3872 * Description:
3873 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3874 * Uses the adapter io control registers to send buf contents to the adapter.
3875 *
3876 * Returns:
3877 * -ERANGE off and count combo out of range
3878 * -EINVAL off, count or buff address invalid
3879 * -EPERM adapter is offline
3880 * value of count, buf contents written
3881 **/
dea31012005-04-17 16:05:31 -05003882static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003883sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3884 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003885 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003886{
3887 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003888 struct device *dev = container_of(kobj, struct device, kobj);
3889 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3891 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003892
James Smartf1126682009-06-10 17:22:44 -04003893 if (phba->sli_rev >= LPFC_SLI_REV4)
3894 return -EPERM;
3895
dea31012005-04-17 16:05:31 -05003896 if ((off + count) > FF_REG_AREA_SIZE)
3897 return -ERANGE;
3898
James Smartf7a919b2011-08-21 21:49:16 -04003899 if (count <= LPFC_REG_WRITE_KEY_SIZE)
3900 return 0;
dea31012005-04-17 16:05:31 -05003901
3902 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3903 return -EINVAL;
3904
James Smartf7a919b2011-08-21 21:49:16 -04003905 /* This is to protect HBA registers from accidental writes. */
3906 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3907 return -EINVAL;
3908
3909 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003910 return -EPERM;
dea31012005-04-17 16:05:31 -05003911
James Smart2e0fef82007-06-17 19:56:36 -05003912 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04003913 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
3914 buf_off += sizeof(uint32_t))
3915 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05003916 phba->ctrl_regs_memmap_p + off + buf_off);
3917
James Smart2e0fef82007-06-17 19:56:36 -05003918 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003919
3920 return count;
3921}
3922
James Smarte59058c2008-08-24 21:49:00 -04003923/**
James Smart3621a712009-04-06 18:47:14 -04003924 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003925 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003926 * @kobj: kernel kobject that contains the kernel class device.
3927 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003928 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003929 * @off: offset into buffer to beginning of data.
3930 * @count: bytes to transfer.
3931 *
3932 * Description:
3933 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3934 * Uses the adapter io control registers to read data into buf.
3935 *
3936 * Returns:
3937 * -ERANGE off and count combo out of range
3938 * -EINVAL off, count or buff address invalid
3939 * value of count, buf contents read
3940 **/
dea31012005-04-17 16:05:31 -05003941static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003942sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3943 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003944 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003945{
3946 size_t buf_off;
3947 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003948 struct device *dev = container_of(kobj, struct device, kobj);
3949 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003950 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3951 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003952
James Smartf1126682009-06-10 17:22:44 -04003953 if (phba->sli_rev >= LPFC_SLI_REV4)
3954 return -EPERM;
3955
dea31012005-04-17 16:05:31 -05003956 if (off > FF_REG_AREA_SIZE)
3957 return -ERANGE;
3958
3959 if ((off + count) > FF_REG_AREA_SIZE)
3960 count = FF_REG_AREA_SIZE - off;
3961
3962 if (count == 0) return 0;
3963
3964 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3965 return -EINVAL;
3966
James Smart2e0fef82007-06-17 19:56:36 -05003967 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003968
3969 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3970 tmp_ptr = (uint32_t *)(buf + buf_off);
3971 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3972 }
3973
James Smart2e0fef82007-06-17 19:56:36 -05003974 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003975
3976 return count;
3977}
3978
3979static struct bin_attribute sysfs_ctlreg_attr = {
3980 .attr = {
3981 .name = "ctlreg",
3982 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003983 },
3984 .size = 256,
3985 .read = sysfs_ctlreg_read,
3986 .write = sysfs_ctlreg_write,
3987};
3988
James Smarte59058c2008-08-24 21:49:00 -04003989/**
James Smart3621a712009-04-06 18:47:14 -04003990 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003991 * @phba: lpfc_hba pointer
3992 **/
dea31012005-04-17 16:05:31 -05003993static void
James Smart2e0fef82007-06-17 19:56:36 -05003994sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003995{
3996 phba->sysfs_mbox.state = SMBOX_IDLE;
3997 phba->sysfs_mbox.offset = 0;
3998
3999 if (phba->sysfs_mbox.mbox) {
4000 mempool_free(phba->sysfs_mbox.mbox,
4001 phba->mbox_mem_pool);
4002 phba->sysfs_mbox.mbox = NULL;
4003 }
4004}
4005
James Smarte59058c2008-08-24 21:49:00 -04004006/**
James Smart3621a712009-04-06 18:47:14 -04004007 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004008 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004009 * @kobj: kernel kobject that contains the kernel class device.
4010 * @bin_attr: kernel attributes passed to us.
4011 * @buf: contains the data to be written to sysfs mbox.
4012 * @off: offset into buffer to beginning of data.
4013 * @count: bytes to transfer.
4014 *
4015 * Description:
4016 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4017 * Uses the sysfs mbox to send buf contents to the adapter.
4018 *
4019 * Returns:
4020 * -ERANGE off and count combo out of range
4021 * -EINVAL off, count or buff address invalid
4022 * zero if count is zero
4023 * -EPERM adapter is offline
4024 * -ENOMEM failed to allocate memory for the mail box
4025 * -EAGAIN offset, state or mbox is NULL
4026 * count number of bytes transferred
4027 **/
dea31012005-04-17 16:05:31 -05004028static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004029sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4030 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004031 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004032{
Tony Jonesee959b02008-02-22 00:13:36 +01004033 struct device *dev = container_of(kobj, struct device, kobj);
4034 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004035 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4036 struct lpfc_hba *phba = vport->phba;
4037 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05004038
4039 if ((count + off) > MAILBOX_CMD_SIZE)
4040 return -ERANGE;
4041
4042 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4043 return -EINVAL;
4044
4045 if (count == 0)
4046 return 0;
4047
4048 if (off == 0) {
4049 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4050 if (!mbox)
4051 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05004052 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004053 }
4054
James Smart2e0fef82007-06-17 19:56:36 -05004055 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004056
4057 if (off == 0) {
4058 if (phba->sysfs_mbox.mbox)
4059 mempool_free(mbox, phba->mbox_mem_pool);
4060 else
4061 phba->sysfs_mbox.mbox = mbox;
4062 phba->sysfs_mbox.state = SMBOX_WRITING;
4063 } else {
4064 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4065 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05004066 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05004067 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004068 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004069 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004070 }
4071 }
4072
James Smart04c68492009-05-22 14:52:52 -04004073 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05004074 buf, count);
4075
4076 phba->sysfs_mbox.offset = off + count;
4077
James Smart2e0fef82007-06-17 19:56:36 -05004078 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004079
4080 return count;
4081}
4082
James Smarte59058c2008-08-24 21:49:00 -04004083/**
James Smart3621a712009-04-06 18:47:14 -04004084 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004085 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004086 * @kobj: kernel kobject that contains the kernel class device.
4087 * @bin_attr: kernel attributes passed to us.
4088 * @buf: contains the data to be read from sysfs mbox.
4089 * @off: offset into buffer to beginning of data.
4090 * @count: bytes to transfer.
4091 *
4092 * Description:
4093 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4094 * Uses the sysfs mbox to receive data from to the adapter.
4095 *
4096 * Returns:
4097 * -ERANGE off greater than mailbox command size
4098 * -EINVAL off, count or buff address invalid
4099 * zero if off and count are zero
4100 * -EACCES adapter over temp
4101 * -EPERM garbage can value to catch a multitude of errors
4102 * -EAGAIN management IO not permitted, state or off error
4103 * -ETIME mailbox timeout
4104 * -ENODEV mailbox error
4105 * count number of bytes transferred
4106 **/
dea31012005-04-17 16:05:31 -05004107static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004108sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4109 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004110 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004111{
Tony Jonesee959b02008-02-22 00:13:36 +01004112 struct device *dev = container_of(kobj, struct device, kobj);
4113 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4115 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004116 int rc;
James Smart04c68492009-05-22 14:52:52 -04004117 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05004118
James Smart1dcb58e2007-04-25 09:51:30 -04004119 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004120 return -ERANGE;
4121
James Smart1dcb58e2007-04-25 09:51:30 -04004122 if ((count + off) > MAILBOX_CMD_SIZE)
4123 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05004124
4125 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4126 return -EINVAL;
4127
4128 if (off && count == 0)
4129 return 0;
4130
James Smart2e0fef82007-06-17 19:56:36 -05004131 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004132
James Smart7af67052007-10-27 13:38:11 -04004133 if (phba->over_temp_state == HBA_OVER_TEMP) {
4134 sysfs_mbox_idle(phba);
4135 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05004136 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04004137 }
4138
dea31012005-04-17 16:05:31 -05004139 if (off == 0 &&
4140 phba->sysfs_mbox.state == SMBOX_WRITING &&
4141 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04004142 pmb = &phba->sysfs_mbox.mbox->u.mb;
4143 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05004144 /* Offline only */
dea31012005-04-17 16:05:31 -05004145 case MBX_INIT_LINK:
4146 case MBX_DOWN_LINK:
4147 case MBX_CONFIG_LINK:
4148 case MBX_CONFIG_RING:
4149 case MBX_RESET_RING:
4150 case MBX_UNREG_LOGIN:
4151 case MBX_CLEAR_LA:
4152 case MBX_DUMP_CONTEXT:
4153 case MBX_RUN_DIAGS:
4154 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05004155 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05004156 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05004157 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05004158 printk(KERN_WARNING "mbox_read:Command 0x%x "
4159 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04004160 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004161 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004162 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004163 return -EPERM;
4164 }
James Smarta8adb832007-10-27 13:37:53 -04004165 case MBX_WRITE_NV:
4166 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05004167 case MBX_LOAD_SM:
4168 case MBX_READ_NV:
4169 case MBX_READ_CONFIG:
4170 case MBX_READ_RCONFIG:
4171 case MBX_READ_STATUS:
4172 case MBX_READ_XRI:
4173 case MBX_READ_REV:
4174 case MBX_READ_LNK_STAT:
4175 case MBX_DUMP_MEMORY:
4176 case MBX_DOWN_LOAD:
4177 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004178 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05004179 case MBX_LOAD_AREA:
4180 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004181 case MBX_BEACON:
4182 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05004183 case MBX_SET_VARIABLE:
4184 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04004185 case MBX_PORT_CAPABILITIES:
4186 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05004187 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04004188 case MBX_SECURITY_MGMT:
4189 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04004190 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4191 printk(KERN_WARNING "mbox_read:Command 0x%x "
4192 "is not permitted\n", pmb->mbxCommand);
4193 sysfs_mbox_idle(phba);
4194 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04004195 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04004196 }
James Smartdcf2a4e2010-09-29 11:18:53 -04004197 break;
dea31012005-04-17 16:05:31 -05004198 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05004199 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05004200 case MBX_REG_LOGIN:
4201 case MBX_REG_LOGIN64:
4202 case MBX_CONFIG_PORT:
4203 case MBX_RUN_BIU_DIAG:
4204 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004205 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004206 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004207 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004208 return -EPERM;
4209 default:
4210 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004211 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004212 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004213 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004214 return -EPERM;
4215 }
4216
James Smart09372822008-01-11 01:52:54 -05004217 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05004218 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05004219 */
James Smartd7c255b2008-08-24 21:50:00 -04004220 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04004221 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4222 pmb->mbxCommand != MBX_RESTART &&
4223 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4224 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04004225 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4226 "1259 mbox: Issued mailbox cmd "
4227 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04004228 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05004229
James Smart92d7f7b2007-06-17 19:56:38 -05004230 phba->sysfs_mbox.mbox->vport = vport;
4231
James Smart58da1ff2008-04-07 10:15:56 -04004232 /* Don't allow mailbox commands to be sent when blocked
4233 * or when in the middle of discovery
4234 */
James Smart495a7142008-06-14 22:52:59 -04004235 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04004236 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004237 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04004238 return -EAGAIN;
4239 }
4240
James Smart2e0fef82007-06-17 19:56:36 -05004241 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004242 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05004243
James Smart2e0fef82007-06-17 19:56:36 -05004244 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004245 rc = lpfc_sli_issue_mbox (phba,
4246 phba->sysfs_mbox.mbox,
4247 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05004248 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004249
4250 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004251 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004252 rc = lpfc_sli_issue_mbox_wait (phba,
4253 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04004254 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05004255 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004256 }
4257
4258 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04004259 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04004260 phba->sysfs_mbox.mbox = NULL;
4261 }
dea31012005-04-17 16:05:31 -05004262 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004263 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004264 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05004265 }
4266 phba->sysfs_mbox.state = SMBOX_READING;
4267 }
4268 else if (phba->sysfs_mbox.offset != off ||
4269 phba->sysfs_mbox.state != SMBOX_READING) {
4270 printk(KERN_WARNING "mbox_read: Bad State\n");
4271 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004272 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004273 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004274 }
4275
James Smart04c68492009-05-22 14:52:52 -04004276 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05004277
4278 phba->sysfs_mbox.offset = off + count;
4279
James Smart1dcb58e2007-04-25 09:51:30 -04004280 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004281 sysfs_mbox_idle(phba);
4282
James Smart2e0fef82007-06-17 19:56:36 -05004283 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004284
4285 return count;
4286}
4287
4288static struct bin_attribute sysfs_mbox_attr = {
4289 .attr = {
4290 .name = "mbox",
4291 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004292 },
James Smartc0c11512011-05-24 11:41:34 -04004293 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004294 .read = sysfs_mbox_read,
4295 .write = sysfs_mbox_write,
4296};
4297
James Smarte59058c2008-08-24 21:49:00 -04004298/**
James Smart3621a712009-04-06 18:47:14 -04004299 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004300 * @vport: address of lpfc vport structure.
4301 *
4302 * Return codes:
4303 * zero on success
4304 * error return code from sysfs_create_bin_file()
4305 **/
dea31012005-04-17 16:05:31 -05004306int
James Smart2e0fef82007-06-17 19:56:36 -05004307lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004308{
James Smart2e0fef82007-06-17 19:56:36 -05004309 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004310 int error;
4311
Tony Jonesee959b02008-02-22 00:13:36 +01004312 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004313 &sysfs_drvr_stat_data_attr);
4314
4315 /* Virtual ports do not need ctrl_reg and mbox */
4316 if (error || vport->port_type == LPFC_NPIV_PORT)
4317 goto out;
4318
4319 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004320 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004321 if (error)
James Smarteada2722008-12-04 22:39:13 -05004322 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004323
Tony Jonesee959b02008-02-22 00:13:36 +01004324 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004325 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004326 if (error)
4327 goto out_remove_ctlreg_attr;
4328
4329 return 0;
4330out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004331 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004332out_remove_stat_attr:
4333 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4334 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004335out:
4336 return error;
4337}
4338
James Smarte59058c2008-08-24 21:49:00 -04004339/**
James Smart3621a712009-04-06 18:47:14 -04004340 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004341 * @vport: address of lpfc vport structure.
4342 **/
dea31012005-04-17 16:05:31 -05004343void
James Smart2e0fef82007-06-17 19:56:36 -05004344lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004345{
James Smart2e0fef82007-06-17 19:56:36 -05004346 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004347 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4348 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004349 /* Virtual ports do not need ctrl_reg and mbox */
4350 if (vport->port_type == LPFC_NPIV_PORT)
4351 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004352 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4353 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004354}
4355
4356
4357/*
4358 * Dynamic FC Host Attributes Support
4359 */
4360
James Smarte59058c2008-08-24 21:49:00 -04004361/**
James Smart3621a712009-04-06 18:47:14 -04004362 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004363 * @shost: kernel scsi host pointer.
4364 **/
dea31012005-04-17 16:05:31 -05004365static void
4366lpfc_get_host_port_id(struct Scsi_Host *shost)
4367{
James Smart2e0fef82007-06-17 19:56:36 -05004368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4369
dea31012005-04-17 16:05:31 -05004370 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004371 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004372}
4373
James Smarte59058c2008-08-24 21:49:00 -04004374/**
James Smart3621a712009-04-06 18:47:14 -04004375 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004376 * @shost: kernel scsi host pointer.
4377 **/
dea31012005-04-17 16:05:31 -05004378static void
4379lpfc_get_host_port_type(struct Scsi_Host *shost)
4380{
James Smart2e0fef82007-06-17 19:56:36 -05004381 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4382 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004383
4384 spin_lock_irq(shost->host_lock);
4385
James Smart92d7f7b2007-06-17 19:56:38 -05004386 if (vport->port_type == LPFC_NPIV_PORT) {
4387 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4388 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004389 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004390 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004391 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4392 else
4393 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4394 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004395 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004396 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4397 else
4398 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4399 }
4400 } else
4401 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4402
4403 spin_unlock_irq(shost->host_lock);
4404}
4405
James Smarte59058c2008-08-24 21:49:00 -04004406/**
James Smart3621a712009-04-06 18:47:14 -04004407 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004408 * @shost: kernel scsi host pointer.
4409 **/
dea31012005-04-17 16:05:31 -05004410static void
4411lpfc_get_host_port_state(struct Scsi_Host *shost)
4412{
James Smart2e0fef82007-06-17 19:56:36 -05004413 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4414 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004415
4416 spin_lock_irq(shost->host_lock);
4417
James Smart2e0fef82007-06-17 19:56:36 -05004418 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004419 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4420 else {
James Smart2e0fef82007-06-17 19:56:36 -05004421 switch (phba->link_state) {
4422 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004423 case LPFC_LINK_DOWN:
4424 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4425 break;
4426 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004427 case LPFC_CLEAR_LA:
4428 case LPFC_HBA_READY:
4429 /* Links up, beyond this port_type reports state */
4430 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4431 break;
4432 case LPFC_HBA_ERROR:
4433 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4434 break;
4435 default:
4436 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4437 break;
4438 }
4439 }
4440
4441 spin_unlock_irq(shost->host_lock);
4442}
4443
James Smarte59058c2008-08-24 21:49:00 -04004444/**
James Smart3621a712009-04-06 18:47:14 -04004445 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004446 * @shost: kernel scsi host pointer.
4447 **/
dea31012005-04-17 16:05:31 -05004448static void
4449lpfc_get_host_speed(struct Scsi_Host *shost)
4450{
James Smart2e0fef82007-06-17 19:56:36 -05004451 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4452 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004453
4454 spin_lock_irq(shost->host_lock);
4455
James Smart2e0fef82007-06-17 19:56:36 -05004456 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004457 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004458 case LPFC_LINK_SPEED_1GHZ:
4459 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004460 break;
James Smart76a95d72010-11-20 23:11:48 -05004461 case LPFC_LINK_SPEED_2GHZ:
4462 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004463 break;
James Smart76a95d72010-11-20 23:11:48 -05004464 case LPFC_LINK_SPEED_4GHZ:
4465 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004466 break;
James Smart76a95d72010-11-20 23:11:48 -05004467 case LPFC_LINK_SPEED_8GHZ:
4468 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004469 break;
James Smart76a95d72010-11-20 23:11:48 -05004470 case LPFC_LINK_SPEED_10GHZ:
4471 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004472 break;
James Smart76a95d72010-11-20 23:11:48 -05004473 case LPFC_LINK_SPEED_16GHZ:
4474 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4475 break;
4476 default:
4477 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004478 break;
4479 }
James Smart09372822008-01-11 01:52:54 -05004480 } else
4481 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004482
4483 spin_unlock_irq(shost->host_lock);
4484}
4485
James Smarte59058c2008-08-24 21:49:00 -04004486/**
James Smart3621a712009-04-06 18:47:14 -04004487 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004488 * @shost: kernel scsi host pointer.
4489 **/
dea31012005-04-17 16:05:31 -05004490static void
4491lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4492{
James Smart2e0fef82007-06-17 19:56:36 -05004493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4494 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004495 u64 node_name;
dea31012005-04-17 16:05:31 -05004496
4497 spin_lock_irq(shost->host_lock);
4498
James Smart73d91e52011-10-10 21:32:10 -04004499 if ((vport->port_state > LPFC_FLOGI) &&
4500 ((vport->fc_flag & FC_FABRIC) ||
4501 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4502 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004503 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004504 else
4505 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004506 node_name = 0;
dea31012005-04-17 16:05:31 -05004507
4508 spin_unlock_irq(shost->host_lock);
4509
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004510 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004511}
4512
James Smarte59058c2008-08-24 21:49:00 -04004513/**
James Smart3621a712009-04-06 18:47:14 -04004514 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004515 * @shost: kernel scsi host pointer.
4516 *
4517 * Notes:
4518 * NULL on error for link down, no mbox pool, sli2 active,
4519 * management not allowed, memory allocation error, or mbox error.
4520 *
4521 * Returns:
4522 * NULL for error
4523 * address of the adapter host statistics
4524 **/
dea31012005-04-17 16:05:31 -05004525static struct fc_host_statistics *
4526lpfc_get_stats(struct Scsi_Host *shost)
4527{
James Smart2e0fef82007-06-17 19:56:36 -05004528 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4529 struct lpfc_hba *phba = vport->phba;
4530 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004531 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004532 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004533 LPFC_MBOXQ_t *pmboxq;
4534 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004535 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004536 int rc = 0;
dea31012005-04-17 16:05:31 -05004537
James Smart92d7f7b2007-06-17 19:56:38 -05004538 /*
4539 * prevent udev from issuing mailbox commands until the port is
4540 * configured.
4541 */
James Smart2e0fef82007-06-17 19:56:36 -05004542 if (phba->link_state < LPFC_LINK_DOWN ||
4543 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004544 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004545 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004546
4547 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004548 return NULL;
4549
dea31012005-04-17 16:05:31 -05004550 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4551 if (!pmboxq)
4552 return NULL;
4553 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4554
James Smart04c68492009-05-22 14:52:52 -04004555 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004556 pmb->mbxCommand = MBX_READ_STATUS;
4557 pmb->mbxOwner = OWN_HOST;
4558 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004559 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004560
James Smart75baf692010-06-08 18:31:21 -04004561 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004562 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004563 else
dea31012005-04-17 16:05:31 -05004564 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4565
4566 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004567 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004568 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004569 return NULL;
4570 }
4571
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004572 memset(hs, 0, sizeof (struct fc_host_statistics));
4573
dea31012005-04-17 16:05:31 -05004574 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004575 /*
4576 * The MBX_READ_STATUS returns tx_k_bytes which has to
4577 * converted to words
4578 */
4579 hs->tx_words = (uint64_t)
4580 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4581 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004582 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004583 hs->rx_words = (uint64_t)
4584 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4585 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004586
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004587 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004588 pmb->mbxCommand = MBX_READ_LNK_STAT;
4589 pmb->mbxOwner = OWN_HOST;
4590 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004591 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004592
James Smart75baf692010-06-08 18:31:21 -04004593 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004594 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004595 else
dea31012005-04-17 16:05:31 -05004596 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4597
4598 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004599 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004600 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004601 return NULL;
4602 }
4603
4604 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4605 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4606 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4607 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4608 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4609 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4610 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4611
James Smart64ba8812006-08-02 15:24:34 -04004612 hs->link_failure_count -= lso->link_failure_count;
4613 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4614 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4615 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4616 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4617 hs->invalid_crc_count -= lso->invalid_crc_count;
4618 hs->error_frames -= lso->error_frames;
4619
James Smart76a95d72010-11-20 23:11:48 -05004620 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004621 hs->lip_count = -1;
4622 hs->nos_count = (phba->link_events >> 1);
4623 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004624 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004625 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004626 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004627 hs->nos_count = -1;
4628 } else {
4629 hs->lip_count = -1;
4630 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004631 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004632 }
4633
4634 hs->dumped_frames = -1;
4635
James Smart64ba8812006-08-02 15:24:34 -04004636 seconds = get_seconds();
4637 if (seconds < psli->stats_start)
4638 hs->seconds_since_last_reset = seconds +
4639 ((unsigned long)-1 - psli->stats_start);
4640 else
4641 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004642
James Smart1dcb58e2007-04-25 09:51:30 -04004643 mempool_free(pmboxq, phba->mbox_mem_pool);
4644
dea31012005-04-17 16:05:31 -05004645 return hs;
4646}
4647
James Smarte59058c2008-08-24 21:49:00 -04004648/**
James Smart3621a712009-04-06 18:47:14 -04004649 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004650 * @shost: kernel scsi host pointer.
4651 **/
James Smart64ba8812006-08-02 15:24:34 -04004652static void
4653lpfc_reset_stats(struct Scsi_Host *shost)
4654{
James Smart2e0fef82007-06-17 19:56:36 -05004655 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4656 struct lpfc_hba *phba = vport->phba;
4657 struct lpfc_sli *psli = &phba->sli;
4658 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004659 LPFC_MBOXQ_t *pmboxq;
4660 MAILBOX_t *pmb;
4661 int rc = 0;
4662
James Smart2e0fef82007-06-17 19:56:36 -05004663 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004664 return;
4665
James Smart64ba8812006-08-02 15:24:34 -04004666 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4667 if (!pmboxq)
4668 return;
4669 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4670
James Smart04c68492009-05-22 14:52:52 -04004671 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004672 pmb->mbxCommand = MBX_READ_STATUS;
4673 pmb->mbxOwner = OWN_HOST;
4674 pmb->un.varWords[0] = 0x1; /* reset request */
4675 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004676 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004677
James Smart2e0fef82007-06-17 19:56:36 -05004678 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004679 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004680 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4681 else
4682 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4683
4684 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004685 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004686 mempool_free(pmboxq, phba->mbox_mem_pool);
4687 return;
4688 }
4689
4690 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4691 pmb->mbxCommand = MBX_READ_LNK_STAT;
4692 pmb->mbxOwner = OWN_HOST;
4693 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004694 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004695
James Smart2e0fef82007-06-17 19:56:36 -05004696 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004697 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004698 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4699 else
4700 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4701
4702 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004703 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004704 mempool_free( pmboxq, phba->mbox_mem_pool);
4705 return;
4706 }
4707
4708 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4709 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4710 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4711 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4712 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4713 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4714 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004715 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004716 lso->link_events = (phba->link_events >> 1);
4717 else
4718 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004719
4720 psli->stats_start = get_seconds();
4721
James Smart1dcb58e2007-04-25 09:51:30 -04004722 mempool_free(pmboxq, phba->mbox_mem_pool);
4723
James Smart64ba8812006-08-02 15:24:34 -04004724 return;
4725}
dea31012005-04-17 16:05:31 -05004726
4727/*
4728 * The LPFC driver treats linkdown handling as target loss events so there
4729 * are no sysfs handlers for link_down_tmo.
4730 */
James Smart685f0bf2007-04-25 09:53:08 -04004731
James Smarte59058c2008-08-24 21:49:00 -04004732/**
James Smart3621a712009-04-06 18:47:14 -04004733 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004734 * @starget: kernel scsi target pointer.
4735 *
4736 * Returns:
4737 * address of the node list if found
4738 * NULL target not found
4739 **/
James Smart685f0bf2007-04-25 09:53:08 -04004740static struct lpfc_nodelist *
4741lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004742{
James Smart2e0fef82007-06-17 19:56:36 -05004743 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4744 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004745 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004746
4747 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004748 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004749 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004750 if (NLP_CHK_NODE_ACT(ndlp) &&
4751 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004752 starget->id == ndlp->nlp_sid) {
4753 spin_unlock_irq(shost->host_lock);
4754 return ndlp;
dea31012005-04-17 16:05:31 -05004755 }
4756 }
4757 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004758 return NULL;
4759}
dea31012005-04-17 16:05:31 -05004760
James Smarte59058c2008-08-24 21:49:00 -04004761/**
James Smart3621a712009-04-06 18:47:14 -04004762 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004763 * @starget: kernel scsi target pointer.
4764 **/
James Smart685f0bf2007-04-25 09:53:08 -04004765static void
4766lpfc_get_starget_port_id(struct scsi_target *starget)
4767{
4768 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4769
4770 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004771}
4772
James Smarte59058c2008-08-24 21:49:00 -04004773/**
James Smart3621a712009-04-06 18:47:14 -04004774 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004775 * @starget: kernel scsi target pointer.
4776 *
4777 * Description: Set the target node name to the ndlp node name wwn or zero.
4778 **/
dea31012005-04-17 16:05:31 -05004779static void
4780lpfc_get_starget_node_name(struct scsi_target *starget)
4781{
James Smart685f0bf2007-04-25 09:53:08 -04004782 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004783
James Smart685f0bf2007-04-25 09:53:08 -04004784 fc_starget_node_name(starget) =
4785 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004786}
4787
James Smarte59058c2008-08-24 21:49:00 -04004788/**
James Smart3621a712009-04-06 18:47:14 -04004789 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004790 * @starget: kernel scsi target pointer.
4791 *
4792 * Description: set the target port name to the ndlp port name wwn or zero.
4793 **/
dea31012005-04-17 16:05:31 -05004794static void
4795lpfc_get_starget_port_name(struct scsi_target *starget)
4796{
James Smart685f0bf2007-04-25 09:53:08 -04004797 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004798
James Smart685f0bf2007-04-25 09:53:08 -04004799 fc_starget_port_name(starget) =
4800 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004801}
4802
James Smarte59058c2008-08-24 21:49:00 -04004803/**
James Smart3621a712009-04-06 18:47:14 -04004804 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004805 * @rport: fc rport address.
4806 * @timeout: new value for dev loss tmo.
4807 *
4808 * Description:
4809 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4810 * dev_loss_tmo to one.
4811 **/
dea31012005-04-17 16:05:31 -05004812static void
dea31012005-04-17 16:05:31 -05004813lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4814{
dea31012005-04-17 16:05:31 -05004815 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004816 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004817 else
James Smartc01f3202006-08-18 17:47:08 -04004818 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004819}
4820
James Smarte59058c2008-08-24 21:49:00 -04004821/**
James Smart3621a712009-04-06 18:47:14 -04004822 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004823 *
4824 * Description:
4825 * Macro that uses field to generate a function with the name lpfc_show_rport_
4826 *
4827 * lpfc_show_rport_##field: returns the bytes formatted in buf
4828 * @cdev: class converted to an fc_rport.
4829 * @buf: on return contains the target_field or zero.
4830 *
4831 * Returns: size of formatted string.
4832 **/
dea31012005-04-17 16:05:31 -05004833#define lpfc_rport_show_function(field, format_string, sz, cast) \
4834static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004835lpfc_show_rport_##field (struct device *dev, \
4836 struct device_attribute *attr, \
4837 char *buf) \
dea31012005-04-17 16:05:31 -05004838{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004839 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004840 struct lpfc_rport_data *rdata = rport->hostdata; \
4841 return snprintf(buf, sz, format_string, \
4842 (rdata->target) ? cast rdata->target->field : 0); \
4843}
4844
4845#define lpfc_rport_rd_attr(field, format_string, sz) \
4846 lpfc_rport_show_function(field, format_string, sz, ) \
4847static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4848
James Smarteada2722008-12-04 22:39:13 -05004849/**
James Smart3621a712009-04-06 18:47:14 -04004850 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004851 * @fc_vport: The fc_vport who's symbolic name has been changed.
4852 *
4853 * Description:
4854 * This function is called by the transport after the @fc_vport's symbolic name
4855 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004856 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004857 **/
4858static void
4859lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4860{
4861 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4862
4863 if (vport->port_state == LPFC_VPORT_READY)
4864 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4865}
dea31012005-04-17 16:05:31 -05004866
James Smartf4b4c682009-05-22 14:53:12 -04004867/**
4868 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4869 * @phba: Pointer to lpfc_hba struct.
4870 *
4871 * This function is called by the lpfc_get_cfgparam() routine to set the
4872 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004873 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004874 * before hba port or vport created.
4875 **/
4876static void
4877lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4878{
4879 phba->cfg_log_verbose = verbose;
4880}
4881
dea31012005-04-17 16:05:31 -05004882struct fc_function_template lpfc_transport_functions = {
4883 /* fixed attributes the driver supports */
4884 .show_host_node_name = 1,
4885 .show_host_port_name = 1,
4886 .show_host_supported_classes = 1,
4887 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004888 .show_host_supported_speeds = 1,
4889 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004890 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004891
4892 /* dynamic attributes the driver supports */
4893 .get_host_port_id = lpfc_get_host_port_id,
4894 .show_host_port_id = 1,
4895
4896 .get_host_port_type = lpfc_get_host_port_type,
4897 .show_host_port_type = 1,
4898
4899 .get_host_port_state = lpfc_get_host_port_state,
4900 .show_host_port_state = 1,
4901
4902 /* active_fc4s is shown but doesn't change (thus no get function) */
4903 .show_host_active_fc4s = 1,
4904
4905 .get_host_speed = lpfc_get_host_speed,
4906 .show_host_speed = 1,
4907
4908 .get_host_fabric_name = lpfc_get_host_fabric_name,
4909 .show_host_fabric_name = 1,
4910
4911 /*
4912 * The LPFC driver treats linkdown handling as target loss events
4913 * so there are no sysfs handlers for link_down_tmo.
4914 */
4915
4916 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004917 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004918
4919 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4920 .show_rport_maxframe_size = 1,
4921 .show_rport_supported_classes = 1,
4922
dea31012005-04-17 16:05:31 -05004923 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4924 .show_rport_dev_loss_tmo = 1,
4925
4926 .get_starget_port_id = lpfc_get_starget_port_id,
4927 .show_starget_port_id = 1,
4928
4929 .get_starget_node_name = lpfc_get_starget_node_name,
4930 .show_starget_node_name = 1,
4931
4932 .get_starget_port_name = lpfc_get_starget_port_name,
4933 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004934
4935 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004936 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4937 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004938
James Smart92d7f7b2007-06-17 19:56:38 -05004939 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004940
4941 .vport_disable = lpfc_vport_disable,
4942
4943 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004944
4945 .bsg_request = lpfc_bsg_request,
4946 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004947};
4948
James Smart98c9ea52007-10-27 13:37:33 -04004949struct fc_function_template lpfc_vport_transport_functions = {
4950 /* fixed attributes the driver supports */
4951 .show_host_node_name = 1,
4952 .show_host_port_name = 1,
4953 .show_host_supported_classes = 1,
4954 .show_host_supported_fc4s = 1,
4955 .show_host_supported_speeds = 1,
4956 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004957 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004958
4959 /* dynamic attributes the driver supports */
4960 .get_host_port_id = lpfc_get_host_port_id,
4961 .show_host_port_id = 1,
4962
4963 .get_host_port_type = lpfc_get_host_port_type,
4964 .show_host_port_type = 1,
4965
4966 .get_host_port_state = lpfc_get_host_port_state,
4967 .show_host_port_state = 1,
4968
4969 /* active_fc4s is shown but doesn't change (thus no get function) */
4970 .show_host_active_fc4s = 1,
4971
4972 .get_host_speed = lpfc_get_host_speed,
4973 .show_host_speed = 1,
4974
4975 .get_host_fabric_name = lpfc_get_host_fabric_name,
4976 .show_host_fabric_name = 1,
4977
4978 /*
4979 * The LPFC driver treats linkdown handling as target loss events
4980 * so there are no sysfs handlers for link_down_tmo.
4981 */
4982
4983 .get_fc_host_stats = lpfc_get_stats,
4984 .reset_fc_host_stats = lpfc_reset_stats,
4985
4986 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4987 .show_rport_maxframe_size = 1,
4988 .show_rport_supported_classes = 1,
4989
4990 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4991 .show_rport_dev_loss_tmo = 1,
4992
4993 .get_starget_port_id = lpfc_get_starget_port_id,
4994 .show_starget_port_id = 1,
4995
4996 .get_starget_node_name = lpfc_get_starget_node_name,
4997 .show_starget_node_name = 1,
4998
4999 .get_starget_port_name = lpfc_get_starget_port_name,
5000 .show_starget_port_name = 1,
5001
5002 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5003 .terminate_rport_io = lpfc_terminate_rport_io,
5004
5005 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005006
5007 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005008};
5009
James Smarte59058c2008-08-24 21:49:00 -04005010/**
James Smart3621a712009-04-06 18:47:14 -04005011 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005012 * @phba: lpfc_hba pointer.
5013 **/
dea31012005-04-17 16:05:31 -05005014void
5015lpfc_get_cfgparam(struct lpfc_hba *phba)
5016{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005017 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5018 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005019 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005020 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5021 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005022 lpfc_ack0_init(phba, lpfc_ack0);
5023 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005024 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005025 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005026 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005027 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005028 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005029 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005030 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5031 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5032 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05005033 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5034 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005035 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005036 if (phba->sli_rev == LPFC_SLI_REV4)
5037 phba->cfg_poll = 0;
5038 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005039 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005040 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005041 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005042 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005043 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005044 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005045 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005046 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005047 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smart84d1b002010-02-12 14:42:33 -05005048 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005049 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005050 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005051 return;
5052}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005053
James Smarte59058c2008-08-24 21:49:00 -04005054/**
James Smart3621a712009-04-06 18:47:14 -04005055 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005056 * @vport: lpfc_vport pointer.
5057 **/
James Smart3de2a652007-08-02 11:09:59 -04005058void
5059lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5060{
James Smarte8b62012007-08-02 11:10:09 -04005061 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005062 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005063 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005064 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5065 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5066 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5067 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5068 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5069 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005070 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005071 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5072 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5073 lpfc_max_luns_init(vport, lpfc_max_luns);
5074 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005075 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005076 return;
5077}