blob: 91542f786edfb61500b7595d77ef20e78b8dea20 [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 Smart3621a712009-04-06 18:47:14 -0400485 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400486 * @dev: class device that is converted into a Scsi_host.
487 * @attr: device attribute, not used.
488 * @buf: on return contains the sum of fc mapped and unmapped.
489 *
490 * Description:
491 * Returns the ascii text number of the sum of the fc mapped and unmapped
492 * vport counts.
493 *
494 * Returns: size of formatted string.
495 **/
dea31012005-04-17 16:05:31 -0500496static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100497lpfc_num_discovered_ports_show(struct device *dev,
498 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500499{
Tony Jonesee959b02008-02-22 00:13:36 +0100500 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
502
503 return snprintf(buf, PAGE_SIZE, "%d\n",
504 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500505}
506
James Smarte59058c2008-08-24 21:49:00 -0400507/**
James Smart3621a712009-04-06 18:47:14 -0400508 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400509 * @shost: Scsi_Host pointer.
510 *
511 * Description:
512 * Bring the link down gracefully then re-init the link. The firmware will
513 * re-init the fiber channel interface as required. Does not issue a LIP.
514 *
515 * Returns:
516 * -EPERM port offline or management commands are being blocked
517 * -ENOMEM cannot allocate memory for the mailbox command
518 * -EIO error sending the mailbox command
519 * zero for success
520 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700521static int
James Smart2e0fef82007-06-17 19:56:36 -0500522lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500523{
James Smart2e0fef82007-06-17 19:56:36 -0500524 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
525 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500526 LPFC_MBOXQ_t *pmboxq;
527 int mbxstatus = MBXERR_ERROR;
528
James Smart2e0fef82007-06-17 19:56:36 -0500529 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500530 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500531 return -EPERM;
532
533 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
534
535 if (!pmboxq)
536 return -ENOMEM;
537
538 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400539 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
540 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400541
James Smart33ccf8d2006-08-17 11:57:58 -0400542 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500543
James Smart04c68492009-05-22 14:52:52 -0400544 if ((mbxstatus == MBX_SUCCESS) &&
545 (pmboxq->u.mb.mbxStatus == 0 ||
546 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400547 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
548 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
549 phba->cfg_link_speed);
550 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
551 phba->fc_ratov * 2);
552 }
553
James Smart5b8bd0c2007-04-25 09:52:49 -0400554 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500555 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400556 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500557
558 if (mbxstatus == MBXERR_ERROR)
559 return -EIO;
560
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700561 return 0;
dea31012005-04-17 16:05:31 -0500562}
563
James Smarte59058c2008-08-24 21:49:00 -0400564/**
James Smart3621a712009-04-06 18:47:14 -0400565 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400566 * @phba: lpfc_hba pointer.
567 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
568 *
569 * Notes:
570 * Assumes any error from lpfc_do_offline() will be negative.
571 * Can wait up to 5 seconds for the port ring buffers count
572 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400573 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400574 *
575 * Returns:
576 * -EIO error posting the event
577 * zero for success
578 **/
James Smart40496f02006-07-06 15:50:22 -0400579static int
James Smart46fa3112007-04-25 09:51:45 -0400580lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
581{
582 struct completion online_compl;
583 struct lpfc_sli_ring *pring;
584 struct lpfc_sli *psli;
585 int status = 0;
586 int cnt = 0;
587 int i;
588
589 init_completion(&online_compl);
590 lpfc_workq_post_event(phba, &status, &online_compl,
591 LPFC_EVT_OFFLINE_PREP);
592 wait_for_completion(&online_compl);
593
594 if (status != 0)
595 return -EIO;
596
597 psli = &phba->sli;
598
James Smart09372822008-01-11 01:52:54 -0500599 /* Wait a little for things to settle down, but not
600 * long enough for dev loss timeout to expire.
601 */
James Smart46fa3112007-04-25 09:51:45 -0400602 for (i = 0; i < psli->num_rings; i++) {
603 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400604 while (pring->txcmplq_cnt) {
605 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500606 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400607 lpfc_printf_log(phba,
608 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400609 "0466 Outstanding IO when "
610 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400611 break;
612 }
613 }
614 }
615
616 init_completion(&online_compl);
617 lpfc_workq_post_event(phba, &status, &online_compl, type);
618 wait_for_completion(&online_compl);
619
620 if (status != 0)
621 return -EIO;
622
623 return 0;
624}
625
James Smarte59058c2008-08-24 21:49:00 -0400626/**
James Smart3621a712009-04-06 18:47:14 -0400627 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400628 * @phba: lpfc_hba pointer.
629 *
630 * Description:
631 * If the port is configured to allow a reset then the hba is brought
632 * offline then online.
633 *
634 * Notes:
635 * Assumes any error from lpfc_do_offline() will be negative.
636 *
637 * Returns:
638 * lpfc_do_offline() return code if not zero
639 * -EIO reset not configured or error posting the event
640 * zero for success
641 **/
James Smart46fa3112007-04-25 09:51:45 -0400642static int
James Smart40496f02006-07-06 15:50:22 -0400643lpfc_selective_reset(struct lpfc_hba *phba)
644{
645 struct completion online_compl;
646 int status = 0;
647
James Smart13815c82008-01-11 01:52:48 -0500648 if (!phba->cfg_enable_hba_reset)
649 return -EIO;
650
James Smart46fa3112007-04-25 09:51:45 -0400651 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400652
653 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400654 return status;
James Smart40496f02006-07-06 15:50:22 -0400655
656 init_completion(&online_compl);
657 lpfc_workq_post_event(phba, &status, &online_compl,
658 LPFC_EVT_ONLINE);
659 wait_for_completion(&online_compl);
660
661 if (status != 0)
662 return -EIO;
663
664 return 0;
665}
666
James Smarte59058c2008-08-24 21:49:00 -0400667/**
James Smart3621a712009-04-06 18:47:14 -0400668 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400669 * @dev: class device that is converted into a Scsi_host.
670 * @attr: device attribute, not used.
671 * @buf: containing the string "selective".
672 * @count: unused variable.
673 *
674 * Description:
675 * If the buf contains the string "selective" then lpfc_selective_reset()
676 * is called to perform the reset.
677 *
678 * Notes:
679 * Assumes any error from lpfc_selective_reset() will be negative.
680 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200681 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400682 *
683 * Returns:
684 * -EINVAL if the buffer does not contain the string "selective"
685 * length of buf if lpfc-selective_reset() if the call succeeds
686 * return value of lpfc_selective_reset() if the call fails
687**/
James Smart40496f02006-07-06 15:50:22 -0400688static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100689lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
690 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400691{
Tony Jonesee959b02008-02-22 00:13:36 +0100692 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500693 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
694 struct lpfc_hba *phba = vport->phba;
695
James Smart40496f02006-07-06 15:50:22 -0400696 int status = -EINVAL;
697
698 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
699 status = lpfc_selective_reset(phba);
700
701 if (status == 0)
702 return strlen(buf);
703 else
704 return status;
705}
706
James Smarte59058c2008-08-24 21:49:00 -0400707/**
James Smart3621a712009-04-06 18:47:14 -0400708 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400709 * @dev: class device that is converted into a Scsi_host.
710 * @attr: device attribute, not used.
711 * @buf: on return contains the ascii number of nport events.
712 *
713 * Returns: size of formatted string.
714 **/
dea31012005-04-17 16:05:31 -0500715static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100716lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
717 char *buf)
dea31012005-04-17 16:05:31 -0500718{
Tony Jonesee959b02008-02-22 00:13:36 +0100719 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500720 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
721 struct lpfc_hba *phba = vport->phba;
722
dea31012005-04-17 16:05:31 -0500723 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
724}
725
James Smarte59058c2008-08-24 21:49:00 -0400726/**
James Smart3621a712009-04-06 18:47:14 -0400727 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400728 * @dev: class device that is converted into a Scsi_host.
729 * @attr: device attribute, not used.
730 * @buf: on return contains the state of the adapter.
731 *
732 * Returns: size of formatted string.
733 **/
dea31012005-04-17 16:05:31 -0500734static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100735lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
736 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500737{
Tony Jonesee959b02008-02-22 00:13:36 +0100738 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
740 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500741 char * state;
742
James Smart2e0fef82007-06-17 19:56:36 -0500743 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500744 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500745 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500746 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500747 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500748 state = "offline";
749 else
750 state = "online";
751
752 return snprintf(buf, PAGE_SIZE, "%s\n", state);
753}
754
James Smarte59058c2008-08-24 21:49:00 -0400755/**
James Smart3621a712009-04-06 18:47:14 -0400756 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400757 * @dev: class device that is converted into a Scsi_host.
758 * @attr: device attribute, not used.
759 * @buf: containing one of the strings "online", "offline", "warm" or "error".
760 * @count: unused variable.
761 *
762 * Returns:
763 * -EACCES if enable hba reset not enabled
764 * -EINVAL if the buffer does not contain a valid string (see above)
765 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
766 * buf length greater than zero indicates success
767 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500768static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100769lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
770 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500771{
Tony Jonesee959b02008-02-22 00:13:36 +0100772 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500773 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
774 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500775 struct completion online_compl;
776 int status=0;
777
James Smart13815c82008-01-11 01:52:48 -0500778 if (!phba->cfg_enable_hba_reset)
779 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500780 init_completion(&online_compl);
781
James Smart46fa3112007-04-25 09:51:45 -0400782 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500783 lpfc_workq_post_event(phba, &status, &online_compl,
784 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400785 wait_for_completion(&online_compl);
786 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
787 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500788 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400789 if (phba->sli_rev == LPFC_SLI_REV4)
790 return -EINVAL;
791 else
792 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400793 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400794 if (phba->sli_rev == LPFC_SLI_REV4)
795 return -EINVAL;
796 else
797 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500798 else
799 return -EINVAL;
800
Jamie Wellnitz41415862006-02-28 19:25:27 -0500801 if (!status)
802 return strlen(buf);
803 else
804 return -EIO;
805}
806
James Smarte59058c2008-08-24 21:49:00 -0400807/**
James Smart3621a712009-04-06 18:47:14 -0400808 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400809 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400810 * @mxri: max xri count.
811 * @axri: available xri count.
812 * @mrpi: max rpi count.
813 * @arpi: available rpi count.
814 * @mvpi: max vpi count.
815 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400816 *
817 * Description:
818 * If an integer pointer for an count is not null then the value for the
819 * count is returned.
820 *
821 * Returns:
822 * zero on error
823 * one for success
824 **/
James Smart311464e2007-08-02 11:10:37 -0400825static int
James Smart858c9f62007-06-17 19:56:39 -0500826lpfc_get_hba_info(struct lpfc_hba *phba,
827 uint32_t *mxri, uint32_t *axri,
828 uint32_t *mrpi, uint32_t *arpi,
829 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500830{
James Smart04c68492009-05-22 14:52:52 -0400831 struct lpfc_sli *psli = &phba->sli;
832 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500833 LPFC_MBOXQ_t *pmboxq;
834 MAILBOX_t *pmb;
835 int rc = 0;
836
837 /*
838 * prevent udev from issuing mailbox commands until the port is
839 * configured.
840 */
841 if (phba->link_state < LPFC_LINK_DOWN ||
842 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400843 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500844 return 0;
845
846 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
847 return 0;
848
849 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
850 if (!pmboxq)
851 return 0;
852 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
853
James Smart04c68492009-05-22 14:52:52 -0400854 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500855 pmb->mbxCommand = MBX_READ_CONFIG;
856 pmb->mbxOwner = OWN_HOST;
857 pmboxq->context1 = NULL;
858
859 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -0400860 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart92d7f7b2007-06-17 19:56:38 -0500861 rc = MBX_NOT_FINISHED;
862 else
863 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
864
865 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500866 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500867 mempool_free(pmboxq, phba->mbox_mem_pool);
868 return 0;
869 }
870
James Smartda0436e2009-05-22 14:51:39 -0400871 if (phba->sli_rev == LPFC_SLI_REV4) {
872 rd_config = &pmboxq->u.mqe.un.rd_config;
873 if (mrpi)
874 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
875 if (arpi)
876 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
877 phba->sli4_hba.max_cfg_param.rpi_used;
878 if (mxri)
879 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
880 if (axri)
881 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
882 phba->sli4_hba.max_cfg_param.xri_used;
883 if (mvpi)
884 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
885 if (avpi)
886 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
887 phba->sli4_hba.max_cfg_param.vpi_used;
888 } else {
889 if (mrpi)
890 *mrpi = pmb->un.varRdConfig.max_rpi;
891 if (arpi)
892 *arpi = pmb->un.varRdConfig.avail_rpi;
893 if (mxri)
894 *mxri = pmb->un.varRdConfig.max_xri;
895 if (axri)
896 *axri = pmb->un.varRdConfig.avail_xri;
897 if (mvpi)
898 *mvpi = pmb->un.varRdConfig.max_vpi;
899 if (avpi)
900 *avpi = pmb->un.varRdConfig.avail_vpi;
901 }
James Smart92d7f7b2007-06-17 19:56:38 -0500902
903 mempool_free(pmboxq, phba->mbox_mem_pool);
904 return 1;
905}
906
James Smarte59058c2008-08-24 21:49:00 -0400907/**
James Smart3621a712009-04-06 18:47:14 -0400908 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400909 * @dev: class device that is converted into a Scsi_host.
910 * @attr: device attribute, not used.
911 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
912 *
913 * Description:
914 * Calls lpfc_get_hba_info() asking for just the mrpi count.
915 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
916 * to "Unknown" and the buffer length is returned, therefore the caller
917 * must check for "Unknown" in the buffer to detect a failure.
918 *
919 * Returns: size of formatted string.
920 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500921static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100922lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
923 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500924{
Tony Jonesee959b02008-02-22 00:13:36 +0100925 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
927 struct lpfc_hba *phba = vport->phba;
928 uint32_t cnt;
929
James Smart858c9f62007-06-17 19:56:39 -0500930 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500931 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
932 return snprintf(buf, PAGE_SIZE, "Unknown\n");
933}
934
James Smarte59058c2008-08-24 21:49:00 -0400935/**
James Smart3621a712009-04-06 18:47:14 -0400936 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400937 * @dev: class device that is converted into a Scsi_host.
938 * @attr: device attribute, not used.
939 * @buf: containing the used rpi count in decimal or "Unknown".
940 *
941 * Description:
942 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
943 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
944 * to "Unknown" and the buffer length is returned, therefore the caller
945 * must check for "Unknown" in the buffer to detect a failure.
946 *
947 * Returns: size of formatted string.
948 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500949static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100950lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
951 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500952{
Tony Jonesee959b02008-02-22 00:13:36 +0100953 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500954 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
955 struct lpfc_hba *phba = vport->phba;
956 uint32_t cnt, acnt;
957
James Smart858c9f62007-06-17 19:56:39 -0500958 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500959 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
960 return snprintf(buf, PAGE_SIZE, "Unknown\n");
961}
962
James Smarte59058c2008-08-24 21:49:00 -0400963/**
James Smart3621a712009-04-06 18:47:14 -0400964 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -0400965 * @dev: class device that is converted into a Scsi_host.
966 * @attr: device attribute, not used.
967 * @buf: on return contains the maximum xri count in decimal or "Unknown".
968 *
969 * Description:
970 * Calls lpfc_get_hba_info() asking for just the mrpi count.
971 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
972 * to "Unknown" and the buffer length is returned, therefore the caller
973 * must check for "Unknown" in the buffer to detect a failure.
974 *
975 * Returns: size of formatted string.
976 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500977static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100978lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
979 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500980{
Tony Jonesee959b02008-02-22 00:13:36 +0100981 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500982 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
983 struct lpfc_hba *phba = vport->phba;
984 uint32_t cnt;
985
James Smart858c9f62007-06-17 19:56:39 -0500986 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500987 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
988 return snprintf(buf, PAGE_SIZE, "Unknown\n");
989}
990
James Smarte59058c2008-08-24 21:49:00 -0400991/**
James Smart3621a712009-04-06 18:47:14 -0400992 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -0400993 * @dev: class device that is converted into a Scsi_host.
994 * @attr: device attribute, not used.
995 * @buf: on return contains the used xri count in decimal or "Unknown".
996 *
997 * Description:
998 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
999 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1000 * to "Unknown" and the buffer length is returned, therefore the caller
1001 * must check for "Unknown" in the buffer to detect a failure.
1002 *
1003 * Returns: size of formatted string.
1004 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001005static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001006lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1007 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001008{
Tony Jonesee959b02008-02-22 00:13:36 +01001009 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1011 struct lpfc_hba *phba = vport->phba;
1012 uint32_t cnt, acnt;
1013
James Smart858c9f62007-06-17 19:56:39 -05001014 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1015 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1016 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1017}
1018
James Smarte59058c2008-08-24 21:49:00 -04001019/**
James Smart3621a712009-04-06 18:47:14 -04001020 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001021 * @dev: class device that is converted into a Scsi_host.
1022 * @attr: device attribute, not used.
1023 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1024 *
1025 * Description:
1026 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1027 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1028 * to "Unknown" and the buffer length is returned, therefore the caller
1029 * must check for "Unknown" in the buffer to detect a failure.
1030 *
1031 * Returns: size of formatted string.
1032 **/
James Smart858c9f62007-06-17 19:56:39 -05001033static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001034lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1035 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001036{
Tony Jonesee959b02008-02-22 00:13:36 +01001037 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001038 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1039 struct lpfc_hba *phba = vport->phba;
1040 uint32_t cnt;
1041
1042 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1043 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1044 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1045}
1046
James Smarte59058c2008-08-24 21:49:00 -04001047/**
James Smart3621a712009-04-06 18:47:14 -04001048 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001049 * @dev: class device that is converted into a Scsi_host.
1050 * @attr: device attribute, not used.
1051 * @buf: on return contains the used vpi count in decimal or "Unknown".
1052 *
1053 * Description:
1054 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1055 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1056 * to "Unknown" and the buffer length is returned, therefore the caller
1057 * must check for "Unknown" in the buffer to detect a failure.
1058 *
1059 * Returns: size of formatted string.
1060 **/
James Smart858c9f62007-06-17 19:56:39 -05001061static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001062lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1063 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001064{
Tony Jonesee959b02008-02-22 00:13:36 +01001065 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001066 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1067 struct lpfc_hba *phba = vport->phba;
1068 uint32_t cnt, acnt;
1069
1070 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001071 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1072 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1073}
1074
James Smarte59058c2008-08-24 21:49:00 -04001075/**
James Smart3621a712009-04-06 18:47:14 -04001076 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001077 * @dev: class device that is converted into a Scsi_host.
1078 * @attr: device attribute, not used.
1079 * @buf: text that must be interpreted to determine if npiv is supported.
1080 *
1081 * Description:
1082 * Buffer will contain text indicating npiv is not suppoerted on the port,
1083 * the port is an NPIV physical port, or it is an npiv virtual port with
1084 * the id of the vport.
1085 *
1086 * Returns: size of formatted string.
1087 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001088static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001089lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1090 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001091{
Tony Jonesee959b02008-02-22 00:13:36 +01001092 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001093 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1094 struct lpfc_hba *phba = vport->phba;
1095
1096 if (!(phba->max_vpi))
1097 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1098 if (vport->port_type == LPFC_PHYSICAL_PORT)
1099 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1100 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1101}
1102
James Smarte59058c2008-08-24 21:49:00 -04001103/**
James Smart3621a712009-04-06 18:47:14 -04001104 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001105 * @dev: class device that is converted into a Scsi_host.
1106 * @attr: device attribute, not used.
1107 * @buf: on return contains the cfg_poll in hex.
1108 *
1109 * Notes:
1110 * cfg_poll should be a lpfc_polling_flags type.
1111 *
1112 * Returns: size of formatted string.
1113 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001114static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001115lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1116 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001117{
Tony Jonesee959b02008-02-22 00:13:36 +01001118 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001119 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1120 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001121
1122 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1123}
1124
James Smarte59058c2008-08-24 21:49:00 -04001125/**
James Smart3621a712009-04-06 18:47:14 -04001126 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001127 * @dev: class device that is converted into a Scsi_host.
1128 * @attr: device attribute, not used.
1129 * @buf: one or more lpfc_polling_flags values.
1130 * @count: not used.
1131 *
1132 * Notes:
1133 * buf contents converted to integer and checked for a valid value.
1134 *
1135 * Returns:
1136 * -EINVAL if the buffer connot be converted or is out of range
1137 * length of the buf on success
1138 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001139static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001140lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1141 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001142{
Tony Jonesee959b02008-02-22 00:13:36 +01001143 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001144 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1145 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001146 uint32_t creg_val;
1147 uint32_t old_val;
1148 int val=0;
1149
1150 if (!isdigit(buf[0]))
1151 return -EINVAL;
1152
1153 if (sscanf(buf, "%i", &val) != 1)
1154 return -EINVAL;
1155
1156 if ((val & 0x3) != val)
1157 return -EINVAL;
1158
James Smart45ed1192009-10-02 15:17:02 -04001159 if (phba->sli_rev == LPFC_SLI_REV4)
1160 val = 0;
1161
James Smart2e0fef82007-06-17 19:56:36 -05001162 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001163
1164 old_val = phba->cfg_poll;
1165
1166 if (val & ENABLE_FCP_RING_POLLING) {
1167 if ((val & DISABLE_FCP_RING_INT) &&
1168 !(old_val & DISABLE_FCP_RING_INT)) {
1169 creg_val = readl(phba->HCregaddr);
1170 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1171 writel(creg_val, phba->HCregaddr);
1172 readl(phba->HCregaddr); /* flush */
1173
1174 lpfc_poll_start_timer(phba);
1175 }
1176 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001177 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001178 return -EINVAL;
1179 }
1180
1181 if (!(val & DISABLE_FCP_RING_INT) &&
1182 (old_val & DISABLE_FCP_RING_INT))
1183 {
James Smart2e0fef82007-06-17 19:56:36 -05001184 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001185 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001186 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001187 creg_val = readl(phba->HCregaddr);
1188 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1189 writel(creg_val, phba->HCregaddr);
1190 readl(phba->HCregaddr); /* flush */
1191 }
1192
1193 phba->cfg_poll = val;
1194
James Smart2e0fef82007-06-17 19:56:36 -05001195 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001196
1197 return strlen(buf);
1198}
dea31012005-04-17 16:05:31 -05001199
James Smarte59058c2008-08-24 21:49:00 -04001200/**
James Smart3621a712009-04-06 18:47:14 -04001201 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001202 *
1203 * Description:
1204 * Macro that given an attr e.g. hba_queue_depth expands
1205 * into a function with the name lpfc_hba_queue_depth_show.
1206 *
1207 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1208 * @dev: class device that is converted into a Scsi_host.
1209 * @attr: device attribute, not used.
1210 * @buf: on return contains the attribute value in decimal.
1211 *
1212 * Returns: size of formatted string.
1213 **/
dea31012005-04-17 16:05:31 -05001214#define lpfc_param_show(attr) \
1215static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001216lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1217 char *buf) \
dea31012005-04-17 16:05:31 -05001218{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001219 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001220 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1221 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001222 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001223 val = phba->cfg_##attr;\
1224 return snprintf(buf, PAGE_SIZE, "%d\n",\
1225 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001226}
1227
James Smarte59058c2008-08-24 21:49:00 -04001228/**
James Smart3621a712009-04-06 18:47:14 -04001229 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001230 *
1231 * Description:
1232 * Macro that given an attr e.g. hba_queue_depth expands
1233 * into a function with the name lpfc_hba_queue_depth_show
1234 *
1235 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1236 * @dev: class device that is converted into a Scsi_host.
1237 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001238 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001239 *
1240 * Returns: size of formatted string.
1241 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001242#define lpfc_param_hex_show(attr) \
1243static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001244lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1245 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001246{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001247 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1249 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001250 int val = 0;\
1251 val = phba->cfg_##attr;\
1252 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1253 phba->cfg_##attr);\
1254}
1255
James Smarte59058c2008-08-24 21:49:00 -04001256/**
James Smart3621a712009-04-06 18:47:14 -04001257 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001258 *
1259 * Description:
1260 * Macro that given an attr e.g. hba_queue_depth expands
1261 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1262 * takes a default argument, a minimum and maximum argument.
1263 *
1264 * lpfc_##attr##_init: Initializes an attribute.
1265 * @phba: pointer the the adapter structure.
1266 * @val: integer attribute value.
1267 *
1268 * Validates the min and max values then sets the adapter config field
1269 * accordingly, or uses the default if out of range and prints an error message.
1270 *
1271 * Returns:
1272 * zero on success
1273 * -EINVAL if default used
1274 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001275#define lpfc_param_init(attr, default, minval, maxval) \
1276static int \
1277lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1278{ \
1279 if (val >= minval && val <= maxval) {\
1280 phba->cfg_##attr = val;\
1281 return 0;\
1282 }\
1283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001284 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1285 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001286 phba->cfg_##attr = default;\
1287 return -EINVAL;\
1288}
1289
James Smarte59058c2008-08-24 21:49:00 -04001290/**
James Smart3621a712009-04-06 18:47:14 -04001291 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001292 *
1293 * Description:
1294 * Macro that given an attr e.g. hba_queue_depth expands
1295 * into a function with the name lpfc_hba_queue_depth_set
1296 *
1297 * lpfc_##attr##_set: Sets an attribute value.
1298 * @phba: pointer the the adapter structure.
1299 * @val: integer attribute value.
1300 *
1301 * Description:
1302 * Validates the min and max values then sets the
1303 * adapter config field if in the valid range. prints error message
1304 * and does not set the parameter if invalid.
1305 *
1306 * Returns:
1307 * zero on success
1308 * -EINVAL if val is invalid
1309 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001310#define lpfc_param_set(attr, default, minval, maxval) \
1311static int \
1312lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1313{ \
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 "0450 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 return -EINVAL;\
1322}
1323
James Smarte59058c2008-08-24 21:49:00 -04001324/**
James Smart3621a712009-04-06 18:47:14 -04001325 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001326 *
1327 * Description:
1328 * Macro that given an attr e.g. hba_queue_depth expands
1329 * into a function with the name lpfc_hba_queue_depth_store.
1330 *
1331 * lpfc_##attr##_store: Set an sttribute value.
1332 * @dev: class device that is converted into a Scsi_host.
1333 * @attr: device attribute, not used.
1334 * @buf: contains the attribute value in ascii.
1335 * @count: not used.
1336 *
1337 * Description:
1338 * Convert the ascii text number to an integer, then
1339 * use the lpfc_##attr##_set function to set the value.
1340 *
1341 * Returns:
1342 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1343 * length of buffer upon success.
1344 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001345#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001346static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001347lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1348 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001349{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001350 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1352 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001353 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001354 if (!isdigit(buf[0]))\
1355 return -EINVAL;\
1356 if (sscanf(buf, "%i", &val) != 1)\
1357 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001358 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001359 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001360 else \
1361 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001362}
1363
James Smarte59058c2008-08-24 21:49:00 -04001364/**
James Smart3621a712009-04-06 18:47:14 -04001365 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001366 *
1367 * Description:
1368 * Macro that given an attr e.g. hba_queue_depth expands
1369 * into a function with the name lpfc_hba_queue_depth_show
1370 *
1371 * lpfc_##attr##_show: prints the attribute value in decimal.
1372 * @dev: class device that is converted into a Scsi_host.
1373 * @attr: device attribute, not used.
1374 * @buf: on return contains the attribute value in decimal.
1375 *
1376 * Returns: length of formatted string.
1377 **/
James Smart3de2a652007-08-02 11:09:59 -04001378#define lpfc_vport_param_show(attr) \
1379static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001380lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1381 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001382{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001383 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001384 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1385 int val = 0;\
1386 val = vport->cfg_##attr;\
1387 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1388}
1389
James Smarte59058c2008-08-24 21:49:00 -04001390/**
James Smart3621a712009-04-06 18:47:14 -04001391 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001392 *
1393 * Description:
1394 * Macro that given an attr e.g.
1395 * hba_queue_depth expands into a function with the name
1396 * lpfc_hba_queue_depth_show
1397 *
James Smart3621a712009-04-06 18:47:14 -04001398 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001399 * @dev: class device that is converted into a Scsi_host.
1400 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001401 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001402 *
1403 * Returns: length of formatted string.
1404 **/
James Smart3de2a652007-08-02 11:09:59 -04001405#define lpfc_vport_param_hex_show(attr) \
1406static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001407lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1408 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001409{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001410 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1412 int val = 0;\
1413 val = vport->cfg_##attr;\
1414 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1415}
1416
James Smarte59058c2008-08-24 21:49:00 -04001417/**
James Smart3621a712009-04-06 18:47:14 -04001418 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001419 *
1420 * Description:
1421 * Macro that given an attr e.g. hba_queue_depth expands
1422 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1423 * takes a default argument, a minimum and maximum argument.
1424 *
1425 * lpfc_##attr##_init: validates the min and max values then sets the
1426 * adapter config field accordingly, or uses the default if out of range
1427 * and prints an error message.
1428 * @phba: pointer the the adapter structure.
1429 * @val: integer attribute value.
1430 *
1431 * Returns:
1432 * zero on success
1433 * -EINVAL if default used
1434 **/
James Smart3de2a652007-08-02 11:09:59 -04001435#define lpfc_vport_param_init(attr, default, minval, maxval) \
1436static int \
1437lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1438{ \
1439 if (val >= minval && val <= maxval) {\
1440 vport->cfg_##attr = val;\
1441 return 0;\
1442 }\
James Smarte8b62012007-08-02 11:10:09 -04001443 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001444 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001445 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001446 vport->cfg_##attr = default;\
1447 return -EINVAL;\
1448}
1449
James Smarte59058c2008-08-24 21:49:00 -04001450/**
James Smart3621a712009-04-06 18:47:14 -04001451 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001452 *
1453 * Description:
1454 * Macro that given an attr e.g. hba_queue_depth expands
1455 * into a function with the name lpfc_hba_queue_depth_set
1456 *
1457 * lpfc_##attr##_set: validates the min and max values then sets the
1458 * adapter config field if in the valid range. prints error message
1459 * and does not set the parameter if invalid.
1460 * @phba: pointer the the adapter structure.
1461 * @val: integer attribute value.
1462 *
1463 * Returns:
1464 * zero on success
1465 * -EINVAL if val is invalid
1466 **/
James Smart3de2a652007-08-02 11:09:59 -04001467#define lpfc_vport_param_set(attr, default, minval, maxval) \
1468static int \
1469lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1470{ \
1471 if (val >= minval && val <= maxval) {\
1472 vport->cfg_##attr = val;\
1473 return 0;\
1474 }\
James Smarte8b62012007-08-02 11:10:09 -04001475 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001476 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001477 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001478 return -EINVAL;\
1479}
1480
James Smarte59058c2008-08-24 21:49:00 -04001481/**
James Smart3621a712009-04-06 18:47:14 -04001482 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001483 *
1484 * Description:
1485 * Macro that given an attr e.g. hba_queue_depth
1486 * expands into a function with the name lpfc_hba_queue_depth_store
1487 *
1488 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1489 * use the lpfc_##attr##_set function to set the value.
1490 * @cdev: class device that is converted into a Scsi_host.
1491 * @buf: contains the attribute value in decimal.
1492 * @count: not used.
1493 *
1494 * Returns:
1495 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1496 * length of buffer upon success.
1497 **/
James Smart3de2a652007-08-02 11:09:59 -04001498#define lpfc_vport_param_store(attr) \
1499static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001500lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1501 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001502{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001503 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1505 int val=0;\
1506 if (!isdigit(buf[0]))\
1507 return -EINVAL;\
1508 if (sscanf(buf, "%i", &val) != 1)\
1509 return -EINVAL;\
1510 if (lpfc_##attr##_set(vport, val) == 0) \
1511 return strlen(buf);\
1512 else \
1513 return -EINVAL;\
1514}
1515
1516
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001517#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1518static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001519module_param(lpfc_##name, int, 0);\
1520MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001521lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001522
1523#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1524static int lpfc_##name = defval;\
1525module_param(lpfc_##name, int, 0);\
1526MODULE_PARM_DESC(lpfc_##name, desc);\
1527lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001528lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001529static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001530
1531#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1532static int lpfc_##name = defval;\
1533module_param(lpfc_##name, int, 0);\
1534MODULE_PARM_DESC(lpfc_##name, desc);\
1535lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001536lpfc_param_init(name, defval, minval, maxval)\
1537lpfc_param_set(name, defval, minval, maxval)\
1538lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001539static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1540 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001541
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001542#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1543static int lpfc_##name = defval;\
1544module_param(lpfc_##name, int, 0);\
1545MODULE_PARM_DESC(lpfc_##name, desc);\
1546lpfc_param_hex_show(name)\
1547lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001548static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001549
1550#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1551static int lpfc_##name = defval;\
1552module_param(lpfc_##name, int, 0);\
1553MODULE_PARM_DESC(lpfc_##name, desc);\
1554lpfc_param_hex_show(name)\
1555lpfc_param_init(name, defval, minval, maxval)\
1556lpfc_param_set(name, defval, minval, maxval)\
1557lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001558static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1559 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001560
James Smart3de2a652007-08-02 11:09:59 -04001561#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1562static int lpfc_##name = defval;\
1563module_param(lpfc_##name, int, 0);\
1564MODULE_PARM_DESC(lpfc_##name, desc);\
1565lpfc_vport_param_init(name, defval, minval, maxval)
1566
1567#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1568static int lpfc_##name = defval;\
1569module_param(lpfc_##name, int, 0);\
1570MODULE_PARM_DESC(lpfc_##name, desc);\
1571lpfc_vport_param_show(name)\
1572lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001573static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001574
1575#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1576static int lpfc_##name = defval;\
1577module_param(lpfc_##name, int, 0);\
1578MODULE_PARM_DESC(lpfc_##name, desc);\
1579lpfc_vport_param_show(name)\
1580lpfc_vport_param_init(name, defval, minval, maxval)\
1581lpfc_vport_param_set(name, defval, minval, maxval)\
1582lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001583static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1584 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001585
1586#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1587static int lpfc_##name = defval;\
1588module_param(lpfc_##name, int, 0);\
1589MODULE_PARM_DESC(lpfc_##name, desc);\
1590lpfc_vport_param_hex_show(name)\
1591lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001592static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001593
1594#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1595static int lpfc_##name = defval;\
1596module_param(lpfc_##name, int, 0);\
1597MODULE_PARM_DESC(lpfc_##name, desc);\
1598lpfc_vport_param_hex_show(name)\
1599lpfc_vport_param_init(name, defval, minval, maxval)\
1600lpfc_vport_param_set(name, defval, minval, maxval)\
1601lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001602static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1603 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001604
James Smart81301a92008-12-04 22:39:46 -05001605static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1606static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1607static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1608static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001609static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1610static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1611static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1612static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1613static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1614static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1615static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1616static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001617static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001618static DEVICE_ATTR(option_rom_version, S_IRUGO,
1619 lpfc_option_rom_version_show, NULL);
1620static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1621 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001622static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001623static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1624static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001625static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001626static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1627 lpfc_board_mode_show, lpfc_board_mode_store);
1628static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1629static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1630static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1631static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1632static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1633static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1634static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1635static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1636static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001637
James Smartc3f28af2006-08-18 17:47:18 -04001638
James Smarta12e07b2006-12-02 13:35:30 -05001639static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001640
James Smarte59058c2008-08-24 21:49:00 -04001641/**
James Smart3621a712009-04-06 18:47:14 -04001642 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001643 * @dev: class device that is converted into a Scsi_host.
1644 * @attr: device attribute, not used.
1645 * @buf: containing the string lpfc_soft_wwn_key.
1646 * @count: must be size of lpfc_soft_wwn_key.
1647 *
1648 * Returns:
1649 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1650 * length of buf indicates success
1651 **/
James Smartc3f28af2006-08-18 17:47:18 -04001652static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001653lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1654 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001655{
Tony Jonesee959b02008-02-22 00:13:36 +01001656 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1658 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001659 unsigned int cnt = count;
1660
1661 /*
1662 * We're doing a simple sanity check for soft_wwpn setting.
1663 * We require that the user write a specific key to enable
1664 * the soft_wwpn attribute to be settable. Once the attribute
1665 * is written, the enable key resets. If further updates are
1666 * desired, the key must be written again to re-enable the
1667 * attribute.
1668 *
1669 * The "key" is not secret - it is a hardcoded string shown
1670 * here. The intent is to protect against the random user or
1671 * application that is just writing attributes.
1672 */
1673
1674 /* count may include a LF at end of string */
1675 if (buf[cnt-1] == '\n')
1676 cnt--;
1677
James Smarta12e07b2006-12-02 13:35:30 -05001678 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1679 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001680 return -EINVAL;
1681
James Smarta12e07b2006-12-02 13:35:30 -05001682 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001683 return count;
1684}
Tony Jonesee959b02008-02-22 00:13:36 +01001685static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1686 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001687
James Smarte59058c2008-08-24 21:49:00 -04001688/**
James Smart3621a712009-04-06 18:47:14 -04001689 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001690 * @dev: class device that is converted into a Scsi_host.
1691 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001692 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001693 *
1694 * Returns: size of formatted string.
1695 **/
James Smartc3f28af2006-08-18 17:47:18 -04001696static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001697lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1698 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001699{
Tony Jonesee959b02008-02-22 00:13:36 +01001700 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1702 struct lpfc_hba *phba = vport->phba;
1703
Randy Dunlapafc071e2006-10-23 21:47:13 -07001704 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1705 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001706}
1707
James Smarte59058c2008-08-24 21:49:00 -04001708/**
James Smart3621a712009-04-06 18:47:14 -04001709 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001710 * @dev class device that is converted into a Scsi_host.
1711 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001712 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001713 * @count: number of wwpn bytes in buf
1714 *
1715 * Returns:
1716 * -EACCES hba reset not enabled, adapter over temp
1717 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1718 * -EIO error taking adapter offline or online
1719 * value of count on success
1720 **/
James Smartc3f28af2006-08-18 17:47:18 -04001721static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001722lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1723 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001724{
Tony Jonesee959b02008-02-22 00:13:36 +01001725 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001726 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1727 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001728 struct completion online_compl;
1729 int stat1=0, stat2=0;
1730 unsigned int i, j, cnt=count;
1731 u8 wwpn[8];
1732
James Smart13815c82008-01-11 01:52:48 -05001733 if (!phba->cfg_enable_hba_reset)
1734 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001735 spin_lock_irq(&phba->hbalock);
1736 if (phba->over_temp_state == HBA_OVER_TEMP) {
1737 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001738 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001739 }
1740 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001741 /* count may include a LF at end of string */
1742 if (buf[cnt-1] == '\n')
1743 cnt--;
1744
James Smarta12e07b2006-12-02 13:35:30 -05001745 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001746 ((cnt == 17) && (*buf++ != 'x')) ||
1747 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1748 return -EINVAL;
1749
James Smarta12e07b2006-12-02 13:35:30 -05001750 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001751
1752 memset(wwpn, 0, sizeof(wwpn));
1753
1754 /* Validate and store the new name */
1755 for (i=0, j=0; i < 16; i++) {
1756 if ((*buf >= 'a') && (*buf <= 'f'))
1757 j = ((j << 4) | ((*buf++ -'a') + 10));
1758 else if ((*buf >= 'A') && (*buf <= 'F'))
1759 j = ((j << 4) | ((*buf++ -'A') + 10));
1760 else if ((*buf >= '0') && (*buf <= '9'))
1761 j = ((j << 4) | (*buf++ -'0'));
1762 else
1763 return -EINVAL;
1764 if (i % 2) {
1765 wwpn[i/2] = j & 0xff;
1766 j = 0;
1767 }
1768 }
1769 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001770 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001771 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001772 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001773
1774 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1775 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1776
James Smart46fa3112007-04-25 09:51:45 -04001777 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001778 if (stat1)
1779 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001780 "0463 lpfc_soft_wwpn attribute set failed to "
1781 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001782 init_completion(&online_compl);
1783 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1784 wait_for_completion(&online_compl);
1785 if (stat2)
1786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001787 "0464 lpfc_soft_wwpn attribute set failed to "
1788 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001789 return (stat1 || stat2) ? -EIO : count;
1790}
Tony Jonesee959b02008-02-22 00:13:36 +01001791static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1792 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001793
James Smarte59058c2008-08-24 21:49:00 -04001794/**
James Smart3621a712009-04-06 18:47:14 -04001795 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001796 * @dev: class device that is converted into a Scsi_host.
1797 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001798 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001799 *
1800 * Returns: size of formatted string.
1801 **/
James Smarta12e07b2006-12-02 13:35:30 -05001802static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001803lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1804 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001805{
Tony Jonesee959b02008-02-22 00:13:36 +01001806 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001807 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001808 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1809 (unsigned long long)phba->cfg_soft_wwnn);
1810}
1811
James Smarte59058c2008-08-24 21:49:00 -04001812/**
James Smart3621a712009-04-06 18:47:14 -04001813 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001814 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001815 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001816 * @count: number of wwnn bytes in buf.
1817 *
1818 * Returns:
1819 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1820 * value of count on success
1821 **/
James Smarta12e07b2006-12-02 13:35:30 -05001822static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001823lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1824 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001825{
Tony Jonesee959b02008-02-22 00:13:36 +01001826 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001827 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001828 unsigned int i, j, cnt=count;
1829 u8 wwnn[8];
1830
1831 /* count may include a LF at end of string */
1832 if (buf[cnt-1] == '\n')
1833 cnt--;
1834
1835 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1836 ((cnt == 17) && (*buf++ != 'x')) ||
1837 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1838 return -EINVAL;
1839
1840 /*
1841 * Allow wwnn to be set many times, as long as the enable is set.
1842 * However, once the wwpn is set, everything locks.
1843 */
1844
1845 memset(wwnn, 0, sizeof(wwnn));
1846
1847 /* Validate and store the new name */
1848 for (i=0, j=0; i < 16; i++) {
1849 if ((*buf >= 'a') && (*buf <= 'f'))
1850 j = ((j << 4) | ((*buf++ -'a') + 10));
1851 else if ((*buf >= 'A') && (*buf <= 'F'))
1852 j = ((j << 4) | ((*buf++ -'A') + 10));
1853 else if ((*buf >= '0') && (*buf <= '9'))
1854 j = ((j << 4) | (*buf++ -'0'));
1855 else
1856 return -EINVAL;
1857 if (i % 2) {
1858 wwnn[i/2] = j & 0xff;
1859 j = 0;
1860 }
1861 }
1862 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1863
1864 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1865 "lpfc%d: soft_wwnn set. Value will take effect upon "
1866 "setting of the soft_wwpn\n", phba->brd_no);
1867
1868 return count;
1869}
Tony Jonesee959b02008-02-22 00:13:36 +01001870static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1871 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001872
James Smartc3f28af2006-08-18 17:47:18 -04001873
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001874static int lpfc_poll = 0;
1875module_param(lpfc_poll, int, 0);
1876MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1877 " 0 - none,"
1878 " 1 - poll with interrupts enabled"
1879 " 3 - poll and disable FCP ring interrupts");
1880
Tony Jonesee959b02008-02-22 00:13:36 +01001881static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1882 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001883
James Smart92d7f7b2007-06-17 19:56:38 -05001884int lpfc_sli_mode = 0;
1885module_param(lpfc_sli_mode, int, 0);
1886MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1887 " 0 - auto (SLI-3 if supported),"
1888 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1889 " 3 - select SLI-3");
1890
James Smart7ee5d432007-10-27 13:37:17 -04001891int lpfc_enable_npiv = 0;
1892module_param(lpfc_enable_npiv, int, 0);
1893MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1894lpfc_param_show(enable_npiv);
1895lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001896static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001897 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001898
dea31012005-04-17 16:05:31 -05001899/*
James Smartc01f3202006-08-18 17:47:08 -04001900# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1901# until the timer expires. Value range is [0,255]. Default value is 30.
1902*/
1903static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1904static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1905module_param(lpfc_nodev_tmo, int, 0);
1906MODULE_PARM_DESC(lpfc_nodev_tmo,
1907 "Seconds driver will hold I/O waiting "
1908 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001909
1910/**
James Smart3621a712009-04-06 18:47:14 -04001911 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04001912 * @dev: class converted to a Scsi_host structure.
1913 * @attr: device attribute, not used.
1914 * @buf: on return contains the dev loss timeout in decimal.
1915 *
1916 * Returns: size of formatted string.
1917 **/
James Smartc01f3202006-08-18 17:47:08 -04001918static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001919lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1920 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001921{
Tony Jonesee959b02008-02-22 00:13:36 +01001922 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001923 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001924 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001925 val = vport->cfg_devloss_tmo;
1926 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001927}
1928
James Smarte59058c2008-08-24 21:49:00 -04001929/**
James Smart3621a712009-04-06 18:47:14 -04001930 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04001931 * @vport: lpfc vport structure pointer.
1932 * @val: contains the nodev timeout value.
1933 *
1934 * Description:
1935 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1936 * a kernel error message is printed and zero is returned.
1937 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1938 * Otherwise nodev tmo is set to the default value.
1939 *
1940 * Returns:
1941 * zero if already set or if val is in range
1942 * -EINVAL val out of range
1943 **/
James Smartc01f3202006-08-18 17:47:08 -04001944static int
James Smart3de2a652007-08-02 11:09:59 -04001945lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001946{
James Smart3de2a652007-08-02 11:09:59 -04001947 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1948 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1949 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001950 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001951 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001952 "parameter because devloss_tmo is "
1953 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001954 return 0;
1955 }
1956
1957 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001958 vport->cfg_nodev_tmo = val;
1959 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001960 return 0;
1961 }
James Smarte8b62012007-08-02 11:10:09 -04001962 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1963 "0400 lpfc_nodev_tmo attribute cannot be set to"
1964 " %d, allowed range is [%d, %d]\n",
1965 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001966 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001967 return -EINVAL;
1968}
1969
James Smarte59058c2008-08-24 21:49:00 -04001970/**
James Smart3621a712009-04-06 18:47:14 -04001971 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04001972 * @vport: lpfc vport structure pointer.
1973 *
1974 * Description:
1975 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1976 **/
James Smart7054a602007-04-25 09:52:34 -04001977static void
James Smart3de2a652007-08-02 11:09:59 -04001978lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001979{
James Smart858c9f62007-06-17 19:56:39 -05001980 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001981 struct lpfc_nodelist *ndlp;
1982
James Smart51ef4c22007-08-02 11:10:31 -04001983 shost = lpfc_shost_from_vport(vport);
1984 spin_lock_irq(shost->host_lock);
1985 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001986 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001987 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1988 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001989}
1990
James Smarte59058c2008-08-24 21:49:00 -04001991/**
James Smart3621a712009-04-06 18:47:14 -04001992 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04001993 * @vport: lpfc vport structure pointer.
1994 * @val: contains the tmo value.
1995 *
1996 * Description:
1997 * If the devloss tmo is already set or the vport dev loss tmo has changed
1998 * then a kernel error message is printed and zero is returned.
1999 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2000 * Otherwise nodev tmo is set to the default value.
2001 *
2002 * Returns:
2003 * zero if already set or if val is in range
2004 * -EINVAL val out of range
2005 **/
James Smartc01f3202006-08-18 17:47:08 -04002006static int
James Smart3de2a652007-08-02 11:09:59 -04002007lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002008{
James Smart3de2a652007-08-02 11:09:59 -04002009 if (vport->dev_loss_tmo_changed ||
2010 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002011 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2012 "0401 Ignoring change to nodev_tmo "
2013 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002014 return 0;
2015 }
James Smartc01f3202006-08-18 17:47:08 -04002016 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002017 vport->cfg_nodev_tmo = val;
2018 vport->cfg_devloss_tmo = val;
2019 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002020 return 0;
2021 }
James Smarte8b62012007-08-02 11:10:09 -04002022 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2023 "0403 lpfc_nodev_tmo attribute cannot be set to"
2024 "%d, allowed range is [%d, %d]\n",
2025 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002026 return -EINVAL;
2027}
2028
James Smart3de2a652007-08-02 11:09:59 -04002029lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002030
Tony Jonesee959b02008-02-22 00:13:36 +01002031static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2032 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002033
2034/*
2035# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2036# disappear until the timer expires. Value range is [0,255]. Default
2037# value is 30.
2038*/
2039module_param(lpfc_devloss_tmo, int, 0);
2040MODULE_PARM_DESC(lpfc_devloss_tmo,
2041 "Seconds driver will hold I/O waiting "
2042 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002043lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2044 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2045lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002046
2047/**
James Smart3621a712009-04-06 18:47:14 -04002048 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002049 * @vport: lpfc vport structure pointer.
2050 * @val: contains the tmo value.
2051 *
2052 * Description:
2053 * If val is in a valid range then set the vport nodev tmo,
2054 * devloss tmo, also set the vport dev loss tmo changed flag.
2055 * Else a kernel error message is printed.
2056 *
2057 * Returns:
2058 * zero if val is in range
2059 * -EINVAL val out of range
2060 **/
James Smartc01f3202006-08-18 17:47:08 -04002061static int
James Smart3de2a652007-08-02 11:09:59 -04002062lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002063{
2064 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002065 vport->cfg_nodev_tmo = val;
2066 vport->cfg_devloss_tmo = val;
2067 vport->dev_loss_tmo_changed = 1;
2068 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002069 return 0;
2070 }
2071
James Smarte8b62012007-08-02 11:10:09 -04002072 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2073 "0404 lpfc_devloss_tmo attribute cannot be set to"
2074 " %d, allowed range is [%d, %d]\n",
2075 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002076 return -EINVAL;
2077}
2078
James Smart3de2a652007-08-02 11:09:59 -04002079lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002080static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2081 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002082
2083/*
dea31012005-04-17 16:05:31 -05002084# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2085# deluged with LOTS of information.
2086# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002087# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002088*/
James Smartf4b4c682009-05-22 14:53:12 -04002089LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002090 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002091
2092/*
James Smart7ee5d432007-10-27 13:37:17 -04002093# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2094# objects that have been registered with the nameserver after login.
2095*/
2096LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2097 "Deregister nameserver objects before LOGO");
2098
2099/*
dea31012005-04-17 16:05:31 -05002100# lun_queue_depth: This parameter is used to limit the number of outstanding
2101# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2102*/
James Smart3de2a652007-08-02 11:09:59 -04002103LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2104 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002105
2106/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002107# hba_queue_depth: This parameter is used to limit the number of outstanding
2108# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2109# value is greater than the maximum number of exchanges supported by the HBA,
2110# then maximum number of exchanges supported by the HBA is used to determine
2111# the hba_queue_depth.
2112*/
2113LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2114 "Max number of FCP commands we can queue to a lpfc HBA");
2115
2116/*
James Smart92d7f7b2007-06-17 19:56:38 -05002117# peer_port_login: This parameter allows/prevents logins
2118# between peer ports hosted on the same physical port.
2119# When this parameter is set 0 peer ports of same physical port
2120# are not allowed to login to each other.
2121# When this parameter is set 1 peer ports of same physical port
2122# are allowed to login to each other.
2123# Default value of this parameter is 0.
2124*/
James Smart3de2a652007-08-02 11:09:59 -04002125LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2126 "Allow peer ports on the same physical port to login to each "
2127 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002128
2129/*
James Smart3de2a652007-08-02 11:09:59 -04002130# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002131# between Virtual Ports and remote initiators.
2132# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2133# other initiators and will attempt to PLOGI all remote ports.
2134# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2135# remote ports and will not attempt to PLOGI to other initiators.
2136# This parameter does not restrict to the physical port.
2137# This parameter does not restrict logins to Fabric resident remote ports.
2138# Default value of this parameter is 1.
2139*/
James Smart3de2a652007-08-02 11:09:59 -04002140static int lpfc_restrict_login = 1;
2141module_param(lpfc_restrict_login, int, 0);
2142MODULE_PARM_DESC(lpfc_restrict_login,
2143 "Restrict virtual ports login to remote initiators.");
2144lpfc_vport_param_show(restrict_login);
2145
James Smarte59058c2008-08-24 21:49:00 -04002146/**
James Smart3621a712009-04-06 18:47:14 -04002147 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002148 * @vport: lpfc vport structure pointer.
2149 * @val: contains the restrict login value.
2150 *
2151 * Description:
2152 * If val is not in a valid range then log a kernel error message and set
2153 * the vport restrict login to one.
2154 * If the port type is physical clear the restrict login flag and return.
2155 * Else set the restrict login flag to val.
2156 *
2157 * Returns:
2158 * zero if val is in range
2159 * -EINVAL val out of range
2160 **/
James Smart3de2a652007-08-02 11:09:59 -04002161static int
2162lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2163{
2164 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002166 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002167 "be set to %d, allowed range is [0, 1]\n",
2168 val);
James Smart3de2a652007-08-02 11:09:59 -04002169 vport->cfg_restrict_login = 1;
2170 return -EINVAL;
2171 }
2172 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2173 vport->cfg_restrict_login = 0;
2174 return 0;
2175 }
2176 vport->cfg_restrict_login = val;
2177 return 0;
2178}
2179
James Smarte59058c2008-08-24 21:49:00 -04002180/**
James Smart3621a712009-04-06 18:47:14 -04002181 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002182 * @vport: lpfc vport structure pointer.
2183 * @val: contains the restrict login value.
2184 *
2185 * Description:
2186 * If val is not in a valid range then log a kernel error message and set
2187 * the vport restrict login to one.
2188 * If the port type is physical and the val is not zero log a kernel
2189 * error message, clear the restrict login flag and return zero.
2190 * Else set the restrict login flag to val.
2191 *
2192 * Returns:
2193 * zero if val is in range
2194 * -EINVAL val out of range
2195 **/
James Smart3de2a652007-08-02 11:09:59 -04002196static int
2197lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2198{
2199 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002200 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002201 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002202 "be set to %d, allowed range is [0, 1]\n",
2203 val);
James Smart3de2a652007-08-02 11:09:59 -04002204 vport->cfg_restrict_login = 1;
2205 return -EINVAL;
2206 }
2207 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002208 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2209 "0468 lpfc_restrict_login must be 0 for "
2210 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002211 vport->cfg_restrict_login = 0;
2212 return 0;
2213 }
2214 vport->cfg_restrict_login = val;
2215 return 0;
2216}
2217lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002218static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2219 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002220
2221/*
dea31012005-04-17 16:05:31 -05002222# Some disk devices have a "select ID" or "select Target" capability.
2223# From a protocol standpoint "select ID" usually means select the
2224# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2225# annex" which contains a table that maps a "select ID" (a number
2226# between 0 and 7F) to an ALPA. By default, for compatibility with
2227# older drivers, the lpfc driver scans this table from low ALPA to high
2228# ALPA.
2229#
2230# Turning on the scan-down variable (on = 1, off = 0) will
2231# cause the lpfc driver to use an inverted table, effectively
2232# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2233#
2234# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2235# and will not work across a fabric. Also this parameter will take
2236# effect only in the case when ALPA map is not available.)
2237*/
James Smart3de2a652007-08-02 11:09:59 -04002238LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2239 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002240
2241/*
dea31012005-04-17 16:05:31 -05002242# lpfc_topology: link topology for init link
2243# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002244# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002245# 0x02 = attempt point-to-point mode only
2246# 0x04 = attempt loop mode only
2247# 0x06 = attempt point-to-point mode then loop
2248# Set point-to-point mode if you want to run as an N_Port.
2249# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2250# Default value is 0.
2251*/
James Smarte59058c2008-08-24 21:49:00 -04002252
2253/**
James Smart3621a712009-04-06 18:47:14 -04002254 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002255 * @phba: lpfc_hba pointer.
2256 * @val: topology value.
2257 *
2258 * Description:
2259 * If val is in a valid range then set the adapter's topology field and
2260 * issue a lip; if the lip fails reset the topology to the old value.
2261 *
2262 * If the value is not in range log a kernel error message and return an error.
2263 *
2264 * Returns:
2265 * zero if val is in range and lip okay
2266 * non-zero return value from lpfc_issue_lip()
2267 * -EINVAL val out of range
2268 **/
James Smarta257bf92009-04-06 18:48:10 -04002269static ssize_t
2270lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2271 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002272{
James Smarta257bf92009-04-06 18:48:10 -04002273 struct Scsi_Host *shost = class_to_shost(dev);
2274 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2275 struct lpfc_hba *phba = vport->phba;
2276 int val = 0;
2277 int nolip = 0;
2278 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002279 int err;
2280 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002281
2282 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2283 nolip = 1;
2284 val_buf = &buf[strlen("nolip ")];
2285 }
2286
2287 if (!isdigit(val_buf[0]))
2288 return -EINVAL;
2289 if (sscanf(val_buf, "%i", &val) != 1)
2290 return -EINVAL;
2291
James Smart83108bd2008-01-11 01:53:09 -05002292 if (val >= 0 && val <= 6) {
2293 prev_val = phba->cfg_topology;
2294 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002295 if (nolip)
2296 return strlen(buf);
2297
James Smart83108bd2008-01-11 01:53:09 -05002298 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002299 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002300 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002301 return -EINVAL;
2302 } else
2303 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002304 }
2305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2306 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2307 "allowed range is [0, 6]\n",
2308 phba->brd_no, val);
2309 return -EINVAL;
2310}
2311static int lpfc_topology = 0;
2312module_param(lpfc_topology, int, 0);
2313MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2314lpfc_param_show(topology)
2315lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002316static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002317 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002318
James Smart21e9a0a2009-05-22 14:53:21 -04002319/**
2320 * lpfc_static_vport_show: Read callback function for
2321 * lpfc_static_vport sysfs file.
2322 * @dev: Pointer to class device object.
2323 * @attr: device attribute structure.
2324 * @buf: Data buffer.
2325 *
2326 * This function is the read call back function for
2327 * lpfc_static_vport sysfs file. The lpfc_static_vport
2328 * sysfs file report the mageability of the vport.
2329 **/
2330static ssize_t
2331lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2332 char *buf)
2333{
2334 struct Scsi_Host *shost = class_to_shost(dev);
2335 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2336 if (vport->vport_flag & STATIC_VPORT)
2337 sprintf(buf, "1\n");
2338 else
2339 sprintf(buf, "0\n");
2340
2341 return strlen(buf);
2342}
2343
2344/*
2345 * Sysfs attribute to control the statistical data collection.
2346 */
2347static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2348 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002349
2350/**
James Smart3621a712009-04-06 18:47:14 -04002351 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002352 * @dev: Pointer to class device.
2353 * @buf: Data buffer.
2354 * @count: Size of the data buffer.
2355 *
2356 * This function get called when an user write to the lpfc_stat_data_ctrl
2357 * sysfs file. This function parse the command written to the sysfs file
2358 * and take appropriate action. These commands are used for controlling
2359 * driver statistical data collection.
2360 * Following are the command this function handles.
2361 *
2362 * setbucket <bucket_type> <base> <step>
2363 * = Set the latency buckets.
2364 * destroybucket = destroy all the buckets.
2365 * start = start data collection
2366 * stop = stop data collection
2367 * reset = reset the collected data
2368 **/
2369static ssize_t
2370lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2371 const char *buf, size_t count)
2372{
2373 struct Scsi_Host *shost = class_to_shost(dev);
2374 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2375 struct lpfc_hba *phba = vport->phba;
2376#define LPFC_MAX_DATA_CTRL_LEN 1024
2377 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2378 unsigned long i;
2379 char *str_ptr, *token;
2380 struct lpfc_vport **vports;
2381 struct Scsi_Host *v_shost;
2382 char *bucket_type_str, *base_str, *step_str;
2383 unsigned long base, step, bucket_type;
2384
2385 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002386 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002387 return -EINVAL;
2388
2389 strcpy(bucket_data, buf);
2390 str_ptr = &bucket_data[0];
2391 /* Ignore this token - this is command token */
2392 token = strsep(&str_ptr, "\t ");
2393 if (!token)
2394 return -EINVAL;
2395
2396 bucket_type_str = strsep(&str_ptr, "\t ");
2397 if (!bucket_type_str)
2398 return -EINVAL;
2399
2400 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2401 bucket_type = LPFC_LINEAR_BUCKET;
2402 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2403 bucket_type = LPFC_POWER2_BUCKET;
2404 else
2405 return -EINVAL;
2406
2407 base_str = strsep(&str_ptr, "\t ");
2408 if (!base_str)
2409 return -EINVAL;
2410 base = simple_strtoul(base_str, NULL, 0);
2411
2412 step_str = strsep(&str_ptr, "\t ");
2413 if (!step_str)
2414 return -EINVAL;
2415 step = simple_strtoul(step_str, NULL, 0);
2416 if (!step)
2417 return -EINVAL;
2418
2419 /* Block the data collection for every vport */
2420 vports = lpfc_create_vport_work_array(phba);
2421 if (vports == NULL)
2422 return -ENOMEM;
2423
James Smartf4b4c682009-05-22 14:53:12 -04002424 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002425 v_shost = lpfc_shost_from_vport(vports[i]);
2426 spin_lock_irq(v_shost->host_lock);
2427 /* Block and reset data collection */
2428 vports[i]->stat_data_blocked = 1;
2429 if (vports[i]->stat_data_enabled)
2430 lpfc_vport_reset_stat_data(vports[i]);
2431 spin_unlock_irq(v_shost->host_lock);
2432 }
2433
2434 /* Set the bucket attributes */
2435 phba->bucket_type = bucket_type;
2436 phba->bucket_base = base;
2437 phba->bucket_step = step;
2438
James Smartf4b4c682009-05-22 14:53:12 -04002439 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002440 v_shost = lpfc_shost_from_vport(vports[i]);
2441
2442 /* Unblock data collection */
2443 spin_lock_irq(v_shost->host_lock);
2444 vports[i]->stat_data_blocked = 0;
2445 spin_unlock_irq(v_shost->host_lock);
2446 }
2447 lpfc_destroy_vport_work_array(phba, vports);
2448 return strlen(buf);
2449 }
2450
2451 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2452 vports = lpfc_create_vport_work_array(phba);
2453 if (vports == NULL)
2454 return -ENOMEM;
2455
James Smartf4b4c682009-05-22 14:53:12 -04002456 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002457 v_shost = lpfc_shost_from_vport(vports[i]);
2458 spin_lock_irq(shost->host_lock);
2459 vports[i]->stat_data_blocked = 1;
2460 lpfc_free_bucket(vport);
2461 vport->stat_data_enabled = 0;
2462 vports[i]->stat_data_blocked = 0;
2463 spin_unlock_irq(shost->host_lock);
2464 }
2465 lpfc_destroy_vport_work_array(phba, vports);
2466 phba->bucket_type = LPFC_NO_BUCKET;
2467 phba->bucket_base = 0;
2468 phba->bucket_step = 0;
2469 return strlen(buf);
2470 }
2471
2472 if (!strncmp(buf, "start", strlen("start"))) {
2473 /* If no buckets configured return error */
2474 if (phba->bucket_type == LPFC_NO_BUCKET)
2475 return -EINVAL;
2476 spin_lock_irq(shost->host_lock);
2477 if (vport->stat_data_enabled) {
2478 spin_unlock_irq(shost->host_lock);
2479 return strlen(buf);
2480 }
2481 lpfc_alloc_bucket(vport);
2482 vport->stat_data_enabled = 1;
2483 spin_unlock_irq(shost->host_lock);
2484 return strlen(buf);
2485 }
2486
2487 if (!strncmp(buf, "stop", strlen("stop"))) {
2488 spin_lock_irq(shost->host_lock);
2489 if (vport->stat_data_enabled == 0) {
2490 spin_unlock_irq(shost->host_lock);
2491 return strlen(buf);
2492 }
2493 lpfc_free_bucket(vport);
2494 vport->stat_data_enabled = 0;
2495 spin_unlock_irq(shost->host_lock);
2496 return strlen(buf);
2497 }
2498
2499 if (!strncmp(buf, "reset", strlen("reset"))) {
2500 if ((phba->bucket_type == LPFC_NO_BUCKET)
2501 || !vport->stat_data_enabled)
2502 return strlen(buf);
2503 spin_lock_irq(shost->host_lock);
2504 vport->stat_data_blocked = 1;
2505 lpfc_vport_reset_stat_data(vport);
2506 vport->stat_data_blocked = 0;
2507 spin_unlock_irq(shost->host_lock);
2508 return strlen(buf);
2509 }
2510 return -EINVAL;
2511}
2512
2513
2514/**
James Smart3621a712009-04-06 18:47:14 -04002515 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002516 * @dev: Pointer to class device object.
2517 * @buf: Data buffer.
2518 *
2519 * This function is the read call back function for
2520 * lpfc_stat_data_ctrl sysfs file. This function report the
2521 * current statistical data collection state.
2522 **/
2523static ssize_t
2524lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2525 char *buf)
2526{
2527 struct Scsi_Host *shost = class_to_shost(dev);
2528 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2529 struct lpfc_hba *phba = vport->phba;
2530 int index = 0;
2531 int i;
2532 char *bucket_type;
2533 unsigned long bucket_value;
2534
2535 switch (phba->bucket_type) {
2536 case LPFC_LINEAR_BUCKET:
2537 bucket_type = "linear";
2538 break;
2539 case LPFC_POWER2_BUCKET:
2540 bucket_type = "power2";
2541 break;
2542 default:
2543 bucket_type = "No Bucket";
2544 break;
2545 }
2546
2547 sprintf(&buf[index], "Statistical Data enabled :%d, "
2548 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2549 " Bucket step :%d\nLatency Ranges :",
2550 vport->stat_data_enabled, vport->stat_data_blocked,
2551 bucket_type, phba->bucket_base, phba->bucket_step);
2552 index = strlen(buf);
2553 if (phba->bucket_type != LPFC_NO_BUCKET) {
2554 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2555 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2556 bucket_value = phba->bucket_base +
2557 phba->bucket_step * i;
2558 else
2559 bucket_value = phba->bucket_base +
2560 (1 << i) * phba->bucket_step;
2561
2562 if (index + 10 > PAGE_SIZE)
2563 break;
2564 sprintf(&buf[index], "%08ld ", bucket_value);
2565 index = strlen(buf);
2566 }
2567 }
2568 sprintf(&buf[index], "\n");
2569 return strlen(buf);
2570}
2571
2572/*
2573 * Sysfs attribute to control the statistical data collection.
2574 */
2575static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2576 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2577
2578/*
2579 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2580 */
2581
2582/*
2583 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2584 * for each target.
2585 */
2586#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2587#define MAX_STAT_DATA_SIZE_PER_TARGET \
2588 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2589
2590
2591/**
James Smart3621a712009-04-06 18:47:14 -04002592 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
James Smartea2151b2008-09-07 11:52:10 -04002593 * @kobj: Pointer to the kernel object
2594 * @bin_attr: Attribute object
2595 * @buff: Buffer pointer
2596 * @off: File offset
2597 * @count: Buffer size
2598 *
2599 * This function is the read call back function for lpfc_drvr_stat_data
2600 * sysfs file. This function export the statistical data to user
2601 * applications.
2602 **/
2603static ssize_t
2604sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2605 char *buf, loff_t off, size_t count)
2606{
2607 struct device *dev = container_of(kobj, struct device,
2608 kobj);
2609 struct Scsi_Host *shost = class_to_shost(dev);
2610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2611 struct lpfc_hba *phba = vport->phba;
2612 int i = 0, index = 0;
2613 unsigned long nport_index;
2614 struct lpfc_nodelist *ndlp = NULL;
2615 nport_index = (unsigned long)off /
2616 MAX_STAT_DATA_SIZE_PER_TARGET;
2617
2618 if (!vport->stat_data_enabled || vport->stat_data_blocked
2619 || (phba->bucket_type == LPFC_NO_BUCKET))
2620 return 0;
2621
2622 spin_lock_irq(shost->host_lock);
2623 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2624 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2625 continue;
2626
2627 if (nport_index > 0) {
2628 nport_index--;
2629 continue;
2630 }
2631
2632 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2633 > count)
2634 break;
2635
2636 if (!ndlp->lat_data)
2637 continue;
2638
2639 /* Print the WWN */
2640 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2641 ndlp->nlp_portname.u.wwn[0],
2642 ndlp->nlp_portname.u.wwn[1],
2643 ndlp->nlp_portname.u.wwn[2],
2644 ndlp->nlp_portname.u.wwn[3],
2645 ndlp->nlp_portname.u.wwn[4],
2646 ndlp->nlp_portname.u.wwn[5],
2647 ndlp->nlp_portname.u.wwn[6],
2648 ndlp->nlp_portname.u.wwn[7]);
2649
2650 index = strlen(buf);
2651
2652 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2653 sprintf(&buf[index], "%010u,",
2654 ndlp->lat_data[i].cmd_count);
2655 index = strlen(buf);
2656 }
2657 sprintf(&buf[index], "\n");
2658 index = strlen(buf);
2659 }
2660 spin_unlock_irq(shost->host_lock);
2661 return index;
2662}
2663
2664static struct bin_attribute sysfs_drvr_stat_data_attr = {
2665 .attr = {
2666 .name = "lpfc_drvr_stat_data",
2667 .mode = S_IRUSR,
2668 .owner = THIS_MODULE,
2669 },
2670 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2671 .read = sysfs_drvr_stat_data_read,
2672 .write = NULL,
2673};
2674
dea31012005-04-17 16:05:31 -05002675/*
2676# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2677# connection.
2678# 0 = auto select (default)
2679# 1 = 1 Gigabaud
2680# 2 = 2 Gigabaud
2681# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002682# 8 = 8 Gigabaud
2683# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002684*/
James Smarte59058c2008-08-24 21:49:00 -04002685
2686/**
James Smart3621a712009-04-06 18:47:14 -04002687 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002688 * @phba: lpfc_hba pointer.
2689 * @val: link speed value.
2690 *
2691 * Description:
2692 * If val is in a valid range then set the adapter's link speed field and
2693 * issue a lip; if the lip fails reset the link speed to the old value.
2694 *
2695 * Notes:
2696 * If the value is not in range log a kernel error message and return an error.
2697 *
2698 * Returns:
2699 * zero if val is in range and lip okay.
2700 * non-zero return value from lpfc_issue_lip()
2701 * -EINVAL val out of range
2702 **/
James Smarta257bf92009-04-06 18:48:10 -04002703static ssize_t
2704lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2705 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002706{
James Smarta257bf92009-04-06 18:48:10 -04002707 struct Scsi_Host *shost = class_to_shost(dev);
2708 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2709 struct lpfc_hba *phba = vport->phba;
2710 int val = 0;
2711 int nolip = 0;
2712 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002713 int err;
2714 uint32_t prev_val;
2715
James Smarta257bf92009-04-06 18:48:10 -04002716 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2717 nolip = 1;
2718 val_buf = &buf[strlen("nolip ")];
2719 }
2720
2721 if (!isdigit(val_buf[0]))
2722 return -EINVAL;
2723 if (sscanf(val_buf, "%i", &val) != 1)
2724 return -EINVAL;
2725
James Smart83108bd2008-01-11 01:53:09 -05002726 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2727 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2728 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2729 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2730 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2731 return -EINVAL;
2732
James Smarta257bf92009-04-06 18:48:10 -04002733 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002734 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2735 prev_val = phba->cfg_link_speed;
2736 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002737 if (nolip)
2738 return strlen(buf);
2739
James Smart83108bd2008-01-11 01:53:09 -05002740 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002741 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002742 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002743 return -EINVAL;
2744 } else
2745 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002746 }
2747
2748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2749 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2750 "allowed range is [0, 8]\n",
2751 phba->brd_no, val);
2752 return -EINVAL;
2753}
2754
2755static int lpfc_link_speed = 0;
2756module_param(lpfc_link_speed, int, 0);
2757MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2758lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002759
2760/**
James Smart3621a712009-04-06 18:47:14 -04002761 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002762 * @phba: lpfc_hba pointer.
2763 * @val: link speed value.
2764 *
2765 * Description:
2766 * If val is in a valid range then set the adapter's link speed field.
2767 *
2768 * Notes:
2769 * If the value is not in range log a kernel error message, clear the link
2770 * speed and return an error.
2771 *
2772 * Returns:
2773 * zero if val saved.
2774 * -EINVAL val out of range
2775 **/
James Smart83108bd2008-01-11 01:53:09 -05002776static int
2777lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2778{
2779 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2780 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2781 phba->cfg_link_speed = val;
2782 return 0;
2783 }
2784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002785 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002786 "be set to %d, allowed values are "
2787 "["LPFC_LINK_SPEED_STRING"]\n", val);
2788 phba->cfg_link_speed = 0;
2789 return -EINVAL;
2790}
2791
Tony Jonesee959b02008-02-22 00:13:36 +01002792static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002793 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002794
2795/*
James Smart0d878412009-10-02 15:16:56 -04002796# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2797# 0 = aer disabled or not supported
2798# 1 = aer supported and enabled (default)
2799# Value range is [0,1]. Default value is 1.
2800*/
2801
2802/**
2803 * lpfc_aer_support_store - Set the adapter for aer support
2804 *
2805 * @dev: class device that is converted into a Scsi_host.
2806 * @attr: device attribute, not used.
2807 * @buf: containing the string "selective".
2808 * @count: unused variable.
2809 *
2810 * Description:
2811 * If the val is 1 and currently the device's AER capability was not
2812 * enabled, invoke the kernel's enable AER helper routine, trying to
2813 * enable the device's AER capability. If the helper routine enabling
2814 * AER returns success, update the device's cfg_aer_support flag to
2815 * indicate AER is supported by the device; otherwise, if the device
2816 * AER capability is already enabled to support AER, then do nothing.
2817 *
2818 * If the val is 0 and currently the device's AER support was enabled,
2819 * invoke the kernel's disable AER helper routine. After that, update
2820 * the device's cfg_aer_support flag to indicate AER is not supported
2821 * by the device; otherwise, if the device AER capability is already
2822 * disabled from supporting AER, then do nothing.
2823 *
2824 * Returns:
2825 * length of the buf on success if val is in range the intended mode
2826 * is supported.
2827 * -EINVAL if val out of range or intended mode is not supported.
2828 **/
2829static ssize_t
2830lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2831 const char *buf, size_t count)
2832{
2833 struct Scsi_Host *shost = class_to_shost(dev);
2834 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2835 struct lpfc_hba *phba = vport->phba;
2836 int val = 0, rc = -EINVAL;
2837
James Smart891478a2009-11-18 15:40:23 -05002838 /* AER not supported on OC devices yet */
2839 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
2840 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04002841 if (!isdigit(buf[0]))
2842 return -EINVAL;
2843 if (sscanf(buf, "%i", &val) != 1)
2844 return -EINVAL;
2845
2846 switch (val) {
2847 case 0:
2848 if (phba->hba_flag & HBA_AER_ENABLED) {
2849 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2850 if (!rc) {
2851 spin_lock_irq(&phba->hbalock);
2852 phba->hba_flag &= ~HBA_AER_ENABLED;
2853 spin_unlock_irq(&phba->hbalock);
2854 phba->cfg_aer_support = 0;
2855 rc = strlen(buf);
2856 } else
James Smart891478a2009-11-18 15:40:23 -05002857 rc = -EPERM;
2858 } else {
James Smart0d878412009-10-02 15:16:56 -04002859 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05002860 rc = strlen(buf);
2861 }
James Smart0d878412009-10-02 15:16:56 -04002862 break;
2863 case 1:
2864 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2865 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2866 if (!rc) {
2867 spin_lock_irq(&phba->hbalock);
2868 phba->hba_flag |= HBA_AER_ENABLED;
2869 spin_unlock_irq(&phba->hbalock);
2870 phba->cfg_aer_support = 1;
2871 rc = strlen(buf);
2872 } else
James Smart891478a2009-11-18 15:40:23 -05002873 rc = -EPERM;
2874 } else {
James Smart0d878412009-10-02 15:16:56 -04002875 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05002876 rc = strlen(buf);
2877 }
James Smart0d878412009-10-02 15:16:56 -04002878 break;
2879 default:
2880 rc = -EINVAL;
2881 break;
2882 }
2883 return rc;
2884}
2885
2886static int lpfc_aer_support = 1;
2887module_param(lpfc_aer_support, int, 1);
2888MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2889lpfc_param_show(aer_support)
2890
2891/**
2892 * lpfc_aer_support_init - Set the initial adapters aer support flag
2893 * @phba: lpfc_hba pointer.
2894 * @val: link speed value.
2895 *
2896 * Description:
2897 * If val is in a valid range [0,1], then set the adapter's initial
2898 * cfg_aer_support field. It will be up to the driver's probe_one
2899 * routine to determine whether the device's AER support can be set
2900 * or not.
2901 *
2902 * Notes:
2903 * If the value is not in range log a kernel error message, and
2904 * choose the default value of setting AER support and return.
2905 *
2906 * Returns:
2907 * zero if val saved.
2908 * -EINVAL val out of range
2909 **/
2910static int
2911lpfc_aer_support_init(struct lpfc_hba *phba, int val)
2912{
James Smart891478a2009-11-18 15:40:23 -05002913 /* AER not supported on OC devices yet */
2914 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
2915 phba->cfg_aer_support = 0;
2916 return -EPERM;
2917 }
2918
James Smart0d878412009-10-02 15:16:56 -04002919 if (val == 0 || val == 1) {
2920 phba->cfg_aer_support = val;
2921 return 0;
2922 }
2923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2924 "2712 lpfc_aer_support attribute value %d out "
2925 "of range, allowed values are 0|1, setting it "
2926 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05002927 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04002928 phba->cfg_aer_support = 1;
2929 return -EINVAL;
2930}
2931
2932static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
2933 lpfc_aer_support_show, lpfc_aer_support_store);
2934
2935/**
2936 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
2937 * @dev: class device that is converted into a Scsi_host.
2938 * @attr: device attribute, not used.
2939 * @buf: containing the string "selective".
2940 * @count: unused variable.
2941 *
2942 * Description:
2943 * If the @buf contains 1 and the device currently has the AER support
2944 * enabled, then invokes the kernel AER helper routine
2945 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
2946 * error status register.
2947 *
2948 * Notes:
2949 *
2950 * Returns:
2951 * -EINVAL if the buf does not contain the 1 or the device is not currently
2952 * enabled with the AER support.
2953 **/
2954static ssize_t
2955lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
2956 const char *buf, size_t count)
2957{
2958 struct Scsi_Host *shost = class_to_shost(dev);
2959 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2960 struct lpfc_hba *phba = vport->phba;
2961 int val, rc = -1;
2962
James Smart891478a2009-11-18 15:40:23 -05002963 /* AER not supported on OC devices yet */
2964 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
2965 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04002966 if (!isdigit(buf[0]))
2967 return -EINVAL;
2968 if (sscanf(buf, "%i", &val) != 1)
2969 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05002970 if (val != 1)
2971 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04002972
James Smart891478a2009-11-18 15:40:23 -05002973 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04002974 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
2975
2976 if (rc == 0)
2977 return strlen(buf);
2978 else
James Smart891478a2009-11-18 15:40:23 -05002979 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04002980}
2981
2982static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
2983 lpfc_aer_cleanup_state);
2984
2985/*
dea31012005-04-17 16:05:31 -05002986# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2987# Value range is [2,3]. Default value is 3.
2988*/
James Smart3de2a652007-08-02 11:09:59 -04002989LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2990 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002991
2992/*
2993# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2994# is [0,1]. Default value is 0.
2995*/
James Smart3de2a652007-08-02 11:09:59 -04002996LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2997 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002998
2999/*
James Smart977b5a02008-09-07 11:52:04 -04003000# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3001# depth. Default value is 0. When the value of this parameter is zero the
3002# SCSI command completion time is not used for controlling I/O queue depth. When
3003# the parameter is set to a non-zero value, the I/O queue depth is controlled
3004# to limit the I/O completion time to the parameter value.
3005# The value is set in milliseconds.
3006*/
3007static int lpfc_max_scsicmpl_time;
3008module_param(lpfc_max_scsicmpl_time, int, 0);
3009MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3010 "Use command completion time to control queue depth");
3011lpfc_vport_param_show(max_scsicmpl_time);
3012lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3013static int
3014lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3015{
3016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3017 struct lpfc_nodelist *ndlp, *next_ndlp;
3018
3019 if (val == vport->cfg_max_scsicmpl_time)
3020 return 0;
3021 if ((val < 0) || (val > 60000))
3022 return -EINVAL;
3023 vport->cfg_max_scsicmpl_time = val;
3024
3025 spin_lock_irq(shost->host_lock);
3026 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3027 if (!NLP_CHK_NODE_ACT(ndlp))
3028 continue;
3029 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3030 continue;
3031 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
3032 }
3033 spin_unlock_irq(shost->host_lock);
3034 return 0;
3035}
3036lpfc_vport_param_store(max_scsicmpl_time);
3037static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3038 lpfc_max_scsicmpl_time_show,
3039 lpfc_max_scsicmpl_time_store);
3040
3041/*
dea31012005-04-17 16:05:31 -05003042# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3043# range is [0,1]. Default value is 0.
3044*/
3045LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3046
3047/*
3048# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3049# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003050# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003051# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3052# cr_delay is set to 0.
3053*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003054LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003055 "interrupt response is generated");
3056
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003057LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003058 "interrupt response is generated");
3059
3060/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003061# lpfc_multi_ring_support: Determines how many rings to spread available
3062# cmd/rsp IOCB entries across.
3063# Value range is [1,2]. Default value is 1.
3064*/
3065LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3066 "SLI rings to spread IOCB entries across");
3067
3068/*
James Smarta4bc3372006-12-02 13:34:16 -05003069# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3070# identifies what rctl value to configure the additional ring for.
3071# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3072*/
James Smart6a9c52c2009-10-02 15:16:51 -04003073LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003074 255, "Identifies RCTL for additional ring configuration");
3075
3076/*
3077# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3078# identifies what type value to configure the additional ring for.
3079# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3080*/
James Smart6a9c52c2009-10-02 15:16:51 -04003081LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003082 255, "Identifies TYPE for additional ring configuration");
3083
3084/*
dea31012005-04-17 16:05:31 -05003085# lpfc_fdmi_on: controls FDMI support.
3086# 0 = no FDMI support
3087# 1 = support FDMI without attribute of hostname
3088# 2 = support FDMI with attribute of hostname
3089# Value range [0,2]. Default value is 0.
3090*/
James Smart3de2a652007-08-02 11:09:59 -04003091LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003092
3093/*
3094# Specifies the maximum number of ELS cmds we can have outstanding (for
3095# discovery). Value range is [1,64]. Default value = 32.
3096*/
James Smart3de2a652007-08-02 11:09:59 -04003097LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003098 "during discovery");
3099
3100/*
James Smart65a29c12006-07-06 15:50:50 -04003101# lpfc_max_luns: maximum allowed LUN.
3102# Value range is [0,65535]. Default value is 255.
3103# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003104*/
James Smart3de2a652007-08-02 11:09:59 -04003105LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003106
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003107/*
3108# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3109# Value range is [1,255], default value is 10.
3110*/
3111LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3112 "Milliseconds driver will wait between polling FCP ring");
3113
James Smart4ff43242006-12-02 13:34:56 -05003114/*
3115# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3116# support this feature
James Smartda0436e2009-05-22 14:51:39 -04003117# 0 = MSI disabled (default)
James Smart4ff43242006-12-02 13:34:56 -05003118# 1 = MSI enabled
James Smartda0436e2009-05-22 14:51:39 -04003119# 2 = MSI-X enabled
3120# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05003121*/
James Smartda0436e2009-05-22 14:51:39 -04003122LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003123 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003124
James Smart13815c82008-01-11 01:52:48 -05003125/*
James Smartda0436e2009-05-22 14:51:39 -04003126# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3127#
3128# Value range is [636,651042]. Default value is 10000.
3129*/
3130LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3131 "Set the maximum number of fast-path FCP interrupts per second");
3132
3133/*
3134# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3135#
3136# Value range is [1,31]. Default value is 4.
3137*/
3138LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3139 "Set the number of fast-path FCP work queues, if possible");
3140
3141/*
3142# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3143#
3144# Value range is [1,7]. Default value is 1.
3145*/
3146LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3147 "Set the number of fast-path FCP event queues, if possible");
3148
3149/*
James Smart13815c82008-01-11 01:52:48 -05003150# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3151# 0 = HBA resets disabled
3152# 1 = HBA resets enabled (default)
3153# Value range is [0,1]. Default value is 1.
3154*/
3155LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003156
James Smart13815c82008-01-11 01:52:48 -05003157/*
3158# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3159# 0 = HBA Heartbeat disabled
3160# 1 = HBA Heartbeat enabled (default)
3161# Value range is [0,1]. Default value is 1.
3162*/
3163LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003164
James Smart83108bd2008-01-11 01:53:09 -05003165/*
James Smart81301a92008-12-04 22:39:46 -05003166# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3167# 0 = BlockGuard disabled (default)
3168# 1 = BlockGuard enabled
3169# Value range is [0,1]. Default value is 0.
3170*/
3171LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3172
James Smart6fb120a2009-05-22 14:52:59 -04003173/*
James Smart81301a92008-12-04 22:39:46 -05003174# lpfc_prot_mask: i
3175# - Bit mask of host protection capabilities used to register with the
3176# SCSI mid-layer
3177# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3178# - Allows you to ultimately specify which profiles to use
3179# - Default will result in registering capabilities for all profiles.
3180#
3181*/
3182unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3183
3184module_param(lpfc_prot_mask, uint, 0);
3185MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3186
3187/*
3188# lpfc_prot_guard: i
3189# - Bit mask of protection guard types to register with the SCSI mid-layer
3190# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3191# - Allows you to ultimately specify which profiles to use
3192# - Default will result in registering capabilities for all guard types
3193#
3194*/
3195unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3196module_param(lpfc_prot_guard, byte, 0);
3197MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3198
3199
3200/*
James Smart3621a712009-04-06 18:47:14 -04003201 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003202 * This value can be set to values between 64 and 256. The default value is
3203 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3204 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3205 */
3206LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3207 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3208
James Smart81301a92008-12-04 22:39:46 -05003209LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3210 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3211 "Max Protection Scatter Gather Segment Count");
3212
Tony Jonesee959b02008-02-22 00:13:36 +01003213struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003214 &dev_attr_bg_info,
3215 &dev_attr_bg_guard_err,
3216 &dev_attr_bg_apptag_err,
3217 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003218 &dev_attr_info,
3219 &dev_attr_serialnum,
3220 &dev_attr_modeldesc,
3221 &dev_attr_modelname,
3222 &dev_attr_programtype,
3223 &dev_attr_portnum,
3224 &dev_attr_fwrev,
3225 &dev_attr_hdw,
3226 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003227 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003228 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003229 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003230 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003231 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003232 &dev_attr_lpfc_temp_sensor,
3233 &dev_attr_lpfc_log_verbose,
3234 &dev_attr_lpfc_lun_queue_depth,
3235 &dev_attr_lpfc_hba_queue_depth,
3236 &dev_attr_lpfc_peer_port_login,
3237 &dev_attr_lpfc_nodev_tmo,
3238 &dev_attr_lpfc_devloss_tmo,
3239 &dev_attr_lpfc_fcp_class,
3240 &dev_attr_lpfc_use_adisc,
3241 &dev_attr_lpfc_ack0,
3242 &dev_attr_lpfc_topology,
3243 &dev_attr_lpfc_scan_down,
3244 &dev_attr_lpfc_link_speed,
3245 &dev_attr_lpfc_cr_delay,
3246 &dev_attr_lpfc_cr_count,
3247 &dev_attr_lpfc_multi_ring_support,
3248 &dev_attr_lpfc_multi_ring_rctl,
3249 &dev_attr_lpfc_multi_ring_type,
3250 &dev_attr_lpfc_fdmi_on,
3251 &dev_attr_lpfc_max_luns,
3252 &dev_attr_lpfc_enable_npiv,
3253 &dev_attr_nport_evt_cnt,
3254 &dev_attr_board_mode,
3255 &dev_attr_max_vpi,
3256 &dev_attr_used_vpi,
3257 &dev_attr_max_rpi,
3258 &dev_attr_used_rpi,
3259 &dev_attr_max_xri,
3260 &dev_attr_used_xri,
3261 &dev_attr_npiv_info,
3262 &dev_attr_issue_reset,
3263 &dev_attr_lpfc_poll,
3264 &dev_attr_lpfc_poll_tmo,
3265 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003266 &dev_attr_lpfc_fcp_imax,
3267 &dev_attr_lpfc_fcp_wq_count,
3268 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003269 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003270 &dev_attr_lpfc_soft_wwnn,
3271 &dev_attr_lpfc_soft_wwpn,
3272 &dev_attr_lpfc_soft_wwn_enable,
3273 &dev_attr_lpfc_enable_hba_reset,
3274 &dev_attr_lpfc_enable_hba_heartbeat,
3275 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003276 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003277 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003278 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003279 &dev_attr_lpfc_aer_support,
3280 &dev_attr_lpfc_aer_state_cleanup,
dea31012005-04-17 16:05:31 -05003281 NULL,
3282};
3283
Tony Jonesee959b02008-02-22 00:13:36 +01003284struct device_attribute *lpfc_vport_attrs[] = {
3285 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003286 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003287 &dev_attr_num_discovered_ports,
3288 &dev_attr_lpfc_drvr_version,
3289 &dev_attr_lpfc_log_verbose,
3290 &dev_attr_lpfc_lun_queue_depth,
3291 &dev_attr_lpfc_nodev_tmo,
3292 &dev_attr_lpfc_devloss_tmo,
3293 &dev_attr_lpfc_hba_queue_depth,
3294 &dev_attr_lpfc_peer_port_login,
3295 &dev_attr_lpfc_restrict_login,
3296 &dev_attr_lpfc_fcp_class,
3297 &dev_attr_lpfc_use_adisc,
3298 &dev_attr_lpfc_fdmi_on,
3299 &dev_attr_lpfc_max_luns,
3300 &dev_attr_nport_evt_cnt,
3301 &dev_attr_npiv_info,
3302 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003303 &dev_attr_lpfc_max_scsicmpl_time,
3304 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003305 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003306 NULL,
3307};
3308
James Smarte59058c2008-08-24 21:49:00 -04003309/**
James Smart3621a712009-04-06 18:47:14 -04003310 * sysfs_ctlreg_write - Write method for writing to ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003311 * @kobj: kernel kobject that contains the kernel class device.
3312 * @bin_attr: kernel attributes passed to us.
3313 * @buf: contains the data to be written to the adapter IOREG space.
3314 * @off: offset into buffer to beginning of data.
3315 * @count: bytes to transfer.
3316 *
3317 * Description:
3318 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3319 * Uses the adapter io control registers to send buf contents to the adapter.
3320 *
3321 * Returns:
3322 * -ERANGE off and count combo out of range
3323 * -EINVAL off, count or buff address invalid
3324 * -EPERM adapter is offline
3325 * value of count, buf contents written
3326 **/
dea31012005-04-17 16:05:31 -05003327static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003328sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3329 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003330{
3331 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003332 struct device *dev = container_of(kobj, struct device, kobj);
3333 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3335 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003336
James Smartf1126682009-06-10 17:22:44 -04003337 if (phba->sli_rev >= LPFC_SLI_REV4)
3338 return -EPERM;
3339
dea31012005-04-17 16:05:31 -05003340 if ((off + count) > FF_REG_AREA_SIZE)
3341 return -ERANGE;
3342
3343 if (count == 0) return 0;
3344
3345 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3346 return -EINVAL;
3347
James Smart2e0fef82007-06-17 19:56:36 -05003348 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003349 return -EPERM;
3350 }
3351
James Smart2e0fef82007-06-17 19:56:36 -05003352 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003353 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3354 writel(*((uint32_t *)(buf + buf_off)),
3355 phba->ctrl_regs_memmap_p + off + buf_off);
3356
James Smart2e0fef82007-06-17 19:56:36 -05003357 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003358
3359 return count;
3360}
3361
James Smarte59058c2008-08-24 21:49:00 -04003362/**
James Smart3621a712009-04-06 18:47:14 -04003363 * sysfs_ctlreg_read - Read method for reading from ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003364 * @kobj: kernel kobject that contains the kernel class device.
3365 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003366 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003367 * @off: offset into buffer to beginning of data.
3368 * @count: bytes to transfer.
3369 *
3370 * Description:
3371 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3372 * Uses the adapter io control registers to read data into buf.
3373 *
3374 * Returns:
3375 * -ERANGE off and count combo out of range
3376 * -EINVAL off, count or buff address invalid
3377 * value of count, buf contents read
3378 **/
dea31012005-04-17 16:05:31 -05003379static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003380sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3381 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003382{
3383 size_t buf_off;
3384 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003385 struct device *dev = container_of(kobj, struct device, kobj);
3386 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3388 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003389
James Smartf1126682009-06-10 17:22:44 -04003390 if (phba->sli_rev >= LPFC_SLI_REV4)
3391 return -EPERM;
3392
dea31012005-04-17 16:05:31 -05003393 if (off > FF_REG_AREA_SIZE)
3394 return -ERANGE;
3395
3396 if ((off + count) > FF_REG_AREA_SIZE)
3397 count = FF_REG_AREA_SIZE - off;
3398
3399 if (count == 0) return 0;
3400
3401 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3402 return -EINVAL;
3403
James Smart2e0fef82007-06-17 19:56:36 -05003404 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003405
3406 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3407 tmp_ptr = (uint32_t *)(buf + buf_off);
3408 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3409 }
3410
James Smart2e0fef82007-06-17 19:56:36 -05003411 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003412
3413 return count;
3414}
3415
3416static struct bin_attribute sysfs_ctlreg_attr = {
3417 .attr = {
3418 .name = "ctlreg",
3419 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003420 },
3421 .size = 256,
3422 .read = sysfs_ctlreg_read,
3423 .write = sysfs_ctlreg_write,
3424};
3425
James Smarte59058c2008-08-24 21:49:00 -04003426/**
James Smart3621a712009-04-06 18:47:14 -04003427 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003428 * @phba: lpfc_hba pointer
3429 **/
dea31012005-04-17 16:05:31 -05003430static void
James Smart2e0fef82007-06-17 19:56:36 -05003431sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003432{
3433 phba->sysfs_mbox.state = SMBOX_IDLE;
3434 phba->sysfs_mbox.offset = 0;
3435
3436 if (phba->sysfs_mbox.mbox) {
3437 mempool_free(phba->sysfs_mbox.mbox,
3438 phba->mbox_mem_pool);
3439 phba->sysfs_mbox.mbox = NULL;
3440 }
3441}
3442
James Smarte59058c2008-08-24 21:49:00 -04003443/**
James Smart3621a712009-04-06 18:47:14 -04003444 * sysfs_mbox_write - Write method for writing information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003445 * @kobj: kernel kobject that contains the kernel class device.
3446 * @bin_attr: kernel attributes passed to us.
3447 * @buf: contains the data to be written to sysfs mbox.
3448 * @off: offset into buffer to beginning of data.
3449 * @count: bytes to transfer.
3450 *
3451 * Description:
3452 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3453 * Uses the sysfs mbox to send buf contents to the adapter.
3454 *
3455 * Returns:
3456 * -ERANGE off and count combo out of range
3457 * -EINVAL off, count or buff address invalid
3458 * zero if count is zero
3459 * -EPERM adapter is offline
3460 * -ENOMEM failed to allocate memory for the mail box
3461 * -EAGAIN offset, state or mbox is NULL
3462 * count number of bytes transferred
3463 **/
dea31012005-04-17 16:05:31 -05003464static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003465sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3466 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003467{
Tony Jonesee959b02008-02-22 00:13:36 +01003468 struct device *dev = container_of(kobj, struct device, kobj);
3469 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003470 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3471 struct lpfc_hba *phba = vport->phba;
3472 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003473
3474 if ((count + off) > MAILBOX_CMD_SIZE)
3475 return -ERANGE;
3476
3477 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3478 return -EINVAL;
3479
3480 if (count == 0)
3481 return 0;
3482
3483 if (off == 0) {
3484 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3485 if (!mbox)
3486 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003487 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003488 }
3489
James Smart2e0fef82007-06-17 19:56:36 -05003490 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003491
3492 if (off == 0) {
3493 if (phba->sysfs_mbox.mbox)
3494 mempool_free(mbox, phba->mbox_mem_pool);
3495 else
3496 phba->sysfs_mbox.mbox = mbox;
3497 phba->sysfs_mbox.state = SMBOX_WRITING;
3498 } else {
3499 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3500 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003501 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003502 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003503 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003504 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003505 }
3506 }
3507
James Smart04c68492009-05-22 14:52:52 -04003508 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003509 buf, count);
3510
3511 phba->sysfs_mbox.offset = off + count;
3512
James Smart2e0fef82007-06-17 19:56:36 -05003513 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003514
3515 return count;
3516}
3517
James Smarte59058c2008-08-24 21:49:00 -04003518/**
James Smart3621a712009-04-06 18:47:14 -04003519 * sysfs_mbox_read - Read method for reading information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003520 * @kobj: kernel kobject that contains the kernel class device.
3521 * @bin_attr: kernel attributes passed to us.
3522 * @buf: contains the data to be read from sysfs mbox.
3523 * @off: offset into buffer to beginning of data.
3524 * @count: bytes to transfer.
3525 *
3526 * Description:
3527 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3528 * Uses the sysfs mbox to receive data from to the adapter.
3529 *
3530 * Returns:
3531 * -ERANGE off greater than mailbox command size
3532 * -EINVAL off, count or buff address invalid
3533 * zero if off and count are zero
3534 * -EACCES adapter over temp
3535 * -EPERM garbage can value to catch a multitude of errors
3536 * -EAGAIN management IO not permitted, state or off error
3537 * -ETIME mailbox timeout
3538 * -ENODEV mailbox error
3539 * count number of bytes transferred
3540 **/
dea31012005-04-17 16:05:31 -05003541static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003542sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3543 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003544{
Tony Jonesee959b02008-02-22 00:13:36 +01003545 struct device *dev = container_of(kobj, struct device, kobj);
3546 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3548 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003549 int rc;
James Smart04c68492009-05-22 14:52:52 -04003550 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003551
James Smart1dcb58e2007-04-25 09:51:30 -04003552 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003553 return -ERANGE;
3554
James Smart1dcb58e2007-04-25 09:51:30 -04003555 if ((count + off) > MAILBOX_CMD_SIZE)
3556 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003557
3558 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3559 return -EINVAL;
3560
3561 if (off && count == 0)
3562 return 0;
3563
James Smart2e0fef82007-06-17 19:56:36 -05003564 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003565
James Smart7af67052007-10-27 13:38:11 -04003566 if (phba->over_temp_state == HBA_OVER_TEMP) {
3567 sysfs_mbox_idle(phba);
3568 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003569 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003570 }
3571
dea31012005-04-17 16:05:31 -05003572 if (off == 0 &&
3573 phba->sysfs_mbox.state == SMBOX_WRITING &&
3574 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003575 pmb = &phba->sysfs_mbox.mbox->u.mb;
3576 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003577 /* Offline only */
dea31012005-04-17 16:05:31 -05003578 case MBX_INIT_LINK:
3579 case MBX_DOWN_LINK:
3580 case MBX_CONFIG_LINK:
3581 case MBX_CONFIG_RING:
3582 case MBX_RESET_RING:
3583 case MBX_UNREG_LOGIN:
3584 case MBX_CLEAR_LA:
3585 case MBX_DUMP_CONTEXT:
3586 case MBX_RUN_DIAGS:
3587 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003588 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003589 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003590 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003591 printk(KERN_WARNING "mbox_read:Command 0x%x "
3592 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003593 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003594 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003595 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003596 return -EPERM;
3597 }
James Smarta8adb832007-10-27 13:37:53 -04003598 case MBX_WRITE_NV:
3599 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003600 case MBX_LOAD_SM:
3601 case MBX_READ_NV:
3602 case MBX_READ_CONFIG:
3603 case MBX_READ_RCONFIG:
3604 case MBX_READ_STATUS:
3605 case MBX_READ_XRI:
3606 case MBX_READ_REV:
3607 case MBX_READ_LNK_STAT:
3608 case MBX_DUMP_MEMORY:
3609 case MBX_DOWN_LOAD:
3610 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003611 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003612 case MBX_LOAD_AREA:
3613 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003614 case MBX_BEACON:
3615 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003616 case MBX_SET_VARIABLE:
3617 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003618 case MBX_PORT_CAPABILITIES:
3619 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003620 break;
3621 case MBX_READ_SPARM64:
3622 case MBX_READ_LA:
3623 case MBX_READ_LA64:
3624 case MBX_REG_LOGIN:
3625 case MBX_REG_LOGIN64:
3626 case MBX_CONFIG_PORT:
3627 case MBX_RUN_BIU_DIAG:
3628 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003629 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003630 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003631 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003632 return -EPERM;
3633 default:
3634 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003635 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003636 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003637 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003638 return -EPERM;
3639 }
3640
James Smart09372822008-01-11 01:52:54 -05003641 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003642 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003643 */
James Smartd7c255b2008-08-24 21:50:00 -04003644 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003645 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3646 pmb->mbxCommand != MBX_RESTART &&
3647 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3648 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003649 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3650 "1259 mbox: Issued mailbox cmd "
3651 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003652 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003653
James Smart92d7f7b2007-06-17 19:56:38 -05003654 phba->sysfs_mbox.mbox->vport = vport;
3655
James Smart58da1ff2008-04-07 10:15:56 -04003656 /* Don't allow mailbox commands to be sent when blocked
3657 * or when in the middle of discovery
3658 */
James Smart495a7142008-06-14 22:52:59 -04003659 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003660 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003661 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003662 return -EAGAIN;
3663 }
3664
James Smart2e0fef82007-06-17 19:56:36 -05003665 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003666 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003667
James Smart2e0fef82007-06-17 19:56:36 -05003668 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003669 rc = lpfc_sli_issue_mbox (phba,
3670 phba->sysfs_mbox.mbox,
3671 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003672 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003673
3674 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003675 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003676 rc = lpfc_sli_issue_mbox_wait (phba,
3677 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003678 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003679 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003680 }
3681
3682 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003683 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003684 phba->sysfs_mbox.mbox = NULL;
3685 }
dea31012005-04-17 16:05:31 -05003686 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003687 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003688 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003689 }
3690 phba->sysfs_mbox.state = SMBOX_READING;
3691 }
3692 else if (phba->sysfs_mbox.offset != off ||
3693 phba->sysfs_mbox.state != SMBOX_READING) {
3694 printk(KERN_WARNING "mbox_read: Bad State\n");
3695 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003696 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003697 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003698 }
3699
James Smart04c68492009-05-22 14:52:52 -04003700 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003701
3702 phba->sysfs_mbox.offset = off + count;
3703
James Smart1dcb58e2007-04-25 09:51:30 -04003704 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003705 sysfs_mbox_idle(phba);
3706
James Smart2e0fef82007-06-17 19:56:36 -05003707 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003708
3709 return count;
3710}
3711
3712static struct bin_attribute sysfs_mbox_attr = {
3713 .attr = {
3714 .name = "mbox",
3715 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003716 },
James Smart1dcb58e2007-04-25 09:51:30 -04003717 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003718 .read = sysfs_mbox_read,
3719 .write = sysfs_mbox_write,
3720};
3721
James Smarte59058c2008-08-24 21:49:00 -04003722/**
James Smart3621a712009-04-06 18:47:14 -04003723 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003724 * @vport: address of lpfc vport structure.
3725 *
3726 * Return codes:
3727 * zero on success
3728 * error return code from sysfs_create_bin_file()
3729 **/
dea31012005-04-17 16:05:31 -05003730int
James Smart2e0fef82007-06-17 19:56:36 -05003731lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003732{
James Smart2e0fef82007-06-17 19:56:36 -05003733 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003734 int error;
3735
Tony Jonesee959b02008-02-22 00:13:36 +01003736 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003737 &sysfs_drvr_stat_data_attr);
3738
3739 /* Virtual ports do not need ctrl_reg and mbox */
3740 if (error || vport->port_type == LPFC_NPIV_PORT)
3741 goto out;
3742
3743 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003744 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003745 if (error)
James Smarteada2722008-12-04 22:39:13 -05003746 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003747
Tony Jonesee959b02008-02-22 00:13:36 +01003748 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003749 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003750 if (error)
3751 goto out_remove_ctlreg_attr;
3752
3753 return 0;
3754out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003755 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003756out_remove_stat_attr:
3757 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3758 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003759out:
3760 return error;
3761}
3762
James Smarte59058c2008-08-24 21:49:00 -04003763/**
James Smart3621a712009-04-06 18:47:14 -04003764 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003765 * @vport: address of lpfc vport structure.
3766 **/
dea31012005-04-17 16:05:31 -05003767void
James Smart2e0fef82007-06-17 19:56:36 -05003768lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003769{
James Smart2e0fef82007-06-17 19:56:36 -05003770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003771 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3772 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003773 /* Virtual ports do not need ctrl_reg and mbox */
3774 if (vport->port_type == LPFC_NPIV_PORT)
3775 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003776 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3777 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003778}
3779
3780
3781/*
3782 * Dynamic FC Host Attributes Support
3783 */
3784
James Smarte59058c2008-08-24 21:49:00 -04003785/**
James Smart3621a712009-04-06 18:47:14 -04003786 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003787 * @shost: kernel scsi host pointer.
3788 **/
dea31012005-04-17 16:05:31 -05003789static void
3790lpfc_get_host_port_id(struct Scsi_Host *shost)
3791{
James Smart2e0fef82007-06-17 19:56:36 -05003792 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3793
dea31012005-04-17 16:05:31 -05003794 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003795 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003796}
3797
James Smarte59058c2008-08-24 21:49:00 -04003798/**
James Smart3621a712009-04-06 18:47:14 -04003799 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003800 * @shost: kernel scsi host pointer.
3801 **/
dea31012005-04-17 16:05:31 -05003802static void
3803lpfc_get_host_port_type(struct Scsi_Host *shost)
3804{
James Smart2e0fef82007-06-17 19:56:36 -05003805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3806 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003807
3808 spin_lock_irq(shost->host_lock);
3809
James Smart92d7f7b2007-06-17 19:56:38 -05003810 if (vport->port_type == LPFC_NPIV_PORT) {
3811 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3812 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003813 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003814 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003815 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3816 else
3817 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3818 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003819 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003820 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3821 else
3822 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3823 }
3824 } else
3825 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3826
3827 spin_unlock_irq(shost->host_lock);
3828}
3829
James Smarte59058c2008-08-24 21:49:00 -04003830/**
James Smart3621a712009-04-06 18:47:14 -04003831 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003832 * @shost: kernel scsi host pointer.
3833 **/
dea31012005-04-17 16:05:31 -05003834static void
3835lpfc_get_host_port_state(struct Scsi_Host *shost)
3836{
James Smart2e0fef82007-06-17 19:56:36 -05003837 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3838 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003839
3840 spin_lock_irq(shost->host_lock);
3841
James Smart2e0fef82007-06-17 19:56:36 -05003842 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003843 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3844 else {
James Smart2e0fef82007-06-17 19:56:36 -05003845 switch (phba->link_state) {
3846 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003847 case LPFC_LINK_DOWN:
3848 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3849 break;
3850 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003851 case LPFC_CLEAR_LA:
3852 case LPFC_HBA_READY:
3853 /* Links up, beyond this port_type reports state */
3854 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3855 break;
3856 case LPFC_HBA_ERROR:
3857 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3858 break;
3859 default:
3860 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3861 break;
3862 }
3863 }
3864
3865 spin_unlock_irq(shost->host_lock);
3866}
3867
James Smarte59058c2008-08-24 21:49:00 -04003868/**
James Smart3621a712009-04-06 18:47:14 -04003869 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003870 * @shost: kernel scsi host pointer.
3871 **/
dea31012005-04-17 16:05:31 -05003872static void
3873lpfc_get_host_speed(struct Scsi_Host *shost)
3874{
James Smart2e0fef82007-06-17 19:56:36 -05003875 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3876 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003877
3878 spin_lock_irq(shost->host_lock);
3879
James Smart2e0fef82007-06-17 19:56:36 -05003880 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003881 switch(phba->fc_linkspeed) {
3882 case LA_1GHZ_LINK:
3883 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3884 break;
3885 case LA_2GHZ_LINK:
3886 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3887 break;
3888 case LA_4GHZ_LINK:
3889 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3890 break;
James Smartb87eab32007-04-25 09:53:28 -04003891 case LA_8GHZ_LINK:
3892 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3893 break;
James Smartf4b4c682009-05-22 14:53:12 -04003894 case LA_10GHZ_LINK:
3895 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3896 break;
dea31012005-04-17 16:05:31 -05003897 default:
3898 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3899 break;
3900 }
James Smart09372822008-01-11 01:52:54 -05003901 } else
3902 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003903
3904 spin_unlock_irq(shost->host_lock);
3905}
3906
James Smarte59058c2008-08-24 21:49:00 -04003907/**
James Smart3621a712009-04-06 18:47:14 -04003908 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04003909 * @shost: kernel scsi host pointer.
3910 **/
dea31012005-04-17 16:05:31 -05003911static void
3912lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3913{
James Smart2e0fef82007-06-17 19:56:36 -05003914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3915 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003916 u64 node_name;
dea31012005-04-17 16:05:31 -05003917
3918 spin_lock_irq(shost->host_lock);
3919
James Smart2e0fef82007-06-17 19:56:36 -05003920 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003921 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003922 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003923 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003924 else
3925 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003926 node_name = 0;
dea31012005-04-17 16:05:31 -05003927
3928 spin_unlock_irq(shost->host_lock);
3929
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003930 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003931}
3932
James Smarte59058c2008-08-24 21:49:00 -04003933/**
James Smart3621a712009-04-06 18:47:14 -04003934 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04003935 * @shost: kernel scsi host pointer.
3936 *
3937 * Notes:
3938 * NULL on error for link down, no mbox pool, sli2 active,
3939 * management not allowed, memory allocation error, or mbox error.
3940 *
3941 * Returns:
3942 * NULL for error
3943 * address of the adapter host statistics
3944 **/
dea31012005-04-17 16:05:31 -05003945static struct fc_host_statistics *
3946lpfc_get_stats(struct Scsi_Host *shost)
3947{
James Smart2e0fef82007-06-17 19:56:36 -05003948 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3949 struct lpfc_hba *phba = vport->phba;
3950 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003951 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003952 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003953 LPFC_MBOXQ_t *pmboxq;
3954 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003955 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003956 int rc = 0;
dea31012005-04-17 16:05:31 -05003957
James Smart92d7f7b2007-06-17 19:56:38 -05003958 /*
3959 * prevent udev from issuing mailbox commands until the port is
3960 * configured.
3961 */
James Smart2e0fef82007-06-17 19:56:36 -05003962 if (phba->link_state < LPFC_LINK_DOWN ||
3963 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04003964 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003965 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003966
3967 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003968 return NULL;
3969
dea31012005-04-17 16:05:31 -05003970 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3971 if (!pmboxq)
3972 return NULL;
3973 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3974
James Smart04c68492009-05-22 14:52:52 -04003975 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05003976 pmb->mbxCommand = MBX_READ_STATUS;
3977 pmb->mbxOwner = OWN_HOST;
3978 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003979 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003980
James Smart2e0fef82007-06-17 19:56:36 -05003981 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart04c68492009-05-22 14:52:52 -04003982 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003983 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003984 else
dea31012005-04-17 16:05:31 -05003985 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3986
3987 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003988 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003989 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003990 return NULL;
3991 }
3992
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003993 memset(hs, 0, sizeof (struct fc_host_statistics));
3994
dea31012005-04-17 16:05:31 -05003995 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3996 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3997 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3998 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3999
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004000 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004001 pmb->mbxCommand = MBX_READ_LNK_STAT;
4002 pmb->mbxOwner = OWN_HOST;
4003 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004004 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004005
James Smart2e0fef82007-06-17 19:56:36 -05004006 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004007 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05004008 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004009 else
dea31012005-04-17 16:05:31 -05004010 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4011
4012 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004013 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004014 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004015 return NULL;
4016 }
4017
4018 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4019 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4020 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4021 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4022 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4023 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4024 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4025
James Smart64ba8812006-08-02 15:24:34 -04004026 hs->link_failure_count -= lso->link_failure_count;
4027 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4028 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4029 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4030 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4031 hs->invalid_crc_count -= lso->invalid_crc_count;
4032 hs->error_frames -= lso->error_frames;
4033
James Smart4d9ab992009-10-02 15:16:39 -04004034 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4035 hs->lip_count = -1;
4036 hs->nos_count = (phba->link_events >> 1);
4037 hs->nos_count -= lso->link_events;
4038 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004039 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004040 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004041 hs->nos_count = -1;
4042 } else {
4043 hs->lip_count = -1;
4044 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004045 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004046 }
4047
4048 hs->dumped_frames = -1;
4049
James Smart64ba8812006-08-02 15:24:34 -04004050 seconds = get_seconds();
4051 if (seconds < psli->stats_start)
4052 hs->seconds_since_last_reset = seconds +
4053 ((unsigned long)-1 - psli->stats_start);
4054 else
4055 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004056
James Smart1dcb58e2007-04-25 09:51:30 -04004057 mempool_free(pmboxq, phba->mbox_mem_pool);
4058
dea31012005-04-17 16:05:31 -05004059 return hs;
4060}
4061
James Smarte59058c2008-08-24 21:49:00 -04004062/**
James Smart3621a712009-04-06 18:47:14 -04004063 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004064 * @shost: kernel scsi host pointer.
4065 **/
James Smart64ba8812006-08-02 15:24:34 -04004066static void
4067lpfc_reset_stats(struct Scsi_Host *shost)
4068{
James Smart2e0fef82007-06-17 19:56:36 -05004069 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4070 struct lpfc_hba *phba = vport->phba;
4071 struct lpfc_sli *psli = &phba->sli;
4072 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004073 LPFC_MBOXQ_t *pmboxq;
4074 MAILBOX_t *pmb;
4075 int rc = 0;
4076
James Smart2e0fef82007-06-17 19:56:36 -05004077 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004078 return;
4079
James Smart64ba8812006-08-02 15:24:34 -04004080 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4081 if (!pmboxq)
4082 return;
4083 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4084
James Smart04c68492009-05-22 14:52:52 -04004085 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004086 pmb->mbxCommand = MBX_READ_STATUS;
4087 pmb->mbxOwner = OWN_HOST;
4088 pmb->un.varWords[0] = 0x1; /* reset request */
4089 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004090 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004091
James Smart2e0fef82007-06-17 19:56:36 -05004092 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004093 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004094 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4095 else
4096 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4097
4098 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004099 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004100 mempool_free(pmboxq, phba->mbox_mem_pool);
4101 return;
4102 }
4103
4104 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4105 pmb->mbxCommand = MBX_READ_LNK_STAT;
4106 pmb->mbxOwner = OWN_HOST;
4107 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004108 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004109
James Smart2e0fef82007-06-17 19:56:36 -05004110 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004111 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004112 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4113 else
4114 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4115
4116 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004117 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004118 mempool_free( pmboxq, phba->mbox_mem_pool);
4119 return;
4120 }
4121
4122 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4123 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4124 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4125 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4126 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4127 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4128 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004129 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4130 lso->link_events = (phba->link_events >> 1);
4131 else
4132 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004133
4134 psli->stats_start = get_seconds();
4135
James Smart1dcb58e2007-04-25 09:51:30 -04004136 mempool_free(pmboxq, phba->mbox_mem_pool);
4137
James Smart64ba8812006-08-02 15:24:34 -04004138 return;
4139}
dea31012005-04-17 16:05:31 -05004140
4141/*
4142 * The LPFC driver treats linkdown handling as target loss events so there
4143 * are no sysfs handlers for link_down_tmo.
4144 */
James Smart685f0bf2007-04-25 09:53:08 -04004145
James Smarte59058c2008-08-24 21:49:00 -04004146/**
James Smart3621a712009-04-06 18:47:14 -04004147 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004148 * @starget: kernel scsi target pointer.
4149 *
4150 * Returns:
4151 * address of the node list if found
4152 * NULL target not found
4153 **/
James Smart685f0bf2007-04-25 09:53:08 -04004154static struct lpfc_nodelist *
4155lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004156{
James Smart2e0fef82007-06-17 19:56:36 -05004157 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004159 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004160
4161 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004162 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004163 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004164 if (NLP_CHK_NODE_ACT(ndlp) &&
4165 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004166 starget->id == ndlp->nlp_sid) {
4167 spin_unlock_irq(shost->host_lock);
4168 return ndlp;
dea31012005-04-17 16:05:31 -05004169 }
4170 }
4171 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004172 return NULL;
4173}
dea31012005-04-17 16:05:31 -05004174
James Smarte59058c2008-08-24 21:49:00 -04004175/**
James Smart3621a712009-04-06 18:47:14 -04004176 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004177 * @starget: kernel scsi target pointer.
4178 **/
James Smart685f0bf2007-04-25 09:53:08 -04004179static void
4180lpfc_get_starget_port_id(struct scsi_target *starget)
4181{
4182 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4183
4184 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004185}
4186
James Smarte59058c2008-08-24 21:49:00 -04004187/**
James Smart3621a712009-04-06 18:47:14 -04004188 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004189 * @starget: kernel scsi target pointer.
4190 *
4191 * Description: Set the target node name to the ndlp node name wwn or zero.
4192 **/
dea31012005-04-17 16:05:31 -05004193static void
4194lpfc_get_starget_node_name(struct scsi_target *starget)
4195{
James Smart685f0bf2007-04-25 09:53:08 -04004196 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004197
James Smart685f0bf2007-04-25 09:53:08 -04004198 fc_starget_node_name(starget) =
4199 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004200}
4201
James Smarte59058c2008-08-24 21:49:00 -04004202/**
James Smart3621a712009-04-06 18:47:14 -04004203 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004204 * @starget: kernel scsi target pointer.
4205 *
4206 * Description: set the target port name to the ndlp port name wwn or zero.
4207 **/
dea31012005-04-17 16:05:31 -05004208static void
4209lpfc_get_starget_port_name(struct scsi_target *starget)
4210{
James Smart685f0bf2007-04-25 09:53:08 -04004211 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004212
James Smart685f0bf2007-04-25 09:53:08 -04004213 fc_starget_port_name(starget) =
4214 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004215}
4216
James Smarte59058c2008-08-24 21:49:00 -04004217/**
James Smart3621a712009-04-06 18:47:14 -04004218 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004219 * @rport: fc rport address.
4220 * @timeout: new value for dev loss tmo.
4221 *
4222 * Description:
4223 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4224 * dev_loss_tmo to one.
4225 **/
dea31012005-04-17 16:05:31 -05004226static void
dea31012005-04-17 16:05:31 -05004227lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4228{
dea31012005-04-17 16:05:31 -05004229 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004230 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004231 else
James Smartc01f3202006-08-18 17:47:08 -04004232 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004233}
4234
James Smarte59058c2008-08-24 21:49:00 -04004235/**
James Smart3621a712009-04-06 18:47:14 -04004236 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004237 *
4238 * Description:
4239 * Macro that uses field to generate a function with the name lpfc_show_rport_
4240 *
4241 * lpfc_show_rport_##field: returns the bytes formatted in buf
4242 * @cdev: class converted to an fc_rport.
4243 * @buf: on return contains the target_field or zero.
4244 *
4245 * Returns: size of formatted string.
4246 **/
dea31012005-04-17 16:05:31 -05004247#define lpfc_rport_show_function(field, format_string, sz, cast) \
4248static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004249lpfc_show_rport_##field (struct device *dev, \
4250 struct device_attribute *attr, \
4251 char *buf) \
dea31012005-04-17 16:05:31 -05004252{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004253 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004254 struct lpfc_rport_data *rdata = rport->hostdata; \
4255 return snprintf(buf, sz, format_string, \
4256 (rdata->target) ? cast rdata->target->field : 0); \
4257}
4258
4259#define lpfc_rport_rd_attr(field, format_string, sz) \
4260 lpfc_rport_show_function(field, format_string, sz, ) \
4261static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4262
James Smarteada2722008-12-04 22:39:13 -05004263/**
James Smart3621a712009-04-06 18:47:14 -04004264 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004265 * @fc_vport: The fc_vport who's symbolic name has been changed.
4266 *
4267 * Description:
4268 * This function is called by the transport after the @fc_vport's symbolic name
4269 * has been changed. This function re-registers the symbolic name with the
4270 * switch to propogate the change into the fabric if the vport is active.
4271 **/
4272static void
4273lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4274{
4275 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4276
4277 if (vport->port_state == LPFC_VPORT_READY)
4278 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4279}
dea31012005-04-17 16:05:31 -05004280
James Smartf4b4c682009-05-22 14:53:12 -04004281/**
4282 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4283 * @phba: Pointer to lpfc_hba struct.
4284 *
4285 * This function is called by the lpfc_get_cfgparam() routine to set the
4286 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4287 * log messsage according to the module's lpfc_log_verbose parameter setting
4288 * before hba port or vport created.
4289 **/
4290static void
4291lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4292{
4293 phba->cfg_log_verbose = verbose;
4294}
4295
dea31012005-04-17 16:05:31 -05004296struct fc_function_template lpfc_transport_functions = {
4297 /* fixed attributes the driver supports */
4298 .show_host_node_name = 1,
4299 .show_host_port_name = 1,
4300 .show_host_supported_classes = 1,
4301 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004302 .show_host_supported_speeds = 1,
4303 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004304 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004305
4306 /* dynamic attributes the driver supports */
4307 .get_host_port_id = lpfc_get_host_port_id,
4308 .show_host_port_id = 1,
4309
4310 .get_host_port_type = lpfc_get_host_port_type,
4311 .show_host_port_type = 1,
4312
4313 .get_host_port_state = lpfc_get_host_port_state,
4314 .show_host_port_state = 1,
4315
4316 /* active_fc4s is shown but doesn't change (thus no get function) */
4317 .show_host_active_fc4s = 1,
4318
4319 .get_host_speed = lpfc_get_host_speed,
4320 .show_host_speed = 1,
4321
4322 .get_host_fabric_name = lpfc_get_host_fabric_name,
4323 .show_host_fabric_name = 1,
4324
4325 /*
4326 * The LPFC driver treats linkdown handling as target loss events
4327 * so there are no sysfs handlers for link_down_tmo.
4328 */
4329
4330 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004331 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004332
4333 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4334 .show_rport_maxframe_size = 1,
4335 .show_rport_supported_classes = 1,
4336
dea31012005-04-17 16:05:31 -05004337 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4338 .show_rport_dev_loss_tmo = 1,
4339
4340 .get_starget_port_id = lpfc_get_starget_port_id,
4341 .show_starget_port_id = 1,
4342
4343 .get_starget_node_name = lpfc_get_starget_node_name,
4344 .show_starget_node_name = 1,
4345
4346 .get_starget_port_name = lpfc_get_starget_port_name,
4347 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004348
4349 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004350 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4351 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004352
James Smart92d7f7b2007-06-17 19:56:38 -05004353 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004354
4355 .vport_disable = lpfc_vport_disable,
4356
4357 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004358
4359 .bsg_request = lpfc_bsg_request,
4360 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004361};
4362
James Smart98c9ea52007-10-27 13:37:33 -04004363struct fc_function_template lpfc_vport_transport_functions = {
4364 /* fixed attributes the driver supports */
4365 .show_host_node_name = 1,
4366 .show_host_port_name = 1,
4367 .show_host_supported_classes = 1,
4368 .show_host_supported_fc4s = 1,
4369 .show_host_supported_speeds = 1,
4370 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004371 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004372
4373 /* dynamic attributes the driver supports */
4374 .get_host_port_id = lpfc_get_host_port_id,
4375 .show_host_port_id = 1,
4376
4377 .get_host_port_type = lpfc_get_host_port_type,
4378 .show_host_port_type = 1,
4379
4380 .get_host_port_state = lpfc_get_host_port_state,
4381 .show_host_port_state = 1,
4382
4383 /* active_fc4s is shown but doesn't change (thus no get function) */
4384 .show_host_active_fc4s = 1,
4385
4386 .get_host_speed = lpfc_get_host_speed,
4387 .show_host_speed = 1,
4388
4389 .get_host_fabric_name = lpfc_get_host_fabric_name,
4390 .show_host_fabric_name = 1,
4391
4392 /*
4393 * The LPFC driver treats linkdown handling as target loss events
4394 * so there are no sysfs handlers for link_down_tmo.
4395 */
4396
4397 .get_fc_host_stats = lpfc_get_stats,
4398 .reset_fc_host_stats = lpfc_reset_stats,
4399
4400 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4401 .show_rport_maxframe_size = 1,
4402 .show_rport_supported_classes = 1,
4403
4404 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4405 .show_rport_dev_loss_tmo = 1,
4406
4407 .get_starget_port_id = lpfc_get_starget_port_id,
4408 .show_starget_port_id = 1,
4409
4410 .get_starget_node_name = lpfc_get_starget_node_name,
4411 .show_starget_node_name = 1,
4412
4413 .get_starget_port_name = lpfc_get_starget_port_name,
4414 .show_starget_port_name = 1,
4415
4416 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4417 .terminate_rport_io = lpfc_terminate_rport_io,
4418
4419 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004420
4421 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004422};
4423
James Smarte59058c2008-08-24 21:49:00 -04004424/**
James Smart3621a712009-04-06 18:47:14 -04004425 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004426 * @phba: lpfc_hba pointer.
4427 **/
dea31012005-04-17 16:05:31 -05004428void
4429lpfc_get_cfgparam(struct lpfc_hba *phba)
4430{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004431 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4432 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004433 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004434 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4435 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004436 lpfc_ack0_init(phba, lpfc_ack0);
4437 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004438 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004439 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004440 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004441 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004442 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4443 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4444 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004445 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4446 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004447 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004448 if (phba->sli_rev == LPFC_SLI_REV4)
4449 phba->cfg_poll = 0;
4450 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004451 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004452 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004453 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004454 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004455 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004456 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004457 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004458 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart6fb120a2009-05-22 14:52:59 -04004459
James Smart3de2a652007-08-02 11:09:59 -04004460 return;
4461}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004462
James Smarte59058c2008-08-24 21:49:00 -04004463/**
James Smart3621a712009-04-06 18:47:14 -04004464 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004465 * @vport: lpfc_vport pointer.
4466 **/
James Smart3de2a652007-08-02 11:09:59 -04004467void
4468lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4469{
James Smarte8b62012007-08-02 11:10:09 -04004470 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004471 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4472 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4473 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4474 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4475 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4476 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4477 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004478 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004479 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4480 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4481 lpfc_max_luns_init(vport, lpfc_max_luns);
4482 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004483 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004484 return;
4485}