blob: c992e8328f9e4a5fe6bd6bc428c89a819034e7c0 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
James Smart0d878412009-10-02 15:16:56 -040026#include <linux/aer.h>
dea31012005-04-17 16:05:31 -050027
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040028#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050029#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h>
31#include <scsi/scsi_tcq.h>
32#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040033#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050034
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_hw.h"
37#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040039#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_disc.h"
41#include "lpfc_scsi.h"
42#include "lpfc.h"
43#include "lpfc_logmsg.h"
44#include "lpfc_version.h"
45#include "lpfc_compat.h"
46#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050047#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050048
James Smartc01f3202006-08-18 17:47:08 -040049#define LPFC_DEF_DEVLOSS_TMO 30
50#define LPFC_MIN_DEVLOSS_TMO 1
51#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050052
James Smart83108bd2008-01-11 01:53:09 -050053#define LPFC_MAX_LINK_SPEED 8
54#define LPFC_LINK_SPEED_BITMAP 0x00000117
55#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040059 * @incr: integer to convert.
60 * @hdw: ascii string holding converted integer plus a string terminator.
61 *
62 * Description:
63 * JEDEC Joint Electron Device Engineering Council.
64 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
65 * character string. The string is then terminated with a NULL in byte 9.
66 * Hex 0-9 becomes ascii '0' to '9'.
67 * Hex a-f becomes ascii '=' to 'B' capital B.
68 *
69 * Notes:
70 * Coded for 32 bit integers only.
71 **/
dea31012005-04-17 16:05:31 -050072static void
73lpfc_jedec_to_ascii(int incr, char hdw[])
74{
75 int i, j;
76 for (i = 0; i < 8; i++) {
77 j = (incr & 0xf);
78 if (j <= 9)
79 hdw[7 - i] = 0x30 + j;
80 else
81 hdw[7 - i] = 0x61 + j - 10;
82 incr = (incr >> 4);
83 }
84 hdw[8] = 0;
85 return;
86}
87
James Smarte59058c2008-08-24 21:49:00 -040088/**
James Smart3621a712009-04-06 18:47:14 -040089 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040090 * @dev: class unused variable.
91 * @attr: device attribute, not used.
92 * @buf: on return contains the module description text.
93 *
94 * Returns: size of formatted string.
95 **/
dea31012005-04-17 16:05:31 -050096static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010097lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
98 char *buf)
dea31012005-04-17 16:05:31 -050099{
100 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
101}
102
James Smart45ed1192009-10-02 15:17:02 -0400103/**
104 * lpfc_enable_fip_show - Return the fip mode of the HBA
105 * @dev: class unused variable.
106 * @attr: device attribute, not used.
107 * @buf: on return contains the module description text.
108 *
109 * Returns: size of formatted string.
110 **/
111static ssize_t
112lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
113 char *buf)
114{
115 struct Scsi_Host *shost = class_to_shost(dev);
116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
117 struct lpfc_hba *phba = vport->phba;
118
119 if (phba->hba_flag & HBA_FIP_SUPPORT)
120 return snprintf(buf, PAGE_SIZE, "1\n");
121 else
122 return snprintf(buf, PAGE_SIZE, "0\n");
123}
124
James Smart81301a92008-12-04 22:39:46 -0500125static ssize_t
126lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
127 char *buf)
128{
129 struct Scsi_Host *shost = class_to_shost(dev);
130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
131 struct lpfc_hba *phba = vport->phba;
132
133 if (phba->cfg_enable_bg)
134 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
135 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
136 else
137 return snprintf(buf, PAGE_SIZE,
138 "BlockGuard Not Supported\n");
139 else
140 return snprintf(buf, PAGE_SIZE,
141 "BlockGuard Disabled\n");
142}
143
144static ssize_t
145lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
146 char *buf)
147{
148 struct Scsi_Host *shost = class_to_shost(dev);
149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
150 struct lpfc_hba *phba = vport->phba;
151
James Smart87b5c322008-12-16 10:34:09 -0500152 return snprintf(buf, PAGE_SIZE, "%llu\n",
153 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500154}
155
156static ssize_t
157lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
158 char *buf)
159{
160 struct Scsi_Host *shost = class_to_shost(dev);
161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
162 struct lpfc_hba *phba = vport->phba;
163
James Smart87b5c322008-12-16 10:34:09 -0500164 return snprintf(buf, PAGE_SIZE, "%llu\n",
165 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500166}
167
168static ssize_t
169lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
170 char *buf)
171{
172 struct Scsi_Host *shost = class_to_shost(dev);
173 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
174 struct lpfc_hba *phba = vport->phba;
175
James Smart87b5c322008-12-16 10:34:09 -0500176 return snprintf(buf, PAGE_SIZE, "%llu\n",
177 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500178}
179
James Smarte59058c2008-08-24 21:49:00 -0400180/**
James Smart3621a712009-04-06 18:47:14 -0400181 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400182 * @dev: class converted to a Scsi_host structure.
183 * @attr: device attribute, not used.
184 * @buf: on return contains the formatted text from lpfc_info().
185 *
186 * Returns: size of formatted string.
187 **/
dea31012005-04-17 16:05:31 -0500188static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100189lpfc_info_show(struct device *dev, struct device_attribute *attr,
190 char *buf)
dea31012005-04-17 16:05:31 -0500191{
Tony Jonesee959b02008-02-22 00:13:36 +0100192 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500193
dea31012005-04-17 16:05:31 -0500194 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
195}
196
James Smarte59058c2008-08-24 21:49:00 -0400197/**
James Smart3621a712009-04-06 18:47:14 -0400198 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400199 * @dev: class converted to a Scsi_host structure.
200 * @attr: device attribute, not used.
201 * @buf: on return contains the formatted text serial number.
202 *
203 * Returns: size of formatted string.
204 **/
dea31012005-04-17 16:05:31 -0500205static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100206lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
207 char *buf)
dea31012005-04-17 16:05:31 -0500208{
Tony Jonesee959b02008-02-22 00:13:36 +0100209 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
211 struct lpfc_hba *phba = vport->phba;
212
dea31012005-04-17 16:05:31 -0500213 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
214}
215
James Smarte59058c2008-08-24 21:49:00 -0400216/**
James Smart3621a712009-04-06 18:47:14 -0400217 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400218 * @dev: class converted to a Scsi_host structure.
219 * @attr: device attribute, not used.
220 * @buf: on return contains the formatted support level.
221 *
222 * Description:
223 * Returns a number indicating the temperature sensor level currently
224 * supported, zero or one in ascii.
225 *
226 * Returns: size of formatted string.
227 **/
dea31012005-04-17 16:05:31 -0500228static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100229lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
230 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400231{
Tony Jonesee959b02008-02-22 00:13:36 +0100232 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400233 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
234 struct lpfc_hba *phba = vport->phba;
235 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
236}
237
James Smarte59058c2008-08-24 21:49:00 -0400238/**
James Smart3621a712009-04-06 18:47:14 -0400239 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400240 * @dev: class converted to a Scsi_host structure.
241 * @attr: device attribute, not used.
242 * @buf: on return contains the scsi vpd model description.
243 *
244 * Returns: size of formatted string.
245 **/
James Smart57127f12007-10-27 13:37:05 -0400246static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100247lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
248 char *buf)
dea31012005-04-17 16:05:31 -0500249{
Tony Jonesee959b02008-02-22 00:13:36 +0100250 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
252 struct lpfc_hba *phba = vport->phba;
253
dea31012005-04-17 16:05:31 -0500254 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
255}
256
James Smarte59058c2008-08-24 21:49:00 -0400257/**
James Smart3621a712009-04-06 18:47:14 -0400258 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400259 * @dev: class converted to a Scsi_host structure.
260 * @attr: device attribute, not used.
261 * @buf: on return contains the scsi vpd model name.
262 *
263 * Returns: size of formatted string.
264 **/
dea31012005-04-17 16:05:31 -0500265static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100266lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
267 char *buf)
dea31012005-04-17 16:05:31 -0500268{
Tony Jonesee959b02008-02-22 00:13:36 +0100269 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500270 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
271 struct lpfc_hba *phba = vport->phba;
272
dea31012005-04-17 16:05:31 -0500273 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
274}
275
James Smarte59058c2008-08-24 21:49:00 -0400276/**
James Smart3621a712009-04-06 18:47:14 -0400277 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400278 * @dev: class converted to a Scsi_host structure.
279 * @attr: device attribute, not used.
280 * @buf: on return contains the scsi vpd program type.
281 *
282 * Returns: size of formatted string.
283 **/
dea31012005-04-17 16:05:31 -0500284static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100285lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
286 char *buf)
dea31012005-04-17 16:05:31 -0500287{
Tony Jonesee959b02008-02-22 00:13:36 +0100288 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
290 struct lpfc_hba *phba = vport->phba;
291
dea31012005-04-17 16:05:31 -0500292 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
293}
294
James Smarte59058c2008-08-24 21:49:00 -0400295/**
James Smart3621a712009-04-06 18:47:14 -0400296 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400297 * @dev: class converted to a Scsi_host structure.
298 * @attr: device attribute, not used.
299 * @buf: on return contains the Menlo Maintenance sli flag.
300 *
301 * Returns: size of formatted string.
302 **/
303static ssize_t
304lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
305{
306 struct Scsi_Host *shost = class_to_shost(dev);
307 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
308 struct lpfc_hba *phba = vport->phba;
309
310 return snprintf(buf, PAGE_SIZE, "%d\n",
311 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
312}
313
314/**
James Smart3621a712009-04-06 18:47:14 -0400315 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400316 * @dev: class converted to a Scsi_host structure.
317 * @attr: device attribute, not used.
318 * @buf: on return contains scsi vpd program type.
319 *
320 * Returns: size of formatted string.
321 **/
dea31012005-04-17 16:05:31 -0500322static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100323lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
324 char *buf)
dea31012005-04-17 16:05:31 -0500325{
Tony Jonesee959b02008-02-22 00:13:36 +0100326 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500327 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
328 struct lpfc_hba *phba = vport->phba;
329
dea31012005-04-17 16:05:31 -0500330 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
331}
332
James Smarte59058c2008-08-24 21:49:00 -0400333/**
James Smart3621a712009-04-06 18:47:14 -0400334 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400335 * @dev: class converted to a Scsi_host structure.
336 * @attr: device attribute, not used.
337 * @buf: on return contains the scsi vpd program type.
338 *
339 * Returns: size of formatted string.
340 **/
dea31012005-04-17 16:05:31 -0500341static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100342lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
343 char *buf)
dea31012005-04-17 16:05:31 -0500344{
Tony Jonesee959b02008-02-22 00:13:36 +0100345 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500346 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
347 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500348 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500349
dea31012005-04-17 16:05:31 -0500350 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500351 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500352}
353
James Smarte59058c2008-08-24 21:49:00 -0400354/**
James Smart3621a712009-04-06 18:47:14 -0400355 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400356 * @dev: class converted to a Scsi_host structure.
357 * @attr: device attribute, not used.
358 * @buf: on return contains the scsi vpd program type.
359 *
360 * Returns: size of formatted string.
361 **/
dea31012005-04-17 16:05:31 -0500362static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100363lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500364{
365 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100366 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500367 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
368 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500369 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500370
dea31012005-04-17 16:05:31 -0500371 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
372 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
373}
James Smarte59058c2008-08-24 21:49:00 -0400374
375/**
James Smart3621a712009-04-06 18:47:14 -0400376 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400377 * @dev: class converted to a Scsi_host structure.
378 * @attr: device attribute, not used.
379 * @buf: on return contains the ROM and FCode ascii strings.
380 *
381 * Returns: size of formatted string.
382 **/
dea31012005-04-17 16:05:31 -0500383static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100384lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
385 char *buf)
dea31012005-04-17 16:05:31 -0500386{
Tony Jonesee959b02008-02-22 00:13:36 +0100387 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
389 struct lpfc_hba *phba = vport->phba;
390
dea31012005-04-17 16:05:31 -0500391 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
392}
James Smarte59058c2008-08-24 21:49:00 -0400393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains text describing the state of the link.
399 *
400 * Notes:
401 * The switch statement has no default so zero will be returned.
402 *
403 * Returns: size of formatted string.
404 **/
dea31012005-04-17 16:05:31 -0500405static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100406lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
407 char *buf)
dea31012005-04-17 16:05:31 -0500408{
Tony Jonesee959b02008-02-22 00:13:36 +0100409 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500410 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
411 struct lpfc_hba *phba = vport->phba;
412 int len = 0;
413
414 switch (phba->link_state) {
415 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500416 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500417 case LPFC_INIT_START:
418 case LPFC_INIT_MBX_CMDS:
419 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500420 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400421 if (phba->hba_flag & LINK_DISABLED)
422 len += snprintf(buf + len, PAGE_SIZE-len,
423 "Link Down - User disabled\n");
424 else
425 len += snprintf(buf + len, PAGE_SIZE-len,
426 "Link Down\n");
dea31012005-04-17 16:05:31 -0500427 break;
428 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500429 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500430 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400431 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500432
433 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500434 case LPFC_LOCAL_CFG_LINK:
435 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500436 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500437 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500438 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500439 case LPFC_FLOGI:
440 case LPFC_FABRIC_CFG_LINK:
441 case LPFC_NS_REG:
442 case LPFC_NS_QRY:
443 case LPFC_BUILD_DISC_LIST:
444 case LPFC_DISC_AUTH:
445 len += snprintf(buf + len, PAGE_SIZE - len,
446 "Discovery\n");
447 break;
448 case LPFC_VPORT_READY:
449 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
450 break;
451
James Smart92d7f7b2007-06-17 19:56:38 -0500452 case LPFC_VPORT_FAILED:
453 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
454 break;
455
456 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500457 len += snprintf(buf + len, PAGE_SIZE - len,
458 "Unknown\n");
459 break;
460 }
James Smart84774a42008-08-24 21:50:06 -0400461 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
462 len += snprintf(buf + len, PAGE_SIZE-len,
463 " Menlo Maint Mode\n");
464 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500465 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500466 len += snprintf(buf + len, PAGE_SIZE-len,
467 " Public Loop\n");
468 else
469 len += snprintf(buf + len, PAGE_SIZE-len,
470 " Private Loop\n");
471 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500472 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500473 len += snprintf(buf + len, PAGE_SIZE-len,
474 " Fabric\n");
475 else
476 len += snprintf(buf + len, PAGE_SIZE-len,
477 " Point-2-Point\n");
478 }
479 }
James Smart2e0fef82007-06-17 19:56:36 -0500480
dea31012005-04-17 16:05:31 -0500481 return len;
482}
483
James Smarte59058c2008-08-24 21:49:00 -0400484/**
James Smart84d1b002010-02-12 14:42:33 -0500485 * lpfc_link_state_store - Transition the link_state on an HBA port
486 * @dev: class device that is converted into a Scsi_host.
487 * @attr: device attribute, not used.
488 * @buf: one or more lpfc_polling_flags values.
489 * @count: not used.
490 *
491 * Returns:
492 * -EINVAL if the buffer is not "up" or "down"
493 * return from link state change function if non-zero
494 * length of the buf on success
495 **/
496static ssize_t
497lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
498 const char *buf, size_t count)
499{
500 struct Scsi_Host *shost = class_to_shost(dev);
501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
502 struct lpfc_hba *phba = vport->phba;
503
504 int status = -EINVAL;
505
506 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
507 (phba->link_state == LPFC_LINK_DOWN))
508 status = phba->lpfc_hba_init_link(phba);
509 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
510 (phba->link_state >= LPFC_LINK_UP))
511 status = phba->lpfc_hba_down_link(phba);
512
513 if (status == 0)
514 return strlen(buf);
515 else
516 return status;
517}
518
519/**
James Smart3621a712009-04-06 18:47:14 -0400520 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400521 * @dev: class device that is converted into a Scsi_host.
522 * @attr: device attribute, not used.
523 * @buf: on return contains the sum of fc mapped and unmapped.
524 *
525 * Description:
526 * Returns the ascii text number of the sum of the fc mapped and unmapped
527 * vport counts.
528 *
529 * Returns: size of formatted string.
530 **/
dea31012005-04-17 16:05:31 -0500531static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100532lpfc_num_discovered_ports_show(struct device *dev,
533 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500534{
Tony Jonesee959b02008-02-22 00:13:36 +0100535 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
537
538 return snprintf(buf, PAGE_SIZE, "%d\n",
539 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500540}
541
James Smarte59058c2008-08-24 21:49:00 -0400542/**
James Smart3621a712009-04-06 18:47:14 -0400543 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400544 * @shost: Scsi_Host pointer.
545 *
546 * Description:
547 * Bring the link down gracefully then re-init the link. The firmware will
548 * re-init the fiber channel interface as required. Does not issue a LIP.
549 *
550 * Returns:
551 * -EPERM port offline or management commands are being blocked
552 * -ENOMEM cannot allocate memory for the mailbox command
553 * -EIO error sending the mailbox command
554 * zero for success
555 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700556static int
James Smart2e0fef82007-06-17 19:56:36 -0500557lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500558{
James Smart2e0fef82007-06-17 19:56:36 -0500559 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
560 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500561 LPFC_MBOXQ_t *pmboxq;
562 int mbxstatus = MBXERR_ERROR;
563
James Smart2e0fef82007-06-17 19:56:36 -0500564 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500565 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500566 return -EPERM;
567
568 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
569
570 if (!pmboxq)
571 return -ENOMEM;
572
573 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400574 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
575 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400576
James Smart33ccf8d2006-08-17 11:57:58 -0400577 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500578
James Smart04c68492009-05-22 14:52:52 -0400579 if ((mbxstatus == MBX_SUCCESS) &&
580 (pmboxq->u.mb.mbxStatus == 0 ||
581 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400582 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
583 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
584 phba->cfg_link_speed);
585 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
586 phba->fc_ratov * 2);
587 }
588
James Smart5b8bd0c2007-04-25 09:52:49 -0400589 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500590 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400591 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500592
593 if (mbxstatus == MBXERR_ERROR)
594 return -EIO;
595
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700596 return 0;
dea31012005-04-17 16:05:31 -0500597}
598
James Smarte59058c2008-08-24 21:49:00 -0400599/**
James Smart3621a712009-04-06 18:47:14 -0400600 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400601 * @phba: lpfc_hba pointer.
602 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
603 *
604 * Notes:
605 * Assumes any error from lpfc_do_offline() will be negative.
606 * Can wait up to 5 seconds for the port ring buffers count
607 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400608 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400609 *
610 * Returns:
611 * -EIO error posting the event
612 * zero for success
613 **/
James Smart40496f02006-07-06 15:50:22 -0400614static int
James Smart46fa3112007-04-25 09:51:45 -0400615lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
616{
617 struct completion online_compl;
618 struct lpfc_sli_ring *pring;
619 struct lpfc_sli *psli;
620 int status = 0;
621 int cnt = 0;
622 int i;
623
624 init_completion(&online_compl);
625 lpfc_workq_post_event(phba, &status, &online_compl,
626 LPFC_EVT_OFFLINE_PREP);
627 wait_for_completion(&online_compl);
628
629 if (status != 0)
630 return -EIO;
631
632 psli = &phba->sli;
633
James Smart09372822008-01-11 01:52:54 -0500634 /* Wait a little for things to settle down, but not
635 * long enough for dev loss timeout to expire.
636 */
James Smart46fa3112007-04-25 09:51:45 -0400637 for (i = 0; i < psli->num_rings; i++) {
638 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400639 while (pring->txcmplq_cnt) {
640 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500641 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400642 lpfc_printf_log(phba,
643 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400644 "0466 Outstanding IO when "
645 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400646 break;
647 }
648 }
649 }
650
651 init_completion(&online_compl);
652 lpfc_workq_post_event(phba, &status, &online_compl, type);
653 wait_for_completion(&online_compl);
654
655 if (status != 0)
656 return -EIO;
657
658 return 0;
659}
660
James Smarte59058c2008-08-24 21:49:00 -0400661/**
James Smart3621a712009-04-06 18:47:14 -0400662 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400663 * @phba: lpfc_hba pointer.
664 *
665 * Description:
666 * If the port is configured to allow a reset then the hba is brought
667 * offline then online.
668 *
669 * Notes:
670 * Assumes any error from lpfc_do_offline() will be negative.
671 *
672 * Returns:
673 * lpfc_do_offline() return code if not zero
674 * -EIO reset not configured or error posting the event
675 * zero for success
676 **/
James Smart46fa3112007-04-25 09:51:45 -0400677static int
James Smart40496f02006-07-06 15:50:22 -0400678lpfc_selective_reset(struct lpfc_hba *phba)
679{
680 struct completion online_compl;
681 int status = 0;
682
James Smart13815c82008-01-11 01:52:48 -0500683 if (!phba->cfg_enable_hba_reset)
684 return -EIO;
685
James Smart46fa3112007-04-25 09:51:45 -0400686 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400687
688 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400689 return status;
James Smart40496f02006-07-06 15:50:22 -0400690
691 init_completion(&online_compl);
692 lpfc_workq_post_event(phba, &status, &online_compl,
693 LPFC_EVT_ONLINE);
694 wait_for_completion(&online_compl);
695
696 if (status != 0)
697 return -EIO;
698
699 return 0;
700}
701
James Smarte59058c2008-08-24 21:49:00 -0400702/**
James Smart3621a712009-04-06 18:47:14 -0400703 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400704 * @dev: class device that is converted into a Scsi_host.
705 * @attr: device attribute, not used.
706 * @buf: containing the string "selective".
707 * @count: unused variable.
708 *
709 * Description:
710 * If the buf contains the string "selective" then lpfc_selective_reset()
711 * is called to perform the reset.
712 *
713 * Notes:
714 * Assumes any error from lpfc_selective_reset() will be negative.
715 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200716 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400717 *
718 * Returns:
719 * -EINVAL if the buffer does not contain the string "selective"
720 * length of buf if lpfc-selective_reset() if the call succeeds
721 * return value of lpfc_selective_reset() if the call fails
722**/
James Smart40496f02006-07-06 15:50:22 -0400723static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100724lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
725 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400726{
Tony Jonesee959b02008-02-22 00:13:36 +0100727 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500728 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
729 struct lpfc_hba *phba = vport->phba;
730
James Smart40496f02006-07-06 15:50:22 -0400731 int status = -EINVAL;
732
733 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
734 status = lpfc_selective_reset(phba);
735
736 if (status == 0)
737 return strlen(buf);
738 else
739 return status;
740}
741
James Smarte59058c2008-08-24 21:49:00 -0400742/**
James Smart3621a712009-04-06 18:47:14 -0400743 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400744 * @dev: class device that is converted into a Scsi_host.
745 * @attr: device attribute, not used.
746 * @buf: on return contains the ascii number of nport events.
747 *
748 * Returns: size of formatted string.
749 **/
dea31012005-04-17 16:05:31 -0500750static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100751lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
752 char *buf)
dea31012005-04-17 16:05:31 -0500753{
Tony Jonesee959b02008-02-22 00:13:36 +0100754 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
756 struct lpfc_hba *phba = vport->phba;
757
dea31012005-04-17 16:05:31 -0500758 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
759}
760
James Smarte59058c2008-08-24 21:49:00 -0400761/**
James Smart3621a712009-04-06 18:47:14 -0400762 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400763 * @dev: class device that is converted into a Scsi_host.
764 * @attr: device attribute, not used.
765 * @buf: on return contains the state of the adapter.
766 *
767 * Returns: size of formatted string.
768 **/
dea31012005-04-17 16:05:31 -0500769static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100770lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
771 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500772{
Tony Jonesee959b02008-02-22 00:13:36 +0100773 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500774 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
775 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500776 char * state;
777
James Smart2e0fef82007-06-17 19:56:36 -0500778 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500779 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500780 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500781 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500782 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500783 state = "offline";
784 else
785 state = "online";
786
787 return snprintf(buf, PAGE_SIZE, "%s\n", state);
788}
789
James Smarte59058c2008-08-24 21:49:00 -0400790/**
James Smart3621a712009-04-06 18:47:14 -0400791 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400792 * @dev: class device that is converted into a Scsi_host.
793 * @attr: device attribute, not used.
794 * @buf: containing one of the strings "online", "offline", "warm" or "error".
795 * @count: unused variable.
796 *
797 * Returns:
798 * -EACCES if enable hba reset not enabled
799 * -EINVAL if the buffer does not contain a valid string (see above)
800 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
801 * buf length greater than zero indicates success
802 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500803static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100804lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
805 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500806{
Tony Jonesee959b02008-02-22 00:13:36 +0100807 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500808 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
809 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500810 struct completion online_compl;
811 int status=0;
812
James Smart13815c82008-01-11 01:52:48 -0500813 if (!phba->cfg_enable_hba_reset)
814 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500815 init_completion(&online_compl);
816
James Smart46fa3112007-04-25 09:51:45 -0400817 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500818 lpfc_workq_post_event(phba, &status, &online_compl,
819 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400820 wait_for_completion(&online_compl);
821 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
822 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500823 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400824 if (phba->sli_rev == LPFC_SLI_REV4)
825 return -EINVAL;
826 else
827 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400828 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400829 if (phba->sli_rev == LPFC_SLI_REV4)
830 return -EINVAL;
831 else
832 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500833 else
834 return -EINVAL;
835
Jamie Wellnitz41415862006-02-28 19:25:27 -0500836 if (!status)
837 return strlen(buf);
838 else
839 return -EIO;
840}
841
James Smarte59058c2008-08-24 21:49:00 -0400842/**
James Smart3621a712009-04-06 18:47:14 -0400843 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400844 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400845 * @mxri: max xri count.
846 * @axri: available xri count.
847 * @mrpi: max rpi count.
848 * @arpi: available rpi count.
849 * @mvpi: max vpi count.
850 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400851 *
852 * Description:
853 * If an integer pointer for an count is not null then the value for the
854 * count is returned.
855 *
856 * Returns:
857 * zero on error
858 * one for success
859 **/
James Smart311464e2007-08-02 11:10:37 -0400860static int
James Smart858c9f62007-06-17 19:56:39 -0500861lpfc_get_hba_info(struct lpfc_hba *phba,
862 uint32_t *mxri, uint32_t *axri,
863 uint32_t *mrpi, uint32_t *arpi,
864 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500865{
James Smart04c68492009-05-22 14:52:52 -0400866 struct lpfc_sli *psli = &phba->sli;
867 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500868 LPFC_MBOXQ_t *pmboxq;
869 MAILBOX_t *pmb;
870 int rc = 0;
871
872 /*
873 * prevent udev from issuing mailbox commands until the port is
874 * configured.
875 */
876 if (phba->link_state < LPFC_LINK_DOWN ||
877 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400878 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500879 return 0;
880
881 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
882 return 0;
883
884 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
885 if (!pmboxq)
886 return 0;
887 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
888
James Smart04c68492009-05-22 14:52:52 -0400889 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500890 pmb->mbxCommand = MBX_READ_CONFIG;
891 pmb->mbxOwner = OWN_HOST;
892 pmboxq->context1 = NULL;
893
894 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -0400895 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart92d7f7b2007-06-17 19:56:38 -0500896 rc = MBX_NOT_FINISHED;
897 else
898 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
899
900 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500901 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500902 mempool_free(pmboxq, phba->mbox_mem_pool);
903 return 0;
904 }
905
James Smartda0436e2009-05-22 14:51:39 -0400906 if (phba->sli_rev == LPFC_SLI_REV4) {
907 rd_config = &pmboxq->u.mqe.un.rd_config;
908 if (mrpi)
909 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
910 if (arpi)
911 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
912 phba->sli4_hba.max_cfg_param.rpi_used;
913 if (mxri)
914 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
915 if (axri)
916 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
917 phba->sli4_hba.max_cfg_param.xri_used;
918 if (mvpi)
919 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
920 if (avpi)
921 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
922 phba->sli4_hba.max_cfg_param.vpi_used;
923 } else {
924 if (mrpi)
925 *mrpi = pmb->un.varRdConfig.max_rpi;
926 if (arpi)
927 *arpi = pmb->un.varRdConfig.avail_rpi;
928 if (mxri)
929 *mxri = pmb->un.varRdConfig.max_xri;
930 if (axri)
931 *axri = pmb->un.varRdConfig.avail_xri;
932 if (mvpi)
933 *mvpi = pmb->un.varRdConfig.max_vpi;
934 if (avpi)
935 *avpi = pmb->un.varRdConfig.avail_vpi;
936 }
James Smart92d7f7b2007-06-17 19:56:38 -0500937
938 mempool_free(pmboxq, phba->mbox_mem_pool);
939 return 1;
940}
941
James Smarte59058c2008-08-24 21:49:00 -0400942/**
James Smart3621a712009-04-06 18:47:14 -0400943 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400944 * @dev: class device that is converted into a Scsi_host.
945 * @attr: device attribute, not used.
946 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
947 *
948 * Description:
949 * Calls lpfc_get_hba_info() asking for just the mrpi count.
950 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
951 * to "Unknown" and the buffer length is returned, therefore the caller
952 * must check for "Unknown" in the buffer to detect a failure.
953 *
954 * Returns: size of formatted string.
955 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500956static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100957lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
958 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500959{
Tony Jonesee959b02008-02-22 00:13:36 +0100960 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500961 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
962 struct lpfc_hba *phba = vport->phba;
963 uint32_t cnt;
964
James Smart858c9f62007-06-17 19:56:39 -0500965 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500966 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
967 return snprintf(buf, PAGE_SIZE, "Unknown\n");
968}
969
James Smarte59058c2008-08-24 21:49:00 -0400970/**
James Smart3621a712009-04-06 18:47:14 -0400971 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400972 * @dev: class device that is converted into a Scsi_host.
973 * @attr: device attribute, not used.
974 * @buf: containing the used rpi count in decimal or "Unknown".
975 *
976 * Description:
977 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
978 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
979 * to "Unknown" and the buffer length is returned, therefore the caller
980 * must check for "Unknown" in the buffer to detect a failure.
981 *
982 * Returns: size of formatted string.
983 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500984static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100985lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
986 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500987{
Tony Jonesee959b02008-02-22 00:13:36 +0100988 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500989 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
990 struct lpfc_hba *phba = vport->phba;
991 uint32_t cnt, acnt;
992
James Smart858c9f62007-06-17 19:56:39 -0500993 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500994 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
995 return snprintf(buf, PAGE_SIZE, "Unknown\n");
996}
997
James Smarte59058c2008-08-24 21:49:00 -0400998/**
James Smart3621a712009-04-06 18:47:14 -0400999 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001000 * @dev: class device that is converted into a Scsi_host.
1001 * @attr: device attribute, not used.
1002 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1003 *
1004 * Description:
1005 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1006 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1007 * to "Unknown" and the buffer length is returned, therefore the caller
1008 * must check for "Unknown" in the buffer to detect a failure.
1009 *
1010 * Returns: size of formatted string.
1011 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001012static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001013lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1014 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001015{
Tony Jonesee959b02008-02-22 00:13:36 +01001016 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001017 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1018 struct lpfc_hba *phba = vport->phba;
1019 uint32_t cnt;
1020
James Smart858c9f62007-06-17 19:56:39 -05001021 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001022 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1023 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1024}
1025
James Smarte59058c2008-08-24 21:49:00 -04001026/**
James Smart3621a712009-04-06 18:47:14 -04001027 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001028 * @dev: class device that is converted into a Scsi_host.
1029 * @attr: device attribute, not used.
1030 * @buf: on return contains the used xri count in decimal or "Unknown".
1031 *
1032 * Description:
1033 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1034 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1035 * to "Unknown" and the buffer length is returned, therefore the caller
1036 * must check for "Unknown" in the buffer to detect a failure.
1037 *
1038 * Returns: size of formatted string.
1039 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001040static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001041lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1042 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001043{
Tony Jonesee959b02008-02-22 00:13:36 +01001044 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001045 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1046 struct lpfc_hba *phba = vport->phba;
1047 uint32_t cnt, acnt;
1048
James Smart858c9f62007-06-17 19:56:39 -05001049 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1050 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1051 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1052}
1053
James Smarte59058c2008-08-24 21:49:00 -04001054/**
James Smart3621a712009-04-06 18:47:14 -04001055 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001056 * @dev: class device that is converted into a Scsi_host.
1057 * @attr: device attribute, not used.
1058 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1059 *
1060 * Description:
1061 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1062 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1063 * to "Unknown" and the buffer length is returned, therefore the caller
1064 * must check for "Unknown" in the buffer to detect a failure.
1065 *
1066 * Returns: size of formatted string.
1067 **/
James Smart858c9f62007-06-17 19:56:39 -05001068static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001069lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1070 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001071{
Tony Jonesee959b02008-02-22 00:13:36 +01001072 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001073 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1074 struct lpfc_hba *phba = vport->phba;
1075 uint32_t cnt;
1076
1077 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1078 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1079 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1080}
1081
James Smarte59058c2008-08-24 21:49:00 -04001082/**
James Smart3621a712009-04-06 18:47:14 -04001083 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001084 * @dev: class device that is converted into a Scsi_host.
1085 * @attr: device attribute, not used.
1086 * @buf: on return contains the used vpi count in decimal or "Unknown".
1087 *
1088 * Description:
1089 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1090 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1091 * to "Unknown" and the buffer length is returned, therefore the caller
1092 * must check for "Unknown" in the buffer to detect a failure.
1093 *
1094 * Returns: size of formatted string.
1095 **/
James Smart858c9f62007-06-17 19:56:39 -05001096static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001097lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1098 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001099{
Tony Jonesee959b02008-02-22 00:13:36 +01001100 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1102 struct lpfc_hba *phba = vport->phba;
1103 uint32_t cnt, acnt;
1104
1105 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001106 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1107 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1108}
1109
James Smarte59058c2008-08-24 21:49:00 -04001110/**
James Smart3621a712009-04-06 18:47:14 -04001111 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001112 * @dev: class device that is converted into a Scsi_host.
1113 * @attr: device attribute, not used.
1114 * @buf: text that must be interpreted to determine if npiv is supported.
1115 *
1116 * Description:
1117 * Buffer will contain text indicating npiv is not suppoerted on the port,
1118 * the port is an NPIV physical port, or it is an npiv virtual port with
1119 * the id of the vport.
1120 *
1121 * Returns: size of formatted string.
1122 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001123static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001124lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1125 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001126{
Tony Jonesee959b02008-02-22 00:13:36 +01001127 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1129 struct lpfc_hba *phba = vport->phba;
1130
1131 if (!(phba->max_vpi))
1132 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1133 if (vport->port_type == LPFC_PHYSICAL_PORT)
1134 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1135 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1136}
1137
James Smarte59058c2008-08-24 21:49:00 -04001138/**
James Smart3621a712009-04-06 18:47:14 -04001139 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001140 * @dev: class device that is converted into a Scsi_host.
1141 * @attr: device attribute, not used.
1142 * @buf: on return contains the cfg_poll in hex.
1143 *
1144 * Notes:
1145 * cfg_poll should be a lpfc_polling_flags type.
1146 *
1147 * Returns: size of formatted string.
1148 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001149static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001150lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1151 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001152{
Tony Jonesee959b02008-02-22 00:13:36 +01001153 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1155 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001156
1157 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1158}
1159
James Smarte59058c2008-08-24 21:49:00 -04001160/**
James Smart3621a712009-04-06 18:47:14 -04001161 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001162 * @dev: class device that is converted into a Scsi_host.
1163 * @attr: device attribute, not used.
1164 * @buf: one or more lpfc_polling_flags values.
1165 * @count: not used.
1166 *
1167 * Notes:
1168 * buf contents converted to integer and checked for a valid value.
1169 *
1170 * Returns:
1171 * -EINVAL if the buffer connot be converted or is out of range
1172 * length of the buf on success
1173 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001174static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001175lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1176 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001177{
Tony Jonesee959b02008-02-22 00:13:36 +01001178 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1180 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001181 uint32_t creg_val;
1182 uint32_t old_val;
1183 int val=0;
1184
1185 if (!isdigit(buf[0]))
1186 return -EINVAL;
1187
1188 if (sscanf(buf, "%i", &val) != 1)
1189 return -EINVAL;
1190
1191 if ((val & 0x3) != val)
1192 return -EINVAL;
1193
James Smart45ed1192009-10-02 15:17:02 -04001194 if (phba->sli_rev == LPFC_SLI_REV4)
1195 val = 0;
1196
James Smart2e0fef82007-06-17 19:56:36 -05001197 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001198
1199 old_val = phba->cfg_poll;
1200
1201 if (val & ENABLE_FCP_RING_POLLING) {
1202 if ((val & DISABLE_FCP_RING_INT) &&
1203 !(old_val & DISABLE_FCP_RING_INT)) {
1204 creg_val = readl(phba->HCregaddr);
1205 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1206 writel(creg_val, phba->HCregaddr);
1207 readl(phba->HCregaddr); /* flush */
1208
1209 lpfc_poll_start_timer(phba);
1210 }
1211 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001212 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001213 return -EINVAL;
1214 }
1215
1216 if (!(val & DISABLE_FCP_RING_INT) &&
1217 (old_val & DISABLE_FCP_RING_INT))
1218 {
James Smart2e0fef82007-06-17 19:56:36 -05001219 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001220 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001221 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001222 creg_val = readl(phba->HCregaddr);
1223 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1224 writel(creg_val, phba->HCregaddr);
1225 readl(phba->HCregaddr); /* flush */
1226 }
1227
1228 phba->cfg_poll = val;
1229
James Smart2e0fef82007-06-17 19:56:36 -05001230 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001231
1232 return strlen(buf);
1233}
dea31012005-04-17 16:05:31 -05001234
James Smarte59058c2008-08-24 21:49:00 -04001235/**
James Smart3621a712009-04-06 18:47:14 -04001236 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001237 *
1238 * Description:
1239 * Macro that given an attr e.g. hba_queue_depth expands
1240 * into a function with the name lpfc_hba_queue_depth_show.
1241 *
1242 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1243 * @dev: class device that is converted into a Scsi_host.
1244 * @attr: device attribute, not used.
1245 * @buf: on return contains the attribute value in decimal.
1246 *
1247 * Returns: size of formatted string.
1248 **/
dea31012005-04-17 16:05:31 -05001249#define lpfc_param_show(attr) \
1250static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001251lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1252 char *buf) \
dea31012005-04-17 16:05:31 -05001253{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001254 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1256 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001257 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001258 val = phba->cfg_##attr;\
1259 return snprintf(buf, PAGE_SIZE, "%d\n",\
1260 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001261}
1262
James Smarte59058c2008-08-24 21:49:00 -04001263/**
James Smart3621a712009-04-06 18:47:14 -04001264 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001265 *
1266 * Description:
1267 * Macro that given an attr e.g. hba_queue_depth expands
1268 * into a function with the name lpfc_hba_queue_depth_show
1269 *
1270 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1271 * @dev: class device that is converted into a Scsi_host.
1272 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001273 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001274 *
1275 * Returns: size of formatted string.
1276 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001277#define lpfc_param_hex_show(attr) \
1278static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001279lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1280 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001281{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001282 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1284 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001285 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001286 val = phba->cfg_##attr;\
1287 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1288 phba->cfg_##attr);\
1289}
1290
James Smarte59058c2008-08-24 21:49:00 -04001291/**
James Smart3621a712009-04-06 18:47:14 -04001292 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001293 *
1294 * Description:
1295 * Macro that given an attr e.g. hba_queue_depth expands
1296 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1297 * takes a default argument, a minimum and maximum argument.
1298 *
1299 * lpfc_##attr##_init: Initializes an attribute.
1300 * @phba: pointer the the adapter structure.
1301 * @val: integer attribute value.
1302 *
1303 * Validates the min and max values then sets the adapter config field
1304 * accordingly, or uses the default if out of range and prints an error message.
1305 *
1306 * Returns:
1307 * zero on success
1308 * -EINVAL if default used
1309 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001310#define lpfc_param_init(attr, default, minval, maxval) \
1311static int \
James Smart84d1b002010-02-12 14:42:33 -05001312lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001313{ \
1314 if (val >= minval && val <= maxval) {\
1315 phba->cfg_##attr = val;\
1316 return 0;\
1317 }\
1318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001319 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1320 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001321 phba->cfg_##attr = default;\
1322 return -EINVAL;\
1323}
1324
James Smarte59058c2008-08-24 21:49:00 -04001325/**
James Smart3621a712009-04-06 18:47:14 -04001326 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001327 *
1328 * Description:
1329 * Macro that given an attr e.g. hba_queue_depth expands
1330 * into a function with the name lpfc_hba_queue_depth_set
1331 *
1332 * lpfc_##attr##_set: Sets an attribute value.
1333 * @phba: pointer the the adapter structure.
1334 * @val: integer attribute value.
1335 *
1336 * Description:
1337 * Validates the min and max values then sets the
1338 * adapter config field if in the valid range. prints error message
1339 * and does not set the parameter if invalid.
1340 *
1341 * Returns:
1342 * zero on success
1343 * -EINVAL if val is invalid
1344 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001345#define lpfc_param_set(attr, default, minval, maxval) \
1346static int \
James Smart84d1b002010-02-12 14:42:33 -05001347lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001348{ \
1349 if (val >= minval && val <= maxval) {\
1350 phba->cfg_##attr = val;\
1351 return 0;\
1352 }\
1353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001354 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1355 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001356 return -EINVAL;\
1357}
1358
James Smarte59058c2008-08-24 21:49:00 -04001359/**
James Smart3621a712009-04-06 18:47:14 -04001360 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001361 *
1362 * Description:
1363 * Macro that given an attr e.g. hba_queue_depth expands
1364 * into a function with the name lpfc_hba_queue_depth_store.
1365 *
1366 * lpfc_##attr##_store: Set an sttribute value.
1367 * @dev: class device that is converted into a Scsi_host.
1368 * @attr: device attribute, not used.
1369 * @buf: contains the attribute value in ascii.
1370 * @count: not used.
1371 *
1372 * Description:
1373 * Convert the ascii text number to an integer, then
1374 * use the lpfc_##attr##_set function to set the value.
1375 *
1376 * Returns:
1377 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1378 * length of buffer upon success.
1379 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001380#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001381static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001382lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1383 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001384{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001385 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1387 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001388 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001389 if (!isdigit(buf[0]))\
1390 return -EINVAL;\
1391 if (sscanf(buf, "%i", &val) != 1)\
1392 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001393 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001394 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001395 else \
1396 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001397}
1398
James Smarte59058c2008-08-24 21:49:00 -04001399/**
James Smart3621a712009-04-06 18:47:14 -04001400 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001401 *
1402 * Description:
1403 * Macro that given an attr e.g. hba_queue_depth expands
1404 * into a function with the name lpfc_hba_queue_depth_show
1405 *
1406 * lpfc_##attr##_show: prints the attribute value in decimal.
1407 * @dev: class device that is converted into a Scsi_host.
1408 * @attr: device attribute, not used.
1409 * @buf: on return contains the attribute value in decimal.
1410 *
1411 * Returns: length of formatted string.
1412 **/
James Smart3de2a652007-08-02 11:09:59 -04001413#define lpfc_vport_param_show(attr) \
1414static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001415lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1416 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001417{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001418 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001419 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001420 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001421 val = vport->cfg_##attr;\
1422 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1423}
1424
James Smarte59058c2008-08-24 21:49:00 -04001425/**
James Smart3621a712009-04-06 18:47:14 -04001426 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001427 *
1428 * Description:
1429 * Macro that given an attr e.g.
1430 * hba_queue_depth expands into a function with the name
1431 * lpfc_hba_queue_depth_show
1432 *
James Smart3621a712009-04-06 18:47:14 -04001433 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001434 * @dev: class device that is converted into a Scsi_host.
1435 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001436 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001437 *
1438 * Returns: length of formatted string.
1439 **/
James Smart3de2a652007-08-02 11:09:59 -04001440#define lpfc_vport_param_hex_show(attr) \
1441static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001442lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1443 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001444{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001445 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001447 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001448 val = vport->cfg_##attr;\
1449 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1450}
1451
James Smarte59058c2008-08-24 21:49:00 -04001452/**
James Smart3621a712009-04-06 18:47:14 -04001453 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001454 *
1455 * Description:
1456 * Macro that given an attr e.g. hba_queue_depth expands
1457 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1458 * takes a default argument, a minimum and maximum argument.
1459 *
1460 * lpfc_##attr##_init: validates the min and max values then sets the
1461 * adapter config field accordingly, or uses the default if out of range
1462 * and prints an error message.
1463 * @phba: pointer the the adapter structure.
1464 * @val: integer attribute value.
1465 *
1466 * Returns:
1467 * zero on success
1468 * -EINVAL if default used
1469 **/
James Smart3de2a652007-08-02 11:09:59 -04001470#define lpfc_vport_param_init(attr, default, minval, maxval) \
1471static int \
James Smart84d1b002010-02-12 14:42:33 -05001472lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001473{ \
1474 if (val >= minval && val <= maxval) {\
1475 vport->cfg_##attr = val;\
1476 return 0;\
1477 }\
James Smarte8b62012007-08-02 11:10:09 -04001478 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001479 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001480 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001481 vport->cfg_##attr = default;\
1482 return -EINVAL;\
1483}
1484
James Smarte59058c2008-08-24 21:49:00 -04001485/**
James Smart3621a712009-04-06 18:47:14 -04001486 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001487 *
1488 * Description:
1489 * Macro that given an attr e.g. hba_queue_depth expands
1490 * into a function with the name lpfc_hba_queue_depth_set
1491 *
1492 * lpfc_##attr##_set: validates the min and max values then sets the
1493 * adapter config field if in the valid range. prints error message
1494 * and does not set the parameter if invalid.
1495 * @phba: pointer the the adapter structure.
1496 * @val: integer attribute value.
1497 *
1498 * Returns:
1499 * zero on success
1500 * -EINVAL if val is invalid
1501 **/
James Smart3de2a652007-08-02 11:09:59 -04001502#define lpfc_vport_param_set(attr, default, minval, maxval) \
1503static int \
James Smart84d1b002010-02-12 14:42:33 -05001504lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001505{ \
1506 if (val >= minval && val <= maxval) {\
1507 vport->cfg_##attr = val;\
1508 return 0;\
1509 }\
James Smarte8b62012007-08-02 11:10:09 -04001510 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001511 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001512 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001513 return -EINVAL;\
1514}
1515
James Smarte59058c2008-08-24 21:49:00 -04001516/**
James Smart3621a712009-04-06 18:47:14 -04001517 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001518 *
1519 * Description:
1520 * Macro that given an attr e.g. hba_queue_depth
1521 * expands into a function with the name lpfc_hba_queue_depth_store
1522 *
1523 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1524 * use the lpfc_##attr##_set function to set the value.
1525 * @cdev: class device that is converted into a Scsi_host.
1526 * @buf: contains the attribute value in decimal.
1527 * @count: not used.
1528 *
1529 * Returns:
1530 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1531 * length of buffer upon success.
1532 **/
James Smart3de2a652007-08-02 11:09:59 -04001533#define lpfc_vport_param_store(attr) \
1534static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001535lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1536 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001537{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001538 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001539 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001540 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001541 if (!isdigit(buf[0]))\
1542 return -EINVAL;\
1543 if (sscanf(buf, "%i", &val) != 1)\
1544 return -EINVAL;\
1545 if (lpfc_##attr##_set(vport, val) == 0) \
1546 return strlen(buf);\
1547 else \
1548 return -EINVAL;\
1549}
1550
1551
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001552#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001553static uint lpfc_##name = defval;\
1554module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001555MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001556lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001557
1558#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001559static uint lpfc_##name = defval;\
1560module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001561MODULE_PARM_DESC(lpfc_##name, desc);\
1562lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001563lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001564static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001565
1566#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001567static uint lpfc_##name = defval;\
1568module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001569MODULE_PARM_DESC(lpfc_##name, desc);\
1570lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001571lpfc_param_init(name, defval, minval, maxval)\
1572lpfc_param_set(name, defval, minval, maxval)\
1573lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001574static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1575 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001576
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001577#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001578static uint lpfc_##name = defval;\
1579module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001580MODULE_PARM_DESC(lpfc_##name, desc);\
1581lpfc_param_hex_show(name)\
1582lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001583static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001584
1585#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001586static uint lpfc_##name = defval;\
1587module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001588MODULE_PARM_DESC(lpfc_##name, desc);\
1589lpfc_param_hex_show(name)\
1590lpfc_param_init(name, defval, minval, maxval)\
1591lpfc_param_set(name, defval, minval, maxval)\
1592lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001593static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1594 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001595
James Smart3de2a652007-08-02 11:09:59 -04001596#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001597static uint lpfc_##name = defval;\
1598module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001599MODULE_PARM_DESC(lpfc_##name, desc);\
1600lpfc_vport_param_init(name, defval, minval, maxval)
1601
1602#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001603static uint lpfc_##name = defval;\
1604module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001605MODULE_PARM_DESC(lpfc_##name, desc);\
1606lpfc_vport_param_show(name)\
1607lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001608static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001609
1610#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001611static uint lpfc_##name = defval;\
1612module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001613MODULE_PARM_DESC(lpfc_##name, desc);\
1614lpfc_vport_param_show(name)\
1615lpfc_vport_param_init(name, defval, minval, maxval)\
1616lpfc_vport_param_set(name, defval, minval, maxval)\
1617lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001618static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1619 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001620
1621#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001622static uint lpfc_##name = defval;\
1623module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001624MODULE_PARM_DESC(lpfc_##name, desc);\
1625lpfc_vport_param_hex_show(name)\
1626lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001627static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001628
1629#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001630static uint lpfc_##name = defval;\
1631module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001632MODULE_PARM_DESC(lpfc_##name, desc);\
1633lpfc_vport_param_hex_show(name)\
1634lpfc_vport_param_init(name, defval, minval, maxval)\
1635lpfc_vport_param_set(name, defval, minval, maxval)\
1636lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001637static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1638 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001639
James Smart81301a92008-12-04 22:39:46 -05001640static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1641static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1642static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1643static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001644static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1645static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1646static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1647static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1648static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1649static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1650static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1651static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001652static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1653 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001654static DEVICE_ATTR(option_rom_version, S_IRUGO,
1655 lpfc_option_rom_version_show, NULL);
1656static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1657 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001658static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001659static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1660static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001661static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001662static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1663 lpfc_board_mode_show, lpfc_board_mode_store);
1664static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1665static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1666static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1667static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1668static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1669static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1670static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1671static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1672static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001673
James Smartc3f28af2006-08-18 17:47:18 -04001674
James Smarta12e07b2006-12-02 13:35:30 -05001675static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001676
James Smarte59058c2008-08-24 21:49:00 -04001677/**
James Smart3621a712009-04-06 18:47:14 -04001678 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001679 * @dev: class device that is converted into a Scsi_host.
1680 * @attr: device attribute, not used.
1681 * @buf: containing the string lpfc_soft_wwn_key.
1682 * @count: must be size of lpfc_soft_wwn_key.
1683 *
1684 * Returns:
1685 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1686 * length of buf indicates success
1687 **/
James Smartc3f28af2006-08-18 17:47:18 -04001688static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001689lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1690 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001691{
Tony Jonesee959b02008-02-22 00:13:36 +01001692 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001693 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1694 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001695 unsigned int cnt = count;
1696
1697 /*
1698 * We're doing a simple sanity check for soft_wwpn setting.
1699 * We require that the user write a specific key to enable
1700 * the soft_wwpn attribute to be settable. Once the attribute
1701 * is written, the enable key resets. If further updates are
1702 * desired, the key must be written again to re-enable the
1703 * attribute.
1704 *
1705 * The "key" is not secret - it is a hardcoded string shown
1706 * here. The intent is to protect against the random user or
1707 * application that is just writing attributes.
1708 */
1709
1710 /* count may include a LF at end of string */
1711 if (buf[cnt-1] == '\n')
1712 cnt--;
1713
James Smarta12e07b2006-12-02 13:35:30 -05001714 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1715 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001716 return -EINVAL;
1717
James Smarta12e07b2006-12-02 13:35:30 -05001718 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001719 return count;
1720}
Tony Jonesee959b02008-02-22 00:13:36 +01001721static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1722 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001723
James Smarte59058c2008-08-24 21:49:00 -04001724/**
James Smart3621a712009-04-06 18:47:14 -04001725 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001726 * @dev: class device that is converted into a Scsi_host.
1727 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001728 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001729 *
1730 * Returns: size of formatted string.
1731 **/
James Smartc3f28af2006-08-18 17:47:18 -04001732static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001733lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1734 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001735{
Tony Jonesee959b02008-02-22 00:13:36 +01001736 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001737 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1738 struct lpfc_hba *phba = vport->phba;
1739
Randy Dunlapafc071e2006-10-23 21:47:13 -07001740 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1741 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001742}
1743
James Smarte59058c2008-08-24 21:49:00 -04001744/**
James Smart3621a712009-04-06 18:47:14 -04001745 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001746 * @dev class device that is converted into a Scsi_host.
1747 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001748 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001749 * @count: number of wwpn bytes in buf
1750 *
1751 * Returns:
1752 * -EACCES hba reset not enabled, adapter over temp
1753 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1754 * -EIO error taking adapter offline or online
1755 * value of count on success
1756 **/
James Smartc3f28af2006-08-18 17:47:18 -04001757static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001758lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1759 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001760{
Tony Jonesee959b02008-02-22 00:13:36 +01001761 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001762 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1763 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001764 struct completion online_compl;
1765 int stat1=0, stat2=0;
1766 unsigned int i, j, cnt=count;
1767 u8 wwpn[8];
1768
James Smart13815c82008-01-11 01:52:48 -05001769 if (!phba->cfg_enable_hba_reset)
1770 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001771 spin_lock_irq(&phba->hbalock);
1772 if (phba->over_temp_state == HBA_OVER_TEMP) {
1773 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001774 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001775 }
1776 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001777 /* count may include a LF at end of string */
1778 if (buf[cnt-1] == '\n')
1779 cnt--;
1780
James Smarta12e07b2006-12-02 13:35:30 -05001781 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001782 ((cnt == 17) && (*buf++ != 'x')) ||
1783 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1784 return -EINVAL;
1785
James Smarta12e07b2006-12-02 13:35:30 -05001786 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001787
1788 memset(wwpn, 0, sizeof(wwpn));
1789
1790 /* Validate and store the new name */
1791 for (i=0, j=0; i < 16; i++) {
1792 if ((*buf >= 'a') && (*buf <= 'f'))
1793 j = ((j << 4) | ((*buf++ -'a') + 10));
1794 else if ((*buf >= 'A') && (*buf <= 'F'))
1795 j = ((j << 4) | ((*buf++ -'A') + 10));
1796 else if ((*buf >= '0') && (*buf <= '9'))
1797 j = ((j << 4) | (*buf++ -'0'));
1798 else
1799 return -EINVAL;
1800 if (i % 2) {
1801 wwpn[i/2] = j & 0xff;
1802 j = 0;
1803 }
1804 }
1805 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001806 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001807 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001808 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001809
1810 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1811 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1812
James Smart46fa3112007-04-25 09:51:45 -04001813 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001814 if (stat1)
1815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001816 "0463 lpfc_soft_wwpn attribute set failed to "
1817 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001818 init_completion(&online_compl);
1819 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1820 wait_for_completion(&online_compl);
1821 if (stat2)
1822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001823 "0464 lpfc_soft_wwpn attribute set failed to "
1824 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001825 return (stat1 || stat2) ? -EIO : count;
1826}
Tony Jonesee959b02008-02-22 00:13:36 +01001827static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1828 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001829
James Smarte59058c2008-08-24 21:49:00 -04001830/**
James Smart3621a712009-04-06 18:47:14 -04001831 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001832 * @dev: class device that is converted into a Scsi_host.
1833 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001834 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001835 *
1836 * Returns: size of formatted string.
1837 **/
James Smarta12e07b2006-12-02 13:35:30 -05001838static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001839lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1840 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001841{
Tony Jonesee959b02008-02-22 00:13:36 +01001842 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001843 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001844 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1845 (unsigned long long)phba->cfg_soft_wwnn);
1846}
1847
James Smarte59058c2008-08-24 21:49:00 -04001848/**
James Smart3621a712009-04-06 18:47:14 -04001849 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001850 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001851 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001852 * @count: number of wwnn bytes in buf.
1853 *
1854 * Returns:
1855 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1856 * value of count on success
1857 **/
James Smarta12e07b2006-12-02 13:35:30 -05001858static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001859lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1860 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001861{
Tony Jonesee959b02008-02-22 00:13:36 +01001862 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001863 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001864 unsigned int i, j, cnt=count;
1865 u8 wwnn[8];
1866
1867 /* count may include a LF at end of string */
1868 if (buf[cnt-1] == '\n')
1869 cnt--;
1870
1871 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1872 ((cnt == 17) && (*buf++ != 'x')) ||
1873 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1874 return -EINVAL;
1875
1876 /*
1877 * Allow wwnn to be set many times, as long as the enable is set.
1878 * However, once the wwpn is set, everything locks.
1879 */
1880
1881 memset(wwnn, 0, sizeof(wwnn));
1882
1883 /* Validate and store the new name */
1884 for (i=0, j=0; i < 16; i++) {
1885 if ((*buf >= 'a') && (*buf <= 'f'))
1886 j = ((j << 4) | ((*buf++ -'a') + 10));
1887 else if ((*buf >= 'A') && (*buf <= 'F'))
1888 j = ((j << 4) | ((*buf++ -'A') + 10));
1889 else if ((*buf >= '0') && (*buf <= '9'))
1890 j = ((j << 4) | (*buf++ -'0'));
1891 else
1892 return -EINVAL;
1893 if (i % 2) {
1894 wwnn[i/2] = j & 0xff;
1895 j = 0;
1896 }
1897 }
1898 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1899
1900 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1901 "lpfc%d: soft_wwnn set. Value will take effect upon "
1902 "setting of the soft_wwpn\n", phba->brd_no);
1903
1904 return count;
1905}
Tony Jonesee959b02008-02-22 00:13:36 +01001906static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1907 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001908
James Smartc3f28af2006-08-18 17:47:18 -04001909
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001910static int lpfc_poll = 0;
1911module_param(lpfc_poll, int, 0);
1912MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1913 " 0 - none,"
1914 " 1 - poll with interrupts enabled"
1915 " 3 - poll and disable FCP ring interrupts");
1916
Tony Jonesee959b02008-02-22 00:13:36 +01001917static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1918 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001919
James Smart92d7f7b2007-06-17 19:56:38 -05001920int lpfc_sli_mode = 0;
1921module_param(lpfc_sli_mode, int, 0);
1922MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1923 " 0 - auto (SLI-3 if supported),"
1924 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1925 " 3 - select SLI-3");
1926
James Smart7ee5d432007-10-27 13:37:17 -04001927int lpfc_enable_npiv = 0;
1928module_param(lpfc_enable_npiv, int, 0);
1929MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1930lpfc_param_show(enable_npiv);
1931lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001932static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001933 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001934
dea31012005-04-17 16:05:31 -05001935/*
James Smart84d1b002010-02-12 14:42:33 -05001936# lpfc_suppress_link_up: Bring link up at initialization
1937# 0x0 = bring link up (issue MBX_INIT_LINK)
1938# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1939# 0x2 = never bring up link
1940# Default value is 0.
1941*/
1942LPFC_ATTR_R(suppress_link_up, 0, 0, 2, "Suppress Link Up at initialization");
1943
1944/*
James Smartc01f3202006-08-18 17:47:08 -04001945# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1946# until the timer expires. Value range is [0,255]. Default value is 30.
1947*/
1948static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1949static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1950module_param(lpfc_nodev_tmo, int, 0);
1951MODULE_PARM_DESC(lpfc_nodev_tmo,
1952 "Seconds driver will hold I/O waiting "
1953 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001954
1955/**
James Smart3621a712009-04-06 18:47:14 -04001956 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04001957 * @dev: class converted to a Scsi_host structure.
1958 * @attr: device attribute, not used.
1959 * @buf: on return contains the dev loss timeout in decimal.
1960 *
1961 * Returns: size of formatted string.
1962 **/
James Smartc01f3202006-08-18 17:47:08 -04001963static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001964lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1965 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001966{
Tony Jonesee959b02008-02-22 00:13:36 +01001967 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001968 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001969 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001970 val = vport->cfg_devloss_tmo;
1971 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001972}
1973
James Smarte59058c2008-08-24 21:49:00 -04001974/**
James Smart3621a712009-04-06 18:47:14 -04001975 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04001976 * @vport: lpfc vport structure pointer.
1977 * @val: contains the nodev timeout value.
1978 *
1979 * Description:
1980 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1981 * a kernel error message is printed and zero is returned.
1982 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1983 * Otherwise nodev tmo is set to the default value.
1984 *
1985 * Returns:
1986 * zero if already set or if val is in range
1987 * -EINVAL val out of range
1988 **/
James Smartc01f3202006-08-18 17:47:08 -04001989static int
James Smart3de2a652007-08-02 11:09:59 -04001990lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001991{
James Smart3de2a652007-08-02 11:09:59 -04001992 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1993 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1994 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001996 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001997 "parameter because devloss_tmo is "
1998 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001999 return 0;
2000 }
2001
2002 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002003 vport->cfg_nodev_tmo = val;
2004 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002005 return 0;
2006 }
James Smarte8b62012007-08-02 11:10:09 -04002007 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2008 "0400 lpfc_nodev_tmo attribute cannot be set to"
2009 " %d, allowed range is [%d, %d]\n",
2010 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002011 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002012 return -EINVAL;
2013}
2014
James Smarte59058c2008-08-24 21:49:00 -04002015/**
James Smart3621a712009-04-06 18:47:14 -04002016 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002017 * @vport: lpfc vport structure pointer.
2018 *
2019 * Description:
2020 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2021 **/
James Smart7054a602007-04-25 09:52:34 -04002022static void
James Smart3de2a652007-08-02 11:09:59 -04002023lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002024{
James Smart858c9f62007-06-17 19:56:39 -05002025 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002026 struct lpfc_nodelist *ndlp;
2027
James Smart51ef4c22007-08-02 11:10:31 -04002028 shost = lpfc_shost_from_vport(vport);
2029 spin_lock_irq(shost->host_lock);
2030 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002031 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002032 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2033 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002034}
2035
James Smarte59058c2008-08-24 21:49:00 -04002036/**
James Smart3621a712009-04-06 18:47:14 -04002037 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002038 * @vport: lpfc vport structure pointer.
2039 * @val: contains the tmo value.
2040 *
2041 * Description:
2042 * If the devloss tmo is already set or the vport dev loss tmo has changed
2043 * then a kernel error message is printed and zero is returned.
2044 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2045 * Otherwise nodev tmo is set to the default value.
2046 *
2047 * Returns:
2048 * zero if already set or if val is in range
2049 * -EINVAL val out of range
2050 **/
James Smartc01f3202006-08-18 17:47:08 -04002051static int
James Smart3de2a652007-08-02 11:09:59 -04002052lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002053{
James Smart3de2a652007-08-02 11:09:59 -04002054 if (vport->dev_loss_tmo_changed ||
2055 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002056 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2057 "0401 Ignoring change to nodev_tmo "
2058 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002059 return 0;
2060 }
James Smartc01f3202006-08-18 17:47:08 -04002061 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002062 vport->cfg_nodev_tmo = val;
2063 vport->cfg_devloss_tmo = val;
2064 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002065 return 0;
2066 }
James Smarte8b62012007-08-02 11:10:09 -04002067 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2068 "0403 lpfc_nodev_tmo attribute cannot be set to"
2069 "%d, allowed range is [%d, %d]\n",
2070 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002071 return -EINVAL;
2072}
2073
James Smart3de2a652007-08-02 11:09:59 -04002074lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002075
Tony Jonesee959b02008-02-22 00:13:36 +01002076static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2077 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002078
2079/*
2080# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2081# disappear until the timer expires. Value range is [0,255]. Default
2082# value is 30.
2083*/
2084module_param(lpfc_devloss_tmo, int, 0);
2085MODULE_PARM_DESC(lpfc_devloss_tmo,
2086 "Seconds driver will hold I/O waiting "
2087 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002088lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2089 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2090lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002091
2092/**
James Smart3621a712009-04-06 18:47:14 -04002093 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002094 * @vport: lpfc vport structure pointer.
2095 * @val: contains the tmo value.
2096 *
2097 * Description:
2098 * If val is in a valid range then set the vport nodev tmo,
2099 * devloss tmo, also set the vport dev loss tmo changed flag.
2100 * Else a kernel error message is printed.
2101 *
2102 * Returns:
2103 * zero if val is in range
2104 * -EINVAL val out of range
2105 **/
James Smartc01f3202006-08-18 17:47:08 -04002106static int
James Smart3de2a652007-08-02 11:09:59 -04002107lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002108{
2109 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002110 vport->cfg_nodev_tmo = val;
2111 vport->cfg_devloss_tmo = val;
2112 vport->dev_loss_tmo_changed = 1;
2113 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002114 return 0;
2115 }
2116
James Smarte8b62012007-08-02 11:10:09 -04002117 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2118 "0404 lpfc_devloss_tmo attribute cannot be set to"
2119 " %d, allowed range is [%d, %d]\n",
2120 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002121 return -EINVAL;
2122}
2123
James Smart3de2a652007-08-02 11:09:59 -04002124lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002125static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2126 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002127
2128/*
dea31012005-04-17 16:05:31 -05002129# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2130# deluged with LOTS of information.
2131# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002132# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002133*/
James Smartf4b4c682009-05-22 14:53:12 -04002134LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002135 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002136
2137/*
James Smart7ee5d432007-10-27 13:37:17 -04002138# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2139# objects that have been registered with the nameserver after login.
2140*/
2141LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2142 "Deregister nameserver objects before LOGO");
2143
2144/*
dea31012005-04-17 16:05:31 -05002145# lun_queue_depth: This parameter is used to limit the number of outstanding
2146# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2147*/
James Smart3de2a652007-08-02 11:09:59 -04002148LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2149 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002150
2151/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002152# hba_queue_depth: This parameter is used to limit the number of outstanding
2153# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2154# value is greater than the maximum number of exchanges supported by the HBA,
2155# then maximum number of exchanges supported by the HBA is used to determine
2156# the hba_queue_depth.
2157*/
2158LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2159 "Max number of FCP commands we can queue to a lpfc HBA");
2160
2161/*
James Smart92d7f7b2007-06-17 19:56:38 -05002162# peer_port_login: This parameter allows/prevents logins
2163# between peer ports hosted on the same physical port.
2164# When this parameter is set 0 peer ports of same physical port
2165# are not allowed to login to each other.
2166# When this parameter is set 1 peer ports of same physical port
2167# are allowed to login to each other.
2168# Default value of this parameter is 0.
2169*/
James Smart3de2a652007-08-02 11:09:59 -04002170LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2171 "Allow peer ports on the same physical port to login to each "
2172 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002173
2174/*
James Smart3de2a652007-08-02 11:09:59 -04002175# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002176# between Virtual Ports and remote initiators.
2177# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2178# other initiators and will attempt to PLOGI all remote ports.
2179# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2180# remote ports and will not attempt to PLOGI to other initiators.
2181# This parameter does not restrict to the physical port.
2182# This parameter does not restrict logins to Fabric resident remote ports.
2183# Default value of this parameter is 1.
2184*/
James Smart3de2a652007-08-02 11:09:59 -04002185static int lpfc_restrict_login = 1;
2186module_param(lpfc_restrict_login, int, 0);
2187MODULE_PARM_DESC(lpfc_restrict_login,
2188 "Restrict virtual ports login to remote initiators.");
2189lpfc_vport_param_show(restrict_login);
2190
James Smarte59058c2008-08-24 21:49:00 -04002191/**
James Smart3621a712009-04-06 18:47:14 -04002192 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002193 * @vport: lpfc vport structure pointer.
2194 * @val: contains the restrict login value.
2195 *
2196 * Description:
2197 * If val is not in a valid range then log a kernel error message and set
2198 * the vport restrict login to one.
2199 * If the port type is physical clear the restrict login flag and return.
2200 * Else set the restrict login flag to val.
2201 *
2202 * Returns:
2203 * zero if val is in range
2204 * -EINVAL val out of range
2205 **/
James Smart3de2a652007-08-02 11:09:59 -04002206static int
2207lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2208{
2209 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002211 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002212 "be set to %d, allowed range is [0, 1]\n",
2213 val);
James Smart3de2a652007-08-02 11:09:59 -04002214 vport->cfg_restrict_login = 1;
2215 return -EINVAL;
2216 }
2217 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2218 vport->cfg_restrict_login = 0;
2219 return 0;
2220 }
2221 vport->cfg_restrict_login = val;
2222 return 0;
2223}
2224
James Smarte59058c2008-08-24 21:49:00 -04002225/**
James Smart3621a712009-04-06 18:47:14 -04002226 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002227 * @vport: lpfc vport structure pointer.
2228 * @val: contains the restrict login value.
2229 *
2230 * Description:
2231 * If val is not in a valid range then log a kernel error message and set
2232 * the vport restrict login to one.
2233 * If the port type is physical and the val is not zero log a kernel
2234 * error message, clear the restrict login flag and return zero.
2235 * Else set the restrict login flag to val.
2236 *
2237 * Returns:
2238 * zero if val is in range
2239 * -EINVAL val out of range
2240 **/
James Smart3de2a652007-08-02 11:09:59 -04002241static int
2242lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2243{
2244 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002245 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002246 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002247 "be set to %d, allowed range is [0, 1]\n",
2248 val);
James Smart3de2a652007-08-02 11:09:59 -04002249 vport->cfg_restrict_login = 1;
2250 return -EINVAL;
2251 }
2252 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002253 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2254 "0468 lpfc_restrict_login must be 0 for "
2255 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002256 vport->cfg_restrict_login = 0;
2257 return 0;
2258 }
2259 vport->cfg_restrict_login = val;
2260 return 0;
2261}
2262lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002263static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2264 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002265
2266/*
dea31012005-04-17 16:05:31 -05002267# Some disk devices have a "select ID" or "select Target" capability.
2268# From a protocol standpoint "select ID" usually means select the
2269# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2270# annex" which contains a table that maps a "select ID" (a number
2271# between 0 and 7F) to an ALPA. By default, for compatibility with
2272# older drivers, the lpfc driver scans this table from low ALPA to high
2273# ALPA.
2274#
2275# Turning on the scan-down variable (on = 1, off = 0) will
2276# cause the lpfc driver to use an inverted table, effectively
2277# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2278#
2279# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2280# and will not work across a fabric. Also this parameter will take
2281# effect only in the case when ALPA map is not available.)
2282*/
James Smart3de2a652007-08-02 11:09:59 -04002283LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2284 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002285
2286/*
dea31012005-04-17 16:05:31 -05002287# lpfc_topology: link topology for init link
2288# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002289# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002290# 0x02 = attempt point-to-point mode only
2291# 0x04 = attempt loop mode only
2292# 0x06 = attempt point-to-point mode then loop
2293# Set point-to-point mode if you want to run as an N_Port.
2294# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2295# Default value is 0.
2296*/
James Smarte59058c2008-08-24 21:49:00 -04002297
2298/**
James Smart3621a712009-04-06 18:47:14 -04002299 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002300 * @phba: lpfc_hba pointer.
2301 * @val: topology value.
2302 *
2303 * Description:
2304 * If val is in a valid range then set the adapter's topology field and
2305 * issue a lip; if the lip fails reset the topology to the old value.
2306 *
2307 * If the value is not in range log a kernel error message and return an error.
2308 *
2309 * Returns:
2310 * zero if val is in range and lip okay
2311 * non-zero return value from lpfc_issue_lip()
2312 * -EINVAL val out of range
2313 **/
James Smarta257bf92009-04-06 18:48:10 -04002314static ssize_t
2315lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2316 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002317{
James Smarta257bf92009-04-06 18:48:10 -04002318 struct Scsi_Host *shost = class_to_shost(dev);
2319 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2320 struct lpfc_hba *phba = vport->phba;
2321 int val = 0;
2322 int nolip = 0;
2323 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002324 int err;
2325 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002326
2327 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2328 nolip = 1;
2329 val_buf = &buf[strlen("nolip ")];
2330 }
2331
2332 if (!isdigit(val_buf[0]))
2333 return -EINVAL;
2334 if (sscanf(val_buf, "%i", &val) != 1)
2335 return -EINVAL;
2336
James Smart83108bd2008-01-11 01:53:09 -05002337 if (val >= 0 && val <= 6) {
2338 prev_val = phba->cfg_topology;
2339 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002340 if (nolip)
2341 return strlen(buf);
2342
James Smart83108bd2008-01-11 01:53:09 -05002343 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002344 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002345 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002346 return -EINVAL;
2347 } else
2348 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002349 }
2350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2351 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2352 "allowed range is [0, 6]\n",
2353 phba->brd_no, val);
2354 return -EINVAL;
2355}
2356static int lpfc_topology = 0;
2357module_param(lpfc_topology, int, 0);
2358MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2359lpfc_param_show(topology)
2360lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002361static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002362 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002363
James Smart21e9a0a2009-05-22 14:53:21 -04002364/**
2365 * lpfc_static_vport_show: Read callback function for
2366 * lpfc_static_vport sysfs file.
2367 * @dev: Pointer to class device object.
2368 * @attr: device attribute structure.
2369 * @buf: Data buffer.
2370 *
2371 * This function is the read call back function for
2372 * lpfc_static_vport sysfs file. The lpfc_static_vport
2373 * sysfs file report the mageability of the vport.
2374 **/
2375static ssize_t
2376lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2377 char *buf)
2378{
2379 struct Scsi_Host *shost = class_to_shost(dev);
2380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2381 if (vport->vport_flag & STATIC_VPORT)
2382 sprintf(buf, "1\n");
2383 else
2384 sprintf(buf, "0\n");
2385
2386 return strlen(buf);
2387}
2388
2389/*
2390 * Sysfs attribute to control the statistical data collection.
2391 */
2392static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2393 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002394
2395/**
James Smart3621a712009-04-06 18:47:14 -04002396 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002397 * @dev: Pointer to class device.
2398 * @buf: Data buffer.
2399 * @count: Size of the data buffer.
2400 *
2401 * This function get called when an user write to the lpfc_stat_data_ctrl
2402 * sysfs file. This function parse the command written to the sysfs file
2403 * and take appropriate action. These commands are used for controlling
2404 * driver statistical data collection.
2405 * Following are the command this function handles.
2406 *
2407 * setbucket <bucket_type> <base> <step>
2408 * = Set the latency buckets.
2409 * destroybucket = destroy all the buckets.
2410 * start = start data collection
2411 * stop = stop data collection
2412 * reset = reset the collected data
2413 **/
2414static ssize_t
2415lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2416 const char *buf, size_t count)
2417{
2418 struct Scsi_Host *shost = class_to_shost(dev);
2419 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2420 struct lpfc_hba *phba = vport->phba;
2421#define LPFC_MAX_DATA_CTRL_LEN 1024
2422 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2423 unsigned long i;
2424 char *str_ptr, *token;
2425 struct lpfc_vport **vports;
2426 struct Scsi_Host *v_shost;
2427 char *bucket_type_str, *base_str, *step_str;
2428 unsigned long base, step, bucket_type;
2429
2430 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002431 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002432 return -EINVAL;
2433
2434 strcpy(bucket_data, buf);
2435 str_ptr = &bucket_data[0];
2436 /* Ignore this token - this is command token */
2437 token = strsep(&str_ptr, "\t ");
2438 if (!token)
2439 return -EINVAL;
2440
2441 bucket_type_str = strsep(&str_ptr, "\t ");
2442 if (!bucket_type_str)
2443 return -EINVAL;
2444
2445 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2446 bucket_type = LPFC_LINEAR_BUCKET;
2447 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2448 bucket_type = LPFC_POWER2_BUCKET;
2449 else
2450 return -EINVAL;
2451
2452 base_str = strsep(&str_ptr, "\t ");
2453 if (!base_str)
2454 return -EINVAL;
2455 base = simple_strtoul(base_str, NULL, 0);
2456
2457 step_str = strsep(&str_ptr, "\t ");
2458 if (!step_str)
2459 return -EINVAL;
2460 step = simple_strtoul(step_str, NULL, 0);
2461 if (!step)
2462 return -EINVAL;
2463
2464 /* Block the data collection for every vport */
2465 vports = lpfc_create_vport_work_array(phba);
2466 if (vports == NULL)
2467 return -ENOMEM;
2468
James Smartf4b4c682009-05-22 14:53:12 -04002469 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002470 v_shost = lpfc_shost_from_vport(vports[i]);
2471 spin_lock_irq(v_shost->host_lock);
2472 /* Block and reset data collection */
2473 vports[i]->stat_data_blocked = 1;
2474 if (vports[i]->stat_data_enabled)
2475 lpfc_vport_reset_stat_data(vports[i]);
2476 spin_unlock_irq(v_shost->host_lock);
2477 }
2478
2479 /* Set the bucket attributes */
2480 phba->bucket_type = bucket_type;
2481 phba->bucket_base = base;
2482 phba->bucket_step = step;
2483
James Smartf4b4c682009-05-22 14:53:12 -04002484 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002485 v_shost = lpfc_shost_from_vport(vports[i]);
2486
2487 /* Unblock data collection */
2488 spin_lock_irq(v_shost->host_lock);
2489 vports[i]->stat_data_blocked = 0;
2490 spin_unlock_irq(v_shost->host_lock);
2491 }
2492 lpfc_destroy_vport_work_array(phba, vports);
2493 return strlen(buf);
2494 }
2495
2496 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2497 vports = lpfc_create_vport_work_array(phba);
2498 if (vports == NULL)
2499 return -ENOMEM;
2500
James Smartf4b4c682009-05-22 14:53:12 -04002501 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002502 v_shost = lpfc_shost_from_vport(vports[i]);
2503 spin_lock_irq(shost->host_lock);
2504 vports[i]->stat_data_blocked = 1;
2505 lpfc_free_bucket(vport);
2506 vport->stat_data_enabled = 0;
2507 vports[i]->stat_data_blocked = 0;
2508 spin_unlock_irq(shost->host_lock);
2509 }
2510 lpfc_destroy_vport_work_array(phba, vports);
2511 phba->bucket_type = LPFC_NO_BUCKET;
2512 phba->bucket_base = 0;
2513 phba->bucket_step = 0;
2514 return strlen(buf);
2515 }
2516
2517 if (!strncmp(buf, "start", strlen("start"))) {
2518 /* If no buckets configured return error */
2519 if (phba->bucket_type == LPFC_NO_BUCKET)
2520 return -EINVAL;
2521 spin_lock_irq(shost->host_lock);
2522 if (vport->stat_data_enabled) {
2523 spin_unlock_irq(shost->host_lock);
2524 return strlen(buf);
2525 }
2526 lpfc_alloc_bucket(vport);
2527 vport->stat_data_enabled = 1;
2528 spin_unlock_irq(shost->host_lock);
2529 return strlen(buf);
2530 }
2531
2532 if (!strncmp(buf, "stop", strlen("stop"))) {
2533 spin_lock_irq(shost->host_lock);
2534 if (vport->stat_data_enabled == 0) {
2535 spin_unlock_irq(shost->host_lock);
2536 return strlen(buf);
2537 }
2538 lpfc_free_bucket(vport);
2539 vport->stat_data_enabled = 0;
2540 spin_unlock_irq(shost->host_lock);
2541 return strlen(buf);
2542 }
2543
2544 if (!strncmp(buf, "reset", strlen("reset"))) {
2545 if ((phba->bucket_type == LPFC_NO_BUCKET)
2546 || !vport->stat_data_enabled)
2547 return strlen(buf);
2548 spin_lock_irq(shost->host_lock);
2549 vport->stat_data_blocked = 1;
2550 lpfc_vport_reset_stat_data(vport);
2551 vport->stat_data_blocked = 0;
2552 spin_unlock_irq(shost->host_lock);
2553 return strlen(buf);
2554 }
2555 return -EINVAL;
2556}
2557
2558
2559/**
James Smart3621a712009-04-06 18:47:14 -04002560 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002561 * @dev: Pointer to class device object.
2562 * @buf: Data buffer.
2563 *
2564 * This function is the read call back function for
2565 * lpfc_stat_data_ctrl sysfs file. This function report the
2566 * current statistical data collection state.
2567 **/
2568static ssize_t
2569lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2570 char *buf)
2571{
2572 struct Scsi_Host *shost = class_to_shost(dev);
2573 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2574 struct lpfc_hba *phba = vport->phba;
2575 int index = 0;
2576 int i;
2577 char *bucket_type;
2578 unsigned long bucket_value;
2579
2580 switch (phba->bucket_type) {
2581 case LPFC_LINEAR_BUCKET:
2582 bucket_type = "linear";
2583 break;
2584 case LPFC_POWER2_BUCKET:
2585 bucket_type = "power2";
2586 break;
2587 default:
2588 bucket_type = "No Bucket";
2589 break;
2590 }
2591
2592 sprintf(&buf[index], "Statistical Data enabled :%d, "
2593 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2594 " Bucket step :%d\nLatency Ranges :",
2595 vport->stat_data_enabled, vport->stat_data_blocked,
2596 bucket_type, phba->bucket_base, phba->bucket_step);
2597 index = strlen(buf);
2598 if (phba->bucket_type != LPFC_NO_BUCKET) {
2599 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2600 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2601 bucket_value = phba->bucket_base +
2602 phba->bucket_step * i;
2603 else
2604 bucket_value = phba->bucket_base +
2605 (1 << i) * phba->bucket_step;
2606
2607 if (index + 10 > PAGE_SIZE)
2608 break;
2609 sprintf(&buf[index], "%08ld ", bucket_value);
2610 index = strlen(buf);
2611 }
2612 }
2613 sprintf(&buf[index], "\n");
2614 return strlen(buf);
2615}
2616
2617/*
2618 * Sysfs attribute to control the statistical data collection.
2619 */
2620static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2621 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2622
2623/*
2624 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2625 */
2626
2627/*
2628 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2629 * for each target.
2630 */
2631#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2632#define MAX_STAT_DATA_SIZE_PER_TARGET \
2633 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2634
2635
2636/**
James Smart3621a712009-04-06 18:47:14 -04002637 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
James Smartea2151b2008-09-07 11:52:10 -04002638 * @kobj: Pointer to the kernel object
2639 * @bin_attr: Attribute object
2640 * @buff: Buffer pointer
2641 * @off: File offset
2642 * @count: Buffer size
2643 *
2644 * This function is the read call back function for lpfc_drvr_stat_data
2645 * sysfs file. This function export the statistical data to user
2646 * applications.
2647 **/
2648static ssize_t
2649sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2650 char *buf, loff_t off, size_t count)
2651{
2652 struct device *dev = container_of(kobj, struct device,
2653 kobj);
2654 struct Scsi_Host *shost = class_to_shost(dev);
2655 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2656 struct lpfc_hba *phba = vport->phba;
2657 int i = 0, index = 0;
2658 unsigned long nport_index;
2659 struct lpfc_nodelist *ndlp = NULL;
2660 nport_index = (unsigned long)off /
2661 MAX_STAT_DATA_SIZE_PER_TARGET;
2662
2663 if (!vport->stat_data_enabled || vport->stat_data_blocked
2664 || (phba->bucket_type == LPFC_NO_BUCKET))
2665 return 0;
2666
2667 spin_lock_irq(shost->host_lock);
2668 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2669 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2670 continue;
2671
2672 if (nport_index > 0) {
2673 nport_index--;
2674 continue;
2675 }
2676
2677 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2678 > count)
2679 break;
2680
2681 if (!ndlp->lat_data)
2682 continue;
2683
2684 /* Print the WWN */
2685 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2686 ndlp->nlp_portname.u.wwn[0],
2687 ndlp->nlp_portname.u.wwn[1],
2688 ndlp->nlp_portname.u.wwn[2],
2689 ndlp->nlp_portname.u.wwn[3],
2690 ndlp->nlp_portname.u.wwn[4],
2691 ndlp->nlp_portname.u.wwn[5],
2692 ndlp->nlp_portname.u.wwn[6],
2693 ndlp->nlp_portname.u.wwn[7]);
2694
2695 index = strlen(buf);
2696
2697 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2698 sprintf(&buf[index], "%010u,",
2699 ndlp->lat_data[i].cmd_count);
2700 index = strlen(buf);
2701 }
2702 sprintf(&buf[index], "\n");
2703 index = strlen(buf);
2704 }
2705 spin_unlock_irq(shost->host_lock);
2706 return index;
2707}
2708
2709static struct bin_attribute sysfs_drvr_stat_data_attr = {
2710 .attr = {
2711 .name = "lpfc_drvr_stat_data",
2712 .mode = S_IRUSR,
2713 .owner = THIS_MODULE,
2714 },
2715 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2716 .read = sysfs_drvr_stat_data_read,
2717 .write = NULL,
2718};
2719
dea31012005-04-17 16:05:31 -05002720/*
2721# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2722# connection.
2723# 0 = auto select (default)
2724# 1 = 1 Gigabaud
2725# 2 = 2 Gigabaud
2726# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002727# 8 = 8 Gigabaud
2728# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002729*/
James Smarte59058c2008-08-24 21:49:00 -04002730
2731/**
James Smart3621a712009-04-06 18:47:14 -04002732 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002733 * @phba: lpfc_hba pointer.
2734 * @val: link speed value.
2735 *
2736 * Description:
2737 * If val is in a valid range then set the adapter's link speed field and
2738 * issue a lip; if the lip fails reset the link speed to the old value.
2739 *
2740 * Notes:
2741 * If the value is not in range log a kernel error message and return an error.
2742 *
2743 * Returns:
2744 * zero if val is in range and lip okay.
2745 * non-zero return value from lpfc_issue_lip()
2746 * -EINVAL val out of range
2747 **/
James Smarta257bf92009-04-06 18:48:10 -04002748static ssize_t
2749lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2750 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002751{
James Smarta257bf92009-04-06 18:48:10 -04002752 struct Scsi_Host *shost = class_to_shost(dev);
2753 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2754 struct lpfc_hba *phba = vport->phba;
2755 int val = 0;
2756 int nolip = 0;
2757 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002758 int err;
2759 uint32_t prev_val;
2760
James Smarta257bf92009-04-06 18:48:10 -04002761 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2762 nolip = 1;
2763 val_buf = &buf[strlen("nolip ")];
2764 }
2765
2766 if (!isdigit(val_buf[0]))
2767 return -EINVAL;
2768 if (sscanf(val_buf, "%i", &val) != 1)
2769 return -EINVAL;
2770
James Smart83108bd2008-01-11 01:53:09 -05002771 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2772 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2773 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2774 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2775 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2776 return -EINVAL;
2777
James Smarta257bf92009-04-06 18:48:10 -04002778 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002779 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2780 prev_val = phba->cfg_link_speed;
2781 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002782 if (nolip)
2783 return strlen(buf);
2784
James Smart83108bd2008-01-11 01:53:09 -05002785 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002786 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002787 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002788 return -EINVAL;
2789 } else
2790 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002791 }
2792
2793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2794 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2795 "allowed range is [0, 8]\n",
2796 phba->brd_no, val);
2797 return -EINVAL;
2798}
2799
2800static int lpfc_link_speed = 0;
2801module_param(lpfc_link_speed, int, 0);
2802MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2803lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002804
2805/**
James Smart3621a712009-04-06 18:47:14 -04002806 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002807 * @phba: lpfc_hba pointer.
2808 * @val: link speed value.
2809 *
2810 * Description:
2811 * If val is in a valid range then set the adapter's link speed field.
2812 *
2813 * Notes:
2814 * If the value is not in range log a kernel error message, clear the link
2815 * speed and return an error.
2816 *
2817 * Returns:
2818 * zero if val saved.
2819 * -EINVAL val out of range
2820 **/
James Smart83108bd2008-01-11 01:53:09 -05002821static int
2822lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2823{
2824 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2825 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2826 phba->cfg_link_speed = val;
2827 return 0;
2828 }
2829 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002830 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002831 "be set to %d, allowed values are "
2832 "["LPFC_LINK_SPEED_STRING"]\n", val);
2833 phba->cfg_link_speed = 0;
2834 return -EINVAL;
2835}
2836
Tony Jonesee959b02008-02-22 00:13:36 +01002837static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002838 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002839
2840/*
James Smart0d878412009-10-02 15:16:56 -04002841# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2842# 0 = aer disabled or not supported
2843# 1 = aer supported and enabled (default)
2844# Value range is [0,1]. Default value is 1.
2845*/
2846
2847/**
2848 * lpfc_aer_support_store - Set the adapter for aer support
2849 *
2850 * @dev: class device that is converted into a Scsi_host.
2851 * @attr: device attribute, not used.
2852 * @buf: containing the string "selective".
2853 * @count: unused variable.
2854 *
2855 * Description:
2856 * If the val is 1 and currently the device's AER capability was not
2857 * enabled, invoke the kernel's enable AER helper routine, trying to
2858 * enable the device's AER capability. If the helper routine enabling
2859 * AER returns success, update the device's cfg_aer_support flag to
2860 * indicate AER is supported by the device; otherwise, if the device
2861 * AER capability is already enabled to support AER, then do nothing.
2862 *
2863 * If the val is 0 and currently the device's AER support was enabled,
2864 * invoke the kernel's disable AER helper routine. After that, update
2865 * the device's cfg_aer_support flag to indicate AER is not supported
2866 * by the device; otherwise, if the device AER capability is already
2867 * disabled from supporting AER, then do nothing.
2868 *
2869 * Returns:
2870 * length of the buf on success if val is in range the intended mode
2871 * is supported.
2872 * -EINVAL if val out of range or intended mode is not supported.
2873 **/
2874static ssize_t
2875lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2876 const char *buf, size_t count)
2877{
2878 struct Scsi_Host *shost = class_to_shost(dev);
2879 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2880 struct lpfc_hba *phba = vport->phba;
2881 int val = 0, rc = -EINVAL;
2882
James Smart891478a2009-11-18 15:40:23 -05002883 /* AER not supported on OC devices yet */
2884 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
2885 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04002886 if (!isdigit(buf[0]))
2887 return -EINVAL;
2888 if (sscanf(buf, "%i", &val) != 1)
2889 return -EINVAL;
2890
2891 switch (val) {
2892 case 0:
2893 if (phba->hba_flag & HBA_AER_ENABLED) {
2894 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2895 if (!rc) {
2896 spin_lock_irq(&phba->hbalock);
2897 phba->hba_flag &= ~HBA_AER_ENABLED;
2898 spin_unlock_irq(&phba->hbalock);
2899 phba->cfg_aer_support = 0;
2900 rc = strlen(buf);
2901 } else
James Smart891478a2009-11-18 15:40:23 -05002902 rc = -EPERM;
2903 } else {
James Smart0d878412009-10-02 15:16:56 -04002904 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05002905 rc = strlen(buf);
2906 }
James Smart0d878412009-10-02 15:16:56 -04002907 break;
2908 case 1:
2909 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2910 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2911 if (!rc) {
2912 spin_lock_irq(&phba->hbalock);
2913 phba->hba_flag |= HBA_AER_ENABLED;
2914 spin_unlock_irq(&phba->hbalock);
2915 phba->cfg_aer_support = 1;
2916 rc = strlen(buf);
2917 } else
James Smart891478a2009-11-18 15:40:23 -05002918 rc = -EPERM;
2919 } else {
James Smart0d878412009-10-02 15:16:56 -04002920 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05002921 rc = strlen(buf);
2922 }
James Smart0d878412009-10-02 15:16:56 -04002923 break;
2924 default:
2925 rc = -EINVAL;
2926 break;
2927 }
2928 return rc;
2929}
2930
2931static int lpfc_aer_support = 1;
2932module_param(lpfc_aer_support, int, 1);
2933MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2934lpfc_param_show(aer_support)
2935
2936/**
2937 * lpfc_aer_support_init - Set the initial adapters aer support flag
2938 * @phba: lpfc_hba pointer.
2939 * @val: link speed value.
2940 *
2941 * Description:
2942 * If val is in a valid range [0,1], then set the adapter's initial
2943 * cfg_aer_support field. It will be up to the driver's probe_one
2944 * routine to determine whether the device's AER support can be set
2945 * or not.
2946 *
2947 * Notes:
2948 * If the value is not in range log a kernel error message, and
2949 * choose the default value of setting AER support and return.
2950 *
2951 * Returns:
2952 * zero if val saved.
2953 * -EINVAL val out of range
2954 **/
2955static int
2956lpfc_aer_support_init(struct lpfc_hba *phba, int val)
2957{
James Smart891478a2009-11-18 15:40:23 -05002958 /* AER not supported on OC devices yet */
2959 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
2960 phba->cfg_aer_support = 0;
2961 return -EPERM;
2962 }
2963
James Smart0d878412009-10-02 15:16:56 -04002964 if (val == 0 || val == 1) {
2965 phba->cfg_aer_support = val;
2966 return 0;
2967 }
2968 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2969 "2712 lpfc_aer_support attribute value %d out "
2970 "of range, allowed values are 0|1, setting it "
2971 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05002972 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04002973 phba->cfg_aer_support = 1;
2974 return -EINVAL;
2975}
2976
2977static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
2978 lpfc_aer_support_show, lpfc_aer_support_store);
2979
2980/**
2981 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
2982 * @dev: class device that is converted into a Scsi_host.
2983 * @attr: device attribute, not used.
2984 * @buf: containing the string "selective".
2985 * @count: unused variable.
2986 *
2987 * Description:
2988 * If the @buf contains 1 and the device currently has the AER support
2989 * enabled, then invokes the kernel AER helper routine
2990 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
2991 * error status register.
2992 *
2993 * Notes:
2994 *
2995 * Returns:
2996 * -EINVAL if the buf does not contain the 1 or the device is not currently
2997 * enabled with the AER support.
2998 **/
2999static ssize_t
3000lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3001 const char *buf, size_t count)
3002{
3003 struct Scsi_Host *shost = class_to_shost(dev);
3004 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3005 struct lpfc_hba *phba = vport->phba;
3006 int val, rc = -1;
3007
James Smart891478a2009-11-18 15:40:23 -05003008 /* AER not supported on OC devices yet */
3009 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
3010 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003011 if (!isdigit(buf[0]))
3012 return -EINVAL;
3013 if (sscanf(buf, "%i", &val) != 1)
3014 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003015 if (val != 1)
3016 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003017
James Smart891478a2009-11-18 15:40:23 -05003018 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003019 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3020
3021 if (rc == 0)
3022 return strlen(buf);
3023 else
James Smart891478a2009-11-18 15:40:23 -05003024 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003025}
3026
3027static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3028 lpfc_aer_cleanup_state);
3029
3030/*
dea31012005-04-17 16:05:31 -05003031# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3032# Value range is [2,3]. Default value is 3.
3033*/
James Smart3de2a652007-08-02 11:09:59 -04003034LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3035 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003036
3037/*
3038# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3039# is [0,1]. Default value is 0.
3040*/
James Smart3de2a652007-08-02 11:09:59 -04003041LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3042 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003043
3044/*
James Smart977b5a02008-09-07 11:52:04 -04003045# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3046# depth. Default value is 0. When the value of this parameter is zero the
3047# SCSI command completion time is not used for controlling I/O queue depth. When
3048# the parameter is set to a non-zero value, the I/O queue depth is controlled
3049# to limit the I/O completion time to the parameter value.
3050# The value is set in milliseconds.
3051*/
3052static int lpfc_max_scsicmpl_time;
3053module_param(lpfc_max_scsicmpl_time, int, 0);
3054MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3055 "Use command completion time to control queue depth");
3056lpfc_vport_param_show(max_scsicmpl_time);
3057lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3058static int
3059lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3060{
3061 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3062 struct lpfc_nodelist *ndlp, *next_ndlp;
3063
3064 if (val == vport->cfg_max_scsicmpl_time)
3065 return 0;
3066 if ((val < 0) || (val > 60000))
3067 return -EINVAL;
3068 vport->cfg_max_scsicmpl_time = val;
3069
3070 spin_lock_irq(shost->host_lock);
3071 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3072 if (!NLP_CHK_NODE_ACT(ndlp))
3073 continue;
3074 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3075 continue;
3076 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
3077 }
3078 spin_unlock_irq(shost->host_lock);
3079 return 0;
3080}
3081lpfc_vport_param_store(max_scsicmpl_time);
3082static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3083 lpfc_max_scsicmpl_time_show,
3084 lpfc_max_scsicmpl_time_store);
3085
3086/*
dea31012005-04-17 16:05:31 -05003087# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3088# range is [0,1]. Default value is 0.
3089*/
3090LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3091
3092/*
3093# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3094# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003095# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003096# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3097# cr_delay is set to 0.
3098*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003099LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003100 "interrupt response is generated");
3101
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003102LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003103 "interrupt response is generated");
3104
3105/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003106# lpfc_multi_ring_support: Determines how many rings to spread available
3107# cmd/rsp IOCB entries across.
3108# Value range is [1,2]. Default value is 1.
3109*/
3110LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3111 "SLI rings to spread IOCB entries across");
3112
3113/*
James Smarta4bc3372006-12-02 13:34:16 -05003114# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3115# identifies what rctl value to configure the additional ring for.
3116# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3117*/
James Smart6a9c52c2009-10-02 15:16:51 -04003118LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003119 255, "Identifies RCTL for additional ring configuration");
3120
3121/*
3122# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3123# identifies what type value to configure the additional ring for.
3124# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3125*/
James Smart6a9c52c2009-10-02 15:16:51 -04003126LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003127 255, "Identifies TYPE for additional ring configuration");
3128
3129/*
dea31012005-04-17 16:05:31 -05003130# lpfc_fdmi_on: controls FDMI support.
3131# 0 = no FDMI support
3132# 1 = support FDMI without attribute of hostname
3133# 2 = support FDMI with attribute of hostname
3134# Value range [0,2]. Default value is 0.
3135*/
James Smart3de2a652007-08-02 11:09:59 -04003136LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003137
3138/*
3139# Specifies the maximum number of ELS cmds we can have outstanding (for
3140# discovery). Value range is [1,64]. Default value = 32.
3141*/
James Smart3de2a652007-08-02 11:09:59 -04003142LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003143 "during discovery");
3144
3145/*
James Smart65a29c12006-07-06 15:50:50 -04003146# lpfc_max_luns: maximum allowed LUN.
3147# Value range is [0,65535]. Default value is 255.
3148# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003149*/
James Smart3de2a652007-08-02 11:09:59 -04003150LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003151
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003152/*
3153# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3154# Value range is [1,255], default value is 10.
3155*/
3156LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3157 "Milliseconds driver will wait between polling FCP ring");
3158
James Smart4ff43242006-12-02 13:34:56 -05003159/*
3160# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3161# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003162# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003163# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003164# 2 = MSI-X enabled (default)
3165# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003166*/
George Kadianakis8605c462010-01-17 21:19:31 +02003167LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003168 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003169
James Smart13815c82008-01-11 01:52:48 -05003170/*
James Smartda0436e2009-05-22 14:51:39 -04003171# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3172#
3173# Value range is [636,651042]. Default value is 10000.
3174*/
3175LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3176 "Set the maximum number of fast-path FCP interrupts per second");
3177
3178/*
3179# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3180#
3181# Value range is [1,31]. Default value is 4.
3182*/
3183LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3184 "Set the number of fast-path FCP work queues, if possible");
3185
3186/*
3187# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3188#
3189# Value range is [1,7]. Default value is 1.
3190*/
3191LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3192 "Set the number of fast-path FCP event queues, if possible");
3193
3194/*
James Smart13815c82008-01-11 01:52:48 -05003195# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3196# 0 = HBA resets disabled
3197# 1 = HBA resets enabled (default)
3198# Value range is [0,1]. Default value is 1.
3199*/
3200LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003201
James Smart13815c82008-01-11 01:52:48 -05003202/*
3203# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3204# 0 = HBA Heartbeat disabled
3205# 1 = HBA Heartbeat enabled (default)
3206# Value range is [0,1]. Default value is 1.
3207*/
3208LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003209
James Smart83108bd2008-01-11 01:53:09 -05003210/*
James Smart81301a92008-12-04 22:39:46 -05003211# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3212# 0 = BlockGuard disabled (default)
3213# 1 = BlockGuard enabled
3214# Value range is [0,1]. Default value is 0.
3215*/
3216LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3217
James Smart6fb120a2009-05-22 14:52:59 -04003218/*
James Smart81301a92008-12-04 22:39:46 -05003219# lpfc_prot_mask: i
3220# - Bit mask of host protection capabilities used to register with the
3221# SCSI mid-layer
3222# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3223# - Allows you to ultimately specify which profiles to use
3224# - Default will result in registering capabilities for all profiles.
3225#
3226*/
3227unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3228
3229module_param(lpfc_prot_mask, uint, 0);
3230MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3231
3232/*
3233# lpfc_prot_guard: i
3234# - Bit mask of protection guard types to register with the SCSI mid-layer
3235# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3236# - Allows you to ultimately specify which profiles to use
3237# - Default will result in registering capabilities for all guard types
3238#
3239*/
3240unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3241module_param(lpfc_prot_guard, byte, 0);
3242MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3243
3244
3245/*
James Smart3621a712009-04-06 18:47:14 -04003246 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003247 * This value can be set to values between 64 and 256. The default value is
3248 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3249 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3250 */
3251LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3252 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3253
James Smart81301a92008-12-04 22:39:46 -05003254LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3255 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3256 "Max Protection Scatter Gather Segment Count");
3257
Tony Jonesee959b02008-02-22 00:13:36 +01003258struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003259 &dev_attr_bg_info,
3260 &dev_attr_bg_guard_err,
3261 &dev_attr_bg_apptag_err,
3262 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003263 &dev_attr_info,
3264 &dev_attr_serialnum,
3265 &dev_attr_modeldesc,
3266 &dev_attr_modelname,
3267 &dev_attr_programtype,
3268 &dev_attr_portnum,
3269 &dev_attr_fwrev,
3270 &dev_attr_hdw,
3271 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003272 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003273 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003274 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003275 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003276 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003277 &dev_attr_lpfc_temp_sensor,
3278 &dev_attr_lpfc_log_verbose,
3279 &dev_attr_lpfc_lun_queue_depth,
3280 &dev_attr_lpfc_hba_queue_depth,
3281 &dev_attr_lpfc_peer_port_login,
3282 &dev_attr_lpfc_nodev_tmo,
3283 &dev_attr_lpfc_devloss_tmo,
3284 &dev_attr_lpfc_fcp_class,
3285 &dev_attr_lpfc_use_adisc,
3286 &dev_attr_lpfc_ack0,
3287 &dev_attr_lpfc_topology,
3288 &dev_attr_lpfc_scan_down,
3289 &dev_attr_lpfc_link_speed,
3290 &dev_attr_lpfc_cr_delay,
3291 &dev_attr_lpfc_cr_count,
3292 &dev_attr_lpfc_multi_ring_support,
3293 &dev_attr_lpfc_multi_ring_rctl,
3294 &dev_attr_lpfc_multi_ring_type,
3295 &dev_attr_lpfc_fdmi_on,
3296 &dev_attr_lpfc_max_luns,
3297 &dev_attr_lpfc_enable_npiv,
3298 &dev_attr_nport_evt_cnt,
3299 &dev_attr_board_mode,
3300 &dev_attr_max_vpi,
3301 &dev_attr_used_vpi,
3302 &dev_attr_max_rpi,
3303 &dev_attr_used_rpi,
3304 &dev_attr_max_xri,
3305 &dev_attr_used_xri,
3306 &dev_attr_npiv_info,
3307 &dev_attr_issue_reset,
3308 &dev_attr_lpfc_poll,
3309 &dev_attr_lpfc_poll_tmo,
3310 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003311 &dev_attr_lpfc_fcp_imax,
3312 &dev_attr_lpfc_fcp_wq_count,
3313 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003314 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003315 &dev_attr_lpfc_soft_wwnn,
3316 &dev_attr_lpfc_soft_wwpn,
3317 &dev_attr_lpfc_soft_wwn_enable,
3318 &dev_attr_lpfc_enable_hba_reset,
3319 &dev_attr_lpfc_enable_hba_heartbeat,
3320 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003321 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003322 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003323 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003324 &dev_attr_lpfc_aer_support,
3325 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003326 &dev_attr_lpfc_suppress_link_up,
dea31012005-04-17 16:05:31 -05003327 NULL,
3328};
3329
Tony Jonesee959b02008-02-22 00:13:36 +01003330struct device_attribute *lpfc_vport_attrs[] = {
3331 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003332 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003333 &dev_attr_num_discovered_ports,
3334 &dev_attr_lpfc_drvr_version,
3335 &dev_attr_lpfc_log_verbose,
3336 &dev_attr_lpfc_lun_queue_depth,
3337 &dev_attr_lpfc_nodev_tmo,
3338 &dev_attr_lpfc_devloss_tmo,
3339 &dev_attr_lpfc_hba_queue_depth,
3340 &dev_attr_lpfc_peer_port_login,
3341 &dev_attr_lpfc_restrict_login,
3342 &dev_attr_lpfc_fcp_class,
3343 &dev_attr_lpfc_use_adisc,
3344 &dev_attr_lpfc_fdmi_on,
3345 &dev_attr_lpfc_max_luns,
3346 &dev_attr_nport_evt_cnt,
3347 &dev_attr_npiv_info,
3348 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003349 &dev_attr_lpfc_max_scsicmpl_time,
3350 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003351 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003352 NULL,
3353};
3354
James Smarte59058c2008-08-24 21:49:00 -04003355/**
James Smart3621a712009-04-06 18:47:14 -04003356 * sysfs_ctlreg_write - Write method for writing to ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003357 * @kobj: kernel kobject that contains the kernel class device.
3358 * @bin_attr: kernel attributes passed to us.
3359 * @buf: contains the data to be written to the adapter IOREG space.
3360 * @off: offset into buffer to beginning of data.
3361 * @count: bytes to transfer.
3362 *
3363 * Description:
3364 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3365 * Uses the adapter io control registers to send buf contents to the adapter.
3366 *
3367 * Returns:
3368 * -ERANGE off and count combo out of range
3369 * -EINVAL off, count or buff address invalid
3370 * -EPERM adapter is offline
3371 * value of count, buf contents written
3372 **/
dea31012005-04-17 16:05:31 -05003373static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003374sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3375 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003376{
3377 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003378 struct device *dev = container_of(kobj, struct device, kobj);
3379 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3381 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003382
James Smartf1126682009-06-10 17:22:44 -04003383 if (phba->sli_rev >= LPFC_SLI_REV4)
3384 return -EPERM;
3385
dea31012005-04-17 16:05:31 -05003386 if ((off + count) > FF_REG_AREA_SIZE)
3387 return -ERANGE;
3388
3389 if (count == 0) return 0;
3390
3391 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3392 return -EINVAL;
3393
James Smart2e0fef82007-06-17 19:56:36 -05003394 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003395 return -EPERM;
3396 }
3397
James Smart2e0fef82007-06-17 19:56:36 -05003398 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003399 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3400 writel(*((uint32_t *)(buf + buf_off)),
3401 phba->ctrl_regs_memmap_p + off + buf_off);
3402
James Smart2e0fef82007-06-17 19:56:36 -05003403 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003404
3405 return count;
3406}
3407
James Smarte59058c2008-08-24 21:49:00 -04003408/**
James Smart3621a712009-04-06 18:47:14 -04003409 * sysfs_ctlreg_read - Read method for reading from ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003410 * @kobj: kernel kobject that contains the kernel class device.
3411 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003412 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003413 * @off: offset into buffer to beginning of data.
3414 * @count: bytes to transfer.
3415 *
3416 * Description:
3417 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3418 * Uses the adapter io control registers to read data into buf.
3419 *
3420 * Returns:
3421 * -ERANGE off and count combo out of range
3422 * -EINVAL off, count or buff address invalid
3423 * value of count, buf contents read
3424 **/
dea31012005-04-17 16:05:31 -05003425static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003426sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3427 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003428{
3429 size_t buf_off;
3430 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003431 struct device *dev = container_of(kobj, struct device, kobj);
3432 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003433 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3434 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003435
James Smartf1126682009-06-10 17:22:44 -04003436 if (phba->sli_rev >= LPFC_SLI_REV4)
3437 return -EPERM;
3438
dea31012005-04-17 16:05:31 -05003439 if (off > FF_REG_AREA_SIZE)
3440 return -ERANGE;
3441
3442 if ((off + count) > FF_REG_AREA_SIZE)
3443 count = FF_REG_AREA_SIZE - off;
3444
3445 if (count == 0) return 0;
3446
3447 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3448 return -EINVAL;
3449
James Smart2e0fef82007-06-17 19:56:36 -05003450 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003451
3452 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3453 tmp_ptr = (uint32_t *)(buf + buf_off);
3454 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3455 }
3456
James Smart2e0fef82007-06-17 19:56:36 -05003457 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003458
3459 return count;
3460}
3461
3462static struct bin_attribute sysfs_ctlreg_attr = {
3463 .attr = {
3464 .name = "ctlreg",
3465 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003466 },
3467 .size = 256,
3468 .read = sysfs_ctlreg_read,
3469 .write = sysfs_ctlreg_write,
3470};
3471
James Smarte59058c2008-08-24 21:49:00 -04003472/**
James Smart3621a712009-04-06 18:47:14 -04003473 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003474 * @phba: lpfc_hba pointer
3475 **/
dea31012005-04-17 16:05:31 -05003476static void
James Smart2e0fef82007-06-17 19:56:36 -05003477sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003478{
3479 phba->sysfs_mbox.state = SMBOX_IDLE;
3480 phba->sysfs_mbox.offset = 0;
3481
3482 if (phba->sysfs_mbox.mbox) {
3483 mempool_free(phba->sysfs_mbox.mbox,
3484 phba->mbox_mem_pool);
3485 phba->sysfs_mbox.mbox = NULL;
3486 }
3487}
3488
James Smarte59058c2008-08-24 21:49:00 -04003489/**
James Smart3621a712009-04-06 18:47:14 -04003490 * sysfs_mbox_write - Write method for writing information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003491 * @kobj: kernel kobject that contains the kernel class device.
3492 * @bin_attr: kernel attributes passed to us.
3493 * @buf: contains the data to be written to sysfs mbox.
3494 * @off: offset into buffer to beginning of data.
3495 * @count: bytes to transfer.
3496 *
3497 * Description:
3498 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3499 * Uses the sysfs mbox to send buf contents to the adapter.
3500 *
3501 * Returns:
3502 * -ERANGE off and count combo out of range
3503 * -EINVAL off, count or buff address invalid
3504 * zero if count is zero
3505 * -EPERM adapter is offline
3506 * -ENOMEM failed to allocate memory for the mail box
3507 * -EAGAIN offset, state or mbox is NULL
3508 * count number of bytes transferred
3509 **/
dea31012005-04-17 16:05:31 -05003510static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003511sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3512 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003513{
Tony Jonesee959b02008-02-22 00:13:36 +01003514 struct device *dev = container_of(kobj, struct device, kobj);
3515 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3517 struct lpfc_hba *phba = vport->phba;
3518 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003519
3520 if ((count + off) > MAILBOX_CMD_SIZE)
3521 return -ERANGE;
3522
3523 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3524 return -EINVAL;
3525
3526 if (count == 0)
3527 return 0;
3528
3529 if (off == 0) {
3530 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3531 if (!mbox)
3532 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003533 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003534 }
3535
James Smart2e0fef82007-06-17 19:56:36 -05003536 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003537
3538 if (off == 0) {
3539 if (phba->sysfs_mbox.mbox)
3540 mempool_free(mbox, phba->mbox_mem_pool);
3541 else
3542 phba->sysfs_mbox.mbox = mbox;
3543 phba->sysfs_mbox.state = SMBOX_WRITING;
3544 } else {
3545 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3546 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003547 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003548 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003549 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003550 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003551 }
3552 }
3553
James Smart04c68492009-05-22 14:52:52 -04003554 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003555 buf, count);
3556
3557 phba->sysfs_mbox.offset = off + count;
3558
James Smart2e0fef82007-06-17 19:56:36 -05003559 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003560
3561 return count;
3562}
3563
James Smarte59058c2008-08-24 21:49:00 -04003564/**
James Smart3621a712009-04-06 18:47:14 -04003565 * sysfs_mbox_read - Read method for reading information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003566 * @kobj: kernel kobject that contains the kernel class device.
3567 * @bin_attr: kernel attributes passed to us.
3568 * @buf: contains the data to be read from sysfs mbox.
3569 * @off: offset into buffer to beginning of data.
3570 * @count: bytes to transfer.
3571 *
3572 * Description:
3573 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3574 * Uses the sysfs mbox to receive data from to the adapter.
3575 *
3576 * Returns:
3577 * -ERANGE off greater than mailbox command size
3578 * -EINVAL off, count or buff address invalid
3579 * zero if off and count are zero
3580 * -EACCES adapter over temp
3581 * -EPERM garbage can value to catch a multitude of errors
3582 * -EAGAIN management IO not permitted, state or off error
3583 * -ETIME mailbox timeout
3584 * -ENODEV mailbox error
3585 * count number of bytes transferred
3586 **/
dea31012005-04-17 16:05:31 -05003587static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003588sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3589 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003590{
Tony Jonesee959b02008-02-22 00:13:36 +01003591 struct device *dev = container_of(kobj, struct device, kobj);
3592 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003593 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3594 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003595 int rc;
James Smart04c68492009-05-22 14:52:52 -04003596 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003597
James Smart1dcb58e2007-04-25 09:51:30 -04003598 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003599 return -ERANGE;
3600
James Smart1dcb58e2007-04-25 09:51:30 -04003601 if ((count + off) > MAILBOX_CMD_SIZE)
3602 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003603
3604 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3605 return -EINVAL;
3606
3607 if (off && count == 0)
3608 return 0;
3609
James Smart2e0fef82007-06-17 19:56:36 -05003610 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003611
James Smart7af67052007-10-27 13:38:11 -04003612 if (phba->over_temp_state == HBA_OVER_TEMP) {
3613 sysfs_mbox_idle(phba);
3614 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003615 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003616 }
3617
dea31012005-04-17 16:05:31 -05003618 if (off == 0 &&
3619 phba->sysfs_mbox.state == SMBOX_WRITING &&
3620 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003621 pmb = &phba->sysfs_mbox.mbox->u.mb;
3622 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003623 /* Offline only */
dea31012005-04-17 16:05:31 -05003624 case MBX_INIT_LINK:
3625 case MBX_DOWN_LINK:
3626 case MBX_CONFIG_LINK:
3627 case MBX_CONFIG_RING:
3628 case MBX_RESET_RING:
3629 case MBX_UNREG_LOGIN:
3630 case MBX_CLEAR_LA:
3631 case MBX_DUMP_CONTEXT:
3632 case MBX_RUN_DIAGS:
3633 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003634 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003635 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003636 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003637 printk(KERN_WARNING "mbox_read:Command 0x%x "
3638 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003639 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003640 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003641 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003642 return -EPERM;
3643 }
James Smarta8adb832007-10-27 13:37:53 -04003644 case MBX_WRITE_NV:
3645 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003646 case MBX_LOAD_SM:
3647 case MBX_READ_NV:
3648 case MBX_READ_CONFIG:
3649 case MBX_READ_RCONFIG:
3650 case MBX_READ_STATUS:
3651 case MBX_READ_XRI:
3652 case MBX_READ_REV:
3653 case MBX_READ_LNK_STAT:
3654 case MBX_DUMP_MEMORY:
3655 case MBX_DOWN_LOAD:
3656 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003657 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003658 case MBX_LOAD_AREA:
3659 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003660 case MBX_BEACON:
3661 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003662 case MBX_SET_VARIABLE:
3663 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003664 case MBX_PORT_CAPABILITIES:
3665 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003666 break;
3667 case MBX_READ_SPARM64:
3668 case MBX_READ_LA:
3669 case MBX_READ_LA64:
3670 case MBX_REG_LOGIN:
3671 case MBX_REG_LOGIN64:
3672 case MBX_CONFIG_PORT:
3673 case MBX_RUN_BIU_DIAG:
3674 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003675 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003676 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003677 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003678 return -EPERM;
3679 default:
3680 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003681 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003682 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003683 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003684 return -EPERM;
3685 }
3686
James Smart09372822008-01-11 01:52:54 -05003687 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003688 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003689 */
James Smartd7c255b2008-08-24 21:50:00 -04003690 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003691 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3692 pmb->mbxCommand != MBX_RESTART &&
3693 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3694 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003695 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3696 "1259 mbox: Issued mailbox cmd "
3697 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003698 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003699
James Smart92d7f7b2007-06-17 19:56:38 -05003700 phba->sysfs_mbox.mbox->vport = vport;
3701
James Smart58da1ff2008-04-07 10:15:56 -04003702 /* Don't allow mailbox commands to be sent when blocked
3703 * or when in the middle of discovery
3704 */
James Smart495a7142008-06-14 22:52:59 -04003705 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003706 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003707 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003708 return -EAGAIN;
3709 }
3710
James Smart2e0fef82007-06-17 19:56:36 -05003711 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003712 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003713
James Smart2e0fef82007-06-17 19:56:36 -05003714 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003715 rc = lpfc_sli_issue_mbox (phba,
3716 phba->sysfs_mbox.mbox,
3717 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003718 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003719
3720 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003721 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003722 rc = lpfc_sli_issue_mbox_wait (phba,
3723 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003724 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003725 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003726 }
3727
3728 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003729 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003730 phba->sysfs_mbox.mbox = NULL;
3731 }
dea31012005-04-17 16:05:31 -05003732 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003733 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003734 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003735 }
3736 phba->sysfs_mbox.state = SMBOX_READING;
3737 }
3738 else if (phba->sysfs_mbox.offset != off ||
3739 phba->sysfs_mbox.state != SMBOX_READING) {
3740 printk(KERN_WARNING "mbox_read: Bad State\n");
3741 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003742 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003743 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003744 }
3745
James Smart04c68492009-05-22 14:52:52 -04003746 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003747
3748 phba->sysfs_mbox.offset = off + count;
3749
James Smart1dcb58e2007-04-25 09:51:30 -04003750 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003751 sysfs_mbox_idle(phba);
3752
James Smart2e0fef82007-06-17 19:56:36 -05003753 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003754
3755 return count;
3756}
3757
3758static struct bin_attribute sysfs_mbox_attr = {
3759 .attr = {
3760 .name = "mbox",
3761 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003762 },
James Smart1dcb58e2007-04-25 09:51:30 -04003763 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003764 .read = sysfs_mbox_read,
3765 .write = sysfs_mbox_write,
3766};
3767
James Smarte59058c2008-08-24 21:49:00 -04003768/**
James Smart3621a712009-04-06 18:47:14 -04003769 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003770 * @vport: address of lpfc vport structure.
3771 *
3772 * Return codes:
3773 * zero on success
3774 * error return code from sysfs_create_bin_file()
3775 **/
dea31012005-04-17 16:05:31 -05003776int
James Smart2e0fef82007-06-17 19:56:36 -05003777lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003778{
James Smart2e0fef82007-06-17 19:56:36 -05003779 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003780 int error;
3781
Tony Jonesee959b02008-02-22 00:13:36 +01003782 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003783 &sysfs_drvr_stat_data_attr);
3784
3785 /* Virtual ports do not need ctrl_reg and mbox */
3786 if (error || vport->port_type == LPFC_NPIV_PORT)
3787 goto out;
3788
3789 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003790 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003791 if (error)
James Smarteada2722008-12-04 22:39:13 -05003792 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003793
Tony Jonesee959b02008-02-22 00:13:36 +01003794 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003795 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003796 if (error)
3797 goto out_remove_ctlreg_attr;
3798
3799 return 0;
3800out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003801 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003802out_remove_stat_attr:
3803 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3804 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003805out:
3806 return error;
3807}
3808
James Smarte59058c2008-08-24 21:49:00 -04003809/**
James Smart3621a712009-04-06 18:47:14 -04003810 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003811 * @vport: address of lpfc vport structure.
3812 **/
dea31012005-04-17 16:05:31 -05003813void
James Smart2e0fef82007-06-17 19:56:36 -05003814lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003815{
James Smart2e0fef82007-06-17 19:56:36 -05003816 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003817 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3818 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003819 /* Virtual ports do not need ctrl_reg and mbox */
3820 if (vport->port_type == LPFC_NPIV_PORT)
3821 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003822 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3823 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003824}
3825
3826
3827/*
3828 * Dynamic FC Host Attributes Support
3829 */
3830
James Smarte59058c2008-08-24 21:49:00 -04003831/**
James Smart3621a712009-04-06 18:47:14 -04003832 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003833 * @shost: kernel scsi host pointer.
3834 **/
dea31012005-04-17 16:05:31 -05003835static void
3836lpfc_get_host_port_id(struct Scsi_Host *shost)
3837{
James Smart2e0fef82007-06-17 19:56:36 -05003838 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3839
dea31012005-04-17 16:05:31 -05003840 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003841 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003842}
3843
James Smarte59058c2008-08-24 21:49:00 -04003844/**
James Smart3621a712009-04-06 18:47:14 -04003845 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003846 * @shost: kernel scsi host pointer.
3847 **/
dea31012005-04-17 16:05:31 -05003848static void
3849lpfc_get_host_port_type(struct Scsi_Host *shost)
3850{
James Smart2e0fef82007-06-17 19:56:36 -05003851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3852 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003853
3854 spin_lock_irq(shost->host_lock);
3855
James Smart92d7f7b2007-06-17 19:56:38 -05003856 if (vport->port_type == LPFC_NPIV_PORT) {
3857 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3858 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003859 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003860 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003861 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3862 else
3863 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3864 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003865 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003866 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3867 else
3868 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3869 }
3870 } else
3871 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3872
3873 spin_unlock_irq(shost->host_lock);
3874}
3875
James Smarte59058c2008-08-24 21:49:00 -04003876/**
James Smart3621a712009-04-06 18:47:14 -04003877 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003878 * @shost: kernel scsi host pointer.
3879 **/
dea31012005-04-17 16:05:31 -05003880static void
3881lpfc_get_host_port_state(struct Scsi_Host *shost)
3882{
James Smart2e0fef82007-06-17 19:56:36 -05003883 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3884 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003885
3886 spin_lock_irq(shost->host_lock);
3887
James Smart2e0fef82007-06-17 19:56:36 -05003888 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003889 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3890 else {
James Smart2e0fef82007-06-17 19:56:36 -05003891 switch (phba->link_state) {
3892 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003893 case LPFC_LINK_DOWN:
3894 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3895 break;
3896 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003897 case LPFC_CLEAR_LA:
3898 case LPFC_HBA_READY:
3899 /* Links up, beyond this port_type reports state */
3900 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3901 break;
3902 case LPFC_HBA_ERROR:
3903 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3904 break;
3905 default:
3906 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3907 break;
3908 }
3909 }
3910
3911 spin_unlock_irq(shost->host_lock);
3912}
3913
James Smarte59058c2008-08-24 21:49:00 -04003914/**
James Smart3621a712009-04-06 18:47:14 -04003915 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003916 * @shost: kernel scsi host pointer.
3917 **/
dea31012005-04-17 16:05:31 -05003918static void
3919lpfc_get_host_speed(struct Scsi_Host *shost)
3920{
James Smart2e0fef82007-06-17 19:56:36 -05003921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3922 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003923
3924 spin_lock_irq(shost->host_lock);
3925
James Smart2e0fef82007-06-17 19:56:36 -05003926 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003927 switch(phba->fc_linkspeed) {
3928 case LA_1GHZ_LINK:
3929 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3930 break;
3931 case LA_2GHZ_LINK:
3932 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3933 break;
3934 case LA_4GHZ_LINK:
3935 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3936 break;
James Smartb87eab32007-04-25 09:53:28 -04003937 case LA_8GHZ_LINK:
3938 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3939 break;
James Smartf4b4c682009-05-22 14:53:12 -04003940 case LA_10GHZ_LINK:
3941 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3942 break;
dea31012005-04-17 16:05:31 -05003943 default:
3944 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3945 break;
3946 }
James Smart09372822008-01-11 01:52:54 -05003947 } else
3948 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003949
3950 spin_unlock_irq(shost->host_lock);
3951}
3952
James Smarte59058c2008-08-24 21:49:00 -04003953/**
James Smart3621a712009-04-06 18:47:14 -04003954 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04003955 * @shost: kernel scsi host pointer.
3956 **/
dea31012005-04-17 16:05:31 -05003957static void
3958lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3959{
James Smart2e0fef82007-06-17 19:56:36 -05003960 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3961 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003962 u64 node_name;
dea31012005-04-17 16:05:31 -05003963
3964 spin_lock_irq(shost->host_lock);
3965
James Smart2e0fef82007-06-17 19:56:36 -05003966 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003967 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003968 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003969 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003970 else
3971 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003972 node_name = 0;
dea31012005-04-17 16:05:31 -05003973
3974 spin_unlock_irq(shost->host_lock);
3975
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003976 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003977}
3978
James Smarte59058c2008-08-24 21:49:00 -04003979/**
James Smart3621a712009-04-06 18:47:14 -04003980 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04003981 * @shost: kernel scsi host pointer.
3982 *
3983 * Notes:
3984 * NULL on error for link down, no mbox pool, sli2 active,
3985 * management not allowed, memory allocation error, or mbox error.
3986 *
3987 * Returns:
3988 * NULL for error
3989 * address of the adapter host statistics
3990 **/
dea31012005-04-17 16:05:31 -05003991static struct fc_host_statistics *
3992lpfc_get_stats(struct Scsi_Host *shost)
3993{
James Smart2e0fef82007-06-17 19:56:36 -05003994 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3995 struct lpfc_hba *phba = vport->phba;
3996 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003997 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003998 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003999 LPFC_MBOXQ_t *pmboxq;
4000 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004001 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004002 int rc = 0;
dea31012005-04-17 16:05:31 -05004003
James Smart92d7f7b2007-06-17 19:56:38 -05004004 /*
4005 * prevent udev from issuing mailbox commands until the port is
4006 * configured.
4007 */
James Smart2e0fef82007-06-17 19:56:36 -05004008 if (phba->link_state < LPFC_LINK_DOWN ||
4009 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004010 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004011 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004012
4013 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004014 return NULL;
4015
dea31012005-04-17 16:05:31 -05004016 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4017 if (!pmboxq)
4018 return NULL;
4019 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4020
James Smart04c68492009-05-22 14:52:52 -04004021 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004022 pmb->mbxCommand = MBX_READ_STATUS;
4023 pmb->mbxOwner = OWN_HOST;
4024 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004025 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004026
James Smart2e0fef82007-06-17 19:56:36 -05004027 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart04c68492009-05-22 14:52:52 -04004028 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05004029 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004030 else
dea31012005-04-17 16:05:31 -05004031 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4032
4033 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004034 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004035 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004036 return NULL;
4037 }
4038
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004039 memset(hs, 0, sizeof (struct fc_host_statistics));
4040
dea31012005-04-17 16:05:31 -05004041 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4042 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4043 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4044 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4045
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004046 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004047 pmb->mbxCommand = MBX_READ_LNK_STAT;
4048 pmb->mbxOwner = OWN_HOST;
4049 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004050 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004051
James Smart2e0fef82007-06-17 19:56:36 -05004052 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004053 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05004054 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004055 else
dea31012005-04-17 16:05:31 -05004056 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4057
4058 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004059 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004060 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004061 return NULL;
4062 }
4063
4064 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4065 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4066 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4067 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4068 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4069 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4070 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4071
James Smart64ba8812006-08-02 15:24:34 -04004072 hs->link_failure_count -= lso->link_failure_count;
4073 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4074 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4075 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4076 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4077 hs->invalid_crc_count -= lso->invalid_crc_count;
4078 hs->error_frames -= lso->error_frames;
4079
James Smart4d9ab992009-10-02 15:16:39 -04004080 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4081 hs->lip_count = -1;
4082 hs->nos_count = (phba->link_events >> 1);
4083 hs->nos_count -= lso->link_events;
4084 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004085 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004086 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004087 hs->nos_count = -1;
4088 } else {
4089 hs->lip_count = -1;
4090 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004091 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004092 }
4093
4094 hs->dumped_frames = -1;
4095
James Smart64ba8812006-08-02 15:24:34 -04004096 seconds = get_seconds();
4097 if (seconds < psli->stats_start)
4098 hs->seconds_since_last_reset = seconds +
4099 ((unsigned long)-1 - psli->stats_start);
4100 else
4101 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004102
James Smart1dcb58e2007-04-25 09:51:30 -04004103 mempool_free(pmboxq, phba->mbox_mem_pool);
4104
dea31012005-04-17 16:05:31 -05004105 return hs;
4106}
4107
James Smarte59058c2008-08-24 21:49:00 -04004108/**
James Smart3621a712009-04-06 18:47:14 -04004109 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004110 * @shost: kernel scsi host pointer.
4111 **/
James Smart64ba8812006-08-02 15:24:34 -04004112static void
4113lpfc_reset_stats(struct Scsi_Host *shost)
4114{
James Smart2e0fef82007-06-17 19:56:36 -05004115 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4116 struct lpfc_hba *phba = vport->phba;
4117 struct lpfc_sli *psli = &phba->sli;
4118 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004119 LPFC_MBOXQ_t *pmboxq;
4120 MAILBOX_t *pmb;
4121 int rc = 0;
4122
James Smart2e0fef82007-06-17 19:56:36 -05004123 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004124 return;
4125
James Smart64ba8812006-08-02 15:24:34 -04004126 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4127 if (!pmboxq)
4128 return;
4129 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4130
James Smart04c68492009-05-22 14:52:52 -04004131 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004132 pmb->mbxCommand = MBX_READ_STATUS;
4133 pmb->mbxOwner = OWN_HOST;
4134 pmb->un.varWords[0] = 0x1; /* reset request */
4135 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004136 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004137
James Smart2e0fef82007-06-17 19:56:36 -05004138 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004139 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004140 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4141 else
4142 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4143
4144 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004145 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004146 mempool_free(pmboxq, phba->mbox_mem_pool);
4147 return;
4148 }
4149
4150 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4151 pmb->mbxCommand = MBX_READ_LNK_STAT;
4152 pmb->mbxOwner = OWN_HOST;
4153 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004154 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004155
James Smart2e0fef82007-06-17 19:56:36 -05004156 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004157 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004158 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4159 else
4160 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4161
4162 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004163 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004164 mempool_free( pmboxq, phba->mbox_mem_pool);
4165 return;
4166 }
4167
4168 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4169 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4170 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4171 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4172 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4173 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4174 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004175 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4176 lso->link_events = (phba->link_events >> 1);
4177 else
4178 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004179
4180 psli->stats_start = get_seconds();
4181
James Smart1dcb58e2007-04-25 09:51:30 -04004182 mempool_free(pmboxq, phba->mbox_mem_pool);
4183
James Smart64ba8812006-08-02 15:24:34 -04004184 return;
4185}
dea31012005-04-17 16:05:31 -05004186
4187/*
4188 * The LPFC driver treats linkdown handling as target loss events so there
4189 * are no sysfs handlers for link_down_tmo.
4190 */
James Smart685f0bf2007-04-25 09:53:08 -04004191
James Smarte59058c2008-08-24 21:49:00 -04004192/**
James Smart3621a712009-04-06 18:47:14 -04004193 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004194 * @starget: kernel scsi target pointer.
4195 *
4196 * Returns:
4197 * address of the node list if found
4198 * NULL target not found
4199 **/
James Smart685f0bf2007-04-25 09:53:08 -04004200static struct lpfc_nodelist *
4201lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004202{
James Smart2e0fef82007-06-17 19:56:36 -05004203 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4204 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004205 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004206
4207 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004208 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004209 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004210 if (NLP_CHK_NODE_ACT(ndlp) &&
4211 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004212 starget->id == ndlp->nlp_sid) {
4213 spin_unlock_irq(shost->host_lock);
4214 return ndlp;
dea31012005-04-17 16:05:31 -05004215 }
4216 }
4217 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004218 return NULL;
4219}
dea31012005-04-17 16:05:31 -05004220
James Smarte59058c2008-08-24 21:49:00 -04004221/**
James Smart3621a712009-04-06 18:47:14 -04004222 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004223 * @starget: kernel scsi target pointer.
4224 **/
James Smart685f0bf2007-04-25 09:53:08 -04004225static void
4226lpfc_get_starget_port_id(struct scsi_target *starget)
4227{
4228 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4229
4230 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004231}
4232
James Smarte59058c2008-08-24 21:49:00 -04004233/**
James Smart3621a712009-04-06 18:47:14 -04004234 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004235 * @starget: kernel scsi target pointer.
4236 *
4237 * Description: Set the target node name to the ndlp node name wwn or zero.
4238 **/
dea31012005-04-17 16:05:31 -05004239static void
4240lpfc_get_starget_node_name(struct scsi_target *starget)
4241{
James Smart685f0bf2007-04-25 09:53:08 -04004242 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004243
James Smart685f0bf2007-04-25 09:53:08 -04004244 fc_starget_node_name(starget) =
4245 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004246}
4247
James Smarte59058c2008-08-24 21:49:00 -04004248/**
James Smart3621a712009-04-06 18:47:14 -04004249 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004250 * @starget: kernel scsi target pointer.
4251 *
4252 * Description: set the target port name to the ndlp port name wwn or zero.
4253 **/
dea31012005-04-17 16:05:31 -05004254static void
4255lpfc_get_starget_port_name(struct scsi_target *starget)
4256{
James Smart685f0bf2007-04-25 09:53:08 -04004257 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004258
James Smart685f0bf2007-04-25 09:53:08 -04004259 fc_starget_port_name(starget) =
4260 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004261}
4262
James Smarte59058c2008-08-24 21:49:00 -04004263/**
James Smart3621a712009-04-06 18:47:14 -04004264 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004265 * @rport: fc rport address.
4266 * @timeout: new value for dev loss tmo.
4267 *
4268 * Description:
4269 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4270 * dev_loss_tmo to one.
4271 **/
dea31012005-04-17 16:05:31 -05004272static void
dea31012005-04-17 16:05:31 -05004273lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4274{
dea31012005-04-17 16:05:31 -05004275 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004276 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004277 else
James Smartc01f3202006-08-18 17:47:08 -04004278 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004279}
4280
James Smarte59058c2008-08-24 21:49:00 -04004281/**
James Smart3621a712009-04-06 18:47:14 -04004282 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004283 *
4284 * Description:
4285 * Macro that uses field to generate a function with the name lpfc_show_rport_
4286 *
4287 * lpfc_show_rport_##field: returns the bytes formatted in buf
4288 * @cdev: class converted to an fc_rport.
4289 * @buf: on return contains the target_field or zero.
4290 *
4291 * Returns: size of formatted string.
4292 **/
dea31012005-04-17 16:05:31 -05004293#define lpfc_rport_show_function(field, format_string, sz, cast) \
4294static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004295lpfc_show_rport_##field (struct device *dev, \
4296 struct device_attribute *attr, \
4297 char *buf) \
dea31012005-04-17 16:05:31 -05004298{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004299 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004300 struct lpfc_rport_data *rdata = rport->hostdata; \
4301 return snprintf(buf, sz, format_string, \
4302 (rdata->target) ? cast rdata->target->field : 0); \
4303}
4304
4305#define lpfc_rport_rd_attr(field, format_string, sz) \
4306 lpfc_rport_show_function(field, format_string, sz, ) \
4307static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4308
James Smarteada2722008-12-04 22:39:13 -05004309/**
James Smart3621a712009-04-06 18:47:14 -04004310 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004311 * @fc_vport: The fc_vport who's symbolic name has been changed.
4312 *
4313 * Description:
4314 * This function is called by the transport after the @fc_vport's symbolic name
4315 * has been changed. This function re-registers the symbolic name with the
4316 * switch to propogate the change into the fabric if the vport is active.
4317 **/
4318static void
4319lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4320{
4321 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4322
4323 if (vport->port_state == LPFC_VPORT_READY)
4324 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4325}
dea31012005-04-17 16:05:31 -05004326
James Smartf4b4c682009-05-22 14:53:12 -04004327/**
4328 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4329 * @phba: Pointer to lpfc_hba struct.
4330 *
4331 * This function is called by the lpfc_get_cfgparam() routine to set the
4332 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4333 * log messsage according to the module's lpfc_log_verbose parameter setting
4334 * before hba port or vport created.
4335 **/
4336static void
4337lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4338{
4339 phba->cfg_log_verbose = verbose;
4340}
4341
dea31012005-04-17 16:05:31 -05004342struct fc_function_template lpfc_transport_functions = {
4343 /* fixed attributes the driver supports */
4344 .show_host_node_name = 1,
4345 .show_host_port_name = 1,
4346 .show_host_supported_classes = 1,
4347 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004348 .show_host_supported_speeds = 1,
4349 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004350 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004351
4352 /* dynamic attributes the driver supports */
4353 .get_host_port_id = lpfc_get_host_port_id,
4354 .show_host_port_id = 1,
4355
4356 .get_host_port_type = lpfc_get_host_port_type,
4357 .show_host_port_type = 1,
4358
4359 .get_host_port_state = lpfc_get_host_port_state,
4360 .show_host_port_state = 1,
4361
4362 /* active_fc4s is shown but doesn't change (thus no get function) */
4363 .show_host_active_fc4s = 1,
4364
4365 .get_host_speed = lpfc_get_host_speed,
4366 .show_host_speed = 1,
4367
4368 .get_host_fabric_name = lpfc_get_host_fabric_name,
4369 .show_host_fabric_name = 1,
4370
4371 /*
4372 * The LPFC driver treats linkdown handling as target loss events
4373 * so there are no sysfs handlers for link_down_tmo.
4374 */
4375
4376 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004377 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004378
4379 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4380 .show_rport_maxframe_size = 1,
4381 .show_rport_supported_classes = 1,
4382
dea31012005-04-17 16:05:31 -05004383 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4384 .show_rport_dev_loss_tmo = 1,
4385
4386 .get_starget_port_id = lpfc_get_starget_port_id,
4387 .show_starget_port_id = 1,
4388
4389 .get_starget_node_name = lpfc_get_starget_node_name,
4390 .show_starget_node_name = 1,
4391
4392 .get_starget_port_name = lpfc_get_starget_port_name,
4393 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004394
4395 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004396 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4397 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004398
James Smart92d7f7b2007-06-17 19:56:38 -05004399 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004400
4401 .vport_disable = lpfc_vport_disable,
4402
4403 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004404
4405 .bsg_request = lpfc_bsg_request,
4406 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004407};
4408
James Smart98c9ea52007-10-27 13:37:33 -04004409struct fc_function_template lpfc_vport_transport_functions = {
4410 /* fixed attributes the driver supports */
4411 .show_host_node_name = 1,
4412 .show_host_port_name = 1,
4413 .show_host_supported_classes = 1,
4414 .show_host_supported_fc4s = 1,
4415 .show_host_supported_speeds = 1,
4416 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004417 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004418
4419 /* dynamic attributes the driver supports */
4420 .get_host_port_id = lpfc_get_host_port_id,
4421 .show_host_port_id = 1,
4422
4423 .get_host_port_type = lpfc_get_host_port_type,
4424 .show_host_port_type = 1,
4425
4426 .get_host_port_state = lpfc_get_host_port_state,
4427 .show_host_port_state = 1,
4428
4429 /* active_fc4s is shown but doesn't change (thus no get function) */
4430 .show_host_active_fc4s = 1,
4431
4432 .get_host_speed = lpfc_get_host_speed,
4433 .show_host_speed = 1,
4434
4435 .get_host_fabric_name = lpfc_get_host_fabric_name,
4436 .show_host_fabric_name = 1,
4437
4438 /*
4439 * The LPFC driver treats linkdown handling as target loss events
4440 * so there are no sysfs handlers for link_down_tmo.
4441 */
4442
4443 .get_fc_host_stats = lpfc_get_stats,
4444 .reset_fc_host_stats = lpfc_reset_stats,
4445
4446 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4447 .show_rport_maxframe_size = 1,
4448 .show_rport_supported_classes = 1,
4449
4450 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4451 .show_rport_dev_loss_tmo = 1,
4452
4453 .get_starget_port_id = lpfc_get_starget_port_id,
4454 .show_starget_port_id = 1,
4455
4456 .get_starget_node_name = lpfc_get_starget_node_name,
4457 .show_starget_node_name = 1,
4458
4459 .get_starget_port_name = lpfc_get_starget_port_name,
4460 .show_starget_port_name = 1,
4461
4462 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4463 .terminate_rport_io = lpfc_terminate_rport_io,
4464
4465 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004466
4467 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004468};
4469
James Smarte59058c2008-08-24 21:49:00 -04004470/**
James Smart3621a712009-04-06 18:47:14 -04004471 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004472 * @phba: lpfc_hba pointer.
4473 **/
dea31012005-04-17 16:05:31 -05004474void
4475lpfc_get_cfgparam(struct lpfc_hba *phba)
4476{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004477 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4478 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004479 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004480 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4481 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004482 lpfc_ack0_init(phba, lpfc_ack0);
4483 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004484 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004485 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004486 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004487 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004488 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4489 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4490 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004491 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4492 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004493 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004494 if (phba->sli_rev == LPFC_SLI_REV4)
4495 phba->cfg_poll = 0;
4496 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004497 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004498 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004499 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004500 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004501 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004502 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004503 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004504 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004505 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart3de2a652007-08-02 11:09:59 -04004506 return;
4507}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004508
James Smarte59058c2008-08-24 21:49:00 -04004509/**
James Smart3621a712009-04-06 18:47:14 -04004510 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004511 * @vport: lpfc_vport pointer.
4512 **/
James Smart3de2a652007-08-02 11:09:59 -04004513void
4514lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4515{
James Smarte8b62012007-08-02 11:10:09 -04004516 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004517 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4518 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4519 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4520 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4521 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4522 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4523 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004524 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004525 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4526 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4527 lpfc_max_luns_init(vport, lpfc_max_luns);
4528 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004529 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004530 return;
4531}