blob: 13215cd396aa2a5233de261424cdbaea3d57aac6 [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;
752
James Smart40496f02006-07-06 15:50:22 -0400753 int status = -EINVAL;
754
755 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500756 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400757
758 if (status == 0)
759 return strlen(buf);
760 else
761 return status;
762}
763
James Smarte59058c2008-08-24 21:49:00 -0400764/**
James Smart88a2cfb2011-07-22 18:36:33 -0400765 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
766 * @phba: lpfc_hba pointer.
767 *
768 * Description:
769 * SLI4 interface type-2 device to wait on the sliport status register for
770 * the readyness after performing a firmware reset.
771 *
772 * Returns:
773 * zero for success
774 **/
775static int
776lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
777{
James Smartf7a919b2011-08-21 21:49:16 -0400778 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400779 int i;
780
James Smartf7a919b2011-08-21 21:49:16 -0400781 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400782 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
783 &portstat_reg.word0);
784
James Smartf7a919b2011-08-21 21:49:16 -0400785 /* verify if privilaged for the request operation */
786 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
787 !bf_get(lpfc_sliport_status_err, &portstat_reg))
788 return -EPERM;
789
James Smart88a2cfb2011-07-22 18:36:33 -0400790 /* wait for the SLI port firmware ready after firmware reset */
791 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
792 msleep(10);
793 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
794 &portstat_reg.word0);
795 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
796 continue;
797 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
798 continue;
799 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
800 continue;
801 break;
802 }
803
804 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
805 return 0;
806 else
807 return -EIO;
808}
809
810/**
James Smart52d52442011-05-24 11:42:45 -0400811 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400812 * @phba: lpfc_hba pointer.
813 *
814 * Description:
James Smart52d52442011-05-24 11:42:45 -0400815 * Request SLI4 interface type-2 device to perform a physical register set
816 * access.
James Smartc0c11512011-05-24 11:41:34 -0400817 *
818 * Returns:
819 * zero for success
820 **/
821static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400822lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400823{
824 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400825 struct pci_dev *pdev = phba->pcidev;
James Smartc0c11512011-05-24 11:41:34 -0400826 uint32_t reg_val;
827 int status = 0;
828 int rc;
829
830 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400831 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400832
James Smart52d52442011-05-24 11:42:45 -0400833 if ((phba->sli_rev < LPFC_SLI_REV4) ||
834 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
835 LPFC_SLI_INTF_IF_TYPE_2))
836 return -EPERM;
837
James Smartb76f2dc2011-07-22 18:37:42 -0400838 /* Disable SR-IOV virtual functions if enabled */
839 if (phba->cfg_sriov_nr_virtfn) {
840 pci_disable_sriov(pdev);
841 phba->cfg_sriov_nr_virtfn = 0;
842 }
James Smartc0c11512011-05-24 11:41:34 -0400843 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
844
845 if (status != 0)
846 return status;
847
848 /* wait for the device to be quiesced before firmware reset */
849 msleep(100);
850
851 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
852 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400853
854 if (opcode == LPFC_FW_DUMP)
855 reg_val |= LPFC_FW_DUMP_REQUEST;
856 else if (opcode == LPFC_FW_RESET)
857 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
858 else if (opcode == LPFC_DV_RESET)
859 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
860
James Smartc0c11512011-05-24 11:41:34 -0400861 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
862 LPFC_CTL_PDEV_CTL_OFFSET);
863 /* flush */
864 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
865
866 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400867 rc = lpfc_sli4_pdev_status_reg_wait(phba);
868
869 if (rc)
James Smartf7a919b2011-08-21 21:49:16 -0400870 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400871
872 init_completion(&online_compl);
873 rc = lpfc_workq_post_event(phba, &status, &online_compl,
874 LPFC_EVT_ONLINE);
875 if (rc == 0)
876 return -ENOMEM;
877
878 wait_for_completion(&online_compl);
879
880 if (status != 0)
881 return -EIO;
882
883 return 0;
884}
885
886/**
James Smart3621a712009-04-06 18:47:14 -0400887 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400888 * @dev: class device that is converted into a Scsi_host.
889 * @attr: device attribute, not used.
890 * @buf: on return contains the ascii number of nport events.
891 *
892 * Returns: size of formatted string.
893 **/
dea31012005-04-17 16:05:31 -0500894static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100895lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
896 char *buf)
dea31012005-04-17 16:05:31 -0500897{
Tony Jonesee959b02008-02-22 00:13:36 +0100898 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
900 struct lpfc_hba *phba = vport->phba;
901
dea31012005-04-17 16:05:31 -0500902 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
903}
904
James Smarte59058c2008-08-24 21:49:00 -0400905/**
James Smart3621a712009-04-06 18:47:14 -0400906 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400907 * @dev: class device that is converted into a Scsi_host.
908 * @attr: device attribute, not used.
909 * @buf: on return contains the state of the adapter.
910 *
911 * Returns: size of formatted string.
912 **/
dea31012005-04-17 16:05:31 -0500913static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100914lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
915 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500916{
Tony Jonesee959b02008-02-22 00:13:36 +0100917 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500918 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
919 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500920 char * state;
921
James Smart2e0fef82007-06-17 19:56:36 -0500922 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500923 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500924 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500925 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500926 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500927 state = "offline";
928 else
929 state = "online";
930
931 return snprintf(buf, PAGE_SIZE, "%s\n", state);
932}
933
James Smarte59058c2008-08-24 21:49:00 -0400934/**
James Smart3621a712009-04-06 18:47:14 -0400935 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400936 * @dev: class device that is converted into a Scsi_host.
937 * @attr: device attribute, not used.
938 * @buf: containing one of the strings "online", "offline", "warm" or "error".
939 * @count: unused variable.
940 *
941 * Returns:
942 * -EACCES if enable hba reset not enabled
943 * -EINVAL if the buffer does not contain a valid string (see above)
944 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
945 * buf length greater than zero indicates success
946 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500947static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100948lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
949 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500950{
Tony Jonesee959b02008-02-22 00:13:36 +0100951 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
953 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500954 struct completion online_compl;
955 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500956 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500957
James Smart13815c82008-01-11 01:52:48 -0500958 if (!phba->cfg_enable_hba_reset)
959 return -EACCES;
James Smart88a2cfb2011-07-22 18:36:33 -0400960
961 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
962 "3050 lpfc_board_mode set to %s\n", buf);
963
Jamie Wellnitz41415862006-02-28 19:25:27 -0500964 init_completion(&online_compl);
965
James Smart46fa3112007-04-25 09:51:45 -0400966 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500967 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500968 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500969 if (rc == 0)
970 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400971 wait_for_completion(&online_compl);
972 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
973 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500974 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400975 if (phba->sli_rev == LPFC_SLI_REV4)
976 return -EINVAL;
977 else
978 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400979 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400980 if (phba->sli_rev == LPFC_SLI_REV4)
981 return -EINVAL;
982 else
983 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -0400984 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -0400985 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
986 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
987 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
988 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
989 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500990 else
991 return -EINVAL;
992
Jamie Wellnitz41415862006-02-28 19:25:27 -0500993 if (!status)
994 return strlen(buf);
995 else
James Smartf7a919b2011-08-21 21:49:16 -0400996 return status;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500997}
998
James Smarte59058c2008-08-24 21:49:00 -0400999/**
James Smart3621a712009-04-06 18:47:14 -04001000 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001001 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001002 * @mxri: max xri count.
1003 * @axri: available xri count.
1004 * @mrpi: max rpi count.
1005 * @arpi: available rpi count.
1006 * @mvpi: max vpi count.
1007 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001008 *
1009 * Description:
1010 * If an integer pointer for an count is not null then the value for the
1011 * count is returned.
1012 *
1013 * Returns:
1014 * zero on error
1015 * one for success
1016 **/
James Smart311464e2007-08-02 11:10:37 -04001017static int
James Smart858c9f62007-06-17 19:56:39 -05001018lpfc_get_hba_info(struct lpfc_hba *phba,
1019 uint32_t *mxri, uint32_t *axri,
1020 uint32_t *mrpi, uint32_t *arpi,
1021 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001022{
James Smart04c68492009-05-22 14:52:52 -04001023 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001024 LPFC_MBOXQ_t *pmboxq;
1025 MAILBOX_t *pmb;
1026 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001027 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001028
1029 /*
1030 * prevent udev from issuing mailbox commands until the port is
1031 * configured.
1032 */
1033 if (phba->link_state < LPFC_LINK_DOWN ||
1034 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001035 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001036 return 0;
1037
1038 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1039 return 0;
1040
1041 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1042 if (!pmboxq)
1043 return 0;
1044 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1045
James Smart04c68492009-05-22 14:52:52 -04001046 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001047 pmb->mbxCommand = MBX_READ_CONFIG;
1048 pmb->mbxOwner = OWN_HOST;
1049 pmboxq->context1 = NULL;
1050
James Smart75baf692010-06-08 18:31:21 -04001051 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001052 rc = MBX_NOT_FINISHED;
1053 else
1054 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1055
1056 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001057 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001058 mempool_free(pmboxq, phba->mbox_mem_pool);
1059 return 0;
1060 }
1061
James Smartda0436e2009-05-22 14:51:39 -04001062 if (phba->sli_rev == LPFC_SLI_REV4) {
1063 rd_config = &pmboxq->u.mqe.un.rd_config;
1064 if (mrpi)
1065 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1066 if (arpi)
1067 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1068 phba->sli4_hba.max_cfg_param.rpi_used;
1069 if (mxri)
1070 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1071 if (axri)
1072 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1073 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001074
1075 /* Account for differences with SLI-3. Get vpi count from
1076 * mailbox data and subtract one for max vpi value.
1077 */
1078 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1079 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1080
James Smartda0436e2009-05-22 14:51:39 -04001081 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001082 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001083 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001084 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001085 } else {
1086 if (mrpi)
1087 *mrpi = pmb->un.varRdConfig.max_rpi;
1088 if (arpi)
1089 *arpi = pmb->un.varRdConfig.avail_rpi;
1090 if (mxri)
1091 *mxri = pmb->un.varRdConfig.max_xri;
1092 if (axri)
1093 *axri = pmb->un.varRdConfig.avail_xri;
1094 if (mvpi)
1095 *mvpi = pmb->un.varRdConfig.max_vpi;
1096 if (avpi)
1097 *avpi = pmb->un.varRdConfig.avail_vpi;
1098 }
James Smart92d7f7b2007-06-17 19:56:38 -05001099
1100 mempool_free(pmboxq, phba->mbox_mem_pool);
1101 return 1;
1102}
1103
James Smarte59058c2008-08-24 21:49:00 -04001104/**
James Smart3621a712009-04-06 18:47:14 -04001105 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001106 * @dev: class device that is converted into a Scsi_host.
1107 * @attr: device attribute, not used.
1108 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1109 *
1110 * Description:
1111 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1112 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1113 * to "Unknown" and the buffer length is returned, therefore the caller
1114 * must check for "Unknown" in the buffer to detect a failure.
1115 *
1116 * Returns: size of formatted string.
1117 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001118static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001119lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1120 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001121{
Tony Jonesee959b02008-02-22 00:13:36 +01001122 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1124 struct lpfc_hba *phba = vport->phba;
1125 uint32_t cnt;
1126
James Smart858c9f62007-06-17 19:56:39 -05001127 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001128 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1129 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1130}
1131
James Smarte59058c2008-08-24 21:49:00 -04001132/**
James Smart3621a712009-04-06 18:47:14 -04001133 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001134 * @dev: class device that is converted into a Scsi_host.
1135 * @attr: device attribute, not used.
1136 * @buf: containing the used rpi count in decimal or "Unknown".
1137 *
1138 * Description:
1139 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1140 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1141 * to "Unknown" and the buffer length is returned, therefore the caller
1142 * must check for "Unknown" in the buffer to detect a failure.
1143 *
1144 * Returns: size of formatted string.
1145 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001146static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001147lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1148 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001149{
Tony Jonesee959b02008-02-22 00:13:36 +01001150 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1152 struct lpfc_hba *phba = vport->phba;
1153 uint32_t cnt, acnt;
1154
James Smart858c9f62007-06-17 19:56:39 -05001155 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001156 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1157 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1158}
1159
James Smarte59058c2008-08-24 21:49:00 -04001160/**
James Smart3621a712009-04-06 18:47:14 -04001161 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001162 * @dev: class device that is converted into a Scsi_host.
1163 * @attr: device attribute, not used.
1164 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1165 *
1166 * Description:
1167 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1168 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1169 * to "Unknown" and the buffer length is returned, therefore the caller
1170 * must check for "Unknown" in the buffer to detect a failure.
1171 *
1172 * Returns: size of formatted string.
1173 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001174static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001175lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1176 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001177{
Tony Jonesee959b02008-02-22 00:13:36 +01001178 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1180 struct lpfc_hba *phba = vport->phba;
1181 uint32_t cnt;
1182
James Smart858c9f62007-06-17 19:56:39 -05001183 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001184 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1185 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1186}
1187
James Smarte59058c2008-08-24 21:49:00 -04001188/**
James Smart3621a712009-04-06 18:47:14 -04001189 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001190 * @dev: class device that is converted into a Scsi_host.
1191 * @attr: device attribute, not used.
1192 * @buf: on return contains the used xri count in decimal or "Unknown".
1193 *
1194 * Description:
1195 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1196 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1197 * to "Unknown" and the buffer length is returned, therefore the caller
1198 * must check for "Unknown" in the buffer to detect a failure.
1199 *
1200 * Returns: size of formatted string.
1201 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001202static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001203lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1204 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001205{
Tony Jonesee959b02008-02-22 00:13:36 +01001206 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001207 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1208 struct lpfc_hba *phba = vport->phba;
1209 uint32_t cnt, acnt;
1210
James Smart858c9f62007-06-17 19:56:39 -05001211 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1212 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1213 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1214}
1215
James Smarte59058c2008-08-24 21:49:00 -04001216/**
James Smart3621a712009-04-06 18:47:14 -04001217 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001218 * @dev: class device that is converted into a Scsi_host.
1219 * @attr: device attribute, not used.
1220 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1221 *
1222 * Description:
1223 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1224 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1225 * to "Unknown" and the buffer length is returned, therefore the caller
1226 * must check for "Unknown" in the buffer to detect a failure.
1227 *
1228 * Returns: size of formatted string.
1229 **/
James Smart858c9f62007-06-17 19:56:39 -05001230static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001231lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1232 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001233{
Tony Jonesee959b02008-02-22 00:13:36 +01001234 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001235 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1236 struct lpfc_hba *phba = vport->phba;
1237 uint32_t cnt;
1238
1239 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1240 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1241 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1242}
1243
James Smarte59058c2008-08-24 21:49:00 -04001244/**
James Smart3621a712009-04-06 18:47:14 -04001245 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001246 * @dev: class device that is converted into a Scsi_host.
1247 * @attr: device attribute, not used.
1248 * @buf: on return contains the used vpi count in decimal or "Unknown".
1249 *
1250 * Description:
1251 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1252 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1253 * to "Unknown" and the buffer length is returned, therefore the caller
1254 * must check for "Unknown" in the buffer to detect a failure.
1255 *
1256 * Returns: size of formatted string.
1257 **/
James Smart858c9f62007-06-17 19:56:39 -05001258static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001259lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1260 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001261{
Tony Jonesee959b02008-02-22 00:13:36 +01001262 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001263 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1264 struct lpfc_hba *phba = vport->phba;
1265 uint32_t cnt, acnt;
1266
1267 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001268 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1269 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1270}
1271
James Smarte59058c2008-08-24 21:49:00 -04001272/**
James Smart3621a712009-04-06 18:47:14 -04001273 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001274 * @dev: class device that is converted into a Scsi_host.
1275 * @attr: device attribute, not used.
1276 * @buf: text that must be interpreted to determine if npiv is supported.
1277 *
1278 * Description:
1279 * Buffer will contain text indicating npiv is not suppoerted on the port,
1280 * the port is an NPIV physical port, or it is an npiv virtual port with
1281 * the id of the vport.
1282 *
1283 * Returns: size of formatted string.
1284 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001285static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001286lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1287 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001288{
Tony Jonesee959b02008-02-22 00:13:36 +01001289 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1291 struct lpfc_hba *phba = vport->phba;
1292
1293 if (!(phba->max_vpi))
1294 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1295 if (vport->port_type == LPFC_PHYSICAL_PORT)
1296 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1297 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1298}
1299
James Smarte59058c2008-08-24 21:49:00 -04001300/**
James Smart3621a712009-04-06 18:47:14 -04001301 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001302 * @dev: class device that is converted into a Scsi_host.
1303 * @attr: device attribute, not used.
1304 * @buf: on return contains the cfg_poll in hex.
1305 *
1306 * Notes:
1307 * cfg_poll should be a lpfc_polling_flags type.
1308 *
1309 * Returns: size of formatted string.
1310 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001311static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001312lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1313 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001314{
Tony Jonesee959b02008-02-22 00:13:36 +01001315 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1317 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001318
1319 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1320}
1321
James Smarte59058c2008-08-24 21:49:00 -04001322/**
James Smart3621a712009-04-06 18:47:14 -04001323 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001324 * @dev: class device that is converted into a Scsi_host.
1325 * @attr: device attribute, not used.
1326 * @buf: one or more lpfc_polling_flags values.
1327 * @count: not used.
1328 *
1329 * Notes:
1330 * buf contents converted to integer and checked for a valid value.
1331 *
1332 * Returns:
1333 * -EINVAL if the buffer connot be converted or is out of range
1334 * length of the buf on success
1335 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001336static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001337lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1338 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001339{
Tony Jonesee959b02008-02-22 00:13:36 +01001340 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001341 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1342 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001343 uint32_t creg_val;
1344 uint32_t old_val;
1345 int val=0;
1346
1347 if (!isdigit(buf[0]))
1348 return -EINVAL;
1349
1350 if (sscanf(buf, "%i", &val) != 1)
1351 return -EINVAL;
1352
1353 if ((val & 0x3) != val)
1354 return -EINVAL;
1355
James Smart45ed1192009-10-02 15:17:02 -04001356 if (phba->sli_rev == LPFC_SLI_REV4)
1357 val = 0;
1358
James Smart88a2cfb2011-07-22 18:36:33 -04001359 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1360 "3051 lpfc_poll changed from %d to %d\n",
1361 phba->cfg_poll, val);
1362
James Smart2e0fef82007-06-17 19:56:36 -05001363 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001364
1365 old_val = phba->cfg_poll;
1366
1367 if (val & ENABLE_FCP_RING_POLLING) {
1368 if ((val & DISABLE_FCP_RING_INT) &&
1369 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001370 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1371 spin_unlock_irq(&phba->hbalock);
1372 return -EINVAL;
1373 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001374 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1375 writel(creg_val, phba->HCregaddr);
1376 readl(phba->HCregaddr); /* flush */
1377
1378 lpfc_poll_start_timer(phba);
1379 }
1380 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001381 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001382 return -EINVAL;
1383 }
1384
1385 if (!(val & DISABLE_FCP_RING_INT) &&
1386 (old_val & DISABLE_FCP_RING_INT))
1387 {
James Smart2e0fef82007-06-17 19:56:36 -05001388 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001389 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001390 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001391 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1392 spin_unlock_irq(&phba->hbalock);
1393 return -EINVAL;
1394 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001395 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1396 writel(creg_val, phba->HCregaddr);
1397 readl(phba->HCregaddr); /* flush */
1398 }
1399
1400 phba->cfg_poll = val;
1401
James Smart2e0fef82007-06-17 19:56:36 -05001402 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001403
1404 return strlen(buf);
1405}
dea31012005-04-17 16:05:31 -05001406
James Smarte59058c2008-08-24 21:49:00 -04001407/**
James Smartbc739052010-08-04 16:11:18 -04001408 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1409 * @dev: class unused variable.
1410 * @attr: device attribute, not used.
1411 * @buf: on return contains the module description text.
1412 *
1413 * Returns: size of formatted string.
1414 **/
1415static ssize_t
1416lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1417 char *buf)
1418{
1419 struct Scsi_Host *shost = class_to_shost(dev);
1420 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1421 struct lpfc_hba *phba = vport->phba;
1422
1423 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1424}
1425
1426/**
1427 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1428 * @dev: class unused variable.
1429 * @attr: device attribute, not used.
1430 * @buf: on return contains the module description text.
1431 *
1432 * Returns: size of formatted string.
1433 **/
1434static ssize_t
1435lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1436 char *buf)
1437{
1438 struct Scsi_Host *shost = class_to_shost(dev);
1439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1440 struct lpfc_hba *phba = vport->phba;
1441
1442 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1443}
1444
1445/**
James Smartab56dc22011-02-16 12:39:57 -05001446 * lpfc_dss_show - Return the current state of dss and the configured state
1447 * @dev: class converted to a Scsi_host structure.
1448 * @attr: device attribute, not used.
1449 * @buf: on return contains the formatted text.
1450 *
1451 * Returns: size of formatted string.
1452 **/
1453static ssize_t
1454lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1455 char *buf)
1456{
1457 struct Scsi_Host *shost = class_to_shost(dev);
1458 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1459 struct lpfc_hba *phba = vport->phba;
1460
1461 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1462 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1463 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1464 "" : "Not ");
1465}
1466
1467/**
James Smart912e3ac2011-05-24 11:42:11 -04001468 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1469 * @dev: class converted to a Scsi_host structure.
1470 * @attr: device attribute, not used.
1471 * @buf: on return contains the formatted support level.
1472 *
1473 * Description:
1474 * Returns the maximum number of virtual functions a physical function can
1475 * support, 0 will be returned if called on virtual function.
1476 *
1477 * Returns: size of formatted string.
1478 **/
1479static ssize_t
1480lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1481 struct device_attribute *attr,
1482 char *buf)
1483{
1484 struct Scsi_Host *shost = class_to_shost(dev);
1485 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1486 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001487 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001488
James Smart0a96e972011-07-22 18:37:28 -04001489 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1490 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001491}
1492
1493/**
James Smart3621a712009-04-06 18:47:14 -04001494 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001495 *
1496 * Description:
1497 * Macro that given an attr e.g. hba_queue_depth expands
1498 * into a function with the name lpfc_hba_queue_depth_show.
1499 *
1500 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1501 * @dev: class device that is converted into a Scsi_host.
1502 * @attr: device attribute, not used.
1503 * @buf: on return contains the attribute value in decimal.
1504 *
1505 * Returns: size of formatted string.
1506 **/
dea31012005-04-17 16:05:31 -05001507#define lpfc_param_show(attr) \
1508static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001509lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1510 char *buf) \
dea31012005-04-17 16:05:31 -05001511{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001512 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001513 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1514 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001515 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001516 val = phba->cfg_##attr;\
1517 return snprintf(buf, PAGE_SIZE, "%d\n",\
1518 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001519}
1520
James Smarte59058c2008-08-24 21:49:00 -04001521/**
James Smart3621a712009-04-06 18:47:14 -04001522 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001523 *
1524 * Description:
1525 * Macro that given an attr e.g. hba_queue_depth expands
1526 * into a function with the name lpfc_hba_queue_depth_show
1527 *
1528 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1529 * @dev: class device that is converted into a Scsi_host.
1530 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001531 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001532 *
1533 * Returns: size of formatted string.
1534 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001535#define lpfc_param_hex_show(attr) \
1536static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001537lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1538 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001539{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001540 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1542 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001543 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001544 val = phba->cfg_##attr;\
1545 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1546 phba->cfg_##attr);\
1547}
1548
James Smarte59058c2008-08-24 21:49:00 -04001549/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001550 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001551 *
1552 * Description:
1553 * Macro that given an attr e.g. hba_queue_depth expands
1554 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1555 * takes a default argument, a minimum and maximum argument.
1556 *
1557 * lpfc_##attr##_init: Initializes an attribute.
1558 * @phba: pointer the the adapter structure.
1559 * @val: integer attribute value.
1560 *
1561 * Validates the min and max values then sets the adapter config field
1562 * accordingly, or uses the default if out of range and prints an error message.
1563 *
1564 * Returns:
1565 * zero on success
1566 * -EINVAL if default used
1567 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001568#define lpfc_param_init(attr, default, minval, maxval) \
1569static int \
James Smart84d1b002010-02-12 14:42:33 -05001570lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001571{ \
1572 if (val >= minval && val <= maxval) {\
1573 phba->cfg_##attr = val;\
1574 return 0;\
1575 }\
1576 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001577 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1578 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001579 phba->cfg_##attr = default;\
1580 return -EINVAL;\
1581}
1582
James Smarte59058c2008-08-24 21:49:00 -04001583/**
James Smart3621a712009-04-06 18:47:14 -04001584 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001585 *
1586 * Description:
1587 * Macro that given an attr e.g. hba_queue_depth expands
1588 * into a function with the name lpfc_hba_queue_depth_set
1589 *
1590 * lpfc_##attr##_set: Sets an attribute value.
1591 * @phba: pointer the the adapter structure.
1592 * @val: integer attribute value.
1593 *
1594 * Description:
1595 * Validates the min and max values then sets the
1596 * adapter config field if in the valid range. prints error message
1597 * and does not set the parameter if invalid.
1598 *
1599 * Returns:
1600 * zero on success
1601 * -EINVAL if val is invalid
1602 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001603#define lpfc_param_set(attr, default, minval, maxval) \
1604static int \
James Smart84d1b002010-02-12 14:42:33 -05001605lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001606{ \
1607 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001608 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1609 "3052 lpfc_" #attr " changed from %d to %d\n", \
1610 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001611 phba->cfg_##attr = val;\
1612 return 0;\
1613 }\
1614 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001615 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1616 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001617 return -EINVAL;\
1618}
1619
James Smarte59058c2008-08-24 21:49:00 -04001620/**
James Smart3621a712009-04-06 18:47:14 -04001621 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001622 *
1623 * Description:
1624 * Macro that given an attr e.g. hba_queue_depth expands
1625 * into a function with the name lpfc_hba_queue_depth_store.
1626 *
1627 * lpfc_##attr##_store: Set an sttribute value.
1628 * @dev: class device that is converted into a Scsi_host.
1629 * @attr: device attribute, not used.
1630 * @buf: contains the attribute value in ascii.
1631 * @count: not used.
1632 *
1633 * Description:
1634 * Convert the ascii text number to an integer, then
1635 * use the lpfc_##attr##_set function to set the value.
1636 *
1637 * Returns:
1638 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1639 * length of buffer upon success.
1640 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001641#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001642static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001643lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1644 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001645{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001646 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001647 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1648 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001649 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001650 if (!isdigit(buf[0]))\
1651 return -EINVAL;\
1652 if (sscanf(buf, "%i", &val) != 1)\
1653 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001654 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001655 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001656 else \
1657 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001658}
1659
James Smarte59058c2008-08-24 21:49:00 -04001660/**
James Smart3621a712009-04-06 18:47:14 -04001661 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001662 *
1663 * Description:
1664 * Macro that given an attr e.g. hba_queue_depth expands
1665 * into a function with the name lpfc_hba_queue_depth_show
1666 *
1667 * lpfc_##attr##_show: prints the attribute value in decimal.
1668 * @dev: class device that is converted into a Scsi_host.
1669 * @attr: device attribute, not used.
1670 * @buf: on return contains the attribute value in decimal.
1671 *
1672 * Returns: length of formatted string.
1673 **/
James Smart3de2a652007-08-02 11:09:59 -04001674#define lpfc_vport_param_show(attr) \
1675static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001676lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1677 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001678{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001679 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001681 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001682 val = vport->cfg_##attr;\
1683 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1684}
1685
James Smarte59058c2008-08-24 21:49:00 -04001686/**
James Smart3621a712009-04-06 18:47:14 -04001687 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001688 *
1689 * Description:
1690 * Macro that given an attr e.g.
1691 * hba_queue_depth expands into a function with the name
1692 * lpfc_hba_queue_depth_show
1693 *
James Smart3621a712009-04-06 18:47:14 -04001694 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001695 * @dev: class device that is converted into a Scsi_host.
1696 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001697 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001698 *
1699 * Returns: length of formatted string.
1700 **/
James Smart3de2a652007-08-02 11:09:59 -04001701#define lpfc_vport_param_hex_show(attr) \
1702static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001703lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1704 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001705{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001706 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001708 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001709 val = vport->cfg_##attr;\
1710 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1711}
1712
James Smarte59058c2008-08-24 21:49:00 -04001713/**
James Smart3621a712009-04-06 18:47:14 -04001714 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001715 *
1716 * Description:
1717 * Macro that given an attr e.g. hba_queue_depth expands
1718 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1719 * takes a default argument, a minimum and maximum argument.
1720 *
1721 * lpfc_##attr##_init: validates the min and max values then sets the
1722 * adapter config field accordingly, or uses the default if out of range
1723 * and prints an error message.
1724 * @phba: pointer the the adapter structure.
1725 * @val: integer attribute value.
1726 *
1727 * Returns:
1728 * zero on success
1729 * -EINVAL if default used
1730 **/
James Smart3de2a652007-08-02 11:09:59 -04001731#define lpfc_vport_param_init(attr, default, minval, maxval) \
1732static int \
James Smart84d1b002010-02-12 14:42:33 -05001733lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001734{ \
1735 if (val >= minval && val <= maxval) {\
1736 vport->cfg_##attr = val;\
1737 return 0;\
1738 }\
James Smarte8b62012007-08-02 11:10:09 -04001739 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001740 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001741 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001742 vport->cfg_##attr = default;\
1743 return -EINVAL;\
1744}
1745
James Smarte59058c2008-08-24 21:49:00 -04001746/**
James Smart3621a712009-04-06 18:47:14 -04001747 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001748 *
1749 * Description:
1750 * Macro that given an attr e.g. hba_queue_depth expands
1751 * into a function with the name lpfc_hba_queue_depth_set
1752 *
1753 * lpfc_##attr##_set: validates the min and max values then sets the
1754 * adapter config field if in the valid range. prints error message
1755 * and does not set the parameter if invalid.
1756 * @phba: pointer the the adapter structure.
1757 * @val: integer attribute value.
1758 *
1759 * Returns:
1760 * zero on success
1761 * -EINVAL if val is invalid
1762 **/
James Smart3de2a652007-08-02 11:09:59 -04001763#define lpfc_vport_param_set(attr, default, minval, maxval) \
1764static int \
James Smart84d1b002010-02-12 14:42:33 -05001765lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001766{ \
1767 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001768 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1769 "3053 lpfc_" #attr " changed from %d to %d\n", \
1770 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001771 vport->cfg_##attr = val;\
1772 return 0;\
1773 }\
James Smarte8b62012007-08-02 11:10:09 -04001774 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001775 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001776 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001777 return -EINVAL;\
1778}
1779
James Smarte59058c2008-08-24 21:49:00 -04001780/**
James Smart3621a712009-04-06 18:47:14 -04001781 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001782 *
1783 * Description:
1784 * Macro that given an attr e.g. hba_queue_depth
1785 * expands into a function with the name lpfc_hba_queue_depth_store
1786 *
1787 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1788 * use the lpfc_##attr##_set function to set the value.
1789 * @cdev: class device that is converted into a Scsi_host.
1790 * @buf: contains the attribute value in decimal.
1791 * @count: not used.
1792 *
1793 * Returns:
1794 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1795 * length of buffer upon success.
1796 **/
James Smart3de2a652007-08-02 11:09:59 -04001797#define lpfc_vport_param_store(attr) \
1798static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001799lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1800 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001801{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001802 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001803 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001804 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001805 if (!isdigit(buf[0]))\
1806 return -EINVAL;\
1807 if (sscanf(buf, "%i", &val) != 1)\
1808 return -EINVAL;\
1809 if (lpfc_##attr##_set(vport, val) == 0) \
1810 return strlen(buf);\
1811 else \
1812 return -EINVAL;\
1813}
1814
1815
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001816#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001817static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001818module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001819MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001820lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001821
1822#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001823static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001824module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001825MODULE_PARM_DESC(lpfc_##name, desc);\
1826lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001827lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001828static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001829
1830#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001831static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001832module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001833MODULE_PARM_DESC(lpfc_##name, desc);\
1834lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001835lpfc_param_init(name, defval, minval, maxval)\
1836lpfc_param_set(name, defval, minval, maxval)\
1837lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001838static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1839 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001840
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001841#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001842static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001843module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001844MODULE_PARM_DESC(lpfc_##name, desc);\
1845lpfc_param_hex_show(name)\
1846lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001847static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001848
1849#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001850static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001851module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001852MODULE_PARM_DESC(lpfc_##name, desc);\
1853lpfc_param_hex_show(name)\
1854lpfc_param_init(name, defval, minval, maxval)\
1855lpfc_param_set(name, defval, minval, maxval)\
1856lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001857static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1858 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001859
James Smart3de2a652007-08-02 11:09:59 -04001860#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001861static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001862module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001863MODULE_PARM_DESC(lpfc_##name, desc);\
1864lpfc_vport_param_init(name, defval, minval, maxval)
1865
1866#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001867static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001868module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001869MODULE_PARM_DESC(lpfc_##name, desc);\
1870lpfc_vport_param_show(name)\
1871lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001872static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001873
1874#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001875static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001876module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001877MODULE_PARM_DESC(lpfc_##name, desc);\
1878lpfc_vport_param_show(name)\
1879lpfc_vport_param_init(name, defval, minval, maxval)\
1880lpfc_vport_param_set(name, defval, minval, maxval)\
1881lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001882static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1883 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001884
1885#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001886static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001887module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001888MODULE_PARM_DESC(lpfc_##name, desc);\
1889lpfc_vport_param_hex_show(name)\
1890lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001891static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001892
1893#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001894static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001895module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001896MODULE_PARM_DESC(lpfc_##name, desc);\
1897lpfc_vport_param_hex_show(name)\
1898lpfc_vport_param_init(name, defval, minval, maxval)\
1899lpfc_vport_param_set(name, defval, minval, maxval)\
1900lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001901static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1902 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001903
James Smart81301a92008-12-04 22:39:46 -05001904static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1905static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1906static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1907static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001908static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1909static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1910static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1911static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1912static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1913static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1914static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1915static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001916static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1917 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001918static DEVICE_ATTR(option_rom_version, S_IRUGO,
1919 lpfc_option_rom_version_show, NULL);
1920static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1921 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001922static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001923static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1924static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001925static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001926static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1927 lpfc_board_mode_show, lpfc_board_mode_store);
1928static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1929static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1930static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1931static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1932static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1933static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1934static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1935static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1936static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001937static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1938static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001939static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001940static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1941 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001942
James Smarta12e07b2006-12-02 13:35:30 -05001943static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001944
James Smarte59058c2008-08-24 21:49:00 -04001945/**
James Smart3621a712009-04-06 18:47:14 -04001946 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001947 * @dev: class device that is converted into a Scsi_host.
1948 * @attr: device attribute, not used.
1949 * @buf: containing the string lpfc_soft_wwn_key.
1950 * @count: must be size of lpfc_soft_wwn_key.
1951 *
1952 * Returns:
1953 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1954 * length of buf indicates success
1955 **/
James Smartc3f28af2006-08-18 17:47:18 -04001956static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001957lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1958 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001959{
Tony Jonesee959b02008-02-22 00:13:36 +01001960 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001961 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1962 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001963 unsigned int cnt = count;
1964
1965 /*
1966 * We're doing a simple sanity check for soft_wwpn setting.
1967 * We require that the user write a specific key to enable
1968 * the soft_wwpn attribute to be settable. Once the attribute
1969 * is written, the enable key resets. If further updates are
1970 * desired, the key must be written again to re-enable the
1971 * attribute.
1972 *
1973 * The "key" is not secret - it is a hardcoded string shown
1974 * here. The intent is to protect against the random user or
1975 * application that is just writing attributes.
1976 */
1977
1978 /* count may include a LF at end of string */
1979 if (buf[cnt-1] == '\n')
1980 cnt--;
1981
James Smarta12e07b2006-12-02 13:35:30 -05001982 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1983 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001984 return -EINVAL;
1985
James Smarta12e07b2006-12-02 13:35:30 -05001986 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001987 return count;
1988}
Tony Jonesee959b02008-02-22 00:13:36 +01001989static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1990 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001991
James Smarte59058c2008-08-24 21:49:00 -04001992/**
James Smart3621a712009-04-06 18:47:14 -04001993 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001994 * @dev: class device that is converted into a Scsi_host.
1995 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001996 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001997 *
1998 * Returns: size of formatted string.
1999 **/
James Smartc3f28af2006-08-18 17:47:18 -04002000static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002001lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2002 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002003{
Tony Jonesee959b02008-02-22 00:13:36 +01002004 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2006 struct lpfc_hba *phba = vport->phba;
2007
Randy Dunlapafc071e2006-10-23 21:47:13 -07002008 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2009 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002010}
2011
James Smarte59058c2008-08-24 21:49:00 -04002012/**
James Smart3621a712009-04-06 18:47:14 -04002013 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002014 * @dev class device that is converted into a Scsi_host.
2015 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002016 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002017 * @count: number of wwpn bytes in buf
2018 *
2019 * Returns:
2020 * -EACCES hba reset not enabled, adapter over temp
2021 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2022 * -EIO error taking adapter offline or online
2023 * value of count on success
2024 **/
James Smartc3f28af2006-08-18 17:47:18 -04002025static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002026lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2027 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002028{
Tony Jonesee959b02008-02-22 00:13:36 +01002029 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2031 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002032 struct completion online_compl;
2033 int stat1=0, stat2=0;
2034 unsigned int i, j, cnt=count;
2035 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002036 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002037
James Smart13815c82008-01-11 01:52:48 -05002038 if (!phba->cfg_enable_hba_reset)
2039 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002040 spin_lock_irq(&phba->hbalock);
2041 if (phba->over_temp_state == HBA_OVER_TEMP) {
2042 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002043 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002044 }
2045 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002046 /* count may include a LF at end of string */
2047 if (buf[cnt-1] == '\n')
2048 cnt--;
2049
James Smarta12e07b2006-12-02 13:35:30 -05002050 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002051 ((cnt == 17) && (*buf++ != 'x')) ||
2052 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2053 return -EINVAL;
2054
James Smarta12e07b2006-12-02 13:35:30 -05002055 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002056
2057 memset(wwpn, 0, sizeof(wwpn));
2058
2059 /* Validate and store the new name */
2060 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002061 int value;
2062
2063 value = hex_to_bin(*buf++);
2064 if (value >= 0)
2065 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002066 else
2067 return -EINVAL;
2068 if (i % 2) {
2069 wwpn[i/2] = j & 0xff;
2070 j = 0;
2071 }
2072 }
2073 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002074 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002075 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002076 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002077
2078 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2079 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2080
James Smart46fa3112007-04-25 09:51:45 -04002081 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002082 if (stat1)
2083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002084 "0463 lpfc_soft_wwpn attribute set failed to "
2085 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002086 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002087 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2088 LPFC_EVT_ONLINE);
2089 if (rc == 0)
2090 return -ENOMEM;
2091
James Smartc3f28af2006-08-18 17:47:18 -04002092 wait_for_completion(&online_compl);
2093 if (stat2)
2094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002095 "0464 lpfc_soft_wwpn attribute set failed to "
2096 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002097 return (stat1 || stat2) ? -EIO : count;
2098}
Tony Jonesee959b02008-02-22 00:13:36 +01002099static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2100 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002101
James Smarte59058c2008-08-24 21:49:00 -04002102/**
James Smart3621a712009-04-06 18:47:14 -04002103 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002104 * @dev: class device that is converted into a Scsi_host.
2105 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002106 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002107 *
2108 * Returns: size of formatted string.
2109 **/
James Smarta12e07b2006-12-02 13:35:30 -05002110static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002111lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2112 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002113{
Tony Jonesee959b02008-02-22 00:13:36 +01002114 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002115 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002116 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2117 (unsigned long long)phba->cfg_soft_wwnn);
2118}
2119
James Smarte59058c2008-08-24 21:49:00 -04002120/**
James Smart3621a712009-04-06 18:47:14 -04002121 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002122 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002123 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002124 * @count: number of wwnn bytes in buf.
2125 *
2126 * Returns:
2127 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2128 * value of count on success
2129 **/
James Smarta12e07b2006-12-02 13:35:30 -05002130static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002131lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2132 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002133{
Tony Jonesee959b02008-02-22 00:13:36 +01002134 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002135 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002136 unsigned int i, j, cnt=count;
2137 u8 wwnn[8];
2138
2139 /* count may include a LF at end of string */
2140 if (buf[cnt-1] == '\n')
2141 cnt--;
2142
2143 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2144 ((cnt == 17) && (*buf++ != 'x')) ||
2145 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2146 return -EINVAL;
2147
2148 /*
2149 * Allow wwnn to be set many times, as long as the enable is set.
2150 * However, once the wwpn is set, everything locks.
2151 */
2152
2153 memset(wwnn, 0, sizeof(wwnn));
2154
2155 /* Validate and store the new name */
2156 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002157 int value;
2158
2159 value = hex_to_bin(*buf++);
2160 if (value >= 0)
2161 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002162 else
2163 return -EINVAL;
2164 if (i % 2) {
2165 wwnn[i/2] = j & 0xff;
2166 j = 0;
2167 }
2168 }
2169 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2170
2171 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2172 "lpfc%d: soft_wwnn set. Value will take effect upon "
2173 "setting of the soft_wwpn\n", phba->brd_no);
2174
2175 return count;
2176}
Tony Jonesee959b02008-02-22 00:13:36 +01002177static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2178 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002179
James Smartc3f28af2006-08-18 17:47:18 -04002180
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002181static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002182module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002183MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2184 " 0 - none,"
2185 " 1 - poll with interrupts enabled"
2186 " 3 - poll and disable FCP ring interrupts");
2187
Tony Jonesee959b02008-02-22 00:13:36 +01002188static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2189 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002190
James Smart92d7f7b2007-06-17 19:56:38 -05002191int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002192module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002193MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2194 " 0 - auto (SLI-3 if supported),"
2195 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2196 " 3 - select SLI-3");
2197
James Smart15672312010-04-06 14:49:03 -04002198int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002199module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002200MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2201lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002202lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002203static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002204
James Smart7d791df2011-07-22 18:37:52 -04002205LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2206 "FCF Fast failover=1 Priority failover=2");
2207
James Smart19ca7602010-11-20 23:11:55 -05002208int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002209module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002210MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2211lpfc_param_show(enable_rrq);
2212lpfc_param_init(enable_rrq, 0, 0, 1);
2213static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2214
dea31012005-04-17 16:05:31 -05002215/*
James Smart84d1b002010-02-12 14:42:33 -05002216# lpfc_suppress_link_up: Bring link up at initialization
2217# 0x0 = bring link up (issue MBX_INIT_LINK)
2218# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2219# 0x2 = never bring up link
2220# Default value is 0.
2221*/
James Smarte40a02c2010-02-26 14:13:54 -05002222LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2223 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2224 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002225/*
2226# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2227# 1 - (1024)
2228# 2 - (2048)
2229# 3 - (3072)
2230# 4 - (4096)
2231# 5 - (5120)
2232*/
2233static ssize_t
2234lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2235{
2236 struct Scsi_Host *shost = class_to_shost(dev);
2237 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2238
2239 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2240}
2241
2242static DEVICE_ATTR(iocb_hw, S_IRUGO,
2243 lpfc_iocb_hw_show, NULL);
2244static ssize_t
2245lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2246{
2247 struct Scsi_Host *shost = class_to_shost(dev);
2248 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2249
2250 return snprintf(buf, PAGE_SIZE, "%d\n",
2251 phba->sli.ring[LPFC_ELS_RING].txq_max);
2252}
2253
2254static DEVICE_ATTR(txq_hw, S_IRUGO,
2255 lpfc_txq_hw_show, NULL);
2256static ssize_t
2257lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2258 char *buf)
2259{
2260 struct Scsi_Host *shost = class_to_shost(dev);
2261 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2262
2263 return snprintf(buf, PAGE_SIZE, "%d\n",
2264 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2265}
2266
2267static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2268 lpfc_txcmplq_hw_show, NULL);
2269
2270int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002271module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002272MODULE_PARM_DESC(lpfc_iocb_cnt,
2273 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2274lpfc_param_show(iocb_cnt);
2275lpfc_param_init(iocb_cnt, 2, 1, 5);
2276static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2277 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002278
2279/*
James Smartc01f3202006-08-18 17:47:08 -04002280# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2281# until the timer expires. Value range is [0,255]. Default value is 30.
2282*/
2283static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2284static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2285module_param(lpfc_nodev_tmo, int, 0);
2286MODULE_PARM_DESC(lpfc_nodev_tmo,
2287 "Seconds driver will hold I/O waiting "
2288 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002289
2290/**
James Smart3621a712009-04-06 18:47:14 -04002291 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002292 * @dev: class converted to a Scsi_host structure.
2293 * @attr: device attribute, not used.
2294 * @buf: on return contains the dev loss timeout in decimal.
2295 *
2296 * Returns: size of formatted string.
2297 **/
James Smartc01f3202006-08-18 17:47:08 -04002298static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002299lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2300 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002301{
Tony Jonesee959b02008-02-22 00:13:36 +01002302 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002304
James Smart3de2a652007-08-02 11:09:59 -04002305 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002306}
2307
James Smarte59058c2008-08-24 21:49:00 -04002308/**
James Smart3621a712009-04-06 18:47:14 -04002309 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002310 * @vport: lpfc vport structure pointer.
2311 * @val: contains the nodev timeout value.
2312 *
2313 * Description:
2314 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2315 * a kernel error message is printed and zero is returned.
2316 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2317 * Otherwise nodev tmo is set to the default value.
2318 *
2319 * Returns:
2320 * zero if already set or if val is in range
2321 * -EINVAL val out of range
2322 **/
James Smartc01f3202006-08-18 17:47:08 -04002323static int
James Smart3de2a652007-08-02 11:09:59 -04002324lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002325{
James Smart3de2a652007-08-02 11:09:59 -04002326 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2327 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2328 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002329 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002330 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002331 "parameter because devloss_tmo is "
2332 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002333 return 0;
2334 }
2335
2336 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002337 vport->cfg_nodev_tmo = val;
2338 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002339 return 0;
2340 }
James Smarte8b62012007-08-02 11:10:09 -04002341 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2342 "0400 lpfc_nodev_tmo attribute cannot be set to"
2343 " %d, allowed range is [%d, %d]\n",
2344 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002345 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002346 return -EINVAL;
2347}
2348
James Smarte59058c2008-08-24 21:49:00 -04002349/**
James Smart3621a712009-04-06 18:47:14 -04002350 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002351 * @vport: lpfc vport structure pointer.
2352 *
2353 * Description:
2354 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2355 **/
James Smart7054a602007-04-25 09:52:34 -04002356static void
James Smart3de2a652007-08-02 11:09:59 -04002357lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002358{
James Smart858c9f62007-06-17 19:56:39 -05002359 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002360 struct lpfc_nodelist *ndlp;
2361
James Smart51ef4c22007-08-02 11:10:31 -04002362 shost = lpfc_shost_from_vport(vport);
2363 spin_lock_irq(shost->host_lock);
2364 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002365 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002366 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2367 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002368}
2369
James Smarte59058c2008-08-24 21:49:00 -04002370/**
James Smart3621a712009-04-06 18:47:14 -04002371 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002372 * @vport: lpfc vport structure pointer.
2373 * @val: contains the tmo value.
2374 *
2375 * Description:
2376 * If the devloss tmo is already set or the vport dev loss tmo has changed
2377 * then a kernel error message is printed and zero is returned.
2378 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2379 * Otherwise nodev tmo is set to the default value.
2380 *
2381 * Returns:
2382 * zero if already set or if val is in range
2383 * -EINVAL val out of range
2384 **/
James Smartc01f3202006-08-18 17:47:08 -04002385static int
James Smart3de2a652007-08-02 11:09:59 -04002386lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002387{
James Smart3de2a652007-08-02 11:09:59 -04002388 if (vport->dev_loss_tmo_changed ||
2389 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002390 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2391 "0401 Ignoring change to nodev_tmo "
2392 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002393 return 0;
2394 }
James Smartc01f3202006-08-18 17:47:08 -04002395 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002396 vport->cfg_nodev_tmo = val;
2397 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002398 /*
2399 * For compat: set the fc_host dev loss so new rports
2400 * will get the value.
2401 */
2402 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002403 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002404 return 0;
2405 }
James Smarte8b62012007-08-02 11:10:09 -04002406 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2407 "0403 lpfc_nodev_tmo attribute cannot be set to"
2408 "%d, allowed range is [%d, %d]\n",
2409 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002410 return -EINVAL;
2411}
2412
James Smart3de2a652007-08-02 11:09:59 -04002413lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002414
Tony Jonesee959b02008-02-22 00:13:36 +01002415static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2416 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002417
2418/*
2419# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2420# disappear until the timer expires. Value range is [0,255]. Default
2421# value is 30.
2422*/
James Smartab56dc22011-02-16 12:39:57 -05002423module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002424MODULE_PARM_DESC(lpfc_devloss_tmo,
2425 "Seconds driver will hold I/O waiting "
2426 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002427lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2428 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2429lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002430
2431/**
James Smart3621a712009-04-06 18:47:14 -04002432 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002433 * @vport: lpfc vport structure pointer.
2434 * @val: contains the tmo value.
2435 *
2436 * Description:
2437 * If val is in a valid range then set the vport nodev tmo,
2438 * devloss tmo, also set the vport dev loss tmo changed flag.
2439 * Else a kernel error message is printed.
2440 *
2441 * Returns:
2442 * zero if val is in range
2443 * -EINVAL val out of range
2444 **/
James Smartc01f3202006-08-18 17:47:08 -04002445static int
James Smart3de2a652007-08-02 11:09:59 -04002446lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002447{
2448 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002449 vport->cfg_nodev_tmo = val;
2450 vport->cfg_devloss_tmo = val;
2451 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002452 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002453 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002454 return 0;
2455 }
2456
James Smarte8b62012007-08-02 11:10:09 -04002457 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2458 "0404 lpfc_devloss_tmo attribute cannot be set to"
2459 " %d, allowed range is [%d, %d]\n",
2460 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002461 return -EINVAL;
2462}
2463
James Smart3de2a652007-08-02 11:09:59 -04002464lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002465static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2466 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002467
2468/*
dea31012005-04-17 16:05:31 -05002469# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2470# deluged with LOTS of information.
2471# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002472# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002473*/
James Smartf4b4c682009-05-22 14:53:12 -04002474LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002475 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002476
2477/*
James Smart7ee5d432007-10-27 13:37:17 -04002478# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2479# objects that have been registered with the nameserver after login.
2480*/
2481LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2482 "Deregister nameserver objects before LOGO");
2483
2484/*
dea31012005-04-17 16:05:31 -05002485# lun_queue_depth: This parameter is used to limit the number of outstanding
2486# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2487*/
James Smart3de2a652007-08-02 11:09:59 -04002488LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2489 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002490
2491/*
James Smart7dc517d2010-07-14 15:32:10 -04002492# tgt_queue_depth: This parameter is used to limit the number of outstanding
2493# commands per target port. Value range is [10,65535]. Default value is 65535.
2494*/
2495LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2496 "Max number of FCP commands we can queue to a specific target port");
2497
2498/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002499# hba_queue_depth: This parameter is used to limit the number of outstanding
2500# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2501# value is greater than the maximum number of exchanges supported by the HBA,
2502# then maximum number of exchanges supported by the HBA is used to determine
2503# the hba_queue_depth.
2504*/
2505LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2506 "Max number of FCP commands we can queue to a lpfc HBA");
2507
2508/*
James Smart92d7f7b2007-06-17 19:56:38 -05002509# peer_port_login: This parameter allows/prevents logins
2510# between peer ports hosted on the same physical port.
2511# When this parameter is set 0 peer ports of same physical port
2512# are not allowed to login to each other.
2513# When this parameter is set 1 peer ports of same physical port
2514# are allowed to login to each other.
2515# Default value of this parameter is 0.
2516*/
James Smart3de2a652007-08-02 11:09:59 -04002517LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2518 "Allow peer ports on the same physical port to login to each "
2519 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002520
2521/*
James Smart3de2a652007-08-02 11:09:59 -04002522# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002523# between Virtual Ports and remote initiators.
2524# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2525# other initiators and will attempt to PLOGI all remote ports.
2526# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2527# remote ports and will not attempt to PLOGI to other initiators.
2528# This parameter does not restrict to the physical port.
2529# This parameter does not restrict logins to Fabric resident remote ports.
2530# Default value of this parameter is 1.
2531*/
James Smart3de2a652007-08-02 11:09:59 -04002532static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002533module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002534MODULE_PARM_DESC(lpfc_restrict_login,
2535 "Restrict virtual ports login to remote initiators.");
2536lpfc_vport_param_show(restrict_login);
2537
James Smarte59058c2008-08-24 21:49:00 -04002538/**
James Smart3621a712009-04-06 18:47:14 -04002539 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002540 * @vport: lpfc vport structure pointer.
2541 * @val: contains the restrict login value.
2542 *
2543 * Description:
2544 * If val is not in a valid range then log a kernel error message and set
2545 * the vport restrict login to one.
2546 * If the port type is physical clear the restrict login flag and return.
2547 * Else set the restrict login flag to val.
2548 *
2549 * Returns:
2550 * zero if val is in range
2551 * -EINVAL val out of range
2552 **/
James Smart3de2a652007-08-02 11:09:59 -04002553static int
2554lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2555{
2556 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002557 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002558 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002559 "be set to %d, allowed range is [0, 1]\n",
2560 val);
James Smart3de2a652007-08-02 11:09:59 -04002561 vport->cfg_restrict_login = 1;
2562 return -EINVAL;
2563 }
2564 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2565 vport->cfg_restrict_login = 0;
2566 return 0;
2567 }
2568 vport->cfg_restrict_login = val;
2569 return 0;
2570}
2571
James Smarte59058c2008-08-24 21:49:00 -04002572/**
James Smart3621a712009-04-06 18:47:14 -04002573 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002574 * @vport: lpfc vport structure pointer.
2575 * @val: contains the restrict login value.
2576 *
2577 * Description:
2578 * If val is not in a valid range then log a kernel error message and set
2579 * the vport restrict login to one.
2580 * If the port type is physical and the val is not zero log a kernel
2581 * error message, clear the restrict login flag and return zero.
2582 * Else set the restrict login flag to val.
2583 *
2584 * Returns:
2585 * zero if val is in range
2586 * -EINVAL val out of range
2587 **/
James Smart3de2a652007-08-02 11:09:59 -04002588static int
2589lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2590{
2591 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002592 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002593 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002594 "be set to %d, allowed range is [0, 1]\n",
2595 val);
James Smart3de2a652007-08-02 11:09:59 -04002596 vport->cfg_restrict_login = 1;
2597 return -EINVAL;
2598 }
2599 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002600 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2601 "0468 lpfc_restrict_login must be 0 for "
2602 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002603 vport->cfg_restrict_login = 0;
2604 return 0;
2605 }
2606 vport->cfg_restrict_login = val;
2607 return 0;
2608}
2609lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002610static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2611 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002612
2613/*
dea31012005-04-17 16:05:31 -05002614# Some disk devices have a "select ID" or "select Target" capability.
2615# From a protocol standpoint "select ID" usually means select the
2616# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2617# annex" which contains a table that maps a "select ID" (a number
2618# between 0 and 7F) to an ALPA. By default, for compatibility with
2619# older drivers, the lpfc driver scans this table from low ALPA to high
2620# ALPA.
2621#
2622# Turning on the scan-down variable (on = 1, off = 0) will
2623# cause the lpfc driver to use an inverted table, effectively
2624# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2625#
2626# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2627# and will not work across a fabric. Also this parameter will take
2628# effect only in the case when ALPA map is not available.)
2629*/
James Smart3de2a652007-08-02 11:09:59 -04002630LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2631 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002632
2633/*
dea31012005-04-17 16:05:31 -05002634# lpfc_topology: link topology for init link
2635# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002636# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002637# 0x02 = attempt point-to-point mode only
2638# 0x04 = attempt loop mode only
2639# 0x06 = attempt point-to-point mode then loop
2640# Set point-to-point mode if you want to run as an N_Port.
2641# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2642# Default value is 0.
2643*/
James Smarte59058c2008-08-24 21:49:00 -04002644
2645/**
James Smart3621a712009-04-06 18:47:14 -04002646 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002647 * @phba: lpfc_hba pointer.
2648 * @val: topology value.
2649 *
2650 * Description:
2651 * If val is in a valid range then set the adapter's topology field and
2652 * issue a lip; if the lip fails reset the topology to the old value.
2653 *
2654 * If the value is not in range log a kernel error message and return an error.
2655 *
2656 * Returns:
2657 * zero if val is in range and lip okay
2658 * non-zero return value from lpfc_issue_lip()
2659 * -EINVAL val out of range
2660 **/
James Smarta257bf92009-04-06 18:48:10 -04002661static ssize_t
2662lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2663 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002664{
James Smarta257bf92009-04-06 18:48:10 -04002665 struct Scsi_Host *shost = class_to_shost(dev);
2666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2667 struct lpfc_hba *phba = vport->phba;
2668 int val = 0;
2669 int nolip = 0;
2670 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002671 int err;
2672 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002673
2674 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2675 nolip = 1;
2676 val_buf = &buf[strlen("nolip ")];
2677 }
2678
2679 if (!isdigit(val_buf[0]))
2680 return -EINVAL;
2681 if (sscanf(val_buf, "%i", &val) != 1)
2682 return -EINVAL;
2683
James Smart83108bd2008-01-11 01:53:09 -05002684 if (val >= 0 && val <= 6) {
2685 prev_val = phba->cfg_topology;
2686 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002687 if (nolip)
2688 return strlen(buf);
2689
James Smart88a2cfb2011-07-22 18:36:33 -04002690 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2691 "3054 lpfc_topology changed from %d to %d\n",
2692 prev_val, val);
James Smart83108bd2008-01-11 01:53:09 -05002693 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002694 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002695 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002696 return -EINVAL;
2697 } else
2698 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002699 }
2700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2701 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2702 "allowed range is [0, 6]\n",
2703 phba->brd_no, val);
2704 return -EINVAL;
2705}
2706static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002707module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002708MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2709lpfc_param_show(topology)
2710lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002711static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002712 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002713
James Smart21e9a0a2009-05-22 14:53:21 -04002714/**
2715 * lpfc_static_vport_show: Read callback function for
2716 * lpfc_static_vport sysfs file.
2717 * @dev: Pointer to class device object.
2718 * @attr: device attribute structure.
2719 * @buf: Data buffer.
2720 *
2721 * This function is the read call back function for
2722 * lpfc_static_vport sysfs file. The lpfc_static_vport
2723 * sysfs file report the mageability of the vport.
2724 **/
2725static ssize_t
2726lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2727 char *buf)
2728{
2729 struct Scsi_Host *shost = class_to_shost(dev);
2730 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2731 if (vport->vport_flag & STATIC_VPORT)
2732 sprintf(buf, "1\n");
2733 else
2734 sprintf(buf, "0\n");
2735
2736 return strlen(buf);
2737}
2738
2739/*
2740 * Sysfs attribute to control the statistical data collection.
2741 */
2742static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2743 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002744
2745/**
James Smart3621a712009-04-06 18:47:14 -04002746 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002747 * @dev: Pointer to class device.
2748 * @buf: Data buffer.
2749 * @count: Size of the data buffer.
2750 *
2751 * This function get called when an user write to the lpfc_stat_data_ctrl
2752 * sysfs file. This function parse the command written to the sysfs file
2753 * and take appropriate action. These commands are used for controlling
2754 * driver statistical data collection.
2755 * Following are the command this function handles.
2756 *
2757 * setbucket <bucket_type> <base> <step>
2758 * = Set the latency buckets.
2759 * destroybucket = destroy all the buckets.
2760 * start = start data collection
2761 * stop = stop data collection
2762 * reset = reset the collected data
2763 **/
2764static ssize_t
2765lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2766 const char *buf, size_t count)
2767{
2768 struct Scsi_Host *shost = class_to_shost(dev);
2769 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2770 struct lpfc_hba *phba = vport->phba;
2771#define LPFC_MAX_DATA_CTRL_LEN 1024
2772 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2773 unsigned long i;
2774 char *str_ptr, *token;
2775 struct lpfc_vport **vports;
2776 struct Scsi_Host *v_shost;
2777 char *bucket_type_str, *base_str, *step_str;
2778 unsigned long base, step, bucket_type;
2779
2780 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002781 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002782 return -EINVAL;
2783
2784 strcpy(bucket_data, buf);
2785 str_ptr = &bucket_data[0];
2786 /* Ignore this token - this is command token */
2787 token = strsep(&str_ptr, "\t ");
2788 if (!token)
2789 return -EINVAL;
2790
2791 bucket_type_str = strsep(&str_ptr, "\t ");
2792 if (!bucket_type_str)
2793 return -EINVAL;
2794
2795 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2796 bucket_type = LPFC_LINEAR_BUCKET;
2797 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2798 bucket_type = LPFC_POWER2_BUCKET;
2799 else
2800 return -EINVAL;
2801
2802 base_str = strsep(&str_ptr, "\t ");
2803 if (!base_str)
2804 return -EINVAL;
2805 base = simple_strtoul(base_str, NULL, 0);
2806
2807 step_str = strsep(&str_ptr, "\t ");
2808 if (!step_str)
2809 return -EINVAL;
2810 step = simple_strtoul(step_str, NULL, 0);
2811 if (!step)
2812 return -EINVAL;
2813
2814 /* Block the data collection for every vport */
2815 vports = lpfc_create_vport_work_array(phba);
2816 if (vports == NULL)
2817 return -ENOMEM;
2818
James Smartf4b4c682009-05-22 14:53:12 -04002819 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002820 v_shost = lpfc_shost_from_vport(vports[i]);
2821 spin_lock_irq(v_shost->host_lock);
2822 /* Block and reset data collection */
2823 vports[i]->stat_data_blocked = 1;
2824 if (vports[i]->stat_data_enabled)
2825 lpfc_vport_reset_stat_data(vports[i]);
2826 spin_unlock_irq(v_shost->host_lock);
2827 }
2828
2829 /* Set the bucket attributes */
2830 phba->bucket_type = bucket_type;
2831 phba->bucket_base = base;
2832 phba->bucket_step = step;
2833
James Smartf4b4c682009-05-22 14:53:12 -04002834 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002835 v_shost = lpfc_shost_from_vport(vports[i]);
2836
2837 /* Unblock data collection */
2838 spin_lock_irq(v_shost->host_lock);
2839 vports[i]->stat_data_blocked = 0;
2840 spin_unlock_irq(v_shost->host_lock);
2841 }
2842 lpfc_destroy_vport_work_array(phba, vports);
2843 return strlen(buf);
2844 }
2845
2846 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2847 vports = lpfc_create_vport_work_array(phba);
2848 if (vports == NULL)
2849 return -ENOMEM;
2850
James Smartf4b4c682009-05-22 14:53:12 -04002851 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002852 v_shost = lpfc_shost_from_vport(vports[i]);
2853 spin_lock_irq(shost->host_lock);
2854 vports[i]->stat_data_blocked = 1;
2855 lpfc_free_bucket(vport);
2856 vport->stat_data_enabled = 0;
2857 vports[i]->stat_data_blocked = 0;
2858 spin_unlock_irq(shost->host_lock);
2859 }
2860 lpfc_destroy_vport_work_array(phba, vports);
2861 phba->bucket_type = LPFC_NO_BUCKET;
2862 phba->bucket_base = 0;
2863 phba->bucket_step = 0;
2864 return strlen(buf);
2865 }
2866
2867 if (!strncmp(buf, "start", strlen("start"))) {
2868 /* If no buckets configured return error */
2869 if (phba->bucket_type == LPFC_NO_BUCKET)
2870 return -EINVAL;
2871 spin_lock_irq(shost->host_lock);
2872 if (vport->stat_data_enabled) {
2873 spin_unlock_irq(shost->host_lock);
2874 return strlen(buf);
2875 }
2876 lpfc_alloc_bucket(vport);
2877 vport->stat_data_enabled = 1;
2878 spin_unlock_irq(shost->host_lock);
2879 return strlen(buf);
2880 }
2881
2882 if (!strncmp(buf, "stop", strlen("stop"))) {
2883 spin_lock_irq(shost->host_lock);
2884 if (vport->stat_data_enabled == 0) {
2885 spin_unlock_irq(shost->host_lock);
2886 return strlen(buf);
2887 }
2888 lpfc_free_bucket(vport);
2889 vport->stat_data_enabled = 0;
2890 spin_unlock_irq(shost->host_lock);
2891 return strlen(buf);
2892 }
2893
2894 if (!strncmp(buf, "reset", strlen("reset"))) {
2895 if ((phba->bucket_type == LPFC_NO_BUCKET)
2896 || !vport->stat_data_enabled)
2897 return strlen(buf);
2898 spin_lock_irq(shost->host_lock);
2899 vport->stat_data_blocked = 1;
2900 lpfc_vport_reset_stat_data(vport);
2901 vport->stat_data_blocked = 0;
2902 spin_unlock_irq(shost->host_lock);
2903 return strlen(buf);
2904 }
2905 return -EINVAL;
2906}
2907
2908
2909/**
James Smart3621a712009-04-06 18:47:14 -04002910 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002911 * @dev: Pointer to class device object.
2912 * @buf: Data buffer.
2913 *
2914 * This function is the read call back function for
2915 * lpfc_stat_data_ctrl sysfs file. This function report the
2916 * current statistical data collection state.
2917 **/
2918static ssize_t
2919lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2920 char *buf)
2921{
2922 struct Scsi_Host *shost = class_to_shost(dev);
2923 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2924 struct lpfc_hba *phba = vport->phba;
2925 int index = 0;
2926 int i;
2927 char *bucket_type;
2928 unsigned long bucket_value;
2929
2930 switch (phba->bucket_type) {
2931 case LPFC_LINEAR_BUCKET:
2932 bucket_type = "linear";
2933 break;
2934 case LPFC_POWER2_BUCKET:
2935 bucket_type = "power2";
2936 break;
2937 default:
2938 bucket_type = "No Bucket";
2939 break;
2940 }
2941
2942 sprintf(&buf[index], "Statistical Data enabled :%d, "
2943 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2944 " Bucket step :%d\nLatency Ranges :",
2945 vport->stat_data_enabled, vport->stat_data_blocked,
2946 bucket_type, phba->bucket_base, phba->bucket_step);
2947 index = strlen(buf);
2948 if (phba->bucket_type != LPFC_NO_BUCKET) {
2949 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2950 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2951 bucket_value = phba->bucket_base +
2952 phba->bucket_step * i;
2953 else
2954 bucket_value = phba->bucket_base +
2955 (1 << i) * phba->bucket_step;
2956
2957 if (index + 10 > PAGE_SIZE)
2958 break;
2959 sprintf(&buf[index], "%08ld ", bucket_value);
2960 index = strlen(buf);
2961 }
2962 }
2963 sprintf(&buf[index], "\n");
2964 return strlen(buf);
2965}
2966
2967/*
2968 * Sysfs attribute to control the statistical data collection.
2969 */
2970static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2971 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2972
2973/*
2974 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2975 */
2976
2977/*
2978 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2979 * for each target.
2980 */
2981#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2982#define MAX_STAT_DATA_SIZE_PER_TARGET \
2983 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2984
2985
2986/**
James Smart3621a712009-04-06 18:47:14 -04002987 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002988 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002989 * @kobj: Pointer to the kernel object
2990 * @bin_attr: Attribute object
2991 * @buff: Buffer pointer
2992 * @off: File offset
2993 * @count: Buffer size
2994 *
2995 * This function is the read call back function for lpfc_drvr_stat_data
2996 * sysfs file. This function export the statistical data to user
2997 * applications.
2998 **/
2999static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003000sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3001 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003002 char *buf, loff_t off, size_t count)
3003{
3004 struct device *dev = container_of(kobj, struct device,
3005 kobj);
3006 struct Scsi_Host *shost = class_to_shost(dev);
3007 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3008 struct lpfc_hba *phba = vport->phba;
3009 int i = 0, index = 0;
3010 unsigned long nport_index;
3011 struct lpfc_nodelist *ndlp = NULL;
3012 nport_index = (unsigned long)off /
3013 MAX_STAT_DATA_SIZE_PER_TARGET;
3014
3015 if (!vport->stat_data_enabled || vport->stat_data_blocked
3016 || (phba->bucket_type == LPFC_NO_BUCKET))
3017 return 0;
3018
3019 spin_lock_irq(shost->host_lock);
3020 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3021 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3022 continue;
3023
3024 if (nport_index > 0) {
3025 nport_index--;
3026 continue;
3027 }
3028
3029 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3030 > count)
3031 break;
3032
3033 if (!ndlp->lat_data)
3034 continue;
3035
3036 /* Print the WWN */
3037 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3038 ndlp->nlp_portname.u.wwn[0],
3039 ndlp->nlp_portname.u.wwn[1],
3040 ndlp->nlp_portname.u.wwn[2],
3041 ndlp->nlp_portname.u.wwn[3],
3042 ndlp->nlp_portname.u.wwn[4],
3043 ndlp->nlp_portname.u.wwn[5],
3044 ndlp->nlp_portname.u.wwn[6],
3045 ndlp->nlp_portname.u.wwn[7]);
3046
3047 index = strlen(buf);
3048
3049 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3050 sprintf(&buf[index], "%010u,",
3051 ndlp->lat_data[i].cmd_count);
3052 index = strlen(buf);
3053 }
3054 sprintf(&buf[index], "\n");
3055 index = strlen(buf);
3056 }
3057 spin_unlock_irq(shost->host_lock);
3058 return index;
3059}
3060
3061static struct bin_attribute sysfs_drvr_stat_data_attr = {
3062 .attr = {
3063 .name = "lpfc_drvr_stat_data",
3064 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003065 },
3066 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3067 .read = sysfs_drvr_stat_data_read,
3068 .write = NULL,
3069};
3070
dea31012005-04-17 16:05:31 -05003071/*
3072# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3073# connection.
James Smart76a95d72010-11-20 23:11:48 -05003074# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003075*/
James Smarte59058c2008-08-24 21:49:00 -04003076/**
James Smart3621a712009-04-06 18:47:14 -04003077 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003078 * @phba: lpfc_hba pointer.
3079 * @val: link speed value.
3080 *
3081 * Description:
3082 * If val is in a valid range then set the adapter's link speed field and
3083 * issue a lip; if the lip fails reset the link speed to the old value.
3084 *
3085 * Notes:
3086 * If the value is not in range log a kernel error message and return an error.
3087 *
3088 * Returns:
3089 * zero if val is in range and lip okay.
3090 * non-zero return value from lpfc_issue_lip()
3091 * -EINVAL val out of range
3092 **/
James Smarta257bf92009-04-06 18:48:10 -04003093static ssize_t
3094lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3095 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003096{
James Smarta257bf92009-04-06 18:48:10 -04003097 struct Scsi_Host *shost = class_to_shost(dev);
3098 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3099 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003100 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003101 int nolip = 0;
3102 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003103 int err;
3104 uint32_t prev_val;
3105
James Smarta257bf92009-04-06 18:48:10 -04003106 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3107 nolip = 1;
3108 val_buf = &buf[strlen("nolip ")];
3109 }
3110
3111 if (!isdigit(val_buf[0]))
3112 return -EINVAL;
3113 if (sscanf(val_buf, "%i", &val) != 1)
3114 return -EINVAL;
3115
James Smart88a2cfb2011-07-22 18:36:33 -04003116 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3117 "3055 lpfc_link_speed changed from %d to %d %s\n",
3118 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3119
James Smart76a95d72010-11-20 23:11:48 -05003120 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3121 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3122 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3123 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3124 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3125 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3126 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3127 "2879 lpfc_link_speed attribute cannot be set "
3128 "to %d. Speed is not supported by this port.\n",
3129 val);
James Smart83108bd2008-01-11 01:53:09 -05003130 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003131 }
3132 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3133 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003134 prev_val = phba->cfg_link_speed;
3135 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003136 if (nolip)
3137 return strlen(buf);
3138
James Smart83108bd2008-01-11 01:53:09 -05003139 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003140 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003141 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003142 return -EINVAL;
3143 } else
3144 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003145 }
James Smart83108bd2008-01-11 01:53:09 -05003146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003147 "0469 lpfc_link_speed attribute cannot be set to %d, "
3148 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003149 return -EINVAL;
3150}
3151
3152static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003153module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003154MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3155lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003156
3157/**
James Smart3621a712009-04-06 18:47:14 -04003158 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003159 * @phba: lpfc_hba pointer.
3160 * @val: link speed value.
3161 *
3162 * Description:
3163 * If val is in a valid range then set the adapter's link speed field.
3164 *
3165 * Notes:
3166 * If the value is not in range log a kernel error message, clear the link
3167 * speed and return an error.
3168 *
3169 * Returns:
3170 * zero if val saved.
3171 * -EINVAL val out of range
3172 **/
James Smart83108bd2008-01-11 01:53:09 -05003173static int
3174lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3175{
James Smart76a95d72010-11-20 23:11:48 -05003176 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3177 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003178 phba->cfg_link_speed = val;
3179 return 0;
3180 }
3181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003182 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003183 "be set to %d, allowed values are "
3184 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003185 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003186 return -EINVAL;
3187}
3188
Tony Jonesee959b02008-02-22 00:13:36 +01003189static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003190 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003191
3192/*
James Smart0d878412009-10-02 15:16:56 -04003193# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3194# 0 = aer disabled or not supported
3195# 1 = aer supported and enabled (default)
3196# Value range is [0,1]. Default value is 1.
3197*/
3198
3199/**
3200 * lpfc_aer_support_store - Set the adapter for aer support
3201 *
3202 * @dev: class device that is converted into a Scsi_host.
3203 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003204 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003205 * @count: unused variable.
3206 *
3207 * Description:
3208 * If the val is 1 and currently the device's AER capability was not
3209 * enabled, invoke the kernel's enable AER helper routine, trying to
3210 * enable the device's AER capability. If the helper routine enabling
3211 * AER returns success, update the device's cfg_aer_support flag to
3212 * indicate AER is supported by the device; otherwise, if the device
3213 * AER capability is already enabled to support AER, then do nothing.
3214 *
3215 * If the val is 0 and currently the device's AER support was enabled,
3216 * invoke the kernel's disable AER helper routine. After that, update
3217 * the device's cfg_aer_support flag to indicate AER is not supported
3218 * by the device; otherwise, if the device AER capability is already
3219 * disabled from supporting AER, then do nothing.
3220 *
3221 * Returns:
3222 * length of the buf on success if val is in range the intended mode
3223 * is supported.
3224 * -EINVAL if val out of range or intended mode is not supported.
3225 **/
3226static ssize_t
3227lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3228 const char *buf, size_t count)
3229{
3230 struct Scsi_Host *shost = class_to_shost(dev);
3231 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3232 struct lpfc_hba *phba = vport->phba;
3233 int val = 0, rc = -EINVAL;
3234
3235 if (!isdigit(buf[0]))
3236 return -EINVAL;
3237 if (sscanf(buf, "%i", &val) != 1)
3238 return -EINVAL;
3239
3240 switch (val) {
3241 case 0:
3242 if (phba->hba_flag & HBA_AER_ENABLED) {
3243 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3244 if (!rc) {
3245 spin_lock_irq(&phba->hbalock);
3246 phba->hba_flag &= ~HBA_AER_ENABLED;
3247 spin_unlock_irq(&phba->hbalock);
3248 phba->cfg_aer_support = 0;
3249 rc = strlen(buf);
3250 } else
James Smart891478a2009-11-18 15:40:23 -05003251 rc = -EPERM;
3252 } else {
James Smart0d878412009-10-02 15:16:56 -04003253 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003254 rc = strlen(buf);
3255 }
James Smart0d878412009-10-02 15:16:56 -04003256 break;
3257 case 1:
3258 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3259 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3260 if (!rc) {
3261 spin_lock_irq(&phba->hbalock);
3262 phba->hba_flag |= HBA_AER_ENABLED;
3263 spin_unlock_irq(&phba->hbalock);
3264 phba->cfg_aer_support = 1;
3265 rc = strlen(buf);
3266 } else
James Smart891478a2009-11-18 15:40:23 -05003267 rc = -EPERM;
3268 } else {
James Smart0d878412009-10-02 15:16:56 -04003269 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003270 rc = strlen(buf);
3271 }
James Smart0d878412009-10-02 15:16:56 -04003272 break;
3273 default:
3274 rc = -EINVAL;
3275 break;
3276 }
3277 return rc;
3278}
3279
3280static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003281module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003282MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3283lpfc_param_show(aer_support)
3284
3285/**
3286 * lpfc_aer_support_init - Set the initial adapters aer support flag
3287 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003288 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003289 *
3290 * Description:
3291 * If val is in a valid range [0,1], then set the adapter's initial
3292 * cfg_aer_support field. It will be up to the driver's probe_one
3293 * routine to determine whether the device's AER support can be set
3294 * or not.
3295 *
3296 * Notes:
3297 * If the value is not in range log a kernel error message, and
3298 * choose the default value of setting AER support and return.
3299 *
3300 * Returns:
3301 * zero if val saved.
3302 * -EINVAL val out of range
3303 **/
3304static int
3305lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3306{
3307 if (val == 0 || val == 1) {
3308 phba->cfg_aer_support = val;
3309 return 0;
3310 }
3311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3312 "2712 lpfc_aer_support attribute value %d out "
3313 "of range, allowed values are 0|1, setting it "
3314 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003315 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003316 phba->cfg_aer_support = 1;
3317 return -EINVAL;
3318}
3319
3320static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3321 lpfc_aer_support_show, lpfc_aer_support_store);
3322
3323/**
3324 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3325 * @dev: class device that is converted into a Scsi_host.
3326 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003327 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003328 * @count: unused variable.
3329 *
3330 * Description:
3331 * If the @buf contains 1 and the device currently has the AER support
3332 * enabled, then invokes the kernel AER helper routine
3333 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3334 * error status register.
3335 *
3336 * Notes:
3337 *
3338 * Returns:
3339 * -EINVAL if the buf does not contain the 1 or the device is not currently
3340 * enabled with the AER support.
3341 **/
3342static ssize_t
3343lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3344 const char *buf, size_t count)
3345{
3346 struct Scsi_Host *shost = class_to_shost(dev);
3347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3348 struct lpfc_hba *phba = vport->phba;
3349 int val, rc = -1;
3350
3351 if (!isdigit(buf[0]))
3352 return -EINVAL;
3353 if (sscanf(buf, "%i", &val) != 1)
3354 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003355 if (val != 1)
3356 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003357
James Smart891478a2009-11-18 15:40:23 -05003358 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003359 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3360
3361 if (rc == 0)
3362 return strlen(buf);
3363 else
James Smart891478a2009-11-18 15:40:23 -05003364 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003365}
3366
3367static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3368 lpfc_aer_cleanup_state);
3369
James Smart912e3ac2011-05-24 11:42:11 -04003370/**
3371 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3372 *
3373 * @dev: class device that is converted into a Scsi_host.
3374 * @attr: device attribute, not used.
3375 * @buf: containing the string the number of vfs to be enabled.
3376 * @count: unused variable.
3377 *
3378 * Description:
3379 * When this api is called either through user sysfs, the driver shall
3380 * try to enable or disable SR-IOV virtual functions according to the
3381 * following:
3382 *
3383 * If zero virtual function has been enabled to the physical function,
3384 * the driver shall invoke the pci enable virtual function api trying
3385 * to enable the virtual functions. If the nr_vfn provided is greater
3386 * than the maximum supported, the maximum virtual function number will
3387 * be used for invoking the api; otherwise, the nr_vfn provided shall
3388 * be used for invoking the api. If the api call returned success, the
3389 * actual number of virtual functions enabled will be set to the driver
3390 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3391 * cfg_sriov_nr_virtfn remains zero.
3392 *
3393 * If none-zero virtual functions have already been enabled to the
3394 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3395 * -EINVAL will be returned and the driver does nothing;
3396 *
3397 * If the nr_vfn provided is zero and none-zero virtual functions have
3398 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3399 * disabling virtual function api shall be invoded to disable all the
3400 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3401 * zero. Otherwise, if zero virtual function has been enabled, do
3402 * nothing.
3403 *
3404 * Returns:
3405 * length of the buf on success if val is in range the intended mode
3406 * is supported.
3407 * -EINVAL if val out of range or intended mode is not supported.
3408 **/
3409static ssize_t
3410lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3411 const char *buf, size_t count)
3412{
3413 struct Scsi_Host *shost = class_to_shost(dev);
3414 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3415 struct lpfc_hba *phba = vport->phba;
3416 struct pci_dev *pdev = phba->pcidev;
3417 int val = 0, rc = -EINVAL;
3418
3419 /* Sanity check on user data */
3420 if (!isdigit(buf[0]))
3421 return -EINVAL;
3422 if (sscanf(buf, "%i", &val) != 1)
3423 return -EINVAL;
3424 if (val < 0)
3425 return -EINVAL;
3426
3427 /* Request disabling virtual functions */
3428 if (val == 0) {
3429 if (phba->cfg_sriov_nr_virtfn > 0) {
3430 pci_disable_sriov(pdev);
3431 phba->cfg_sriov_nr_virtfn = 0;
3432 }
3433 return strlen(buf);
3434 }
3435
3436 /* Request enabling virtual functions */
3437 if (phba->cfg_sriov_nr_virtfn > 0) {
3438 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3439 "3018 There are %d virtual functions "
3440 "enabled on physical function.\n",
3441 phba->cfg_sriov_nr_virtfn);
3442 return -EEXIST;
3443 }
3444
3445 if (val <= LPFC_MAX_VFN_PER_PFN)
3446 phba->cfg_sriov_nr_virtfn = val;
3447 else {
3448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3449 "3019 Enabling %d virtual functions is not "
3450 "allowed.\n", val);
3451 return -EINVAL;
3452 }
3453
3454 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3455 if (rc) {
3456 phba->cfg_sriov_nr_virtfn = 0;
3457 rc = -EPERM;
3458 } else
3459 rc = strlen(buf);
3460
3461 return rc;
3462}
3463
3464static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3465module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3466MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3467lpfc_param_show(sriov_nr_virtfn)
3468
3469/**
3470 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3471 * @phba: lpfc_hba pointer.
3472 * @val: link speed value.
3473 *
3474 * Description:
3475 * If val is in a valid range [0,255], then set the adapter's initial
3476 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3477 * number shall be used instead. It will be up to the driver's probe_one
3478 * routine to determine whether the device's SR-IOV is supported or not.
3479 *
3480 * Returns:
3481 * zero if val saved.
3482 * -EINVAL val out of range
3483 **/
3484static int
3485lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3486{
3487 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3488 phba->cfg_sriov_nr_virtfn = val;
3489 return 0;
3490 }
3491
3492 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3493 "3017 Enabling %d virtual functions is not "
3494 "allowed.\n", val);
3495 return -EINVAL;
3496}
3497static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3498 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3499
James Smart0d878412009-10-02 15:16:56 -04003500/*
dea31012005-04-17 16:05:31 -05003501# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3502# Value range is [2,3]. Default value is 3.
3503*/
James Smart3de2a652007-08-02 11:09:59 -04003504LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3505 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003506
3507/*
3508# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3509# is [0,1]. Default value is 0.
3510*/
James Smart3de2a652007-08-02 11:09:59 -04003511LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3512 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003513
3514/*
James Smart977b5a02008-09-07 11:52:04 -04003515# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3516# depth. Default value is 0. When the value of this parameter is zero the
3517# SCSI command completion time is not used for controlling I/O queue depth. When
3518# the parameter is set to a non-zero value, the I/O queue depth is controlled
3519# to limit the I/O completion time to the parameter value.
3520# The value is set in milliseconds.
3521*/
3522static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003523module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003524MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3525 "Use command completion time to control queue depth");
3526lpfc_vport_param_show(max_scsicmpl_time);
3527lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3528static int
3529lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3530{
3531 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3532 struct lpfc_nodelist *ndlp, *next_ndlp;
3533
3534 if (val == vport->cfg_max_scsicmpl_time)
3535 return 0;
3536 if ((val < 0) || (val > 60000))
3537 return -EINVAL;
3538 vport->cfg_max_scsicmpl_time = val;
3539
3540 spin_lock_irq(shost->host_lock);
3541 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3542 if (!NLP_CHK_NODE_ACT(ndlp))
3543 continue;
3544 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3545 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003546 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003547 }
3548 spin_unlock_irq(shost->host_lock);
3549 return 0;
3550}
3551lpfc_vport_param_store(max_scsicmpl_time);
3552static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3553 lpfc_max_scsicmpl_time_show,
3554 lpfc_max_scsicmpl_time_store);
3555
3556/*
dea31012005-04-17 16:05:31 -05003557# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3558# range is [0,1]. Default value is 0.
3559*/
3560LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3561
3562/*
3563# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3564# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003565# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003566# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3567# cr_delay is set to 0.
3568*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003569LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003570 "interrupt response is generated");
3571
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003572LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003573 "interrupt response is generated");
3574
3575/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003576# lpfc_multi_ring_support: Determines how many rings to spread available
3577# cmd/rsp IOCB entries across.
3578# Value range is [1,2]. Default value is 1.
3579*/
3580LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3581 "SLI rings to spread IOCB entries across");
3582
3583/*
James Smarta4bc3372006-12-02 13:34:16 -05003584# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3585# identifies what rctl value to configure the additional ring for.
3586# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3587*/
James Smart6a9c52c2009-10-02 15:16:51 -04003588LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003589 255, "Identifies RCTL for additional ring configuration");
3590
3591/*
3592# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3593# identifies what type value to configure the additional ring for.
3594# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3595*/
James Smart6a9c52c2009-10-02 15:16:51 -04003596LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003597 255, "Identifies TYPE for additional ring configuration");
3598
3599/*
dea31012005-04-17 16:05:31 -05003600# lpfc_fdmi_on: controls FDMI support.
3601# 0 = no FDMI support
3602# 1 = support FDMI without attribute of hostname
3603# 2 = support FDMI with attribute of hostname
3604# Value range [0,2]. Default value is 0.
3605*/
James Smart3de2a652007-08-02 11:09:59 -04003606LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003607
3608/*
3609# Specifies the maximum number of ELS cmds we can have outstanding (for
3610# discovery). Value range is [1,64]. Default value = 32.
3611*/
James Smart3de2a652007-08-02 11:09:59 -04003612LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003613 "during discovery");
3614
3615/*
James Smart65a29c12006-07-06 15:50:50 -04003616# lpfc_max_luns: maximum allowed LUN.
3617# Value range is [0,65535]. Default value is 255.
3618# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003619*/
James Smart3de2a652007-08-02 11:09:59 -04003620LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003621
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003622/*
3623# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3624# Value range is [1,255], default value is 10.
3625*/
3626LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3627 "Milliseconds driver will wait between polling FCP ring");
3628
James Smart4ff43242006-12-02 13:34:56 -05003629/*
3630# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3631# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003632# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003633# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003634# 2 = MSI-X enabled (default)
3635# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003636*/
George Kadianakis8605c462010-01-17 21:19:31 +02003637LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003638 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003639
James Smart13815c82008-01-11 01:52:48 -05003640/*
James Smartda0436e2009-05-22 14:51:39 -04003641# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3642#
3643# Value range is [636,651042]. Default value is 10000.
3644*/
3645LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3646 "Set the maximum number of fast-path FCP interrupts per second");
3647
3648/*
3649# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3650#
3651# Value range is [1,31]. Default value is 4.
3652*/
3653LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3654 "Set the number of fast-path FCP work queues, if possible");
3655
3656/*
3657# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3658#
3659# Value range is [1,7]. Default value is 1.
3660*/
3661LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3662 "Set the number of fast-path FCP event queues, if possible");
3663
3664/*
James Smart13815c82008-01-11 01:52:48 -05003665# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3666# 0 = HBA resets disabled
3667# 1 = HBA resets enabled (default)
3668# Value range is [0,1]. Default value is 1.
3669*/
3670LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003671
James Smart13815c82008-01-11 01:52:48 -05003672/*
James Smarteb7a3392010-11-20 23:12:02 -05003673# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003674# 0 = HBA Heartbeat disabled
3675# 1 = HBA Heartbeat enabled (default)
3676# Value range is [0,1]. Default value is 1.
3677*/
James Smarteb7a3392010-11-20 23:12:02 -05003678LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003679
James Smart83108bd2008-01-11 01:53:09 -05003680/*
James Smart81301a92008-12-04 22:39:46 -05003681# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3682# 0 = BlockGuard disabled (default)
3683# 1 = BlockGuard enabled
3684# Value range is [0,1]. Default value is 0.
3685*/
3686LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3687
James Smart6fb120a2009-05-22 14:52:59 -04003688/*
James Smart81301a92008-12-04 22:39:46 -05003689# lpfc_prot_mask: i
3690# - Bit mask of host protection capabilities used to register with the
3691# SCSI mid-layer
3692# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3693# - Allows you to ultimately specify which profiles to use
3694# - Default will result in registering capabilities for all profiles.
3695#
3696*/
James Smart7c56b9f2011-07-22 18:36:25 -04003697unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3698 SHOST_DIX_TYPE0_PROTECTION |
3699 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003700
James Smartab56dc22011-02-16 12:39:57 -05003701module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003702MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3703
3704/*
3705# lpfc_prot_guard: i
3706# - Bit mask of protection guard types to register with the SCSI mid-layer
3707# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3708# - Allows you to ultimately specify which profiles to use
3709# - Default will result in registering capabilities for all guard types
3710#
3711*/
3712unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003713module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003714MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3715
James Smart92494142011-02-16 12:39:44 -05003716/*
3717 * Delay initial NPort discovery when Clean Address bit is cleared in
3718 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3719 * This parameter can have value 0 or 1.
3720 * When this parameter is set to 0, no delay is added to the initial
3721 * discovery.
3722 * When this parameter is set to non-zero value, initial Nport discovery is
3723 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3724 * accept and FCID/Fabric name/Fabric portname is changed.
3725 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3726 * when Clean Address bit is cleared in FLOGI/FDISC
3727 * accept and FCID/Fabric name/Fabric portname is changed.
3728 * Default value is 0.
3729 */
3730int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003731module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003732MODULE_PARM_DESC(lpfc_delay_discovery,
3733 "Delay NPort discovery when Clean Address bit is cleared. "
3734 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003735
3736/*
James Smart3621a712009-04-06 18:47:14 -04003737 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003738 * This value can be set to values between 64 and 256. The default value is
3739 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3740 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3741 */
3742LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3743 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3744
James Smart81301a92008-12-04 22:39:46 -05003745LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3746 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3747 "Max Protection Scatter Gather Segment Count");
3748
Tony Jonesee959b02008-02-22 00:13:36 +01003749struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003750 &dev_attr_bg_info,
3751 &dev_attr_bg_guard_err,
3752 &dev_attr_bg_apptag_err,
3753 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003754 &dev_attr_info,
3755 &dev_attr_serialnum,
3756 &dev_attr_modeldesc,
3757 &dev_attr_modelname,
3758 &dev_attr_programtype,
3759 &dev_attr_portnum,
3760 &dev_attr_fwrev,
3761 &dev_attr_hdw,
3762 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003763 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003764 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003765 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003766 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003767 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003768 &dev_attr_lpfc_temp_sensor,
3769 &dev_attr_lpfc_log_verbose,
3770 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003771 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003772 &dev_attr_lpfc_hba_queue_depth,
3773 &dev_attr_lpfc_peer_port_login,
3774 &dev_attr_lpfc_nodev_tmo,
3775 &dev_attr_lpfc_devloss_tmo,
3776 &dev_attr_lpfc_fcp_class,
3777 &dev_attr_lpfc_use_adisc,
3778 &dev_attr_lpfc_ack0,
3779 &dev_attr_lpfc_topology,
3780 &dev_attr_lpfc_scan_down,
3781 &dev_attr_lpfc_link_speed,
3782 &dev_attr_lpfc_cr_delay,
3783 &dev_attr_lpfc_cr_count,
3784 &dev_attr_lpfc_multi_ring_support,
3785 &dev_attr_lpfc_multi_ring_rctl,
3786 &dev_attr_lpfc_multi_ring_type,
3787 &dev_attr_lpfc_fdmi_on,
3788 &dev_attr_lpfc_max_luns,
3789 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04003790 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05003791 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003792 &dev_attr_nport_evt_cnt,
3793 &dev_attr_board_mode,
3794 &dev_attr_max_vpi,
3795 &dev_attr_used_vpi,
3796 &dev_attr_max_rpi,
3797 &dev_attr_used_rpi,
3798 &dev_attr_max_xri,
3799 &dev_attr_used_xri,
3800 &dev_attr_npiv_info,
3801 &dev_attr_issue_reset,
3802 &dev_attr_lpfc_poll,
3803 &dev_attr_lpfc_poll_tmo,
3804 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003805 &dev_attr_lpfc_fcp_imax,
3806 &dev_attr_lpfc_fcp_wq_count,
3807 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003808 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003809 &dev_attr_lpfc_soft_wwnn,
3810 &dev_attr_lpfc_soft_wwpn,
3811 &dev_attr_lpfc_soft_wwn_enable,
3812 &dev_attr_lpfc_enable_hba_reset,
3813 &dev_attr_lpfc_enable_hba_heartbeat,
3814 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003815 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003816 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003817 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003818 &dev_attr_lpfc_aer_support,
3819 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04003820 &dev_attr_lpfc_sriov_nr_virtfn,
James Smart84d1b002010-02-12 14:42:33 -05003821 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003822 &dev_attr_lpfc_iocb_cnt,
3823 &dev_attr_iocb_hw,
3824 &dev_attr_txq_hw,
3825 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003826 &dev_attr_lpfc_fips_level,
3827 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003828 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04003829 &dev_attr_lpfc_sriov_hw_max_virtfn,
dea31012005-04-17 16:05:31 -05003830 NULL,
3831};
3832
Tony Jonesee959b02008-02-22 00:13:36 +01003833struct device_attribute *lpfc_vport_attrs[] = {
3834 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003835 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003836 &dev_attr_num_discovered_ports,
3837 &dev_attr_lpfc_drvr_version,
3838 &dev_attr_lpfc_log_verbose,
3839 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003840 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003841 &dev_attr_lpfc_nodev_tmo,
3842 &dev_attr_lpfc_devloss_tmo,
3843 &dev_attr_lpfc_hba_queue_depth,
3844 &dev_attr_lpfc_peer_port_login,
3845 &dev_attr_lpfc_restrict_login,
3846 &dev_attr_lpfc_fcp_class,
3847 &dev_attr_lpfc_use_adisc,
3848 &dev_attr_lpfc_fdmi_on,
3849 &dev_attr_lpfc_max_luns,
3850 &dev_attr_nport_evt_cnt,
3851 &dev_attr_npiv_info,
3852 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003853 &dev_attr_lpfc_max_scsicmpl_time,
3854 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003855 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003856 &dev_attr_lpfc_fips_level,
3857 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003858 NULL,
3859};
3860
James Smarte59058c2008-08-24 21:49:00 -04003861/**
James Smart3621a712009-04-06 18:47:14 -04003862 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003863 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003864 * @kobj: kernel kobject that contains the kernel class device.
3865 * @bin_attr: kernel attributes passed to us.
3866 * @buf: contains the data to be written to the adapter IOREG space.
3867 * @off: offset into buffer to beginning of data.
3868 * @count: bytes to transfer.
3869 *
3870 * Description:
3871 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3872 * Uses the adapter io control registers to send buf contents to the adapter.
3873 *
3874 * Returns:
3875 * -ERANGE off and count combo out of range
3876 * -EINVAL off, count or buff address invalid
3877 * -EPERM adapter is offline
3878 * value of count, buf contents written
3879 **/
dea31012005-04-17 16:05:31 -05003880static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003881sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3882 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003883 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003884{
3885 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003886 struct device *dev = container_of(kobj, struct device, kobj);
3887 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003888 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3889 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003890
James Smartf1126682009-06-10 17:22:44 -04003891 if (phba->sli_rev >= LPFC_SLI_REV4)
3892 return -EPERM;
3893
dea31012005-04-17 16:05:31 -05003894 if ((off + count) > FF_REG_AREA_SIZE)
3895 return -ERANGE;
3896
James Smartf7a919b2011-08-21 21:49:16 -04003897 if (count <= LPFC_REG_WRITE_KEY_SIZE)
3898 return 0;
dea31012005-04-17 16:05:31 -05003899
3900 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3901 return -EINVAL;
3902
James Smartf7a919b2011-08-21 21:49:16 -04003903 /* This is to protect HBA registers from accidental writes. */
3904 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3905 return -EINVAL;
3906
3907 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003908 return -EPERM;
dea31012005-04-17 16:05:31 -05003909
James Smart2e0fef82007-06-17 19:56:36 -05003910 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04003911 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
3912 buf_off += sizeof(uint32_t))
3913 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05003914 phba->ctrl_regs_memmap_p + off + buf_off);
3915
James Smart2e0fef82007-06-17 19:56:36 -05003916 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003917
3918 return count;
3919}
3920
James Smarte59058c2008-08-24 21:49:00 -04003921/**
James Smart3621a712009-04-06 18:47:14 -04003922 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003923 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003924 * @kobj: kernel kobject that contains the kernel class device.
3925 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003926 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003927 * @off: offset into buffer to beginning of data.
3928 * @count: bytes to transfer.
3929 *
3930 * Description:
3931 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3932 * Uses the adapter io control registers to read data into buf.
3933 *
3934 * Returns:
3935 * -ERANGE off and count combo out of range
3936 * -EINVAL off, count or buff address invalid
3937 * value of count, buf contents read
3938 **/
dea31012005-04-17 16:05:31 -05003939static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003940sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3941 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003942 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003943{
3944 size_t buf_off;
3945 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003946 struct device *dev = container_of(kobj, struct device, kobj);
3947 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003948 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3949 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003950
James Smartf1126682009-06-10 17:22:44 -04003951 if (phba->sli_rev >= LPFC_SLI_REV4)
3952 return -EPERM;
3953
dea31012005-04-17 16:05:31 -05003954 if (off > FF_REG_AREA_SIZE)
3955 return -ERANGE;
3956
3957 if ((off + count) > FF_REG_AREA_SIZE)
3958 count = FF_REG_AREA_SIZE - off;
3959
3960 if (count == 0) return 0;
3961
3962 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3963 return -EINVAL;
3964
James Smart2e0fef82007-06-17 19:56:36 -05003965 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003966
3967 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3968 tmp_ptr = (uint32_t *)(buf + buf_off);
3969 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3970 }
3971
James Smart2e0fef82007-06-17 19:56:36 -05003972 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003973
3974 return count;
3975}
3976
3977static struct bin_attribute sysfs_ctlreg_attr = {
3978 .attr = {
3979 .name = "ctlreg",
3980 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003981 },
3982 .size = 256,
3983 .read = sysfs_ctlreg_read,
3984 .write = sysfs_ctlreg_write,
3985};
3986
James Smarte59058c2008-08-24 21:49:00 -04003987/**
James Smart3621a712009-04-06 18:47:14 -04003988 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003989 * @phba: lpfc_hba pointer
3990 **/
dea31012005-04-17 16:05:31 -05003991static void
James Smart2e0fef82007-06-17 19:56:36 -05003992sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003993{
3994 phba->sysfs_mbox.state = SMBOX_IDLE;
3995 phba->sysfs_mbox.offset = 0;
3996
3997 if (phba->sysfs_mbox.mbox) {
3998 mempool_free(phba->sysfs_mbox.mbox,
3999 phba->mbox_mem_pool);
4000 phba->sysfs_mbox.mbox = NULL;
4001 }
4002}
4003
James Smarte59058c2008-08-24 21:49:00 -04004004/**
James Smart3621a712009-04-06 18:47:14 -04004005 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004006 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004007 * @kobj: kernel kobject that contains the kernel class device.
4008 * @bin_attr: kernel attributes passed to us.
4009 * @buf: contains the data to be written to sysfs mbox.
4010 * @off: offset into buffer to beginning of data.
4011 * @count: bytes to transfer.
4012 *
4013 * Description:
4014 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4015 * Uses the sysfs mbox to send buf contents to the adapter.
4016 *
4017 * Returns:
4018 * -ERANGE off and count combo out of range
4019 * -EINVAL off, count or buff address invalid
4020 * zero if count is zero
4021 * -EPERM adapter is offline
4022 * -ENOMEM failed to allocate memory for the mail box
4023 * -EAGAIN offset, state or mbox is NULL
4024 * count number of bytes transferred
4025 **/
dea31012005-04-17 16:05:31 -05004026static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004027sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4028 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004029 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004030{
Tony Jonesee959b02008-02-22 00:13:36 +01004031 struct device *dev = container_of(kobj, struct device, kobj);
4032 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4034 struct lpfc_hba *phba = vport->phba;
4035 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05004036
4037 if ((count + off) > MAILBOX_CMD_SIZE)
4038 return -ERANGE;
4039
4040 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4041 return -EINVAL;
4042
4043 if (count == 0)
4044 return 0;
4045
4046 if (off == 0) {
4047 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4048 if (!mbox)
4049 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05004050 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004051 }
4052
James Smart2e0fef82007-06-17 19:56:36 -05004053 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004054
4055 if (off == 0) {
4056 if (phba->sysfs_mbox.mbox)
4057 mempool_free(mbox, phba->mbox_mem_pool);
4058 else
4059 phba->sysfs_mbox.mbox = mbox;
4060 phba->sysfs_mbox.state = SMBOX_WRITING;
4061 } else {
4062 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4063 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05004064 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05004065 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004066 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004067 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004068 }
4069 }
4070
James Smart04c68492009-05-22 14:52:52 -04004071 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05004072 buf, count);
4073
4074 phba->sysfs_mbox.offset = off + count;
4075
James Smart2e0fef82007-06-17 19:56:36 -05004076 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004077
4078 return count;
4079}
4080
James Smarte59058c2008-08-24 21:49:00 -04004081/**
James Smart3621a712009-04-06 18:47:14 -04004082 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004083 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004084 * @kobj: kernel kobject that contains the kernel class device.
4085 * @bin_attr: kernel attributes passed to us.
4086 * @buf: contains the data to be read from sysfs mbox.
4087 * @off: offset into buffer to beginning of data.
4088 * @count: bytes to transfer.
4089 *
4090 * Description:
4091 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4092 * Uses the sysfs mbox to receive data from to the adapter.
4093 *
4094 * Returns:
4095 * -ERANGE off greater than mailbox command size
4096 * -EINVAL off, count or buff address invalid
4097 * zero if off and count are zero
4098 * -EACCES adapter over temp
4099 * -EPERM garbage can value to catch a multitude of errors
4100 * -EAGAIN management IO not permitted, state or off error
4101 * -ETIME mailbox timeout
4102 * -ENODEV mailbox error
4103 * count number of bytes transferred
4104 **/
dea31012005-04-17 16:05:31 -05004105static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004106sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4107 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004108 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004109{
Tony Jonesee959b02008-02-22 00:13:36 +01004110 struct device *dev = container_of(kobj, struct device, kobj);
4111 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004112 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4113 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004114 int rc;
James Smart04c68492009-05-22 14:52:52 -04004115 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05004116
James Smart1dcb58e2007-04-25 09:51:30 -04004117 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004118 return -ERANGE;
4119
James Smart1dcb58e2007-04-25 09:51:30 -04004120 if ((count + off) > MAILBOX_CMD_SIZE)
4121 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05004122
4123 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4124 return -EINVAL;
4125
4126 if (off && count == 0)
4127 return 0;
4128
James Smart2e0fef82007-06-17 19:56:36 -05004129 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004130
James Smart7af67052007-10-27 13:38:11 -04004131 if (phba->over_temp_state == HBA_OVER_TEMP) {
4132 sysfs_mbox_idle(phba);
4133 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05004134 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04004135 }
4136
dea31012005-04-17 16:05:31 -05004137 if (off == 0 &&
4138 phba->sysfs_mbox.state == SMBOX_WRITING &&
4139 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04004140 pmb = &phba->sysfs_mbox.mbox->u.mb;
4141 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05004142 /* Offline only */
dea31012005-04-17 16:05:31 -05004143 case MBX_INIT_LINK:
4144 case MBX_DOWN_LINK:
4145 case MBX_CONFIG_LINK:
4146 case MBX_CONFIG_RING:
4147 case MBX_RESET_RING:
4148 case MBX_UNREG_LOGIN:
4149 case MBX_CLEAR_LA:
4150 case MBX_DUMP_CONTEXT:
4151 case MBX_RUN_DIAGS:
4152 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05004153 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05004154 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05004155 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05004156 printk(KERN_WARNING "mbox_read:Command 0x%x "
4157 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04004158 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004159 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004160 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004161 return -EPERM;
4162 }
James Smarta8adb832007-10-27 13:37:53 -04004163 case MBX_WRITE_NV:
4164 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05004165 case MBX_LOAD_SM:
4166 case MBX_READ_NV:
4167 case MBX_READ_CONFIG:
4168 case MBX_READ_RCONFIG:
4169 case MBX_READ_STATUS:
4170 case MBX_READ_XRI:
4171 case MBX_READ_REV:
4172 case MBX_READ_LNK_STAT:
4173 case MBX_DUMP_MEMORY:
4174 case MBX_DOWN_LOAD:
4175 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004176 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05004177 case MBX_LOAD_AREA:
4178 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004179 case MBX_BEACON:
4180 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05004181 case MBX_SET_VARIABLE:
4182 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04004183 case MBX_PORT_CAPABILITIES:
4184 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05004185 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04004186 case MBX_SECURITY_MGMT:
4187 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04004188 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4189 printk(KERN_WARNING "mbox_read:Command 0x%x "
4190 "is not permitted\n", pmb->mbxCommand);
4191 sysfs_mbox_idle(phba);
4192 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04004193 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04004194 }
James Smartdcf2a4e2010-09-29 11:18:53 -04004195 break;
dea31012005-04-17 16:05:31 -05004196 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05004197 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05004198 case MBX_REG_LOGIN:
4199 case MBX_REG_LOGIN64:
4200 case MBX_CONFIG_PORT:
4201 case MBX_RUN_BIU_DIAG:
4202 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004203 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004204 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004205 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004206 return -EPERM;
4207 default:
4208 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004209 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004210 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004211 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004212 return -EPERM;
4213 }
4214
James Smart09372822008-01-11 01:52:54 -05004215 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05004216 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05004217 */
James Smartd7c255b2008-08-24 21:50:00 -04004218 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04004219 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4220 pmb->mbxCommand != MBX_RESTART &&
4221 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4222 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04004223 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4224 "1259 mbox: Issued mailbox cmd "
4225 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04004226 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05004227
James Smart92d7f7b2007-06-17 19:56:38 -05004228 phba->sysfs_mbox.mbox->vport = vport;
4229
James Smart58da1ff2008-04-07 10:15:56 -04004230 /* Don't allow mailbox commands to be sent when blocked
4231 * or when in the middle of discovery
4232 */
James Smart495a7142008-06-14 22:52:59 -04004233 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04004234 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004235 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04004236 return -EAGAIN;
4237 }
4238
James Smart2e0fef82007-06-17 19:56:36 -05004239 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004240 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05004241
James Smart2e0fef82007-06-17 19:56:36 -05004242 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004243 rc = lpfc_sli_issue_mbox (phba,
4244 phba->sysfs_mbox.mbox,
4245 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05004246 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004247
4248 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004249 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004250 rc = lpfc_sli_issue_mbox_wait (phba,
4251 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04004252 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05004253 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004254 }
4255
4256 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04004257 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04004258 phba->sysfs_mbox.mbox = NULL;
4259 }
dea31012005-04-17 16:05:31 -05004260 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004261 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004262 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05004263 }
4264 phba->sysfs_mbox.state = SMBOX_READING;
4265 }
4266 else if (phba->sysfs_mbox.offset != off ||
4267 phba->sysfs_mbox.state != SMBOX_READING) {
4268 printk(KERN_WARNING "mbox_read: Bad State\n");
4269 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004270 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004271 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004272 }
4273
James Smart04c68492009-05-22 14:52:52 -04004274 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05004275
4276 phba->sysfs_mbox.offset = off + count;
4277
James Smart1dcb58e2007-04-25 09:51:30 -04004278 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004279 sysfs_mbox_idle(phba);
4280
James Smart2e0fef82007-06-17 19:56:36 -05004281 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004282
4283 return count;
4284}
4285
4286static struct bin_attribute sysfs_mbox_attr = {
4287 .attr = {
4288 .name = "mbox",
4289 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004290 },
James Smartc0c11512011-05-24 11:41:34 -04004291 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004292 .read = sysfs_mbox_read,
4293 .write = sysfs_mbox_write,
4294};
4295
James Smarte59058c2008-08-24 21:49:00 -04004296/**
James Smart3621a712009-04-06 18:47:14 -04004297 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004298 * @vport: address of lpfc vport structure.
4299 *
4300 * Return codes:
4301 * zero on success
4302 * error return code from sysfs_create_bin_file()
4303 **/
dea31012005-04-17 16:05:31 -05004304int
James Smart2e0fef82007-06-17 19:56:36 -05004305lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004306{
James Smart2e0fef82007-06-17 19:56:36 -05004307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004308 int error;
4309
Tony Jonesee959b02008-02-22 00:13:36 +01004310 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004311 &sysfs_drvr_stat_data_attr);
4312
4313 /* Virtual ports do not need ctrl_reg and mbox */
4314 if (error || vport->port_type == LPFC_NPIV_PORT)
4315 goto out;
4316
4317 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004318 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004319 if (error)
James Smarteada2722008-12-04 22:39:13 -05004320 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004321
Tony Jonesee959b02008-02-22 00:13:36 +01004322 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004323 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004324 if (error)
4325 goto out_remove_ctlreg_attr;
4326
4327 return 0;
4328out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004329 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004330out_remove_stat_attr:
4331 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4332 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004333out:
4334 return error;
4335}
4336
James Smarte59058c2008-08-24 21:49:00 -04004337/**
James Smart3621a712009-04-06 18:47:14 -04004338 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004339 * @vport: address of lpfc vport structure.
4340 **/
dea31012005-04-17 16:05:31 -05004341void
James Smart2e0fef82007-06-17 19:56:36 -05004342lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004343{
James Smart2e0fef82007-06-17 19:56:36 -05004344 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004345 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4346 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004347 /* Virtual ports do not need ctrl_reg and mbox */
4348 if (vport->port_type == LPFC_NPIV_PORT)
4349 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004350 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4351 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004352}
4353
4354
4355/*
4356 * Dynamic FC Host Attributes Support
4357 */
4358
James Smarte59058c2008-08-24 21:49:00 -04004359/**
James Smart3621a712009-04-06 18:47:14 -04004360 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004361 * @shost: kernel scsi host pointer.
4362 **/
dea31012005-04-17 16:05:31 -05004363static void
4364lpfc_get_host_port_id(struct Scsi_Host *shost)
4365{
James Smart2e0fef82007-06-17 19:56:36 -05004366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4367
dea31012005-04-17 16:05:31 -05004368 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004369 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004370}
4371
James Smarte59058c2008-08-24 21:49:00 -04004372/**
James Smart3621a712009-04-06 18:47:14 -04004373 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004374 * @shost: kernel scsi host pointer.
4375 **/
dea31012005-04-17 16:05:31 -05004376static void
4377lpfc_get_host_port_type(struct Scsi_Host *shost)
4378{
James Smart2e0fef82007-06-17 19:56:36 -05004379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4380 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004381
4382 spin_lock_irq(shost->host_lock);
4383
James Smart92d7f7b2007-06-17 19:56:38 -05004384 if (vport->port_type == LPFC_NPIV_PORT) {
4385 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4386 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004387 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004388 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004389 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4390 else
4391 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4392 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004393 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004394 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4395 else
4396 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4397 }
4398 } else
4399 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4400
4401 spin_unlock_irq(shost->host_lock);
4402}
4403
James Smarte59058c2008-08-24 21:49:00 -04004404/**
James Smart3621a712009-04-06 18:47:14 -04004405 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004406 * @shost: kernel scsi host pointer.
4407 **/
dea31012005-04-17 16:05:31 -05004408static void
4409lpfc_get_host_port_state(struct Scsi_Host *shost)
4410{
James Smart2e0fef82007-06-17 19:56:36 -05004411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4412 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004413
4414 spin_lock_irq(shost->host_lock);
4415
James Smart2e0fef82007-06-17 19:56:36 -05004416 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004417 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4418 else {
James Smart2e0fef82007-06-17 19:56:36 -05004419 switch (phba->link_state) {
4420 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004421 case LPFC_LINK_DOWN:
4422 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4423 break;
4424 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004425 case LPFC_CLEAR_LA:
4426 case LPFC_HBA_READY:
4427 /* Links up, beyond this port_type reports state */
4428 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4429 break;
4430 case LPFC_HBA_ERROR:
4431 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4432 break;
4433 default:
4434 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4435 break;
4436 }
4437 }
4438
4439 spin_unlock_irq(shost->host_lock);
4440}
4441
James Smarte59058c2008-08-24 21:49:00 -04004442/**
James Smart3621a712009-04-06 18:47:14 -04004443 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004444 * @shost: kernel scsi host pointer.
4445 **/
dea31012005-04-17 16:05:31 -05004446static void
4447lpfc_get_host_speed(struct Scsi_Host *shost)
4448{
James Smart2e0fef82007-06-17 19:56:36 -05004449 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4450 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004451
4452 spin_lock_irq(shost->host_lock);
4453
James Smart2e0fef82007-06-17 19:56:36 -05004454 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004455 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004456 case LPFC_LINK_SPEED_1GHZ:
4457 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004458 break;
James Smart76a95d72010-11-20 23:11:48 -05004459 case LPFC_LINK_SPEED_2GHZ:
4460 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004461 break;
James Smart76a95d72010-11-20 23:11:48 -05004462 case LPFC_LINK_SPEED_4GHZ:
4463 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004464 break;
James Smart76a95d72010-11-20 23:11:48 -05004465 case LPFC_LINK_SPEED_8GHZ:
4466 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004467 break;
James Smart76a95d72010-11-20 23:11:48 -05004468 case LPFC_LINK_SPEED_10GHZ:
4469 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004470 break;
James Smart76a95d72010-11-20 23:11:48 -05004471 case LPFC_LINK_SPEED_16GHZ:
4472 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4473 break;
4474 default:
4475 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004476 break;
4477 }
James Smart09372822008-01-11 01:52:54 -05004478 } else
4479 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004480
4481 spin_unlock_irq(shost->host_lock);
4482}
4483
James Smarte59058c2008-08-24 21:49:00 -04004484/**
James Smart3621a712009-04-06 18:47:14 -04004485 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004486 * @shost: kernel scsi host pointer.
4487 **/
dea31012005-04-17 16:05:31 -05004488static void
4489lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4490{
James Smart2e0fef82007-06-17 19:56:36 -05004491 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4492 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004493 u64 node_name;
dea31012005-04-17 16:05:31 -05004494
4495 spin_lock_irq(shost->host_lock);
4496
James Smart2e0fef82007-06-17 19:56:36 -05004497 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004498 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004499 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004500 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004501 else
4502 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004503 node_name = 0;
dea31012005-04-17 16:05:31 -05004504
4505 spin_unlock_irq(shost->host_lock);
4506
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004507 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004508}
4509
James Smarte59058c2008-08-24 21:49:00 -04004510/**
James Smart3621a712009-04-06 18:47:14 -04004511 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004512 * @shost: kernel scsi host pointer.
4513 *
4514 * Notes:
4515 * NULL on error for link down, no mbox pool, sli2 active,
4516 * management not allowed, memory allocation error, or mbox error.
4517 *
4518 * Returns:
4519 * NULL for error
4520 * address of the adapter host statistics
4521 **/
dea31012005-04-17 16:05:31 -05004522static struct fc_host_statistics *
4523lpfc_get_stats(struct Scsi_Host *shost)
4524{
James Smart2e0fef82007-06-17 19:56:36 -05004525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4526 struct lpfc_hba *phba = vport->phba;
4527 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004528 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004529 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004530 LPFC_MBOXQ_t *pmboxq;
4531 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004532 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004533 int rc = 0;
dea31012005-04-17 16:05:31 -05004534
James Smart92d7f7b2007-06-17 19:56:38 -05004535 /*
4536 * prevent udev from issuing mailbox commands until the port is
4537 * configured.
4538 */
James Smart2e0fef82007-06-17 19:56:36 -05004539 if (phba->link_state < LPFC_LINK_DOWN ||
4540 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004541 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004542 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004543
4544 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004545 return NULL;
4546
dea31012005-04-17 16:05:31 -05004547 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4548 if (!pmboxq)
4549 return NULL;
4550 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4551
James Smart04c68492009-05-22 14:52:52 -04004552 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004553 pmb->mbxCommand = MBX_READ_STATUS;
4554 pmb->mbxOwner = OWN_HOST;
4555 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004556 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004557
James Smart75baf692010-06-08 18:31:21 -04004558 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004559 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004560 else
dea31012005-04-17 16:05:31 -05004561 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4562
4563 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004564 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004565 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004566 return NULL;
4567 }
4568
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004569 memset(hs, 0, sizeof (struct fc_host_statistics));
4570
dea31012005-04-17 16:05:31 -05004571 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4572 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4573 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4574 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4575
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004576 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004577 pmb->mbxCommand = MBX_READ_LNK_STAT;
4578 pmb->mbxOwner = OWN_HOST;
4579 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004580 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004581
James Smart75baf692010-06-08 18:31:21 -04004582 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004583 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004584 else
dea31012005-04-17 16:05:31 -05004585 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4586
4587 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004588 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004589 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004590 return NULL;
4591 }
4592
4593 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4594 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4595 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4596 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4597 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4598 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4599 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4600
James Smart64ba8812006-08-02 15:24:34 -04004601 hs->link_failure_count -= lso->link_failure_count;
4602 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4603 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4604 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4605 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4606 hs->invalid_crc_count -= lso->invalid_crc_count;
4607 hs->error_frames -= lso->error_frames;
4608
James Smart76a95d72010-11-20 23:11:48 -05004609 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004610 hs->lip_count = -1;
4611 hs->nos_count = (phba->link_events >> 1);
4612 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004613 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004614 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004615 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004616 hs->nos_count = -1;
4617 } else {
4618 hs->lip_count = -1;
4619 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004620 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004621 }
4622
4623 hs->dumped_frames = -1;
4624
James Smart64ba8812006-08-02 15:24:34 -04004625 seconds = get_seconds();
4626 if (seconds < psli->stats_start)
4627 hs->seconds_since_last_reset = seconds +
4628 ((unsigned long)-1 - psli->stats_start);
4629 else
4630 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004631
James Smart1dcb58e2007-04-25 09:51:30 -04004632 mempool_free(pmboxq, phba->mbox_mem_pool);
4633
dea31012005-04-17 16:05:31 -05004634 return hs;
4635}
4636
James Smarte59058c2008-08-24 21:49:00 -04004637/**
James Smart3621a712009-04-06 18:47:14 -04004638 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004639 * @shost: kernel scsi host pointer.
4640 **/
James Smart64ba8812006-08-02 15:24:34 -04004641static void
4642lpfc_reset_stats(struct Scsi_Host *shost)
4643{
James Smart2e0fef82007-06-17 19:56:36 -05004644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4645 struct lpfc_hba *phba = vport->phba;
4646 struct lpfc_sli *psli = &phba->sli;
4647 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004648 LPFC_MBOXQ_t *pmboxq;
4649 MAILBOX_t *pmb;
4650 int rc = 0;
4651
James Smart2e0fef82007-06-17 19:56:36 -05004652 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004653 return;
4654
James Smart64ba8812006-08-02 15:24:34 -04004655 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4656 if (!pmboxq)
4657 return;
4658 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4659
James Smart04c68492009-05-22 14:52:52 -04004660 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004661 pmb->mbxCommand = MBX_READ_STATUS;
4662 pmb->mbxOwner = OWN_HOST;
4663 pmb->un.varWords[0] = 0x1; /* reset request */
4664 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004665 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004666
James Smart2e0fef82007-06-17 19:56:36 -05004667 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004668 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004669 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4670 else
4671 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4672
4673 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004674 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004675 mempool_free(pmboxq, phba->mbox_mem_pool);
4676 return;
4677 }
4678
4679 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4680 pmb->mbxCommand = MBX_READ_LNK_STAT;
4681 pmb->mbxOwner = OWN_HOST;
4682 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004683 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004684
James Smart2e0fef82007-06-17 19:56:36 -05004685 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004686 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004687 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4688 else
4689 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4690
4691 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004692 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004693 mempool_free( pmboxq, phba->mbox_mem_pool);
4694 return;
4695 }
4696
4697 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4698 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4699 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4700 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4701 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4702 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4703 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004704 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004705 lso->link_events = (phba->link_events >> 1);
4706 else
4707 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004708
4709 psli->stats_start = get_seconds();
4710
James Smart1dcb58e2007-04-25 09:51:30 -04004711 mempool_free(pmboxq, phba->mbox_mem_pool);
4712
James Smart64ba8812006-08-02 15:24:34 -04004713 return;
4714}
dea31012005-04-17 16:05:31 -05004715
4716/*
4717 * The LPFC driver treats linkdown handling as target loss events so there
4718 * are no sysfs handlers for link_down_tmo.
4719 */
James Smart685f0bf2007-04-25 09:53:08 -04004720
James Smarte59058c2008-08-24 21:49:00 -04004721/**
James Smart3621a712009-04-06 18:47:14 -04004722 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004723 * @starget: kernel scsi target pointer.
4724 *
4725 * Returns:
4726 * address of the node list if found
4727 * NULL target not found
4728 **/
James Smart685f0bf2007-04-25 09:53:08 -04004729static struct lpfc_nodelist *
4730lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004731{
James Smart2e0fef82007-06-17 19:56:36 -05004732 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4733 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004734 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004735
4736 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004737 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004738 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004739 if (NLP_CHK_NODE_ACT(ndlp) &&
4740 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004741 starget->id == ndlp->nlp_sid) {
4742 spin_unlock_irq(shost->host_lock);
4743 return ndlp;
dea31012005-04-17 16:05:31 -05004744 }
4745 }
4746 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004747 return NULL;
4748}
dea31012005-04-17 16:05:31 -05004749
James Smarte59058c2008-08-24 21:49:00 -04004750/**
James Smart3621a712009-04-06 18:47:14 -04004751 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004752 * @starget: kernel scsi target pointer.
4753 **/
James Smart685f0bf2007-04-25 09:53:08 -04004754static void
4755lpfc_get_starget_port_id(struct scsi_target *starget)
4756{
4757 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4758
4759 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004760}
4761
James Smarte59058c2008-08-24 21:49:00 -04004762/**
James Smart3621a712009-04-06 18:47:14 -04004763 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004764 * @starget: kernel scsi target pointer.
4765 *
4766 * Description: Set the target node name to the ndlp node name wwn or zero.
4767 **/
dea31012005-04-17 16:05:31 -05004768static void
4769lpfc_get_starget_node_name(struct scsi_target *starget)
4770{
James Smart685f0bf2007-04-25 09:53:08 -04004771 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004772
James Smart685f0bf2007-04-25 09:53:08 -04004773 fc_starget_node_name(starget) =
4774 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004775}
4776
James Smarte59058c2008-08-24 21:49:00 -04004777/**
James Smart3621a712009-04-06 18:47:14 -04004778 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004779 * @starget: kernel scsi target pointer.
4780 *
4781 * Description: set the target port name to the ndlp port name wwn or zero.
4782 **/
dea31012005-04-17 16:05:31 -05004783static void
4784lpfc_get_starget_port_name(struct scsi_target *starget)
4785{
James Smart685f0bf2007-04-25 09:53:08 -04004786 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004787
James Smart685f0bf2007-04-25 09:53:08 -04004788 fc_starget_port_name(starget) =
4789 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004790}
4791
James Smarte59058c2008-08-24 21:49:00 -04004792/**
James Smart3621a712009-04-06 18:47:14 -04004793 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004794 * @rport: fc rport address.
4795 * @timeout: new value for dev loss tmo.
4796 *
4797 * Description:
4798 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4799 * dev_loss_tmo to one.
4800 **/
dea31012005-04-17 16:05:31 -05004801static void
dea31012005-04-17 16:05:31 -05004802lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4803{
dea31012005-04-17 16:05:31 -05004804 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004805 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004806 else
James Smartc01f3202006-08-18 17:47:08 -04004807 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004808}
4809
James Smarte59058c2008-08-24 21:49:00 -04004810/**
James Smart3621a712009-04-06 18:47:14 -04004811 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004812 *
4813 * Description:
4814 * Macro that uses field to generate a function with the name lpfc_show_rport_
4815 *
4816 * lpfc_show_rport_##field: returns the bytes formatted in buf
4817 * @cdev: class converted to an fc_rport.
4818 * @buf: on return contains the target_field or zero.
4819 *
4820 * Returns: size of formatted string.
4821 **/
dea31012005-04-17 16:05:31 -05004822#define lpfc_rport_show_function(field, format_string, sz, cast) \
4823static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004824lpfc_show_rport_##field (struct device *dev, \
4825 struct device_attribute *attr, \
4826 char *buf) \
dea31012005-04-17 16:05:31 -05004827{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004828 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004829 struct lpfc_rport_data *rdata = rport->hostdata; \
4830 return snprintf(buf, sz, format_string, \
4831 (rdata->target) ? cast rdata->target->field : 0); \
4832}
4833
4834#define lpfc_rport_rd_attr(field, format_string, sz) \
4835 lpfc_rport_show_function(field, format_string, sz, ) \
4836static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4837
James Smarteada2722008-12-04 22:39:13 -05004838/**
James Smart3621a712009-04-06 18:47:14 -04004839 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004840 * @fc_vport: The fc_vport who's symbolic name has been changed.
4841 *
4842 * Description:
4843 * This function is called by the transport after the @fc_vport's symbolic name
4844 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004845 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004846 **/
4847static void
4848lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4849{
4850 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4851
4852 if (vport->port_state == LPFC_VPORT_READY)
4853 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4854}
dea31012005-04-17 16:05:31 -05004855
James Smartf4b4c682009-05-22 14:53:12 -04004856/**
4857 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4858 * @phba: Pointer to lpfc_hba struct.
4859 *
4860 * This function is called by the lpfc_get_cfgparam() routine to set the
4861 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004862 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004863 * before hba port or vport created.
4864 **/
4865static void
4866lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4867{
4868 phba->cfg_log_verbose = verbose;
4869}
4870
dea31012005-04-17 16:05:31 -05004871struct fc_function_template lpfc_transport_functions = {
4872 /* fixed attributes the driver supports */
4873 .show_host_node_name = 1,
4874 .show_host_port_name = 1,
4875 .show_host_supported_classes = 1,
4876 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004877 .show_host_supported_speeds = 1,
4878 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004879 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004880
4881 /* dynamic attributes the driver supports */
4882 .get_host_port_id = lpfc_get_host_port_id,
4883 .show_host_port_id = 1,
4884
4885 .get_host_port_type = lpfc_get_host_port_type,
4886 .show_host_port_type = 1,
4887
4888 .get_host_port_state = lpfc_get_host_port_state,
4889 .show_host_port_state = 1,
4890
4891 /* active_fc4s is shown but doesn't change (thus no get function) */
4892 .show_host_active_fc4s = 1,
4893
4894 .get_host_speed = lpfc_get_host_speed,
4895 .show_host_speed = 1,
4896
4897 .get_host_fabric_name = lpfc_get_host_fabric_name,
4898 .show_host_fabric_name = 1,
4899
4900 /*
4901 * The LPFC driver treats linkdown handling as target loss events
4902 * so there are no sysfs handlers for link_down_tmo.
4903 */
4904
4905 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004906 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004907
4908 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4909 .show_rport_maxframe_size = 1,
4910 .show_rport_supported_classes = 1,
4911
dea31012005-04-17 16:05:31 -05004912 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4913 .show_rport_dev_loss_tmo = 1,
4914
4915 .get_starget_port_id = lpfc_get_starget_port_id,
4916 .show_starget_port_id = 1,
4917
4918 .get_starget_node_name = lpfc_get_starget_node_name,
4919 .show_starget_node_name = 1,
4920
4921 .get_starget_port_name = lpfc_get_starget_port_name,
4922 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004923
4924 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004925 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4926 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004927
James Smart92d7f7b2007-06-17 19:56:38 -05004928 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004929
4930 .vport_disable = lpfc_vport_disable,
4931
4932 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004933
4934 .bsg_request = lpfc_bsg_request,
4935 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004936};
4937
James Smart98c9ea52007-10-27 13:37:33 -04004938struct fc_function_template lpfc_vport_transport_functions = {
4939 /* fixed attributes the driver supports */
4940 .show_host_node_name = 1,
4941 .show_host_port_name = 1,
4942 .show_host_supported_classes = 1,
4943 .show_host_supported_fc4s = 1,
4944 .show_host_supported_speeds = 1,
4945 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004946 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004947
4948 /* dynamic attributes the driver supports */
4949 .get_host_port_id = lpfc_get_host_port_id,
4950 .show_host_port_id = 1,
4951
4952 .get_host_port_type = lpfc_get_host_port_type,
4953 .show_host_port_type = 1,
4954
4955 .get_host_port_state = lpfc_get_host_port_state,
4956 .show_host_port_state = 1,
4957
4958 /* active_fc4s is shown but doesn't change (thus no get function) */
4959 .show_host_active_fc4s = 1,
4960
4961 .get_host_speed = lpfc_get_host_speed,
4962 .show_host_speed = 1,
4963
4964 .get_host_fabric_name = lpfc_get_host_fabric_name,
4965 .show_host_fabric_name = 1,
4966
4967 /*
4968 * The LPFC driver treats linkdown handling as target loss events
4969 * so there are no sysfs handlers for link_down_tmo.
4970 */
4971
4972 .get_fc_host_stats = lpfc_get_stats,
4973 .reset_fc_host_stats = lpfc_reset_stats,
4974
4975 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4976 .show_rport_maxframe_size = 1,
4977 .show_rport_supported_classes = 1,
4978
4979 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4980 .show_rport_dev_loss_tmo = 1,
4981
4982 .get_starget_port_id = lpfc_get_starget_port_id,
4983 .show_starget_port_id = 1,
4984
4985 .get_starget_node_name = lpfc_get_starget_node_name,
4986 .show_starget_node_name = 1,
4987
4988 .get_starget_port_name = lpfc_get_starget_port_name,
4989 .show_starget_port_name = 1,
4990
4991 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4992 .terminate_rport_io = lpfc_terminate_rport_io,
4993
4994 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004995
4996 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004997};
4998
James Smarte59058c2008-08-24 21:49:00 -04004999/**
James Smart3621a712009-04-06 18:47:14 -04005000 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005001 * @phba: lpfc_hba pointer.
5002 **/
dea31012005-04-17 16:05:31 -05005003void
5004lpfc_get_cfgparam(struct lpfc_hba *phba)
5005{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005006 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5007 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005008 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005009 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5010 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005011 lpfc_ack0_init(phba, lpfc_ack0);
5012 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005013 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005014 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005015 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005016 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005017 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005018 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005019 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5020 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5021 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05005022 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5023 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005024 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005025 if (phba->sli_rev == LPFC_SLI_REV4)
5026 phba->cfg_poll = 0;
5027 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005028 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005029 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005030 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005031 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005032 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005033 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005034 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005035 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005036 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smart84d1b002010-02-12 14:42:33 -05005037 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005038 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005039 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005040 return;
5041}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005042
James Smarte59058c2008-08-24 21:49:00 -04005043/**
James Smart3621a712009-04-06 18:47:14 -04005044 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005045 * @vport: lpfc_vport pointer.
5046 **/
James Smart3de2a652007-08-02 11:09:59 -04005047void
5048lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5049{
James Smarte8b62012007-08-02 11:10:09 -04005050 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005051 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005052 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005053 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5054 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5055 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5056 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5057 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5058 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005059 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005060 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5061 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5062 lpfc_max_luns_init(vport, lpfc_max_luns);
5063 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005064 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005065 return;
5066}