blob: a7c6b7390554f425da014f31d1fb69efe1592c99 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/gfp.h>
dea31012005-04-17 16:05:31 -050028
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050030#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_tcq.h>
33#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040034#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050035
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_logmsg.h"
45#include "lpfc_version.h"
46#include "lpfc_compat.h"
47#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050048#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050049
James Smartc01f3202006-08-18 17:47:08 -040050#define LPFC_DEF_DEVLOSS_TMO 30
51#define LPFC_MIN_DEVLOSS_TMO 1
52#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050053
James Smart83108bd2008-01-11 01:53:09 -050054#define LPFC_MAX_LINK_SPEED 8
55#define LPFC_LINK_SPEED_BITMAP 0x00000117
56#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
57
James Smarte59058c2008-08-24 21:49:00 -040058/**
James Smart3621a712009-04-06 18:47:14 -040059 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040060 * @incr: integer to convert.
61 * @hdw: ascii string holding converted integer plus a string terminator.
62 *
63 * Description:
64 * JEDEC Joint Electron Device Engineering Council.
65 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
66 * character string. The string is then terminated with a NULL in byte 9.
67 * Hex 0-9 becomes ascii '0' to '9'.
68 * Hex a-f becomes ascii '=' to 'B' capital B.
69 *
70 * Notes:
71 * Coded for 32 bit integers only.
72 **/
dea31012005-04-17 16:05:31 -050073static void
74lpfc_jedec_to_ascii(int incr, char hdw[])
75{
76 int i, j;
77 for (i = 0; i < 8; i++) {
78 j = (incr & 0xf);
79 if (j <= 9)
80 hdw[7 - i] = 0x30 + j;
81 else
82 hdw[7 - i] = 0x61 + j - 10;
83 incr = (incr >> 4);
84 }
85 hdw[8] = 0;
86 return;
87}
88
James Smarte59058c2008-08-24 21:49:00 -040089/**
James Smart3621a712009-04-06 18:47:14 -040090 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040091 * @dev: class unused variable.
92 * @attr: device attribute, not used.
93 * @buf: on return contains the module description text.
94 *
95 * Returns: size of formatted string.
96 **/
dea31012005-04-17 16:05:31 -050097static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010098lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
99 char *buf)
dea31012005-04-17 16:05:31 -0500100{
101 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
102}
103
James Smart45ed1192009-10-02 15:17:02 -0400104/**
105 * lpfc_enable_fip_show - Return the fip mode of the HBA
106 * @dev: class unused variable.
107 * @attr: device attribute, not used.
108 * @buf: on return contains the module description text.
109 *
110 * Returns: size of formatted string.
111 **/
112static ssize_t
113lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
114 char *buf)
115{
116 struct Scsi_Host *shost = class_to_shost(dev);
117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
118 struct lpfc_hba *phba = vport->phba;
119
120 if (phba->hba_flag & HBA_FIP_SUPPORT)
121 return snprintf(buf, PAGE_SIZE, "1\n");
122 else
123 return snprintf(buf, PAGE_SIZE, "0\n");
124}
125
James Smart81301a92008-12-04 22:39:46 -0500126static ssize_t
127lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
128 char *buf)
129{
130 struct Scsi_Host *shost = class_to_shost(dev);
131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
132 struct lpfc_hba *phba = vport->phba;
133
134 if (phba->cfg_enable_bg)
135 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
136 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Not Supported\n");
140 else
141 return snprintf(buf, PAGE_SIZE,
142 "BlockGuard Disabled\n");
143}
144
145static ssize_t
146lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
147 char *buf)
148{
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
152
James Smart87b5c322008-12-16 10:34:09 -0500153 return snprintf(buf, PAGE_SIZE, "%llu\n",
154 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500155}
156
157static ssize_t
158lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
159 char *buf)
160{
161 struct Scsi_Host *shost = class_to_shost(dev);
162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
163 struct lpfc_hba *phba = vport->phba;
164
James Smart87b5c322008-12-16 10:34:09 -0500165 return snprintf(buf, PAGE_SIZE, "%llu\n",
166 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500167}
168
169static ssize_t
170lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
171 char *buf)
172{
173 struct Scsi_Host *shost = class_to_shost(dev);
174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
175 struct lpfc_hba *phba = vport->phba;
176
James Smart87b5c322008-12-16 10:34:09 -0500177 return snprintf(buf, PAGE_SIZE, "%llu\n",
178 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500179}
180
James Smarte59058c2008-08-24 21:49:00 -0400181/**
James Smart3621a712009-04-06 18:47:14 -0400182 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400183 * @dev: class converted to a Scsi_host structure.
184 * @attr: device attribute, not used.
185 * @buf: on return contains the formatted text from lpfc_info().
186 *
187 * Returns: size of formatted string.
188 **/
dea31012005-04-17 16:05:31 -0500189static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100190lpfc_info_show(struct device *dev, struct device_attribute *attr,
191 char *buf)
dea31012005-04-17 16:05:31 -0500192{
Tony Jonesee959b02008-02-22 00:13:36 +0100193 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500194
dea31012005-04-17 16:05:31 -0500195 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
196}
197
James Smarte59058c2008-08-24 21:49:00 -0400198/**
James Smart3621a712009-04-06 18:47:14 -0400199 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400200 * @dev: class converted to a Scsi_host structure.
201 * @attr: device attribute, not used.
202 * @buf: on return contains the formatted text serial number.
203 *
204 * Returns: size of formatted string.
205 **/
dea31012005-04-17 16:05:31 -0500206static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100207lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
208 char *buf)
dea31012005-04-17 16:05:31 -0500209{
Tony Jonesee959b02008-02-22 00:13:36 +0100210 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500211 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
212 struct lpfc_hba *phba = vport->phba;
213
dea31012005-04-17 16:05:31 -0500214 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
215}
216
James Smarte59058c2008-08-24 21:49:00 -0400217/**
James Smart3621a712009-04-06 18:47:14 -0400218 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400219 * @dev: class converted to a Scsi_host structure.
220 * @attr: device attribute, not used.
221 * @buf: on return contains the formatted support level.
222 *
223 * Description:
224 * Returns a number indicating the temperature sensor level currently
225 * supported, zero or one in ascii.
226 *
227 * Returns: size of formatted string.
228 **/
dea31012005-04-17 16:05:31 -0500229static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100230lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
231 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400232{
Tony Jonesee959b02008-02-22 00:13:36 +0100233 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
235 struct lpfc_hba *phba = vport->phba;
236 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
237}
238
James Smarte59058c2008-08-24 21:49:00 -0400239/**
James Smart3621a712009-04-06 18:47:14 -0400240 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400241 * @dev: class converted to a Scsi_host structure.
242 * @attr: device attribute, not used.
243 * @buf: on return contains the scsi vpd model description.
244 *
245 * Returns: size of formatted string.
246 **/
James Smart57127f12007-10-27 13:37:05 -0400247static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100248lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
249 char *buf)
dea31012005-04-17 16:05:31 -0500250{
Tony Jonesee959b02008-02-22 00:13:36 +0100251 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500252 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
253 struct lpfc_hba *phba = vport->phba;
254
dea31012005-04-17 16:05:31 -0500255 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
256}
257
James Smarte59058c2008-08-24 21:49:00 -0400258/**
James Smart3621a712009-04-06 18:47:14 -0400259 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400260 * @dev: class converted to a Scsi_host structure.
261 * @attr: device attribute, not used.
262 * @buf: on return contains the scsi vpd model name.
263 *
264 * Returns: size of formatted string.
265 **/
dea31012005-04-17 16:05:31 -0500266static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100267lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
268 char *buf)
dea31012005-04-17 16:05:31 -0500269{
Tony Jonesee959b02008-02-22 00:13:36 +0100270 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
272 struct lpfc_hba *phba = vport->phba;
273
dea31012005-04-17 16:05:31 -0500274 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
275}
276
James Smarte59058c2008-08-24 21:49:00 -0400277/**
James Smart3621a712009-04-06 18:47:14 -0400278 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400279 * @dev: class converted to a Scsi_host structure.
280 * @attr: device attribute, not used.
281 * @buf: on return contains the scsi vpd program type.
282 *
283 * Returns: size of formatted string.
284 **/
dea31012005-04-17 16:05:31 -0500285static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100286lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
287 char *buf)
dea31012005-04-17 16:05:31 -0500288{
Tony Jonesee959b02008-02-22 00:13:36 +0100289 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
291 struct lpfc_hba *phba = vport->phba;
292
dea31012005-04-17 16:05:31 -0500293 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
294}
295
James Smarte59058c2008-08-24 21:49:00 -0400296/**
James Smart3621a712009-04-06 18:47:14 -0400297 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400298 * @dev: class converted to a Scsi_host structure.
299 * @attr: device attribute, not used.
300 * @buf: on return contains the Menlo Maintenance sli flag.
301 *
302 * Returns: size of formatted string.
303 **/
304static ssize_t
305lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
306{
307 struct Scsi_Host *shost = class_to_shost(dev);
308 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
309 struct lpfc_hba *phba = vport->phba;
310
311 return snprintf(buf, PAGE_SIZE, "%d\n",
312 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
313}
314
315/**
James Smart3621a712009-04-06 18:47:14 -0400316 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400317 * @dev: class converted to a Scsi_host structure.
318 * @attr: device attribute, not used.
319 * @buf: on return contains scsi vpd program type.
320 *
321 * Returns: size of formatted string.
322 **/
dea31012005-04-17 16:05:31 -0500323static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100324lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
325 char *buf)
dea31012005-04-17 16:05:31 -0500326{
Tony Jonesee959b02008-02-22 00:13:36 +0100327 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500328 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
329 struct lpfc_hba *phba = vport->phba;
330
dea31012005-04-17 16:05:31 -0500331 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
332}
333
James Smarte59058c2008-08-24 21:49:00 -0400334/**
James Smart3621a712009-04-06 18:47:14 -0400335 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400336 * @dev: class converted to a Scsi_host structure.
337 * @attr: device attribute, not used.
338 * @buf: on return contains the scsi vpd program type.
339 *
340 * Returns: size of formatted string.
341 **/
dea31012005-04-17 16:05:31 -0500342static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100343lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
344 char *buf)
dea31012005-04-17 16:05:31 -0500345{
Tony Jonesee959b02008-02-22 00:13:36 +0100346 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
348 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500349 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500350
dea31012005-04-17 16:05:31 -0500351 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500352 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500353}
354
James Smarte59058c2008-08-24 21:49:00 -0400355/**
James Smart3621a712009-04-06 18:47:14 -0400356 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400357 * @dev: class converted to a Scsi_host structure.
358 * @attr: device attribute, not used.
359 * @buf: on return contains the scsi vpd program type.
360 *
361 * Returns: size of formatted string.
362 **/
dea31012005-04-17 16:05:31 -0500363static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100364lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500365{
366 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100367 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
369 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500370 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500371
dea31012005-04-17 16:05:31 -0500372 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
373 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
374}
James Smarte59058c2008-08-24 21:49:00 -0400375
376/**
James Smart3621a712009-04-06 18:47:14 -0400377 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400378 * @dev: class converted to a Scsi_host structure.
379 * @attr: device attribute, not used.
380 * @buf: on return contains the ROM and FCode ascii strings.
381 *
382 * Returns: size of formatted string.
383 **/
dea31012005-04-17 16:05:31 -0500384static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100385lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
386 char *buf)
dea31012005-04-17 16:05:31 -0500387{
Tony Jonesee959b02008-02-22 00:13:36 +0100388 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
390 struct lpfc_hba *phba = vport->phba;
391
dea31012005-04-17 16:05:31 -0500392 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
393}
James Smarte59058c2008-08-24 21:49:00 -0400394
395/**
James Smart3621a712009-04-06 18:47:14 -0400396 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400397 * @dev: class converted to a Scsi_host structure.
398 * @attr: device attribute, not used.
399 * @buf: on return contains text describing the state of the link.
400 *
401 * Notes:
402 * The switch statement has no default so zero will be returned.
403 *
404 * Returns: size of formatted string.
405 **/
dea31012005-04-17 16:05:31 -0500406static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100407lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
408 char *buf)
dea31012005-04-17 16:05:31 -0500409{
Tony Jonesee959b02008-02-22 00:13:36 +0100410 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
412 struct lpfc_hba *phba = vport->phba;
413 int len = 0;
414
415 switch (phba->link_state) {
416 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500417 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500418 case LPFC_INIT_START:
419 case LPFC_INIT_MBX_CMDS:
420 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500421 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400422 if (phba->hba_flag & LINK_DISABLED)
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down - User disabled\n");
425 else
426 len += snprintf(buf + len, PAGE_SIZE-len,
427 "Link Down\n");
dea31012005-04-17 16:05:31 -0500428 break;
429 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500430 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500431 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400432 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500433
434 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500435 case LPFC_LOCAL_CFG_LINK:
436 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500437 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500438 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500439 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500440 case LPFC_FLOGI:
441 case LPFC_FABRIC_CFG_LINK:
442 case LPFC_NS_REG:
443 case LPFC_NS_QRY:
444 case LPFC_BUILD_DISC_LIST:
445 case LPFC_DISC_AUTH:
446 len += snprintf(buf + len, PAGE_SIZE - len,
447 "Discovery\n");
448 break;
449 case LPFC_VPORT_READY:
450 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
451 break;
452
James Smart92d7f7b2007-06-17 19:56:38 -0500453 case LPFC_VPORT_FAILED:
454 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
455 break;
456
457 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500458 len += snprintf(buf + len, PAGE_SIZE - len,
459 "Unknown\n");
460 break;
461 }
James Smart84774a42008-08-24 21:50:06 -0400462 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
463 len += snprintf(buf + len, PAGE_SIZE-len,
464 " Menlo Maint Mode\n");
465 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500466 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Public Loop\n");
469 else
470 len += snprintf(buf + len, PAGE_SIZE-len,
471 " Private Loop\n");
472 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500473 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Fabric\n");
476 else
477 len += snprintf(buf + len, PAGE_SIZE-len,
478 " Point-2-Point\n");
479 }
480 }
James Smart2e0fef82007-06-17 19:56:36 -0500481
dea31012005-04-17 16:05:31 -0500482 return len;
483}
484
James Smarte59058c2008-08-24 21:49:00 -0400485/**
James Smart84d1b002010-02-12 14:42:33 -0500486 * lpfc_link_state_store - Transition the link_state on an HBA port
487 * @dev: class device that is converted into a Scsi_host.
488 * @attr: device attribute, not used.
489 * @buf: one or more lpfc_polling_flags values.
490 * @count: not used.
491 *
492 * Returns:
493 * -EINVAL if the buffer is not "up" or "down"
494 * return from link state change function if non-zero
495 * length of the buf on success
496 **/
497static ssize_t
498lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
499 const char *buf, size_t count)
500{
501 struct Scsi_Host *shost = class_to_shost(dev);
502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 struct lpfc_hba *phba = vport->phba;
504
505 int status = -EINVAL;
506
507 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
508 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400509 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500510 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
511 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400512 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500513
514 if (status == 0)
515 return strlen(buf);
516 else
517 return status;
518}
519
520/**
James Smart3621a712009-04-06 18:47:14 -0400521 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400522 * @dev: class device that is converted into a Scsi_host.
523 * @attr: device attribute, not used.
524 * @buf: on return contains the sum of fc mapped and unmapped.
525 *
526 * Description:
527 * Returns the ascii text number of the sum of the fc mapped and unmapped
528 * vport counts.
529 *
530 * Returns: size of formatted string.
531 **/
dea31012005-04-17 16:05:31 -0500532static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100533lpfc_num_discovered_ports_show(struct device *dev,
534 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500535{
Tony Jonesee959b02008-02-22 00:13:36 +0100536 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500537 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
538
539 return snprintf(buf, PAGE_SIZE, "%d\n",
540 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500541}
542
James Smarte59058c2008-08-24 21:49:00 -0400543/**
James Smart3621a712009-04-06 18:47:14 -0400544 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400545 * @shost: Scsi_Host pointer.
546 *
547 * Description:
548 * Bring the link down gracefully then re-init the link. The firmware will
549 * re-init the fiber channel interface as required. Does not issue a LIP.
550 *
551 * Returns:
552 * -EPERM port offline or management commands are being blocked
553 * -ENOMEM cannot allocate memory for the mailbox command
554 * -EIO error sending the mailbox command
555 * zero for success
556 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700557static int
James Smart2e0fef82007-06-17 19:56:36 -0500558lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500559{
James Smart2e0fef82007-06-17 19:56:36 -0500560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
561 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500562 LPFC_MBOXQ_t *pmboxq;
563 int mbxstatus = MBXERR_ERROR;
564
James Smart2e0fef82007-06-17 19:56:36 -0500565 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500566 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500567 return -EPERM;
568
569 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
570
571 if (!pmboxq)
572 return -ENOMEM;
573
574 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400575 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
576 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400577
James Smart33ccf8d2006-08-17 11:57:58 -0400578 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500579
James Smart04c68492009-05-22 14:52:52 -0400580 if ((mbxstatus == MBX_SUCCESS) &&
581 (pmboxq->u.mb.mbxStatus == 0 ||
582 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400583 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
584 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
585 phba->cfg_link_speed);
586 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
587 phba->fc_ratov * 2);
588 }
589
James Smart5b8bd0c2007-04-25 09:52:49 -0400590 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500591 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400592 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500593
594 if (mbxstatus == MBXERR_ERROR)
595 return -EIO;
596
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700597 return 0;
dea31012005-04-17 16:05:31 -0500598}
599
James Smarte59058c2008-08-24 21:49:00 -0400600/**
James Smart3621a712009-04-06 18:47:14 -0400601 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400602 * @phba: lpfc_hba pointer.
603 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
604 *
605 * Notes:
606 * Assumes any error from lpfc_do_offline() will be negative.
607 * Can wait up to 5 seconds for the port ring buffers count
608 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400609 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400610 *
611 * Returns:
612 * -EIO error posting the event
613 * zero for success
614 **/
James Smart40496f02006-07-06 15:50:22 -0400615static int
James Smart46fa3112007-04-25 09:51:45 -0400616lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
617{
618 struct completion online_compl;
619 struct lpfc_sli_ring *pring;
620 struct lpfc_sli *psli;
621 int status = 0;
622 int cnt = 0;
623 int i;
624
625 init_completion(&online_compl);
626 lpfc_workq_post_event(phba, &status, &online_compl,
627 LPFC_EVT_OFFLINE_PREP);
628 wait_for_completion(&online_compl);
629
630 if (status != 0)
631 return -EIO;
632
633 psli = &phba->sli;
634
James Smart09372822008-01-11 01:52:54 -0500635 /* Wait a little for things to settle down, but not
636 * long enough for dev loss timeout to expire.
637 */
James Smart46fa3112007-04-25 09:51:45 -0400638 for (i = 0; i < psli->num_rings; i++) {
639 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400640 while (pring->txcmplq_cnt) {
641 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500642 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400643 lpfc_printf_log(phba,
644 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400645 "0466 Outstanding IO when "
646 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400647 break;
648 }
649 }
650 }
651
652 init_completion(&online_compl);
653 lpfc_workq_post_event(phba, &status, &online_compl, type);
654 wait_for_completion(&online_compl);
655
656 if (status != 0)
657 return -EIO;
658
659 return 0;
660}
661
James Smarte59058c2008-08-24 21:49:00 -0400662/**
James Smart3621a712009-04-06 18:47:14 -0400663 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400664 * @phba: lpfc_hba pointer.
665 *
666 * Description:
667 * If the port is configured to allow a reset then the hba is brought
668 * offline then online.
669 *
670 * Notes:
671 * Assumes any error from lpfc_do_offline() will be negative.
672 *
673 * Returns:
674 * lpfc_do_offline() return code if not zero
675 * -EIO reset not configured or error posting the event
676 * zero for success
677 **/
James Smart46fa3112007-04-25 09:51:45 -0400678static int
James Smart40496f02006-07-06 15:50:22 -0400679lpfc_selective_reset(struct lpfc_hba *phba)
680{
681 struct completion online_compl;
682 int status = 0;
683
James Smart13815c82008-01-11 01:52:48 -0500684 if (!phba->cfg_enable_hba_reset)
685 return -EIO;
686
James Smart46fa3112007-04-25 09:51:45 -0400687 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400688
689 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400690 return status;
James Smart40496f02006-07-06 15:50:22 -0400691
692 init_completion(&online_compl);
693 lpfc_workq_post_event(phba, &status, &online_compl,
694 LPFC_EVT_ONLINE);
695 wait_for_completion(&online_compl);
696
697 if (status != 0)
698 return -EIO;
699
700 return 0;
701}
702
James Smarte59058c2008-08-24 21:49:00 -0400703/**
James Smart3621a712009-04-06 18:47:14 -0400704 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400705 * @dev: class device that is converted into a Scsi_host.
706 * @attr: device attribute, not used.
707 * @buf: containing the string "selective".
708 * @count: unused variable.
709 *
710 * Description:
711 * If the buf contains the string "selective" then lpfc_selective_reset()
712 * is called to perform the reset.
713 *
714 * Notes:
715 * Assumes any error from lpfc_selective_reset() will be negative.
716 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200717 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400718 *
719 * Returns:
720 * -EINVAL if the buffer does not contain the string "selective"
721 * length of buf if lpfc-selective_reset() if the call succeeds
722 * return value of lpfc_selective_reset() if the call fails
723**/
James Smart40496f02006-07-06 15:50:22 -0400724static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100725lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
726 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400727{
Tony Jonesee959b02008-02-22 00:13:36 +0100728 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500729 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
730 struct lpfc_hba *phba = vport->phba;
731
James Smart40496f02006-07-06 15:50:22 -0400732 int status = -EINVAL;
733
734 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
735 status = lpfc_selective_reset(phba);
736
737 if (status == 0)
738 return strlen(buf);
739 else
740 return status;
741}
742
James Smarte59058c2008-08-24 21:49:00 -0400743/**
James Smart3621a712009-04-06 18:47:14 -0400744 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400745 * @dev: class device that is converted into a Scsi_host.
746 * @attr: device attribute, not used.
747 * @buf: on return contains the ascii number of nport events.
748 *
749 * Returns: size of formatted string.
750 **/
dea31012005-04-17 16:05:31 -0500751static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100752lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
753 char *buf)
dea31012005-04-17 16:05:31 -0500754{
Tony Jonesee959b02008-02-22 00:13:36 +0100755 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500756 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
757 struct lpfc_hba *phba = vport->phba;
758
dea31012005-04-17 16:05:31 -0500759 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
760}
761
James Smarte59058c2008-08-24 21:49:00 -0400762/**
James Smart3621a712009-04-06 18:47:14 -0400763 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400764 * @dev: class device that is converted into a Scsi_host.
765 * @attr: device attribute, not used.
766 * @buf: on return contains the state of the adapter.
767 *
768 * Returns: size of formatted string.
769 **/
dea31012005-04-17 16:05:31 -0500770static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100771lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
772 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500773{
Tony Jonesee959b02008-02-22 00:13:36 +0100774 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
776 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500777 char * state;
778
James Smart2e0fef82007-06-17 19:56:36 -0500779 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500780 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500781 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500782 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500783 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500784 state = "offline";
785 else
786 state = "online";
787
788 return snprintf(buf, PAGE_SIZE, "%s\n", state);
789}
790
James Smarte59058c2008-08-24 21:49:00 -0400791/**
James Smart3621a712009-04-06 18:47:14 -0400792 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400793 * @dev: class device that is converted into a Scsi_host.
794 * @attr: device attribute, not used.
795 * @buf: containing one of the strings "online", "offline", "warm" or "error".
796 * @count: unused variable.
797 *
798 * Returns:
799 * -EACCES if enable hba reset not enabled
800 * -EINVAL if the buffer does not contain a valid string (see above)
801 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
802 * buf length greater than zero indicates success
803 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500804static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100805lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
806 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500807{
Tony Jonesee959b02008-02-22 00:13:36 +0100808 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
810 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500811 struct completion online_compl;
812 int status=0;
813
James Smart13815c82008-01-11 01:52:48 -0500814 if (!phba->cfg_enable_hba_reset)
815 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500816 init_completion(&online_compl);
817
James Smart46fa3112007-04-25 09:51:45 -0400818 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500819 lpfc_workq_post_event(phba, &status, &online_compl,
820 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400821 wait_for_completion(&online_compl);
822 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
823 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500824 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400825 if (phba->sli_rev == LPFC_SLI_REV4)
826 return -EINVAL;
827 else
828 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400829 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400830 if (phba->sli_rev == LPFC_SLI_REV4)
831 return -EINVAL;
832 else
833 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500834 else
835 return -EINVAL;
836
Jamie Wellnitz41415862006-02-28 19:25:27 -0500837 if (!status)
838 return strlen(buf);
839 else
840 return -EIO;
841}
842
James Smarte59058c2008-08-24 21:49:00 -0400843/**
James Smart3621a712009-04-06 18:47:14 -0400844 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400845 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400846 * @mxri: max xri count.
847 * @axri: available xri count.
848 * @mrpi: max rpi count.
849 * @arpi: available rpi count.
850 * @mvpi: max vpi count.
851 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400852 *
853 * Description:
854 * If an integer pointer for an count is not null then the value for the
855 * count is returned.
856 *
857 * Returns:
858 * zero on error
859 * one for success
860 **/
James Smart311464e2007-08-02 11:10:37 -0400861static int
James Smart858c9f62007-06-17 19:56:39 -0500862lpfc_get_hba_info(struct lpfc_hba *phba,
863 uint32_t *mxri, uint32_t *axri,
864 uint32_t *mrpi, uint32_t *arpi,
865 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500866{
James Smart04c68492009-05-22 14:52:52 -0400867 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500868 LPFC_MBOXQ_t *pmboxq;
869 MAILBOX_t *pmb;
870 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400871 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500872
873 /*
874 * prevent udev from issuing mailbox commands until the port is
875 * configured.
876 */
877 if (phba->link_state < LPFC_LINK_DOWN ||
878 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400879 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500880 return 0;
881
882 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
883 return 0;
884
885 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
886 if (!pmboxq)
887 return 0;
888 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
889
James Smart04c68492009-05-22 14:52:52 -0400890 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500891 pmb->mbxCommand = MBX_READ_CONFIG;
892 pmb->mbxOwner = OWN_HOST;
893 pmboxq->context1 = NULL;
894
James Smart75baf692010-06-08 18:31:21 -0400895 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500896 rc = MBX_NOT_FINISHED;
897 else
898 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
899
900 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500901 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500902 mempool_free(pmboxq, phba->mbox_mem_pool);
903 return 0;
904 }
905
James Smartda0436e2009-05-22 14:51:39 -0400906 if (phba->sli_rev == LPFC_SLI_REV4) {
907 rd_config = &pmboxq->u.mqe.un.rd_config;
908 if (mrpi)
909 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
910 if (arpi)
911 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
912 phba->sli4_hba.max_cfg_param.rpi_used;
913 if (mxri)
914 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
915 if (axri)
916 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
917 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400918
919 /* Account for differences with SLI-3. Get vpi count from
920 * mailbox data and subtract one for max vpi value.
921 */
922 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
923 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
924
James Smartda0436e2009-05-22 14:51:39 -0400925 if (mvpi)
James Smart15672312010-04-06 14:49:03 -0400926 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -0400927 if (avpi)
James Smart15672312010-04-06 14:49:03 -0400928 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -0400929 } else {
930 if (mrpi)
931 *mrpi = pmb->un.varRdConfig.max_rpi;
932 if (arpi)
933 *arpi = pmb->un.varRdConfig.avail_rpi;
934 if (mxri)
935 *mxri = pmb->un.varRdConfig.max_xri;
936 if (axri)
937 *axri = pmb->un.varRdConfig.avail_xri;
938 if (mvpi)
939 *mvpi = pmb->un.varRdConfig.max_vpi;
940 if (avpi)
941 *avpi = pmb->un.varRdConfig.avail_vpi;
942 }
James Smart92d7f7b2007-06-17 19:56:38 -0500943
944 mempool_free(pmboxq, phba->mbox_mem_pool);
945 return 1;
946}
947
James Smarte59058c2008-08-24 21:49:00 -0400948/**
James Smart3621a712009-04-06 18:47:14 -0400949 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400950 * @dev: class device that is converted into a Scsi_host.
951 * @attr: device attribute, not used.
952 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
953 *
954 * Description:
955 * Calls lpfc_get_hba_info() asking for just the mrpi count.
956 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
957 * to "Unknown" and the buffer length is returned, therefore the caller
958 * must check for "Unknown" in the buffer to detect a failure.
959 *
960 * Returns: size of formatted string.
961 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500962static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100963lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
964 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500965{
Tony Jonesee959b02008-02-22 00:13:36 +0100966 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500967 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
968 struct lpfc_hba *phba = vport->phba;
969 uint32_t cnt;
970
James Smart858c9f62007-06-17 19:56:39 -0500971 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500972 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
973 return snprintf(buf, PAGE_SIZE, "Unknown\n");
974}
975
James Smarte59058c2008-08-24 21:49:00 -0400976/**
James Smart3621a712009-04-06 18:47:14 -0400977 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400978 * @dev: class device that is converted into a Scsi_host.
979 * @attr: device attribute, not used.
980 * @buf: containing the used rpi count in decimal or "Unknown".
981 *
982 * Description:
983 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
984 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
985 * to "Unknown" and the buffer length is returned, therefore the caller
986 * must check for "Unknown" in the buffer to detect a failure.
987 *
988 * Returns: size of formatted string.
989 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500990static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100991lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
992 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500993{
Tony Jonesee959b02008-02-22 00:13:36 +0100994 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500995 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
996 struct lpfc_hba *phba = vport->phba;
997 uint32_t cnt, acnt;
998
James Smart858c9f62007-06-17 19:56:39 -0500999 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001000 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1001 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1002}
1003
James Smarte59058c2008-08-24 21:49:00 -04001004/**
James Smart3621a712009-04-06 18:47:14 -04001005 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001006 * @dev: class device that is converted into a Scsi_host.
1007 * @attr: device attribute, not used.
1008 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1009 *
1010 * Description:
1011 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1012 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1013 * to "Unknown" and the buffer length is returned, therefore the caller
1014 * must check for "Unknown" in the buffer to detect a failure.
1015 *
1016 * Returns: size of formatted string.
1017 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001018static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001019lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1020 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001021{
Tony Jonesee959b02008-02-22 00:13:36 +01001022 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001023 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1024 struct lpfc_hba *phba = vport->phba;
1025 uint32_t cnt;
1026
James Smart858c9f62007-06-17 19:56:39 -05001027 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001028 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1029 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1030}
1031
James Smarte59058c2008-08-24 21:49:00 -04001032/**
James Smart3621a712009-04-06 18:47:14 -04001033 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001034 * @dev: class device that is converted into a Scsi_host.
1035 * @attr: device attribute, not used.
1036 * @buf: on return contains the used xri count in decimal or "Unknown".
1037 *
1038 * Description:
1039 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1040 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1041 * to "Unknown" and the buffer length is returned, therefore the caller
1042 * must check for "Unknown" in the buffer to detect a failure.
1043 *
1044 * Returns: size of formatted string.
1045 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001046static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001047lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1048 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001049{
Tony Jonesee959b02008-02-22 00:13:36 +01001050 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001051 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1052 struct lpfc_hba *phba = vport->phba;
1053 uint32_t cnt, acnt;
1054
James Smart858c9f62007-06-17 19:56:39 -05001055 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1056 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1057 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1058}
1059
James Smarte59058c2008-08-24 21:49:00 -04001060/**
James Smart3621a712009-04-06 18:47:14 -04001061 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001062 * @dev: class device that is converted into a Scsi_host.
1063 * @attr: device attribute, not used.
1064 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1065 *
1066 * Description:
1067 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1068 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1069 * to "Unknown" and the buffer length is returned, therefore the caller
1070 * must check for "Unknown" in the buffer to detect a failure.
1071 *
1072 * Returns: size of formatted string.
1073 **/
James Smart858c9f62007-06-17 19:56:39 -05001074static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001075lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1076 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001077{
Tony Jonesee959b02008-02-22 00:13:36 +01001078 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001079 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1080 struct lpfc_hba *phba = vport->phba;
1081 uint32_t cnt;
1082
1083 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1084 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1085 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1086}
1087
James Smarte59058c2008-08-24 21:49:00 -04001088/**
James Smart3621a712009-04-06 18:47:14 -04001089 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001090 * @dev: class device that is converted into a Scsi_host.
1091 * @attr: device attribute, not used.
1092 * @buf: on return contains the used vpi count in decimal or "Unknown".
1093 *
1094 * Description:
1095 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1096 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1097 * to "Unknown" and the buffer length is returned, therefore the caller
1098 * must check for "Unknown" in the buffer to detect a failure.
1099 *
1100 * Returns: size of formatted string.
1101 **/
James Smart858c9f62007-06-17 19:56:39 -05001102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001103lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1104 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001105{
Tony Jonesee959b02008-02-22 00:13:36 +01001106 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1108 struct lpfc_hba *phba = vport->phba;
1109 uint32_t cnt, acnt;
1110
1111 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001112 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1113 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1114}
1115
James Smarte59058c2008-08-24 21:49:00 -04001116/**
James Smart3621a712009-04-06 18:47:14 -04001117 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001118 * @dev: class device that is converted into a Scsi_host.
1119 * @attr: device attribute, not used.
1120 * @buf: text that must be interpreted to determine if npiv is supported.
1121 *
1122 * Description:
1123 * Buffer will contain text indicating npiv is not suppoerted on the port,
1124 * the port is an NPIV physical port, or it is an npiv virtual port with
1125 * the id of the vport.
1126 *
1127 * Returns: size of formatted string.
1128 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001129static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001130lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1131 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001132{
Tony Jonesee959b02008-02-22 00:13:36 +01001133 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1135 struct lpfc_hba *phba = vport->phba;
1136
1137 if (!(phba->max_vpi))
1138 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1139 if (vport->port_type == LPFC_PHYSICAL_PORT)
1140 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1141 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1142}
1143
James Smarte59058c2008-08-24 21:49:00 -04001144/**
James Smart3621a712009-04-06 18:47:14 -04001145 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001146 * @dev: class device that is converted into a Scsi_host.
1147 * @attr: device attribute, not used.
1148 * @buf: on return contains the cfg_poll in hex.
1149 *
1150 * Notes:
1151 * cfg_poll should be a lpfc_polling_flags type.
1152 *
1153 * Returns: size of formatted string.
1154 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001155static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001156lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1157 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001158{
Tony Jonesee959b02008-02-22 00:13:36 +01001159 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001160 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1161 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001162
1163 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1164}
1165
James Smarte59058c2008-08-24 21:49:00 -04001166/**
James Smart3621a712009-04-06 18:47:14 -04001167 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001168 * @dev: class device that is converted into a Scsi_host.
1169 * @attr: device attribute, not used.
1170 * @buf: one or more lpfc_polling_flags values.
1171 * @count: not used.
1172 *
1173 * Notes:
1174 * buf contents converted to integer and checked for a valid value.
1175 *
1176 * Returns:
1177 * -EINVAL if the buffer connot be converted or is out of range
1178 * length of the buf on success
1179 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001180static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001181lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1182 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001183{
Tony Jonesee959b02008-02-22 00:13:36 +01001184 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001185 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1186 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001187 uint32_t creg_val;
1188 uint32_t old_val;
1189 int val=0;
1190
1191 if (!isdigit(buf[0]))
1192 return -EINVAL;
1193
1194 if (sscanf(buf, "%i", &val) != 1)
1195 return -EINVAL;
1196
1197 if ((val & 0x3) != val)
1198 return -EINVAL;
1199
James Smart45ed1192009-10-02 15:17:02 -04001200 if (phba->sli_rev == LPFC_SLI_REV4)
1201 val = 0;
1202
James Smart2e0fef82007-06-17 19:56:36 -05001203 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001204
1205 old_val = phba->cfg_poll;
1206
1207 if (val & ENABLE_FCP_RING_POLLING) {
1208 if ((val & DISABLE_FCP_RING_INT) &&
1209 !(old_val & DISABLE_FCP_RING_INT)) {
1210 creg_val = readl(phba->HCregaddr);
1211 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1212 writel(creg_val, phba->HCregaddr);
1213 readl(phba->HCregaddr); /* flush */
1214
1215 lpfc_poll_start_timer(phba);
1216 }
1217 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001218 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001219 return -EINVAL;
1220 }
1221
1222 if (!(val & DISABLE_FCP_RING_INT) &&
1223 (old_val & DISABLE_FCP_RING_INT))
1224 {
James Smart2e0fef82007-06-17 19:56:36 -05001225 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001226 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001227 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001228 creg_val = readl(phba->HCregaddr);
1229 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1230 writel(creg_val, phba->HCregaddr);
1231 readl(phba->HCregaddr); /* flush */
1232 }
1233
1234 phba->cfg_poll = val;
1235
James Smart2e0fef82007-06-17 19:56:36 -05001236 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001237
1238 return strlen(buf);
1239}
dea31012005-04-17 16:05:31 -05001240
James Smarte59058c2008-08-24 21:49:00 -04001241/**
James Smart3621a712009-04-06 18:47:14 -04001242 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001243 *
1244 * Description:
1245 * Macro that given an attr e.g. hba_queue_depth expands
1246 * into a function with the name lpfc_hba_queue_depth_show.
1247 *
1248 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1249 * @dev: class device that is converted into a Scsi_host.
1250 * @attr: device attribute, not used.
1251 * @buf: on return contains the attribute value in decimal.
1252 *
1253 * Returns: size of formatted string.
1254 **/
dea31012005-04-17 16:05:31 -05001255#define lpfc_param_show(attr) \
1256static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001257lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1258 char *buf) \
dea31012005-04-17 16:05:31 -05001259{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001260 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1262 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001263 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001264 val = phba->cfg_##attr;\
1265 return snprintf(buf, PAGE_SIZE, "%d\n",\
1266 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001267}
1268
James Smarte59058c2008-08-24 21:49:00 -04001269/**
James Smart3621a712009-04-06 18:47:14 -04001270 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001271 *
1272 * Description:
1273 * Macro that given an attr e.g. hba_queue_depth expands
1274 * into a function with the name lpfc_hba_queue_depth_show
1275 *
1276 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1277 * @dev: class device that is converted into a Scsi_host.
1278 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001279 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001280 *
1281 * Returns: size of formatted string.
1282 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001283#define lpfc_param_hex_show(attr) \
1284static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001285lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1286 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001287{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001288 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1290 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001291 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001292 val = phba->cfg_##attr;\
1293 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1294 phba->cfg_##attr);\
1295}
1296
James Smarte59058c2008-08-24 21:49:00 -04001297/**
James Smart3621a712009-04-06 18:47:14 -04001298 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001299 *
1300 * Description:
1301 * Macro that given an attr e.g. hba_queue_depth expands
1302 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1303 * takes a default argument, a minimum and maximum argument.
1304 *
1305 * lpfc_##attr##_init: Initializes an attribute.
1306 * @phba: pointer the the adapter structure.
1307 * @val: integer attribute value.
1308 *
1309 * Validates the min and max values then sets the adapter config field
1310 * accordingly, or uses the default if out of range and prints an error message.
1311 *
1312 * Returns:
1313 * zero on success
1314 * -EINVAL if default used
1315 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001316#define lpfc_param_init(attr, default, minval, maxval) \
1317static int \
James Smart84d1b002010-02-12 14:42:33 -05001318lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001319{ \
1320 if (val >= minval && val <= maxval) {\
1321 phba->cfg_##attr = val;\
1322 return 0;\
1323 }\
1324 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001325 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1326 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001327 phba->cfg_##attr = default;\
1328 return -EINVAL;\
1329}
1330
James Smarte59058c2008-08-24 21:49:00 -04001331/**
James Smart3621a712009-04-06 18:47:14 -04001332 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001333 *
1334 * Description:
1335 * Macro that given an attr e.g. hba_queue_depth expands
1336 * into a function with the name lpfc_hba_queue_depth_set
1337 *
1338 * lpfc_##attr##_set: Sets an attribute value.
1339 * @phba: pointer the the adapter structure.
1340 * @val: integer attribute value.
1341 *
1342 * Description:
1343 * Validates the min and max values then sets the
1344 * adapter config field if in the valid range. prints error message
1345 * and does not set the parameter if invalid.
1346 *
1347 * Returns:
1348 * zero on success
1349 * -EINVAL if val is invalid
1350 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001351#define lpfc_param_set(attr, default, minval, maxval) \
1352static int \
James Smart84d1b002010-02-12 14:42:33 -05001353lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001354{ \
1355 if (val >= minval && val <= maxval) {\
1356 phba->cfg_##attr = val;\
1357 return 0;\
1358 }\
1359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001360 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1361 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001362 return -EINVAL;\
1363}
1364
James Smarte59058c2008-08-24 21:49:00 -04001365/**
James Smart3621a712009-04-06 18:47:14 -04001366 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001367 *
1368 * Description:
1369 * Macro that given an attr e.g. hba_queue_depth expands
1370 * into a function with the name lpfc_hba_queue_depth_store.
1371 *
1372 * lpfc_##attr##_store: Set an sttribute value.
1373 * @dev: class device that is converted into a Scsi_host.
1374 * @attr: device attribute, not used.
1375 * @buf: contains the attribute value in ascii.
1376 * @count: not used.
1377 *
1378 * Description:
1379 * Convert the ascii text number to an integer, then
1380 * use the lpfc_##attr##_set function to set the value.
1381 *
1382 * Returns:
1383 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1384 * length of buffer upon success.
1385 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001386#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001387static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001388lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1389 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001390{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001391 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001392 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1393 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001394 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001395 if (!isdigit(buf[0]))\
1396 return -EINVAL;\
1397 if (sscanf(buf, "%i", &val) != 1)\
1398 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001399 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001400 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001401 else \
1402 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001403}
1404
James Smarte59058c2008-08-24 21:49:00 -04001405/**
James Smart3621a712009-04-06 18:47:14 -04001406 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001407 *
1408 * Description:
1409 * Macro that given an attr e.g. hba_queue_depth expands
1410 * into a function with the name lpfc_hba_queue_depth_show
1411 *
1412 * lpfc_##attr##_show: prints the attribute value in decimal.
1413 * @dev: class device that is converted into a Scsi_host.
1414 * @attr: device attribute, not used.
1415 * @buf: on return contains the attribute value in decimal.
1416 *
1417 * Returns: length of formatted string.
1418 **/
James Smart3de2a652007-08-02 11:09:59 -04001419#define lpfc_vport_param_show(attr) \
1420static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001421lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1422 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001423{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001424 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001425 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001426 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001427 val = vport->cfg_##attr;\
1428 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1429}
1430
James Smarte59058c2008-08-24 21:49:00 -04001431/**
James Smart3621a712009-04-06 18:47:14 -04001432 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001433 *
1434 * Description:
1435 * Macro that given an attr e.g.
1436 * hba_queue_depth expands into a function with the name
1437 * lpfc_hba_queue_depth_show
1438 *
James Smart3621a712009-04-06 18:47:14 -04001439 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001440 * @dev: class device that is converted into a Scsi_host.
1441 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001442 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001443 *
1444 * Returns: length of formatted string.
1445 **/
James Smart3de2a652007-08-02 11:09:59 -04001446#define lpfc_vport_param_hex_show(attr) \
1447static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001448lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1449 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001450{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001451 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001452 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001453 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001454 val = vport->cfg_##attr;\
1455 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1456}
1457
James Smarte59058c2008-08-24 21:49:00 -04001458/**
James Smart3621a712009-04-06 18:47:14 -04001459 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001460 *
1461 * Description:
1462 * Macro that given an attr e.g. hba_queue_depth expands
1463 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1464 * takes a default argument, a minimum and maximum argument.
1465 *
1466 * lpfc_##attr##_init: validates the min and max values then sets the
1467 * adapter config field accordingly, or uses the default if out of range
1468 * and prints an error message.
1469 * @phba: pointer the the adapter structure.
1470 * @val: integer attribute value.
1471 *
1472 * Returns:
1473 * zero on success
1474 * -EINVAL if default used
1475 **/
James Smart3de2a652007-08-02 11:09:59 -04001476#define lpfc_vport_param_init(attr, default, minval, maxval) \
1477static int \
James Smart84d1b002010-02-12 14:42:33 -05001478lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001479{ \
1480 if (val >= minval && val <= maxval) {\
1481 vport->cfg_##attr = val;\
1482 return 0;\
1483 }\
James Smarte8b62012007-08-02 11:10:09 -04001484 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001485 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001486 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001487 vport->cfg_##attr = default;\
1488 return -EINVAL;\
1489}
1490
James Smarte59058c2008-08-24 21:49:00 -04001491/**
James Smart3621a712009-04-06 18:47:14 -04001492 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001493 *
1494 * Description:
1495 * Macro that given an attr e.g. hba_queue_depth expands
1496 * into a function with the name lpfc_hba_queue_depth_set
1497 *
1498 * lpfc_##attr##_set: validates the min and max values then sets the
1499 * adapter config field if in the valid range. prints error message
1500 * and does not set the parameter if invalid.
1501 * @phba: pointer the the adapter structure.
1502 * @val: integer attribute value.
1503 *
1504 * Returns:
1505 * zero on success
1506 * -EINVAL if val is invalid
1507 **/
James Smart3de2a652007-08-02 11:09:59 -04001508#define lpfc_vport_param_set(attr, default, minval, maxval) \
1509static int \
James Smart84d1b002010-02-12 14:42:33 -05001510lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001511{ \
1512 if (val >= minval && val <= maxval) {\
1513 vport->cfg_##attr = val;\
1514 return 0;\
1515 }\
James Smarte8b62012007-08-02 11:10:09 -04001516 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001517 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001518 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001519 return -EINVAL;\
1520}
1521
James Smarte59058c2008-08-24 21:49:00 -04001522/**
James Smart3621a712009-04-06 18:47:14 -04001523 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001524 *
1525 * Description:
1526 * Macro that given an attr e.g. hba_queue_depth
1527 * expands into a function with the name lpfc_hba_queue_depth_store
1528 *
1529 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1530 * use the lpfc_##attr##_set function to set the value.
1531 * @cdev: class device that is converted into a Scsi_host.
1532 * @buf: contains the attribute value in decimal.
1533 * @count: not used.
1534 *
1535 * Returns:
1536 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1537 * length of buffer upon success.
1538 **/
James Smart3de2a652007-08-02 11:09:59 -04001539#define lpfc_vport_param_store(attr) \
1540static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001541lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1542 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001543{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001544 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001545 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001546 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001547 if (!isdigit(buf[0]))\
1548 return -EINVAL;\
1549 if (sscanf(buf, "%i", &val) != 1)\
1550 return -EINVAL;\
1551 if (lpfc_##attr##_set(vport, val) == 0) \
1552 return strlen(buf);\
1553 else \
1554 return -EINVAL;\
1555}
1556
1557
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001558#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001559static uint lpfc_##name = defval;\
1560module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001561MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001562lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001563
1564#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001565static uint lpfc_##name = defval;\
1566module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001567MODULE_PARM_DESC(lpfc_##name, desc);\
1568lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001569lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001570static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001571
1572#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001573static uint lpfc_##name = defval;\
1574module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001575MODULE_PARM_DESC(lpfc_##name, desc);\
1576lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001577lpfc_param_init(name, defval, minval, maxval)\
1578lpfc_param_set(name, defval, minval, maxval)\
1579lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001580static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1581 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001582
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001583#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001584static uint lpfc_##name = defval;\
1585module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001586MODULE_PARM_DESC(lpfc_##name, desc);\
1587lpfc_param_hex_show(name)\
1588lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001589static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001590
1591#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001592static uint lpfc_##name = defval;\
1593module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001594MODULE_PARM_DESC(lpfc_##name, desc);\
1595lpfc_param_hex_show(name)\
1596lpfc_param_init(name, defval, minval, maxval)\
1597lpfc_param_set(name, defval, minval, maxval)\
1598lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001599static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1600 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001601
James Smart3de2a652007-08-02 11:09:59 -04001602#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001603static uint lpfc_##name = defval;\
1604module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001605MODULE_PARM_DESC(lpfc_##name, desc);\
1606lpfc_vport_param_init(name, defval, minval, maxval)
1607
1608#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001609static uint lpfc_##name = defval;\
1610module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001611MODULE_PARM_DESC(lpfc_##name, desc);\
1612lpfc_vport_param_show(name)\
1613lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001614static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001615
1616#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001617static uint lpfc_##name = defval;\
1618module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001619MODULE_PARM_DESC(lpfc_##name, desc);\
1620lpfc_vport_param_show(name)\
1621lpfc_vport_param_init(name, defval, minval, maxval)\
1622lpfc_vport_param_set(name, defval, minval, maxval)\
1623lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001624static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1625 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001626
1627#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001628static uint lpfc_##name = defval;\
1629module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001630MODULE_PARM_DESC(lpfc_##name, desc);\
1631lpfc_vport_param_hex_show(name)\
1632lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001633static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001634
1635#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001636static uint lpfc_##name = defval;\
1637module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001638MODULE_PARM_DESC(lpfc_##name, desc);\
1639lpfc_vport_param_hex_show(name)\
1640lpfc_vport_param_init(name, defval, minval, maxval)\
1641lpfc_vport_param_set(name, defval, minval, maxval)\
1642lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001643static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1644 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001645
James Smart81301a92008-12-04 22:39:46 -05001646static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1647static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1648static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1649static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001650static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1651static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1652static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1653static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1654static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1655static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1656static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1657static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001658static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1659 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001660static DEVICE_ATTR(option_rom_version, S_IRUGO,
1661 lpfc_option_rom_version_show, NULL);
1662static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1663 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001664static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001665static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1666static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001667static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001668static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1669 lpfc_board_mode_show, lpfc_board_mode_store);
1670static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1671static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1672static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1673static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1674static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1675static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1676static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1677static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1678static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001679
James Smartc3f28af2006-08-18 17:47:18 -04001680
James Smarta12e07b2006-12-02 13:35:30 -05001681static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001682
James Smarte59058c2008-08-24 21:49:00 -04001683/**
James Smart3621a712009-04-06 18:47:14 -04001684 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001685 * @dev: class device that is converted into a Scsi_host.
1686 * @attr: device attribute, not used.
1687 * @buf: containing the string lpfc_soft_wwn_key.
1688 * @count: must be size of lpfc_soft_wwn_key.
1689 *
1690 * Returns:
1691 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1692 * length of buf indicates success
1693 **/
James Smartc3f28af2006-08-18 17:47:18 -04001694static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001695lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1696 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001697{
Tony Jonesee959b02008-02-22 00:13:36 +01001698 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1700 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001701 unsigned int cnt = count;
1702
1703 /*
1704 * We're doing a simple sanity check for soft_wwpn setting.
1705 * We require that the user write a specific key to enable
1706 * the soft_wwpn attribute to be settable. Once the attribute
1707 * is written, the enable key resets. If further updates are
1708 * desired, the key must be written again to re-enable the
1709 * attribute.
1710 *
1711 * The "key" is not secret - it is a hardcoded string shown
1712 * here. The intent is to protect against the random user or
1713 * application that is just writing attributes.
1714 */
1715
1716 /* count may include a LF at end of string */
1717 if (buf[cnt-1] == '\n')
1718 cnt--;
1719
James Smarta12e07b2006-12-02 13:35:30 -05001720 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1721 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001722 return -EINVAL;
1723
James Smarta12e07b2006-12-02 13:35:30 -05001724 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001725 return count;
1726}
Tony Jonesee959b02008-02-22 00:13:36 +01001727static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1728 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001729
James Smarte59058c2008-08-24 21:49:00 -04001730/**
James Smart3621a712009-04-06 18:47:14 -04001731 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001732 * @dev: class device that is converted into a Scsi_host.
1733 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001734 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001735 *
1736 * Returns: size of formatted string.
1737 **/
James Smartc3f28af2006-08-18 17:47:18 -04001738static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001739lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1740 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001741{
Tony Jonesee959b02008-02-22 00:13:36 +01001742 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1744 struct lpfc_hba *phba = vport->phba;
1745
Randy Dunlapafc071e2006-10-23 21:47:13 -07001746 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1747 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001748}
1749
James Smarte59058c2008-08-24 21:49:00 -04001750/**
James Smart3621a712009-04-06 18:47:14 -04001751 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001752 * @dev class device that is converted into a Scsi_host.
1753 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001754 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001755 * @count: number of wwpn bytes in buf
1756 *
1757 * Returns:
1758 * -EACCES hba reset not enabled, adapter over temp
1759 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1760 * -EIO error taking adapter offline or online
1761 * value of count on success
1762 **/
James Smartc3f28af2006-08-18 17:47:18 -04001763static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001764lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1765 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001766{
Tony Jonesee959b02008-02-22 00:13:36 +01001767 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001768 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1769 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001770 struct completion online_compl;
1771 int stat1=0, stat2=0;
1772 unsigned int i, j, cnt=count;
1773 u8 wwpn[8];
1774
James Smart13815c82008-01-11 01:52:48 -05001775 if (!phba->cfg_enable_hba_reset)
1776 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001777 spin_lock_irq(&phba->hbalock);
1778 if (phba->over_temp_state == HBA_OVER_TEMP) {
1779 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001780 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001781 }
1782 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001783 /* count may include a LF at end of string */
1784 if (buf[cnt-1] == '\n')
1785 cnt--;
1786
James Smarta12e07b2006-12-02 13:35:30 -05001787 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001788 ((cnt == 17) && (*buf++ != 'x')) ||
1789 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1790 return -EINVAL;
1791
James Smarta12e07b2006-12-02 13:35:30 -05001792 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001793
1794 memset(wwpn, 0, sizeof(wwpn));
1795
1796 /* Validate and store the new name */
1797 for (i=0, j=0; i < 16; i++) {
1798 if ((*buf >= 'a') && (*buf <= 'f'))
1799 j = ((j << 4) | ((*buf++ -'a') + 10));
1800 else if ((*buf >= 'A') && (*buf <= 'F'))
1801 j = ((j << 4) | ((*buf++ -'A') + 10));
1802 else if ((*buf >= '0') && (*buf <= '9'))
1803 j = ((j << 4) | (*buf++ -'0'));
1804 else
1805 return -EINVAL;
1806 if (i % 2) {
1807 wwpn[i/2] = j & 0xff;
1808 j = 0;
1809 }
1810 }
1811 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001812 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001813 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001814 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001815
1816 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1817 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1818
James Smart46fa3112007-04-25 09:51:45 -04001819 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001820 if (stat1)
1821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001822 "0463 lpfc_soft_wwpn attribute set failed to "
1823 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001824 init_completion(&online_compl);
1825 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1826 wait_for_completion(&online_compl);
1827 if (stat2)
1828 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001829 "0464 lpfc_soft_wwpn attribute set failed to "
1830 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001831 return (stat1 || stat2) ? -EIO : count;
1832}
Tony Jonesee959b02008-02-22 00:13:36 +01001833static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1834 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001835
James Smarte59058c2008-08-24 21:49:00 -04001836/**
James Smart3621a712009-04-06 18:47:14 -04001837 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001838 * @dev: class device that is converted into a Scsi_host.
1839 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001840 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001841 *
1842 * Returns: size of formatted string.
1843 **/
James Smarta12e07b2006-12-02 13:35:30 -05001844static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001845lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1846 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001847{
Tony Jonesee959b02008-02-22 00:13:36 +01001848 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001849 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001850 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1851 (unsigned long long)phba->cfg_soft_wwnn);
1852}
1853
James Smarte59058c2008-08-24 21:49:00 -04001854/**
James Smart3621a712009-04-06 18:47:14 -04001855 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001856 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001857 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001858 * @count: number of wwnn bytes in buf.
1859 *
1860 * Returns:
1861 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1862 * value of count on success
1863 **/
James Smarta12e07b2006-12-02 13:35:30 -05001864static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001865lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1866 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001867{
Tony Jonesee959b02008-02-22 00:13:36 +01001868 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001869 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001870 unsigned int i, j, cnt=count;
1871 u8 wwnn[8];
1872
1873 /* count may include a LF at end of string */
1874 if (buf[cnt-1] == '\n')
1875 cnt--;
1876
1877 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1878 ((cnt == 17) && (*buf++ != 'x')) ||
1879 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1880 return -EINVAL;
1881
1882 /*
1883 * Allow wwnn to be set many times, as long as the enable is set.
1884 * However, once the wwpn is set, everything locks.
1885 */
1886
1887 memset(wwnn, 0, sizeof(wwnn));
1888
1889 /* Validate and store the new name */
1890 for (i=0, j=0; i < 16; i++) {
1891 if ((*buf >= 'a') && (*buf <= 'f'))
1892 j = ((j << 4) | ((*buf++ -'a') + 10));
1893 else if ((*buf >= 'A') && (*buf <= 'F'))
1894 j = ((j << 4) | ((*buf++ -'A') + 10));
1895 else if ((*buf >= '0') && (*buf <= '9'))
1896 j = ((j << 4) | (*buf++ -'0'));
1897 else
1898 return -EINVAL;
1899 if (i % 2) {
1900 wwnn[i/2] = j & 0xff;
1901 j = 0;
1902 }
1903 }
1904 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1905
1906 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1907 "lpfc%d: soft_wwnn set. Value will take effect upon "
1908 "setting of the soft_wwpn\n", phba->brd_no);
1909
1910 return count;
1911}
Tony Jonesee959b02008-02-22 00:13:36 +01001912static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1913 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001914
James Smartc3f28af2006-08-18 17:47:18 -04001915
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001916static int lpfc_poll = 0;
1917module_param(lpfc_poll, int, 0);
1918MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1919 " 0 - none,"
1920 " 1 - poll with interrupts enabled"
1921 " 3 - poll and disable FCP ring interrupts");
1922
Tony Jonesee959b02008-02-22 00:13:36 +01001923static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1924 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001925
James Smart92d7f7b2007-06-17 19:56:38 -05001926int lpfc_sli_mode = 0;
1927module_param(lpfc_sli_mode, int, 0);
1928MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1929 " 0 - auto (SLI-3 if supported),"
1930 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1931 " 3 - select SLI-3");
1932
James Smart15672312010-04-06 14:49:03 -04001933int lpfc_enable_npiv = 1;
James Smart7ee5d432007-10-27 13:37:17 -04001934module_param(lpfc_enable_npiv, int, 0);
1935MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1936lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04001937lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04001938static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001939
dea31012005-04-17 16:05:31 -05001940/*
James Smart84d1b002010-02-12 14:42:33 -05001941# lpfc_suppress_link_up: Bring link up at initialization
1942# 0x0 = bring link up (issue MBX_INIT_LINK)
1943# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1944# 0x2 = never bring up link
1945# Default value is 0.
1946*/
James Smarte40a02c2010-02-26 14:13:54 -05001947LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1948 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1949 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04001950/*
1951# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1952# 1 - (1024)
1953# 2 - (2048)
1954# 3 - (3072)
1955# 4 - (4096)
1956# 5 - (5120)
1957*/
1958static ssize_t
1959lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1960{
1961 struct Scsi_Host *shost = class_to_shost(dev);
1962 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1963
1964 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
1965}
1966
1967static DEVICE_ATTR(iocb_hw, S_IRUGO,
1968 lpfc_iocb_hw_show, NULL);
1969static ssize_t
1970lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1971{
1972 struct Scsi_Host *shost = class_to_shost(dev);
1973 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1974
1975 return snprintf(buf, PAGE_SIZE, "%d\n",
1976 phba->sli.ring[LPFC_ELS_RING].txq_max);
1977}
1978
1979static DEVICE_ATTR(txq_hw, S_IRUGO,
1980 lpfc_txq_hw_show, NULL);
1981static ssize_t
1982lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
1983 char *buf)
1984{
1985 struct Scsi_Host *shost = class_to_shost(dev);
1986 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1987
1988 return snprintf(buf, PAGE_SIZE, "%d\n",
1989 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
1990}
1991
1992static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
1993 lpfc_txcmplq_hw_show, NULL);
1994
1995int lpfc_iocb_cnt = 2;
1996module_param(lpfc_iocb_cnt, int, 1);
1997MODULE_PARM_DESC(lpfc_iocb_cnt,
1998 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
1999lpfc_param_show(iocb_cnt);
2000lpfc_param_init(iocb_cnt, 2, 1, 5);
2001static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2002 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002003
2004/*
James Smartc01f3202006-08-18 17:47:08 -04002005# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2006# until the timer expires. Value range is [0,255]. Default value is 30.
2007*/
2008static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2009static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2010module_param(lpfc_nodev_tmo, int, 0);
2011MODULE_PARM_DESC(lpfc_nodev_tmo,
2012 "Seconds driver will hold I/O waiting "
2013 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002014
2015/**
James Smart3621a712009-04-06 18:47:14 -04002016 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002017 * @dev: class converted to a Scsi_host structure.
2018 * @attr: device attribute, not used.
2019 * @buf: on return contains the dev loss timeout in decimal.
2020 *
2021 * Returns: size of formatted string.
2022 **/
James Smartc01f3202006-08-18 17:47:08 -04002023static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002024lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2025 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002026{
Tony Jonesee959b02008-02-22 00:13:36 +01002027 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002028 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002029
James Smart3de2a652007-08-02 11:09:59 -04002030 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002031}
2032
James Smarte59058c2008-08-24 21:49:00 -04002033/**
James Smart3621a712009-04-06 18:47:14 -04002034 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002035 * @vport: lpfc vport structure pointer.
2036 * @val: contains the nodev timeout value.
2037 *
2038 * Description:
2039 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2040 * a kernel error message is printed and zero is returned.
2041 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2042 * Otherwise nodev tmo is set to the default value.
2043 *
2044 * Returns:
2045 * zero if already set or if val is in range
2046 * -EINVAL val out of range
2047 **/
James Smartc01f3202006-08-18 17:47:08 -04002048static int
James Smart3de2a652007-08-02 11:09:59 -04002049lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002050{
James Smart3de2a652007-08-02 11:09:59 -04002051 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2052 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2053 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002055 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002056 "parameter because devloss_tmo is "
2057 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002058 return 0;
2059 }
2060
2061 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002062 vport->cfg_nodev_tmo = val;
2063 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002064 return 0;
2065 }
James Smarte8b62012007-08-02 11:10:09 -04002066 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2067 "0400 lpfc_nodev_tmo attribute cannot be set to"
2068 " %d, allowed range is [%d, %d]\n",
2069 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002070 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002071 return -EINVAL;
2072}
2073
James Smarte59058c2008-08-24 21:49:00 -04002074/**
James Smart3621a712009-04-06 18:47:14 -04002075 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002076 * @vport: lpfc vport structure pointer.
2077 *
2078 * Description:
2079 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2080 **/
James Smart7054a602007-04-25 09:52:34 -04002081static void
James Smart3de2a652007-08-02 11:09:59 -04002082lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002083{
James Smart858c9f62007-06-17 19:56:39 -05002084 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002085 struct lpfc_nodelist *ndlp;
2086
James Smart51ef4c22007-08-02 11:10:31 -04002087 shost = lpfc_shost_from_vport(vport);
2088 spin_lock_irq(shost->host_lock);
2089 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002090 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002091 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2092 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002093}
2094
James Smarte59058c2008-08-24 21:49:00 -04002095/**
James Smart3621a712009-04-06 18:47:14 -04002096 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002097 * @vport: lpfc vport structure pointer.
2098 * @val: contains the tmo value.
2099 *
2100 * Description:
2101 * If the devloss tmo is already set or the vport dev loss tmo has changed
2102 * then a kernel error message is printed and zero is returned.
2103 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2104 * Otherwise nodev tmo is set to the default value.
2105 *
2106 * Returns:
2107 * zero if already set or if val is in range
2108 * -EINVAL val out of range
2109 **/
James Smartc01f3202006-08-18 17:47:08 -04002110static int
James Smart3de2a652007-08-02 11:09:59 -04002111lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002112{
James Smart3de2a652007-08-02 11:09:59 -04002113 if (vport->dev_loss_tmo_changed ||
2114 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002115 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2116 "0401 Ignoring change to nodev_tmo "
2117 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002118 return 0;
2119 }
James Smartc01f3202006-08-18 17:47:08 -04002120 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002121 vport->cfg_nodev_tmo = val;
2122 vport->cfg_devloss_tmo = val;
2123 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002124 return 0;
2125 }
James Smarte8b62012007-08-02 11:10:09 -04002126 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2127 "0403 lpfc_nodev_tmo attribute cannot be set to"
2128 "%d, allowed range is [%d, %d]\n",
2129 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002130 return -EINVAL;
2131}
2132
James Smart3de2a652007-08-02 11:09:59 -04002133lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002134
Tony Jonesee959b02008-02-22 00:13:36 +01002135static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2136 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002137
2138/*
2139# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2140# disappear until the timer expires. Value range is [0,255]. Default
2141# value is 30.
2142*/
2143module_param(lpfc_devloss_tmo, int, 0);
2144MODULE_PARM_DESC(lpfc_devloss_tmo,
2145 "Seconds driver will hold I/O waiting "
2146 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002147lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2148 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2149lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002150
2151/**
James Smart3621a712009-04-06 18:47:14 -04002152 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002153 * @vport: lpfc vport structure pointer.
2154 * @val: contains the tmo value.
2155 *
2156 * Description:
2157 * If val is in a valid range then set the vport nodev tmo,
2158 * devloss tmo, also set the vport dev loss tmo changed flag.
2159 * Else a kernel error message is printed.
2160 *
2161 * Returns:
2162 * zero if val is in range
2163 * -EINVAL val out of range
2164 **/
James Smartc01f3202006-08-18 17:47:08 -04002165static int
James Smart3de2a652007-08-02 11:09:59 -04002166lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002167{
2168 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002169 vport->cfg_nodev_tmo = val;
2170 vport->cfg_devloss_tmo = val;
2171 vport->dev_loss_tmo_changed = 1;
2172 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002173 return 0;
2174 }
2175
James Smarte8b62012007-08-02 11:10:09 -04002176 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2177 "0404 lpfc_devloss_tmo attribute cannot be set to"
2178 " %d, allowed range is [%d, %d]\n",
2179 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002180 return -EINVAL;
2181}
2182
James Smart3de2a652007-08-02 11:09:59 -04002183lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002184static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2185 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002186
2187/*
dea31012005-04-17 16:05:31 -05002188# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2189# deluged with LOTS of information.
2190# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002191# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002192*/
James Smartf4b4c682009-05-22 14:53:12 -04002193LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002194 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002195
2196/*
James Smart7ee5d432007-10-27 13:37:17 -04002197# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2198# objects that have been registered with the nameserver after login.
2199*/
2200LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2201 "Deregister nameserver objects before LOGO");
2202
2203/*
dea31012005-04-17 16:05:31 -05002204# lun_queue_depth: This parameter is used to limit the number of outstanding
2205# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2206*/
James Smart3de2a652007-08-02 11:09:59 -04002207LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2208 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002209
2210/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002211# hba_queue_depth: This parameter is used to limit the number of outstanding
2212# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2213# value is greater than the maximum number of exchanges supported by the HBA,
2214# then maximum number of exchanges supported by the HBA is used to determine
2215# the hba_queue_depth.
2216*/
2217LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2218 "Max number of FCP commands we can queue to a lpfc HBA");
2219
2220/*
James Smart92d7f7b2007-06-17 19:56:38 -05002221# peer_port_login: This parameter allows/prevents logins
2222# between peer ports hosted on the same physical port.
2223# When this parameter is set 0 peer ports of same physical port
2224# are not allowed to login to each other.
2225# When this parameter is set 1 peer ports of same physical port
2226# are allowed to login to each other.
2227# Default value of this parameter is 0.
2228*/
James Smart3de2a652007-08-02 11:09:59 -04002229LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2230 "Allow peer ports on the same physical port to login to each "
2231 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002232
2233/*
James Smart3de2a652007-08-02 11:09:59 -04002234# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002235# between Virtual Ports and remote initiators.
2236# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2237# other initiators and will attempt to PLOGI all remote ports.
2238# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2239# remote ports and will not attempt to PLOGI to other initiators.
2240# This parameter does not restrict to the physical port.
2241# This parameter does not restrict logins to Fabric resident remote ports.
2242# Default value of this parameter is 1.
2243*/
James Smart3de2a652007-08-02 11:09:59 -04002244static int lpfc_restrict_login = 1;
2245module_param(lpfc_restrict_login, int, 0);
2246MODULE_PARM_DESC(lpfc_restrict_login,
2247 "Restrict virtual ports login to remote initiators.");
2248lpfc_vport_param_show(restrict_login);
2249
James Smarte59058c2008-08-24 21:49:00 -04002250/**
James Smart3621a712009-04-06 18:47:14 -04002251 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002252 * @vport: lpfc vport structure pointer.
2253 * @val: contains the restrict login value.
2254 *
2255 * Description:
2256 * If val is not in a valid range then log a kernel error message and set
2257 * the vport restrict login to one.
2258 * If the port type is physical clear the restrict login flag and return.
2259 * Else set the restrict login flag to val.
2260 *
2261 * Returns:
2262 * zero if val is in range
2263 * -EINVAL val out of range
2264 **/
James Smart3de2a652007-08-02 11:09:59 -04002265static int
2266lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2267{
2268 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002269 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002270 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002271 "be set to %d, allowed range is [0, 1]\n",
2272 val);
James Smart3de2a652007-08-02 11:09:59 -04002273 vport->cfg_restrict_login = 1;
2274 return -EINVAL;
2275 }
2276 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2277 vport->cfg_restrict_login = 0;
2278 return 0;
2279 }
2280 vport->cfg_restrict_login = val;
2281 return 0;
2282}
2283
James Smarte59058c2008-08-24 21:49:00 -04002284/**
James Smart3621a712009-04-06 18:47:14 -04002285 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002286 * @vport: lpfc vport structure pointer.
2287 * @val: contains the restrict login value.
2288 *
2289 * Description:
2290 * If val is not in a valid range then log a kernel error message and set
2291 * the vport restrict login to one.
2292 * If the port type is physical and the val is not zero log a kernel
2293 * error message, clear the restrict login flag and return zero.
2294 * Else set the restrict login flag to val.
2295 *
2296 * Returns:
2297 * zero if val is in range
2298 * -EINVAL val out of range
2299 **/
James Smart3de2a652007-08-02 11:09:59 -04002300static int
2301lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2302{
2303 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002304 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002305 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002306 "be set to %d, allowed range is [0, 1]\n",
2307 val);
James Smart3de2a652007-08-02 11:09:59 -04002308 vport->cfg_restrict_login = 1;
2309 return -EINVAL;
2310 }
2311 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002312 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2313 "0468 lpfc_restrict_login must be 0 for "
2314 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002315 vport->cfg_restrict_login = 0;
2316 return 0;
2317 }
2318 vport->cfg_restrict_login = val;
2319 return 0;
2320}
2321lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002322static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2323 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002324
2325/*
dea31012005-04-17 16:05:31 -05002326# Some disk devices have a "select ID" or "select Target" capability.
2327# From a protocol standpoint "select ID" usually means select the
2328# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2329# annex" which contains a table that maps a "select ID" (a number
2330# between 0 and 7F) to an ALPA. By default, for compatibility with
2331# older drivers, the lpfc driver scans this table from low ALPA to high
2332# ALPA.
2333#
2334# Turning on the scan-down variable (on = 1, off = 0) will
2335# cause the lpfc driver to use an inverted table, effectively
2336# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2337#
2338# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2339# and will not work across a fabric. Also this parameter will take
2340# effect only in the case when ALPA map is not available.)
2341*/
James Smart3de2a652007-08-02 11:09:59 -04002342LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2343 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002344
2345/*
dea31012005-04-17 16:05:31 -05002346# lpfc_topology: link topology for init link
2347# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002348# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002349# 0x02 = attempt point-to-point mode only
2350# 0x04 = attempt loop mode only
2351# 0x06 = attempt point-to-point mode then loop
2352# Set point-to-point mode if you want to run as an N_Port.
2353# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2354# Default value is 0.
2355*/
James Smarte59058c2008-08-24 21:49:00 -04002356
2357/**
James Smart3621a712009-04-06 18:47:14 -04002358 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002359 * @phba: lpfc_hba pointer.
2360 * @val: topology value.
2361 *
2362 * Description:
2363 * If val is in a valid range then set the adapter's topology field and
2364 * issue a lip; if the lip fails reset the topology to the old value.
2365 *
2366 * If the value is not in range log a kernel error message and return an error.
2367 *
2368 * Returns:
2369 * zero if val is in range and lip okay
2370 * non-zero return value from lpfc_issue_lip()
2371 * -EINVAL val out of range
2372 **/
James Smarta257bf92009-04-06 18:48:10 -04002373static ssize_t
2374lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2375 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002376{
James Smarta257bf92009-04-06 18:48:10 -04002377 struct Scsi_Host *shost = class_to_shost(dev);
2378 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2379 struct lpfc_hba *phba = vport->phba;
2380 int val = 0;
2381 int nolip = 0;
2382 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002383 int err;
2384 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002385
2386 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2387 nolip = 1;
2388 val_buf = &buf[strlen("nolip ")];
2389 }
2390
2391 if (!isdigit(val_buf[0]))
2392 return -EINVAL;
2393 if (sscanf(val_buf, "%i", &val) != 1)
2394 return -EINVAL;
2395
James Smart83108bd2008-01-11 01:53:09 -05002396 if (val >= 0 && val <= 6) {
2397 prev_val = phba->cfg_topology;
2398 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002399 if (nolip)
2400 return strlen(buf);
2401
James Smart83108bd2008-01-11 01:53:09 -05002402 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002403 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002404 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002405 return -EINVAL;
2406 } else
2407 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002408 }
2409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2410 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2411 "allowed range is [0, 6]\n",
2412 phba->brd_no, val);
2413 return -EINVAL;
2414}
2415static int lpfc_topology = 0;
2416module_param(lpfc_topology, int, 0);
2417MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2418lpfc_param_show(topology)
2419lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002420static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002421 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002422
James Smart21e9a0a2009-05-22 14:53:21 -04002423/**
2424 * lpfc_static_vport_show: Read callback function for
2425 * lpfc_static_vport sysfs file.
2426 * @dev: Pointer to class device object.
2427 * @attr: device attribute structure.
2428 * @buf: Data buffer.
2429 *
2430 * This function is the read call back function for
2431 * lpfc_static_vport sysfs file. The lpfc_static_vport
2432 * sysfs file report the mageability of the vport.
2433 **/
2434static ssize_t
2435lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2436 char *buf)
2437{
2438 struct Scsi_Host *shost = class_to_shost(dev);
2439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2440 if (vport->vport_flag & STATIC_VPORT)
2441 sprintf(buf, "1\n");
2442 else
2443 sprintf(buf, "0\n");
2444
2445 return strlen(buf);
2446}
2447
2448/*
2449 * Sysfs attribute to control the statistical data collection.
2450 */
2451static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2452 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002453
2454/**
James Smart3621a712009-04-06 18:47:14 -04002455 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002456 * @dev: Pointer to class device.
2457 * @buf: Data buffer.
2458 * @count: Size of the data buffer.
2459 *
2460 * This function get called when an user write to the lpfc_stat_data_ctrl
2461 * sysfs file. This function parse the command written to the sysfs file
2462 * and take appropriate action. These commands are used for controlling
2463 * driver statistical data collection.
2464 * Following are the command this function handles.
2465 *
2466 * setbucket <bucket_type> <base> <step>
2467 * = Set the latency buckets.
2468 * destroybucket = destroy all the buckets.
2469 * start = start data collection
2470 * stop = stop data collection
2471 * reset = reset the collected data
2472 **/
2473static ssize_t
2474lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2475 const char *buf, size_t count)
2476{
2477 struct Scsi_Host *shost = class_to_shost(dev);
2478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2479 struct lpfc_hba *phba = vport->phba;
2480#define LPFC_MAX_DATA_CTRL_LEN 1024
2481 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2482 unsigned long i;
2483 char *str_ptr, *token;
2484 struct lpfc_vport **vports;
2485 struct Scsi_Host *v_shost;
2486 char *bucket_type_str, *base_str, *step_str;
2487 unsigned long base, step, bucket_type;
2488
2489 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002490 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002491 return -EINVAL;
2492
2493 strcpy(bucket_data, buf);
2494 str_ptr = &bucket_data[0];
2495 /* Ignore this token - this is command token */
2496 token = strsep(&str_ptr, "\t ");
2497 if (!token)
2498 return -EINVAL;
2499
2500 bucket_type_str = strsep(&str_ptr, "\t ");
2501 if (!bucket_type_str)
2502 return -EINVAL;
2503
2504 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2505 bucket_type = LPFC_LINEAR_BUCKET;
2506 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2507 bucket_type = LPFC_POWER2_BUCKET;
2508 else
2509 return -EINVAL;
2510
2511 base_str = strsep(&str_ptr, "\t ");
2512 if (!base_str)
2513 return -EINVAL;
2514 base = simple_strtoul(base_str, NULL, 0);
2515
2516 step_str = strsep(&str_ptr, "\t ");
2517 if (!step_str)
2518 return -EINVAL;
2519 step = simple_strtoul(step_str, NULL, 0);
2520 if (!step)
2521 return -EINVAL;
2522
2523 /* Block the data collection for every vport */
2524 vports = lpfc_create_vport_work_array(phba);
2525 if (vports == NULL)
2526 return -ENOMEM;
2527
James Smartf4b4c682009-05-22 14:53:12 -04002528 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002529 v_shost = lpfc_shost_from_vport(vports[i]);
2530 spin_lock_irq(v_shost->host_lock);
2531 /* Block and reset data collection */
2532 vports[i]->stat_data_blocked = 1;
2533 if (vports[i]->stat_data_enabled)
2534 lpfc_vport_reset_stat_data(vports[i]);
2535 spin_unlock_irq(v_shost->host_lock);
2536 }
2537
2538 /* Set the bucket attributes */
2539 phba->bucket_type = bucket_type;
2540 phba->bucket_base = base;
2541 phba->bucket_step = step;
2542
James Smartf4b4c682009-05-22 14:53:12 -04002543 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002544 v_shost = lpfc_shost_from_vport(vports[i]);
2545
2546 /* Unblock data collection */
2547 spin_lock_irq(v_shost->host_lock);
2548 vports[i]->stat_data_blocked = 0;
2549 spin_unlock_irq(v_shost->host_lock);
2550 }
2551 lpfc_destroy_vport_work_array(phba, vports);
2552 return strlen(buf);
2553 }
2554
2555 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2556 vports = lpfc_create_vport_work_array(phba);
2557 if (vports == NULL)
2558 return -ENOMEM;
2559
James Smartf4b4c682009-05-22 14:53:12 -04002560 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002561 v_shost = lpfc_shost_from_vport(vports[i]);
2562 spin_lock_irq(shost->host_lock);
2563 vports[i]->stat_data_blocked = 1;
2564 lpfc_free_bucket(vport);
2565 vport->stat_data_enabled = 0;
2566 vports[i]->stat_data_blocked = 0;
2567 spin_unlock_irq(shost->host_lock);
2568 }
2569 lpfc_destroy_vport_work_array(phba, vports);
2570 phba->bucket_type = LPFC_NO_BUCKET;
2571 phba->bucket_base = 0;
2572 phba->bucket_step = 0;
2573 return strlen(buf);
2574 }
2575
2576 if (!strncmp(buf, "start", strlen("start"))) {
2577 /* If no buckets configured return error */
2578 if (phba->bucket_type == LPFC_NO_BUCKET)
2579 return -EINVAL;
2580 spin_lock_irq(shost->host_lock);
2581 if (vport->stat_data_enabled) {
2582 spin_unlock_irq(shost->host_lock);
2583 return strlen(buf);
2584 }
2585 lpfc_alloc_bucket(vport);
2586 vport->stat_data_enabled = 1;
2587 spin_unlock_irq(shost->host_lock);
2588 return strlen(buf);
2589 }
2590
2591 if (!strncmp(buf, "stop", strlen("stop"))) {
2592 spin_lock_irq(shost->host_lock);
2593 if (vport->stat_data_enabled == 0) {
2594 spin_unlock_irq(shost->host_lock);
2595 return strlen(buf);
2596 }
2597 lpfc_free_bucket(vport);
2598 vport->stat_data_enabled = 0;
2599 spin_unlock_irq(shost->host_lock);
2600 return strlen(buf);
2601 }
2602
2603 if (!strncmp(buf, "reset", strlen("reset"))) {
2604 if ((phba->bucket_type == LPFC_NO_BUCKET)
2605 || !vport->stat_data_enabled)
2606 return strlen(buf);
2607 spin_lock_irq(shost->host_lock);
2608 vport->stat_data_blocked = 1;
2609 lpfc_vport_reset_stat_data(vport);
2610 vport->stat_data_blocked = 0;
2611 spin_unlock_irq(shost->host_lock);
2612 return strlen(buf);
2613 }
2614 return -EINVAL;
2615}
2616
2617
2618/**
James Smart3621a712009-04-06 18:47:14 -04002619 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002620 * @dev: Pointer to class device object.
2621 * @buf: Data buffer.
2622 *
2623 * This function is the read call back function for
2624 * lpfc_stat_data_ctrl sysfs file. This function report the
2625 * current statistical data collection state.
2626 **/
2627static ssize_t
2628lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2629 char *buf)
2630{
2631 struct Scsi_Host *shost = class_to_shost(dev);
2632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2633 struct lpfc_hba *phba = vport->phba;
2634 int index = 0;
2635 int i;
2636 char *bucket_type;
2637 unsigned long bucket_value;
2638
2639 switch (phba->bucket_type) {
2640 case LPFC_LINEAR_BUCKET:
2641 bucket_type = "linear";
2642 break;
2643 case LPFC_POWER2_BUCKET:
2644 bucket_type = "power2";
2645 break;
2646 default:
2647 bucket_type = "No Bucket";
2648 break;
2649 }
2650
2651 sprintf(&buf[index], "Statistical Data enabled :%d, "
2652 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2653 " Bucket step :%d\nLatency Ranges :",
2654 vport->stat_data_enabled, vport->stat_data_blocked,
2655 bucket_type, phba->bucket_base, phba->bucket_step);
2656 index = strlen(buf);
2657 if (phba->bucket_type != LPFC_NO_BUCKET) {
2658 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2659 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2660 bucket_value = phba->bucket_base +
2661 phba->bucket_step * i;
2662 else
2663 bucket_value = phba->bucket_base +
2664 (1 << i) * phba->bucket_step;
2665
2666 if (index + 10 > PAGE_SIZE)
2667 break;
2668 sprintf(&buf[index], "%08ld ", bucket_value);
2669 index = strlen(buf);
2670 }
2671 }
2672 sprintf(&buf[index], "\n");
2673 return strlen(buf);
2674}
2675
2676/*
2677 * Sysfs attribute to control the statistical data collection.
2678 */
2679static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2680 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2681
2682/*
2683 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2684 */
2685
2686/*
2687 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2688 * for each target.
2689 */
2690#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2691#define MAX_STAT_DATA_SIZE_PER_TARGET \
2692 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2693
2694
2695/**
James Smart3621a712009-04-06 18:47:14 -04002696 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002697 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002698 * @kobj: Pointer to the kernel object
2699 * @bin_attr: Attribute object
2700 * @buff: Buffer pointer
2701 * @off: File offset
2702 * @count: Buffer size
2703 *
2704 * This function is the read call back function for lpfc_drvr_stat_data
2705 * sysfs file. This function export the statistical data to user
2706 * applications.
2707 **/
2708static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002709sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2710 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002711 char *buf, loff_t off, size_t count)
2712{
2713 struct device *dev = container_of(kobj, struct device,
2714 kobj);
2715 struct Scsi_Host *shost = class_to_shost(dev);
2716 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2717 struct lpfc_hba *phba = vport->phba;
2718 int i = 0, index = 0;
2719 unsigned long nport_index;
2720 struct lpfc_nodelist *ndlp = NULL;
2721 nport_index = (unsigned long)off /
2722 MAX_STAT_DATA_SIZE_PER_TARGET;
2723
2724 if (!vport->stat_data_enabled || vport->stat_data_blocked
2725 || (phba->bucket_type == LPFC_NO_BUCKET))
2726 return 0;
2727
2728 spin_lock_irq(shost->host_lock);
2729 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2730 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2731 continue;
2732
2733 if (nport_index > 0) {
2734 nport_index--;
2735 continue;
2736 }
2737
2738 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2739 > count)
2740 break;
2741
2742 if (!ndlp->lat_data)
2743 continue;
2744
2745 /* Print the WWN */
2746 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2747 ndlp->nlp_portname.u.wwn[0],
2748 ndlp->nlp_portname.u.wwn[1],
2749 ndlp->nlp_portname.u.wwn[2],
2750 ndlp->nlp_portname.u.wwn[3],
2751 ndlp->nlp_portname.u.wwn[4],
2752 ndlp->nlp_portname.u.wwn[5],
2753 ndlp->nlp_portname.u.wwn[6],
2754 ndlp->nlp_portname.u.wwn[7]);
2755
2756 index = strlen(buf);
2757
2758 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2759 sprintf(&buf[index], "%010u,",
2760 ndlp->lat_data[i].cmd_count);
2761 index = strlen(buf);
2762 }
2763 sprintf(&buf[index], "\n");
2764 index = strlen(buf);
2765 }
2766 spin_unlock_irq(shost->host_lock);
2767 return index;
2768}
2769
2770static struct bin_attribute sysfs_drvr_stat_data_attr = {
2771 .attr = {
2772 .name = "lpfc_drvr_stat_data",
2773 .mode = S_IRUSR,
2774 .owner = THIS_MODULE,
2775 },
2776 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2777 .read = sysfs_drvr_stat_data_read,
2778 .write = NULL,
2779};
2780
dea31012005-04-17 16:05:31 -05002781/*
2782# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2783# connection.
2784# 0 = auto select (default)
2785# 1 = 1 Gigabaud
2786# 2 = 2 Gigabaud
2787# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002788# 8 = 8 Gigabaud
2789# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002790*/
James Smarte59058c2008-08-24 21:49:00 -04002791
2792/**
James Smart3621a712009-04-06 18:47:14 -04002793 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002794 * @phba: lpfc_hba pointer.
2795 * @val: link speed value.
2796 *
2797 * Description:
2798 * If val is in a valid range then set the adapter's link speed field and
2799 * issue a lip; if the lip fails reset the link speed to the old value.
2800 *
2801 * Notes:
2802 * If the value is not in range log a kernel error message and return an error.
2803 *
2804 * Returns:
2805 * zero if val is in range and lip okay.
2806 * non-zero return value from lpfc_issue_lip()
2807 * -EINVAL val out of range
2808 **/
James Smarta257bf92009-04-06 18:48:10 -04002809static ssize_t
2810lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2811 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002812{
James Smarta257bf92009-04-06 18:48:10 -04002813 struct Scsi_Host *shost = class_to_shost(dev);
2814 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2815 struct lpfc_hba *phba = vport->phba;
2816 int val = 0;
2817 int nolip = 0;
2818 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002819 int err;
2820 uint32_t prev_val;
2821
James Smarta257bf92009-04-06 18:48:10 -04002822 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2823 nolip = 1;
2824 val_buf = &buf[strlen("nolip ")];
2825 }
2826
2827 if (!isdigit(val_buf[0]))
2828 return -EINVAL;
2829 if (sscanf(val_buf, "%i", &val) != 1)
2830 return -EINVAL;
2831
James Smart83108bd2008-01-11 01:53:09 -05002832 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2833 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2834 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2835 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2836 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2837 return -EINVAL;
2838
James Smarta257bf92009-04-06 18:48:10 -04002839 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002840 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2841 prev_val = phba->cfg_link_speed;
2842 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002843 if (nolip)
2844 return strlen(buf);
2845
James Smart83108bd2008-01-11 01:53:09 -05002846 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002847 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002848 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002849 return -EINVAL;
2850 } else
2851 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002852 }
2853
2854 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2855 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2856 "allowed range is [0, 8]\n",
2857 phba->brd_no, val);
2858 return -EINVAL;
2859}
2860
2861static int lpfc_link_speed = 0;
2862module_param(lpfc_link_speed, int, 0);
2863MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2864lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002865
2866/**
James Smart3621a712009-04-06 18:47:14 -04002867 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002868 * @phba: lpfc_hba pointer.
2869 * @val: link speed value.
2870 *
2871 * Description:
2872 * If val is in a valid range then set the adapter's link speed field.
2873 *
2874 * Notes:
2875 * If the value is not in range log a kernel error message, clear the link
2876 * speed and return an error.
2877 *
2878 * Returns:
2879 * zero if val saved.
2880 * -EINVAL val out of range
2881 **/
James Smart83108bd2008-01-11 01:53:09 -05002882static int
2883lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2884{
2885 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2886 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2887 phba->cfg_link_speed = val;
2888 return 0;
2889 }
2890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002891 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002892 "be set to %d, allowed values are "
2893 "["LPFC_LINK_SPEED_STRING"]\n", val);
2894 phba->cfg_link_speed = 0;
2895 return -EINVAL;
2896}
2897
Tony Jonesee959b02008-02-22 00:13:36 +01002898static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002899 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002900
2901/*
James Smart0d878412009-10-02 15:16:56 -04002902# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2903# 0 = aer disabled or not supported
2904# 1 = aer supported and enabled (default)
2905# Value range is [0,1]. Default value is 1.
2906*/
2907
2908/**
2909 * lpfc_aer_support_store - Set the adapter for aer support
2910 *
2911 * @dev: class device that is converted into a Scsi_host.
2912 * @attr: device attribute, not used.
2913 * @buf: containing the string "selective".
2914 * @count: unused variable.
2915 *
2916 * Description:
2917 * If the val is 1 and currently the device's AER capability was not
2918 * enabled, invoke the kernel's enable AER helper routine, trying to
2919 * enable the device's AER capability. If the helper routine enabling
2920 * AER returns success, update the device's cfg_aer_support flag to
2921 * indicate AER is supported by the device; otherwise, if the device
2922 * AER capability is already enabled to support AER, then do nothing.
2923 *
2924 * If the val is 0 and currently the device's AER support was enabled,
2925 * invoke the kernel's disable AER helper routine. After that, update
2926 * the device's cfg_aer_support flag to indicate AER is not supported
2927 * by the device; otherwise, if the device AER capability is already
2928 * disabled from supporting AER, then do nothing.
2929 *
2930 * Returns:
2931 * length of the buf on success if val is in range the intended mode
2932 * is supported.
2933 * -EINVAL if val out of range or intended mode is not supported.
2934 **/
2935static ssize_t
2936lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2937 const char *buf, size_t count)
2938{
2939 struct Scsi_Host *shost = class_to_shost(dev);
2940 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2941 struct lpfc_hba *phba = vport->phba;
2942 int val = 0, rc = -EINVAL;
2943
2944 if (!isdigit(buf[0]))
2945 return -EINVAL;
2946 if (sscanf(buf, "%i", &val) != 1)
2947 return -EINVAL;
2948
2949 switch (val) {
2950 case 0:
2951 if (phba->hba_flag & HBA_AER_ENABLED) {
2952 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2953 if (!rc) {
2954 spin_lock_irq(&phba->hbalock);
2955 phba->hba_flag &= ~HBA_AER_ENABLED;
2956 spin_unlock_irq(&phba->hbalock);
2957 phba->cfg_aer_support = 0;
2958 rc = strlen(buf);
2959 } else
James Smart891478a2009-11-18 15:40:23 -05002960 rc = -EPERM;
2961 } else {
James Smart0d878412009-10-02 15:16:56 -04002962 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05002963 rc = strlen(buf);
2964 }
James Smart0d878412009-10-02 15:16:56 -04002965 break;
2966 case 1:
2967 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2968 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2969 if (!rc) {
2970 spin_lock_irq(&phba->hbalock);
2971 phba->hba_flag |= HBA_AER_ENABLED;
2972 spin_unlock_irq(&phba->hbalock);
2973 phba->cfg_aer_support = 1;
2974 rc = strlen(buf);
2975 } else
James Smart891478a2009-11-18 15:40:23 -05002976 rc = -EPERM;
2977 } else {
James Smart0d878412009-10-02 15:16:56 -04002978 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05002979 rc = strlen(buf);
2980 }
James Smart0d878412009-10-02 15:16:56 -04002981 break;
2982 default:
2983 rc = -EINVAL;
2984 break;
2985 }
2986 return rc;
2987}
2988
2989static int lpfc_aer_support = 1;
2990module_param(lpfc_aer_support, int, 1);
2991MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2992lpfc_param_show(aer_support)
2993
2994/**
2995 * lpfc_aer_support_init - Set the initial adapters aer support flag
2996 * @phba: lpfc_hba pointer.
2997 * @val: link speed value.
2998 *
2999 * Description:
3000 * If val is in a valid range [0,1], then set the adapter's initial
3001 * cfg_aer_support field. It will be up to the driver's probe_one
3002 * routine to determine whether the device's AER support can be set
3003 * or not.
3004 *
3005 * Notes:
3006 * If the value is not in range log a kernel error message, and
3007 * choose the default value of setting AER support and return.
3008 *
3009 * Returns:
3010 * zero if val saved.
3011 * -EINVAL val out of range
3012 **/
3013static int
3014lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3015{
3016 if (val == 0 || val == 1) {
3017 phba->cfg_aer_support = val;
3018 return 0;
3019 }
3020 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3021 "2712 lpfc_aer_support attribute value %d out "
3022 "of range, allowed values are 0|1, setting it "
3023 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003024 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003025 phba->cfg_aer_support = 1;
3026 return -EINVAL;
3027}
3028
3029static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3030 lpfc_aer_support_show, lpfc_aer_support_store);
3031
3032/**
3033 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3034 * @dev: class device that is converted into a Scsi_host.
3035 * @attr: device attribute, not used.
3036 * @buf: containing the string "selective".
3037 * @count: unused variable.
3038 *
3039 * Description:
3040 * If the @buf contains 1 and the device currently has the AER support
3041 * enabled, then invokes the kernel AER helper routine
3042 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3043 * error status register.
3044 *
3045 * Notes:
3046 *
3047 * Returns:
3048 * -EINVAL if the buf does not contain the 1 or the device is not currently
3049 * enabled with the AER support.
3050 **/
3051static ssize_t
3052lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3053 const char *buf, size_t count)
3054{
3055 struct Scsi_Host *shost = class_to_shost(dev);
3056 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3057 struct lpfc_hba *phba = vport->phba;
3058 int val, rc = -1;
3059
3060 if (!isdigit(buf[0]))
3061 return -EINVAL;
3062 if (sscanf(buf, "%i", &val) != 1)
3063 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003064 if (val != 1)
3065 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003066
James Smart891478a2009-11-18 15:40:23 -05003067 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003068 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3069
3070 if (rc == 0)
3071 return strlen(buf);
3072 else
James Smart891478a2009-11-18 15:40:23 -05003073 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003074}
3075
3076static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3077 lpfc_aer_cleanup_state);
3078
3079/*
dea31012005-04-17 16:05:31 -05003080# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3081# Value range is [2,3]. Default value is 3.
3082*/
James Smart3de2a652007-08-02 11:09:59 -04003083LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3084 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003085
3086/*
3087# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3088# is [0,1]. Default value is 0.
3089*/
James Smart3de2a652007-08-02 11:09:59 -04003090LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3091 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003092
3093/*
James Smart977b5a02008-09-07 11:52:04 -04003094# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3095# depth. Default value is 0. When the value of this parameter is zero the
3096# SCSI command completion time is not used for controlling I/O queue depth. When
3097# the parameter is set to a non-zero value, the I/O queue depth is controlled
3098# to limit the I/O completion time to the parameter value.
3099# The value is set in milliseconds.
3100*/
3101static int lpfc_max_scsicmpl_time;
3102module_param(lpfc_max_scsicmpl_time, int, 0);
3103MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3104 "Use command completion time to control queue depth");
3105lpfc_vport_param_show(max_scsicmpl_time);
3106lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3107static int
3108lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3109{
3110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3111 struct lpfc_nodelist *ndlp, *next_ndlp;
3112
3113 if (val == vport->cfg_max_scsicmpl_time)
3114 return 0;
3115 if ((val < 0) || (val > 60000))
3116 return -EINVAL;
3117 vport->cfg_max_scsicmpl_time = val;
3118
3119 spin_lock_irq(shost->host_lock);
3120 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3121 if (!NLP_CHK_NODE_ACT(ndlp))
3122 continue;
3123 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3124 continue;
3125 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
3126 }
3127 spin_unlock_irq(shost->host_lock);
3128 return 0;
3129}
3130lpfc_vport_param_store(max_scsicmpl_time);
3131static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3132 lpfc_max_scsicmpl_time_show,
3133 lpfc_max_scsicmpl_time_store);
3134
3135/*
dea31012005-04-17 16:05:31 -05003136# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3137# range is [0,1]. Default value is 0.
3138*/
3139LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3140
3141/*
3142# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3143# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003144# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003145# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3146# cr_delay is set to 0.
3147*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003148LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003149 "interrupt response is generated");
3150
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003151LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003152 "interrupt response is generated");
3153
3154/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003155# lpfc_multi_ring_support: Determines how many rings to spread available
3156# cmd/rsp IOCB entries across.
3157# Value range is [1,2]. Default value is 1.
3158*/
3159LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3160 "SLI rings to spread IOCB entries across");
3161
3162/*
James Smarta4bc3372006-12-02 13:34:16 -05003163# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3164# identifies what rctl value to configure the additional ring for.
3165# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3166*/
James Smart6a9c52c2009-10-02 15:16:51 -04003167LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003168 255, "Identifies RCTL for additional ring configuration");
3169
3170/*
3171# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3172# identifies what type value to configure the additional ring for.
3173# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3174*/
James Smart6a9c52c2009-10-02 15:16:51 -04003175LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003176 255, "Identifies TYPE for additional ring configuration");
3177
3178/*
dea31012005-04-17 16:05:31 -05003179# lpfc_fdmi_on: controls FDMI support.
3180# 0 = no FDMI support
3181# 1 = support FDMI without attribute of hostname
3182# 2 = support FDMI with attribute of hostname
3183# Value range [0,2]. Default value is 0.
3184*/
James Smart3de2a652007-08-02 11:09:59 -04003185LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003186
3187/*
3188# Specifies the maximum number of ELS cmds we can have outstanding (for
3189# discovery). Value range is [1,64]. Default value = 32.
3190*/
James Smart3de2a652007-08-02 11:09:59 -04003191LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003192 "during discovery");
3193
3194/*
James Smart65a29c12006-07-06 15:50:50 -04003195# lpfc_max_luns: maximum allowed LUN.
3196# Value range is [0,65535]. Default value is 255.
3197# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003198*/
James Smart3de2a652007-08-02 11:09:59 -04003199LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003200
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003201/*
3202# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3203# Value range is [1,255], default value is 10.
3204*/
3205LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3206 "Milliseconds driver will wait between polling FCP ring");
3207
James Smart4ff43242006-12-02 13:34:56 -05003208/*
3209# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3210# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003211# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003212# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003213# 2 = MSI-X enabled (default)
3214# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003215*/
George Kadianakis8605c462010-01-17 21:19:31 +02003216LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003217 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003218
James Smart13815c82008-01-11 01:52:48 -05003219/*
James Smartda0436e2009-05-22 14:51:39 -04003220# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3221#
3222# Value range is [636,651042]. Default value is 10000.
3223*/
3224LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3225 "Set the maximum number of fast-path FCP interrupts per second");
3226
3227/*
3228# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3229#
3230# Value range is [1,31]. Default value is 4.
3231*/
3232LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3233 "Set the number of fast-path FCP work queues, if possible");
3234
3235/*
3236# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3237#
3238# Value range is [1,7]. Default value is 1.
3239*/
3240LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3241 "Set the number of fast-path FCP event queues, if possible");
3242
3243/*
James Smart13815c82008-01-11 01:52:48 -05003244# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3245# 0 = HBA resets disabled
3246# 1 = HBA resets enabled (default)
3247# Value range is [0,1]. Default value is 1.
3248*/
3249LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003250
James Smart13815c82008-01-11 01:52:48 -05003251/*
3252# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3253# 0 = HBA Heartbeat disabled
3254# 1 = HBA Heartbeat enabled (default)
3255# Value range is [0,1]. Default value is 1.
3256*/
3257LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003258
James Smart83108bd2008-01-11 01:53:09 -05003259/*
James Smart81301a92008-12-04 22:39:46 -05003260# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3261# 0 = BlockGuard disabled (default)
3262# 1 = BlockGuard enabled
3263# Value range is [0,1]. Default value is 0.
3264*/
3265LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3266
James Smart6fb120a2009-05-22 14:52:59 -04003267/*
James Smart81301a92008-12-04 22:39:46 -05003268# lpfc_prot_mask: i
3269# - Bit mask of host protection capabilities used to register with the
3270# SCSI mid-layer
3271# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3272# - Allows you to ultimately specify which profiles to use
3273# - Default will result in registering capabilities for all profiles.
3274#
3275*/
3276unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3277
3278module_param(lpfc_prot_mask, uint, 0);
3279MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3280
3281/*
3282# lpfc_prot_guard: i
3283# - Bit mask of protection guard types to register with the SCSI mid-layer
3284# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3285# - Allows you to ultimately specify which profiles to use
3286# - Default will result in registering capabilities for all guard types
3287#
3288*/
3289unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3290module_param(lpfc_prot_guard, byte, 0);
3291MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3292
3293
3294/*
James Smart3621a712009-04-06 18:47:14 -04003295 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003296 * This value can be set to values between 64 and 256. The default value is
3297 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3298 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3299 */
3300LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3301 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3302
James Smart81301a92008-12-04 22:39:46 -05003303LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3304 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3305 "Max Protection Scatter Gather Segment Count");
3306
Tony Jonesee959b02008-02-22 00:13:36 +01003307struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003308 &dev_attr_bg_info,
3309 &dev_attr_bg_guard_err,
3310 &dev_attr_bg_apptag_err,
3311 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003312 &dev_attr_info,
3313 &dev_attr_serialnum,
3314 &dev_attr_modeldesc,
3315 &dev_attr_modelname,
3316 &dev_attr_programtype,
3317 &dev_attr_portnum,
3318 &dev_attr_fwrev,
3319 &dev_attr_hdw,
3320 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003321 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003322 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003323 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003324 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003325 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003326 &dev_attr_lpfc_temp_sensor,
3327 &dev_attr_lpfc_log_verbose,
3328 &dev_attr_lpfc_lun_queue_depth,
3329 &dev_attr_lpfc_hba_queue_depth,
3330 &dev_attr_lpfc_peer_port_login,
3331 &dev_attr_lpfc_nodev_tmo,
3332 &dev_attr_lpfc_devloss_tmo,
3333 &dev_attr_lpfc_fcp_class,
3334 &dev_attr_lpfc_use_adisc,
3335 &dev_attr_lpfc_ack0,
3336 &dev_attr_lpfc_topology,
3337 &dev_attr_lpfc_scan_down,
3338 &dev_attr_lpfc_link_speed,
3339 &dev_attr_lpfc_cr_delay,
3340 &dev_attr_lpfc_cr_count,
3341 &dev_attr_lpfc_multi_ring_support,
3342 &dev_attr_lpfc_multi_ring_rctl,
3343 &dev_attr_lpfc_multi_ring_type,
3344 &dev_attr_lpfc_fdmi_on,
3345 &dev_attr_lpfc_max_luns,
3346 &dev_attr_lpfc_enable_npiv,
3347 &dev_attr_nport_evt_cnt,
3348 &dev_attr_board_mode,
3349 &dev_attr_max_vpi,
3350 &dev_attr_used_vpi,
3351 &dev_attr_max_rpi,
3352 &dev_attr_used_rpi,
3353 &dev_attr_max_xri,
3354 &dev_attr_used_xri,
3355 &dev_attr_npiv_info,
3356 &dev_attr_issue_reset,
3357 &dev_attr_lpfc_poll,
3358 &dev_attr_lpfc_poll_tmo,
3359 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003360 &dev_attr_lpfc_fcp_imax,
3361 &dev_attr_lpfc_fcp_wq_count,
3362 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003363 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003364 &dev_attr_lpfc_soft_wwnn,
3365 &dev_attr_lpfc_soft_wwpn,
3366 &dev_attr_lpfc_soft_wwn_enable,
3367 &dev_attr_lpfc_enable_hba_reset,
3368 &dev_attr_lpfc_enable_hba_heartbeat,
3369 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003370 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003371 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003372 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003373 &dev_attr_lpfc_aer_support,
3374 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003375 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003376 &dev_attr_lpfc_iocb_cnt,
3377 &dev_attr_iocb_hw,
3378 &dev_attr_txq_hw,
3379 &dev_attr_txcmplq_hw,
dea31012005-04-17 16:05:31 -05003380 NULL,
3381};
3382
Tony Jonesee959b02008-02-22 00:13:36 +01003383struct device_attribute *lpfc_vport_attrs[] = {
3384 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003385 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003386 &dev_attr_num_discovered_ports,
3387 &dev_attr_lpfc_drvr_version,
3388 &dev_attr_lpfc_log_verbose,
3389 &dev_attr_lpfc_lun_queue_depth,
3390 &dev_attr_lpfc_nodev_tmo,
3391 &dev_attr_lpfc_devloss_tmo,
3392 &dev_attr_lpfc_hba_queue_depth,
3393 &dev_attr_lpfc_peer_port_login,
3394 &dev_attr_lpfc_restrict_login,
3395 &dev_attr_lpfc_fcp_class,
3396 &dev_attr_lpfc_use_adisc,
3397 &dev_attr_lpfc_fdmi_on,
3398 &dev_attr_lpfc_max_luns,
3399 &dev_attr_nport_evt_cnt,
3400 &dev_attr_npiv_info,
3401 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003402 &dev_attr_lpfc_max_scsicmpl_time,
3403 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003404 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003405 NULL,
3406};
3407
James Smarte59058c2008-08-24 21:49:00 -04003408/**
James Smart3621a712009-04-06 18:47:14 -04003409 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003410 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003411 * @kobj: kernel kobject that contains the kernel class device.
3412 * @bin_attr: kernel attributes passed to us.
3413 * @buf: contains the data to be written to the adapter IOREG space.
3414 * @off: offset into buffer to beginning of data.
3415 * @count: bytes to transfer.
3416 *
3417 * Description:
3418 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3419 * Uses the adapter io control registers to send buf contents to the adapter.
3420 *
3421 * Returns:
3422 * -ERANGE off and count combo out of range
3423 * -EINVAL off, count or buff address invalid
3424 * -EPERM adapter is offline
3425 * value of count, buf contents written
3426 **/
dea31012005-04-17 16:05:31 -05003427static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003428sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3429 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003430 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003431{
3432 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003433 struct device *dev = container_of(kobj, struct device, kobj);
3434 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003435 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3436 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003437
James Smartf1126682009-06-10 17:22:44 -04003438 if (phba->sli_rev >= LPFC_SLI_REV4)
3439 return -EPERM;
3440
dea31012005-04-17 16:05:31 -05003441 if ((off + count) > FF_REG_AREA_SIZE)
3442 return -ERANGE;
3443
3444 if (count == 0) return 0;
3445
3446 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3447 return -EINVAL;
3448
James Smart2e0fef82007-06-17 19:56:36 -05003449 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003450 return -EPERM;
3451 }
3452
James Smart2e0fef82007-06-17 19:56:36 -05003453 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003454 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3455 writel(*((uint32_t *)(buf + buf_off)),
3456 phba->ctrl_regs_memmap_p + off + buf_off);
3457
James Smart2e0fef82007-06-17 19:56:36 -05003458 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003459
3460 return count;
3461}
3462
James Smarte59058c2008-08-24 21:49:00 -04003463/**
James Smart3621a712009-04-06 18:47:14 -04003464 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003465 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003466 * @kobj: kernel kobject that contains the kernel class device.
3467 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003468 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003469 * @off: offset into buffer to beginning of data.
3470 * @count: bytes to transfer.
3471 *
3472 * Description:
3473 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3474 * Uses the adapter io control registers to read data into buf.
3475 *
3476 * Returns:
3477 * -ERANGE off and count combo out of range
3478 * -EINVAL off, count or buff address invalid
3479 * value of count, buf contents read
3480 **/
dea31012005-04-17 16:05:31 -05003481static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003482sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3483 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003484 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003485{
3486 size_t buf_off;
3487 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003488 struct device *dev = container_of(kobj, struct device, kobj);
3489 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003490 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3491 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003492
James Smartf1126682009-06-10 17:22:44 -04003493 if (phba->sli_rev >= LPFC_SLI_REV4)
3494 return -EPERM;
3495
dea31012005-04-17 16:05:31 -05003496 if (off > FF_REG_AREA_SIZE)
3497 return -ERANGE;
3498
3499 if ((off + count) > FF_REG_AREA_SIZE)
3500 count = FF_REG_AREA_SIZE - off;
3501
3502 if (count == 0) return 0;
3503
3504 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3505 return -EINVAL;
3506
James Smart2e0fef82007-06-17 19:56:36 -05003507 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003508
3509 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3510 tmp_ptr = (uint32_t *)(buf + buf_off);
3511 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3512 }
3513
James Smart2e0fef82007-06-17 19:56:36 -05003514 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003515
3516 return count;
3517}
3518
3519static struct bin_attribute sysfs_ctlreg_attr = {
3520 .attr = {
3521 .name = "ctlreg",
3522 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003523 },
3524 .size = 256,
3525 .read = sysfs_ctlreg_read,
3526 .write = sysfs_ctlreg_write,
3527};
3528
James Smarte59058c2008-08-24 21:49:00 -04003529/**
James Smart3621a712009-04-06 18:47:14 -04003530 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003531 * @phba: lpfc_hba pointer
3532 **/
dea31012005-04-17 16:05:31 -05003533static void
James Smart2e0fef82007-06-17 19:56:36 -05003534sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003535{
3536 phba->sysfs_mbox.state = SMBOX_IDLE;
3537 phba->sysfs_mbox.offset = 0;
3538
3539 if (phba->sysfs_mbox.mbox) {
3540 mempool_free(phba->sysfs_mbox.mbox,
3541 phba->mbox_mem_pool);
3542 phba->sysfs_mbox.mbox = NULL;
3543 }
3544}
3545
James Smarte59058c2008-08-24 21:49:00 -04003546/**
James Smart3621a712009-04-06 18:47:14 -04003547 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003548 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003549 * @kobj: kernel kobject that contains the kernel class device.
3550 * @bin_attr: kernel attributes passed to us.
3551 * @buf: contains the data to be written to sysfs mbox.
3552 * @off: offset into buffer to beginning of data.
3553 * @count: bytes to transfer.
3554 *
3555 * Description:
3556 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3557 * Uses the sysfs mbox to send buf contents to the adapter.
3558 *
3559 * Returns:
3560 * -ERANGE off and count combo out of range
3561 * -EINVAL off, count or buff address invalid
3562 * zero if count is zero
3563 * -EPERM adapter is offline
3564 * -ENOMEM failed to allocate memory for the mail box
3565 * -EAGAIN offset, state or mbox is NULL
3566 * count number of bytes transferred
3567 **/
dea31012005-04-17 16:05:31 -05003568static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003569sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3570 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003571 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003572{
Tony Jonesee959b02008-02-22 00:13:36 +01003573 struct device *dev = container_of(kobj, struct device, kobj);
3574 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003575 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3576 struct lpfc_hba *phba = vport->phba;
3577 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003578
3579 if ((count + off) > MAILBOX_CMD_SIZE)
3580 return -ERANGE;
3581
3582 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3583 return -EINVAL;
3584
3585 if (count == 0)
3586 return 0;
3587
3588 if (off == 0) {
3589 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3590 if (!mbox)
3591 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003592 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003593 }
3594
James Smart2e0fef82007-06-17 19:56:36 -05003595 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003596
3597 if (off == 0) {
3598 if (phba->sysfs_mbox.mbox)
3599 mempool_free(mbox, phba->mbox_mem_pool);
3600 else
3601 phba->sysfs_mbox.mbox = mbox;
3602 phba->sysfs_mbox.state = SMBOX_WRITING;
3603 } else {
3604 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3605 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003606 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003607 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003608 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003609 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003610 }
3611 }
3612
James Smart04c68492009-05-22 14:52:52 -04003613 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003614 buf, count);
3615
3616 phba->sysfs_mbox.offset = off + count;
3617
James Smart2e0fef82007-06-17 19:56:36 -05003618 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003619
3620 return count;
3621}
3622
James Smarte59058c2008-08-24 21:49:00 -04003623/**
James Smart3621a712009-04-06 18:47:14 -04003624 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003625 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003626 * @kobj: kernel kobject that contains the kernel class device.
3627 * @bin_attr: kernel attributes passed to us.
3628 * @buf: contains the data to be read from sysfs mbox.
3629 * @off: offset into buffer to beginning of data.
3630 * @count: bytes to transfer.
3631 *
3632 * Description:
3633 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3634 * Uses the sysfs mbox to receive data from to the adapter.
3635 *
3636 * Returns:
3637 * -ERANGE off greater than mailbox command size
3638 * -EINVAL off, count or buff address invalid
3639 * zero if off and count are zero
3640 * -EACCES adapter over temp
3641 * -EPERM garbage can value to catch a multitude of errors
3642 * -EAGAIN management IO not permitted, state or off error
3643 * -ETIME mailbox timeout
3644 * -ENODEV mailbox error
3645 * count number of bytes transferred
3646 **/
dea31012005-04-17 16:05:31 -05003647static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003648sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3649 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003650 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003651{
Tony Jonesee959b02008-02-22 00:13:36 +01003652 struct device *dev = container_of(kobj, struct device, kobj);
3653 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003654 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3655 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003656 int rc;
James Smart04c68492009-05-22 14:52:52 -04003657 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003658
James Smart1dcb58e2007-04-25 09:51:30 -04003659 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003660 return -ERANGE;
3661
James Smart1dcb58e2007-04-25 09:51:30 -04003662 if ((count + off) > MAILBOX_CMD_SIZE)
3663 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003664
3665 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3666 return -EINVAL;
3667
3668 if (off && count == 0)
3669 return 0;
3670
James Smart2e0fef82007-06-17 19:56:36 -05003671 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003672
James Smart7af67052007-10-27 13:38:11 -04003673 if (phba->over_temp_state == HBA_OVER_TEMP) {
3674 sysfs_mbox_idle(phba);
3675 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003676 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003677 }
3678
dea31012005-04-17 16:05:31 -05003679 if (off == 0 &&
3680 phba->sysfs_mbox.state == SMBOX_WRITING &&
3681 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003682 pmb = &phba->sysfs_mbox.mbox->u.mb;
3683 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003684 /* Offline only */
dea31012005-04-17 16:05:31 -05003685 case MBX_INIT_LINK:
3686 case MBX_DOWN_LINK:
3687 case MBX_CONFIG_LINK:
3688 case MBX_CONFIG_RING:
3689 case MBX_RESET_RING:
3690 case MBX_UNREG_LOGIN:
3691 case MBX_CLEAR_LA:
3692 case MBX_DUMP_CONTEXT:
3693 case MBX_RUN_DIAGS:
3694 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003695 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003696 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003697 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003698 printk(KERN_WARNING "mbox_read:Command 0x%x "
3699 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003700 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003701 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003702 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003703 return -EPERM;
3704 }
James Smarta8adb832007-10-27 13:37:53 -04003705 case MBX_WRITE_NV:
3706 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003707 case MBX_LOAD_SM:
3708 case MBX_READ_NV:
3709 case MBX_READ_CONFIG:
3710 case MBX_READ_RCONFIG:
3711 case MBX_READ_STATUS:
3712 case MBX_READ_XRI:
3713 case MBX_READ_REV:
3714 case MBX_READ_LNK_STAT:
3715 case MBX_DUMP_MEMORY:
3716 case MBX_DOWN_LOAD:
3717 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003718 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003719 case MBX_LOAD_AREA:
3720 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003721 case MBX_BEACON:
3722 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003723 case MBX_SET_VARIABLE:
3724 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003725 case MBX_PORT_CAPABILITIES:
3726 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003727 break;
3728 case MBX_READ_SPARM64:
3729 case MBX_READ_LA:
3730 case MBX_READ_LA64:
3731 case MBX_REG_LOGIN:
3732 case MBX_REG_LOGIN64:
3733 case MBX_CONFIG_PORT:
3734 case MBX_RUN_BIU_DIAG:
3735 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003736 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003737 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003738 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003739 return -EPERM;
3740 default:
3741 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003742 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003743 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003744 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003745 return -EPERM;
3746 }
3747
James Smart09372822008-01-11 01:52:54 -05003748 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003749 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003750 */
James Smartd7c255b2008-08-24 21:50:00 -04003751 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003752 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3753 pmb->mbxCommand != MBX_RESTART &&
3754 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3755 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003756 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3757 "1259 mbox: Issued mailbox cmd "
3758 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003759 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003760
James Smart92d7f7b2007-06-17 19:56:38 -05003761 phba->sysfs_mbox.mbox->vport = vport;
3762
James Smart58da1ff2008-04-07 10:15:56 -04003763 /* Don't allow mailbox commands to be sent when blocked
3764 * or when in the middle of discovery
3765 */
James Smart495a7142008-06-14 22:52:59 -04003766 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003767 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003768 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003769 return -EAGAIN;
3770 }
3771
James Smart2e0fef82007-06-17 19:56:36 -05003772 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003773 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003774
James Smart2e0fef82007-06-17 19:56:36 -05003775 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003776 rc = lpfc_sli_issue_mbox (phba,
3777 phba->sysfs_mbox.mbox,
3778 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003779 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003780
3781 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003782 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003783 rc = lpfc_sli_issue_mbox_wait (phba,
3784 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003785 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003786 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003787 }
3788
3789 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003790 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003791 phba->sysfs_mbox.mbox = NULL;
3792 }
dea31012005-04-17 16:05:31 -05003793 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003794 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003795 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003796 }
3797 phba->sysfs_mbox.state = SMBOX_READING;
3798 }
3799 else if (phba->sysfs_mbox.offset != off ||
3800 phba->sysfs_mbox.state != SMBOX_READING) {
3801 printk(KERN_WARNING "mbox_read: Bad State\n");
3802 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003803 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003804 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003805 }
3806
James Smart04c68492009-05-22 14:52:52 -04003807 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003808
3809 phba->sysfs_mbox.offset = off + count;
3810
James Smart1dcb58e2007-04-25 09:51:30 -04003811 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003812 sysfs_mbox_idle(phba);
3813
James Smart2e0fef82007-06-17 19:56:36 -05003814 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003815
3816 return count;
3817}
3818
3819static struct bin_attribute sysfs_mbox_attr = {
3820 .attr = {
3821 .name = "mbox",
3822 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003823 },
James Smart1dcb58e2007-04-25 09:51:30 -04003824 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003825 .read = sysfs_mbox_read,
3826 .write = sysfs_mbox_write,
3827};
3828
James Smarte59058c2008-08-24 21:49:00 -04003829/**
James Smart3621a712009-04-06 18:47:14 -04003830 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003831 * @vport: address of lpfc vport structure.
3832 *
3833 * Return codes:
3834 * zero on success
3835 * error return code from sysfs_create_bin_file()
3836 **/
dea31012005-04-17 16:05:31 -05003837int
James Smart2e0fef82007-06-17 19:56:36 -05003838lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003839{
James Smart2e0fef82007-06-17 19:56:36 -05003840 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003841 int error;
3842
Tony Jonesee959b02008-02-22 00:13:36 +01003843 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003844 &sysfs_drvr_stat_data_attr);
3845
3846 /* Virtual ports do not need ctrl_reg and mbox */
3847 if (error || vport->port_type == LPFC_NPIV_PORT)
3848 goto out;
3849
3850 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003851 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003852 if (error)
James Smarteada2722008-12-04 22:39:13 -05003853 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003854
Tony Jonesee959b02008-02-22 00:13:36 +01003855 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003856 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003857 if (error)
3858 goto out_remove_ctlreg_attr;
3859
3860 return 0;
3861out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003862 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003863out_remove_stat_attr:
3864 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3865 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003866out:
3867 return error;
3868}
3869
James Smarte59058c2008-08-24 21:49:00 -04003870/**
James Smart3621a712009-04-06 18:47:14 -04003871 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003872 * @vport: address of lpfc vport structure.
3873 **/
dea31012005-04-17 16:05:31 -05003874void
James Smart2e0fef82007-06-17 19:56:36 -05003875lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003876{
James Smart2e0fef82007-06-17 19:56:36 -05003877 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003878 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3879 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003880 /* Virtual ports do not need ctrl_reg and mbox */
3881 if (vport->port_type == LPFC_NPIV_PORT)
3882 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003883 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3884 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003885}
3886
3887
3888/*
3889 * Dynamic FC Host Attributes Support
3890 */
3891
James Smarte59058c2008-08-24 21:49:00 -04003892/**
James Smart3621a712009-04-06 18:47:14 -04003893 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003894 * @shost: kernel scsi host pointer.
3895 **/
dea31012005-04-17 16:05:31 -05003896static void
3897lpfc_get_host_port_id(struct Scsi_Host *shost)
3898{
James Smart2e0fef82007-06-17 19:56:36 -05003899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3900
dea31012005-04-17 16:05:31 -05003901 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003902 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003903}
3904
James Smarte59058c2008-08-24 21:49:00 -04003905/**
James Smart3621a712009-04-06 18:47:14 -04003906 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003907 * @shost: kernel scsi host pointer.
3908 **/
dea31012005-04-17 16:05:31 -05003909static void
3910lpfc_get_host_port_type(struct Scsi_Host *shost)
3911{
James Smart2e0fef82007-06-17 19:56:36 -05003912 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3913 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003914
3915 spin_lock_irq(shost->host_lock);
3916
James Smart92d7f7b2007-06-17 19:56:38 -05003917 if (vport->port_type == LPFC_NPIV_PORT) {
3918 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3919 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003920 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003921 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003922 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3923 else
3924 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3925 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003926 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003927 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3928 else
3929 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3930 }
3931 } else
3932 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3933
3934 spin_unlock_irq(shost->host_lock);
3935}
3936
James Smarte59058c2008-08-24 21:49:00 -04003937/**
James Smart3621a712009-04-06 18:47:14 -04003938 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003939 * @shost: kernel scsi host pointer.
3940 **/
dea31012005-04-17 16:05:31 -05003941static void
3942lpfc_get_host_port_state(struct Scsi_Host *shost)
3943{
James Smart2e0fef82007-06-17 19:56:36 -05003944 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3945 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003946
3947 spin_lock_irq(shost->host_lock);
3948
James Smart2e0fef82007-06-17 19:56:36 -05003949 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003950 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3951 else {
James Smart2e0fef82007-06-17 19:56:36 -05003952 switch (phba->link_state) {
3953 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003954 case LPFC_LINK_DOWN:
3955 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3956 break;
3957 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003958 case LPFC_CLEAR_LA:
3959 case LPFC_HBA_READY:
3960 /* Links up, beyond this port_type reports state */
3961 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3962 break;
3963 case LPFC_HBA_ERROR:
3964 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3965 break;
3966 default:
3967 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3968 break;
3969 }
3970 }
3971
3972 spin_unlock_irq(shost->host_lock);
3973}
3974
James Smarte59058c2008-08-24 21:49:00 -04003975/**
James Smart3621a712009-04-06 18:47:14 -04003976 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003977 * @shost: kernel scsi host pointer.
3978 **/
dea31012005-04-17 16:05:31 -05003979static void
3980lpfc_get_host_speed(struct Scsi_Host *shost)
3981{
James Smart2e0fef82007-06-17 19:56:36 -05003982 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3983 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003984
3985 spin_lock_irq(shost->host_lock);
3986
James Smart2e0fef82007-06-17 19:56:36 -05003987 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003988 switch(phba->fc_linkspeed) {
3989 case LA_1GHZ_LINK:
3990 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3991 break;
3992 case LA_2GHZ_LINK:
3993 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3994 break;
3995 case LA_4GHZ_LINK:
3996 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3997 break;
James Smartb87eab32007-04-25 09:53:28 -04003998 case LA_8GHZ_LINK:
3999 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4000 break;
James Smartf4b4c682009-05-22 14:53:12 -04004001 case LA_10GHZ_LINK:
4002 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4003 break;
dea31012005-04-17 16:05:31 -05004004 default:
4005 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4006 break;
4007 }
James Smart09372822008-01-11 01:52:54 -05004008 } else
4009 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004010
4011 spin_unlock_irq(shost->host_lock);
4012}
4013
James Smarte59058c2008-08-24 21:49:00 -04004014/**
James Smart3621a712009-04-06 18:47:14 -04004015 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004016 * @shost: kernel scsi host pointer.
4017 **/
dea31012005-04-17 16:05:31 -05004018static void
4019lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4020{
James Smart2e0fef82007-06-17 19:56:36 -05004021 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4022 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004023 u64 node_name;
dea31012005-04-17 16:05:31 -05004024
4025 spin_lock_irq(shost->host_lock);
4026
James Smart2e0fef82007-06-17 19:56:36 -05004027 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05004028 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004029 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004030 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004031 else
4032 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004033 node_name = 0;
dea31012005-04-17 16:05:31 -05004034
4035 spin_unlock_irq(shost->host_lock);
4036
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004037 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004038}
4039
James Smarte59058c2008-08-24 21:49:00 -04004040/**
James Smart3621a712009-04-06 18:47:14 -04004041 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004042 * @shost: kernel scsi host pointer.
4043 *
4044 * Notes:
4045 * NULL on error for link down, no mbox pool, sli2 active,
4046 * management not allowed, memory allocation error, or mbox error.
4047 *
4048 * Returns:
4049 * NULL for error
4050 * address of the adapter host statistics
4051 **/
dea31012005-04-17 16:05:31 -05004052static struct fc_host_statistics *
4053lpfc_get_stats(struct Scsi_Host *shost)
4054{
James Smart2e0fef82007-06-17 19:56:36 -05004055 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4056 struct lpfc_hba *phba = vport->phba;
4057 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004058 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004059 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004060 LPFC_MBOXQ_t *pmboxq;
4061 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004062 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004063 int rc = 0;
dea31012005-04-17 16:05:31 -05004064
James Smart92d7f7b2007-06-17 19:56:38 -05004065 /*
4066 * prevent udev from issuing mailbox commands until the port is
4067 * configured.
4068 */
James Smart2e0fef82007-06-17 19:56:36 -05004069 if (phba->link_state < LPFC_LINK_DOWN ||
4070 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004071 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004072 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004073
4074 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004075 return NULL;
4076
dea31012005-04-17 16:05:31 -05004077 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4078 if (!pmboxq)
4079 return NULL;
4080 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4081
James Smart04c68492009-05-22 14:52:52 -04004082 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004083 pmb->mbxCommand = MBX_READ_STATUS;
4084 pmb->mbxOwner = OWN_HOST;
4085 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004086 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004087
James Smart75baf692010-06-08 18:31:21 -04004088 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004089 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004090 else
dea31012005-04-17 16:05:31 -05004091 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4092
4093 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004094 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004095 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004096 return NULL;
4097 }
4098
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004099 memset(hs, 0, sizeof (struct fc_host_statistics));
4100
dea31012005-04-17 16:05:31 -05004101 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4102 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4103 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4104 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4105
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004106 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004107 pmb->mbxCommand = MBX_READ_LNK_STAT;
4108 pmb->mbxOwner = OWN_HOST;
4109 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004110 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004111
James Smart75baf692010-06-08 18:31:21 -04004112 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004113 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004114 else
dea31012005-04-17 16:05:31 -05004115 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4116
4117 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004118 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004119 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004120 return NULL;
4121 }
4122
4123 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4124 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4125 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4126 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4127 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4128 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4129 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4130
James Smart64ba8812006-08-02 15:24:34 -04004131 hs->link_failure_count -= lso->link_failure_count;
4132 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4133 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4134 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4135 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4136 hs->invalid_crc_count -= lso->invalid_crc_count;
4137 hs->error_frames -= lso->error_frames;
4138
James Smart4d9ab992009-10-02 15:16:39 -04004139 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4140 hs->lip_count = -1;
4141 hs->nos_count = (phba->link_events >> 1);
4142 hs->nos_count -= lso->link_events;
4143 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004144 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004145 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004146 hs->nos_count = -1;
4147 } else {
4148 hs->lip_count = -1;
4149 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004150 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004151 }
4152
4153 hs->dumped_frames = -1;
4154
James Smart64ba8812006-08-02 15:24:34 -04004155 seconds = get_seconds();
4156 if (seconds < psli->stats_start)
4157 hs->seconds_since_last_reset = seconds +
4158 ((unsigned long)-1 - psli->stats_start);
4159 else
4160 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004161
James Smart1dcb58e2007-04-25 09:51:30 -04004162 mempool_free(pmboxq, phba->mbox_mem_pool);
4163
dea31012005-04-17 16:05:31 -05004164 return hs;
4165}
4166
James Smarte59058c2008-08-24 21:49:00 -04004167/**
James Smart3621a712009-04-06 18:47:14 -04004168 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004169 * @shost: kernel scsi host pointer.
4170 **/
James Smart64ba8812006-08-02 15:24:34 -04004171static void
4172lpfc_reset_stats(struct Scsi_Host *shost)
4173{
James Smart2e0fef82007-06-17 19:56:36 -05004174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4175 struct lpfc_hba *phba = vport->phba;
4176 struct lpfc_sli *psli = &phba->sli;
4177 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004178 LPFC_MBOXQ_t *pmboxq;
4179 MAILBOX_t *pmb;
4180 int rc = 0;
4181
James Smart2e0fef82007-06-17 19:56:36 -05004182 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004183 return;
4184
James Smart64ba8812006-08-02 15:24:34 -04004185 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4186 if (!pmboxq)
4187 return;
4188 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4189
James Smart04c68492009-05-22 14:52:52 -04004190 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004191 pmb->mbxCommand = MBX_READ_STATUS;
4192 pmb->mbxOwner = OWN_HOST;
4193 pmb->un.varWords[0] = 0x1; /* reset request */
4194 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004195 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004196
James Smart2e0fef82007-06-17 19:56:36 -05004197 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004198 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004199 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4200 else
4201 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4202
4203 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004204 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004205 mempool_free(pmboxq, phba->mbox_mem_pool);
4206 return;
4207 }
4208
4209 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4210 pmb->mbxCommand = MBX_READ_LNK_STAT;
4211 pmb->mbxOwner = OWN_HOST;
4212 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004213 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004214
James Smart2e0fef82007-06-17 19:56:36 -05004215 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004216 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004217 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4218 else
4219 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4220
4221 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004222 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004223 mempool_free( pmboxq, phba->mbox_mem_pool);
4224 return;
4225 }
4226
4227 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4228 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4229 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4230 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4231 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4232 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4233 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004234 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4235 lso->link_events = (phba->link_events >> 1);
4236 else
4237 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004238
4239 psli->stats_start = get_seconds();
4240
James Smart1dcb58e2007-04-25 09:51:30 -04004241 mempool_free(pmboxq, phba->mbox_mem_pool);
4242
James Smart64ba8812006-08-02 15:24:34 -04004243 return;
4244}
dea31012005-04-17 16:05:31 -05004245
4246/*
4247 * The LPFC driver treats linkdown handling as target loss events so there
4248 * are no sysfs handlers for link_down_tmo.
4249 */
James Smart685f0bf2007-04-25 09:53:08 -04004250
James Smarte59058c2008-08-24 21:49:00 -04004251/**
James Smart3621a712009-04-06 18:47:14 -04004252 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004253 * @starget: kernel scsi target pointer.
4254 *
4255 * Returns:
4256 * address of the node list if found
4257 * NULL target not found
4258 **/
James Smart685f0bf2007-04-25 09:53:08 -04004259static struct lpfc_nodelist *
4260lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004261{
James Smart2e0fef82007-06-17 19:56:36 -05004262 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4263 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004264 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004265
4266 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004267 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004268 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004269 if (NLP_CHK_NODE_ACT(ndlp) &&
4270 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004271 starget->id == ndlp->nlp_sid) {
4272 spin_unlock_irq(shost->host_lock);
4273 return ndlp;
dea31012005-04-17 16:05:31 -05004274 }
4275 }
4276 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004277 return NULL;
4278}
dea31012005-04-17 16:05:31 -05004279
James Smarte59058c2008-08-24 21:49:00 -04004280/**
James Smart3621a712009-04-06 18:47:14 -04004281 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004282 * @starget: kernel scsi target pointer.
4283 **/
James Smart685f0bf2007-04-25 09:53:08 -04004284static void
4285lpfc_get_starget_port_id(struct scsi_target *starget)
4286{
4287 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4288
4289 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004290}
4291
James Smarte59058c2008-08-24 21:49:00 -04004292/**
James Smart3621a712009-04-06 18:47:14 -04004293 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004294 * @starget: kernel scsi target pointer.
4295 *
4296 * Description: Set the target node name to the ndlp node name wwn or zero.
4297 **/
dea31012005-04-17 16:05:31 -05004298static void
4299lpfc_get_starget_node_name(struct scsi_target *starget)
4300{
James Smart685f0bf2007-04-25 09:53:08 -04004301 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004302
James Smart685f0bf2007-04-25 09:53:08 -04004303 fc_starget_node_name(starget) =
4304 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004305}
4306
James Smarte59058c2008-08-24 21:49:00 -04004307/**
James Smart3621a712009-04-06 18:47:14 -04004308 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004309 * @starget: kernel scsi target pointer.
4310 *
4311 * Description: set the target port name to the ndlp port name wwn or zero.
4312 **/
dea31012005-04-17 16:05:31 -05004313static void
4314lpfc_get_starget_port_name(struct scsi_target *starget)
4315{
James Smart685f0bf2007-04-25 09:53:08 -04004316 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004317
James Smart685f0bf2007-04-25 09:53:08 -04004318 fc_starget_port_name(starget) =
4319 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004320}
4321
James Smarte59058c2008-08-24 21:49:00 -04004322/**
James Smart3621a712009-04-06 18:47:14 -04004323 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004324 * @rport: fc rport address.
4325 * @timeout: new value for dev loss tmo.
4326 *
4327 * Description:
4328 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4329 * dev_loss_tmo to one.
4330 **/
dea31012005-04-17 16:05:31 -05004331static void
dea31012005-04-17 16:05:31 -05004332lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4333{
dea31012005-04-17 16:05:31 -05004334 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004335 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004336 else
James Smartc01f3202006-08-18 17:47:08 -04004337 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004338}
4339
James Smarte59058c2008-08-24 21:49:00 -04004340/**
James Smart3621a712009-04-06 18:47:14 -04004341 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004342 *
4343 * Description:
4344 * Macro that uses field to generate a function with the name lpfc_show_rport_
4345 *
4346 * lpfc_show_rport_##field: returns the bytes formatted in buf
4347 * @cdev: class converted to an fc_rport.
4348 * @buf: on return contains the target_field or zero.
4349 *
4350 * Returns: size of formatted string.
4351 **/
dea31012005-04-17 16:05:31 -05004352#define lpfc_rport_show_function(field, format_string, sz, cast) \
4353static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004354lpfc_show_rport_##field (struct device *dev, \
4355 struct device_attribute *attr, \
4356 char *buf) \
dea31012005-04-17 16:05:31 -05004357{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004358 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004359 struct lpfc_rport_data *rdata = rport->hostdata; \
4360 return snprintf(buf, sz, format_string, \
4361 (rdata->target) ? cast rdata->target->field : 0); \
4362}
4363
4364#define lpfc_rport_rd_attr(field, format_string, sz) \
4365 lpfc_rport_show_function(field, format_string, sz, ) \
4366static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4367
James Smarteada2722008-12-04 22:39:13 -05004368/**
James Smart3621a712009-04-06 18:47:14 -04004369 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004370 * @fc_vport: The fc_vport who's symbolic name has been changed.
4371 *
4372 * Description:
4373 * This function is called by the transport after the @fc_vport's symbolic name
4374 * has been changed. This function re-registers the symbolic name with the
4375 * switch to propogate the change into the fabric if the vport is active.
4376 **/
4377static void
4378lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4379{
4380 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4381
4382 if (vport->port_state == LPFC_VPORT_READY)
4383 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4384}
dea31012005-04-17 16:05:31 -05004385
James Smartf4b4c682009-05-22 14:53:12 -04004386/**
4387 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4388 * @phba: Pointer to lpfc_hba struct.
4389 *
4390 * This function is called by the lpfc_get_cfgparam() routine to set the
4391 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4392 * log messsage according to the module's lpfc_log_verbose parameter setting
4393 * before hba port or vport created.
4394 **/
4395static void
4396lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4397{
4398 phba->cfg_log_verbose = verbose;
4399}
4400
dea31012005-04-17 16:05:31 -05004401struct fc_function_template lpfc_transport_functions = {
4402 /* fixed attributes the driver supports */
4403 .show_host_node_name = 1,
4404 .show_host_port_name = 1,
4405 .show_host_supported_classes = 1,
4406 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004407 .show_host_supported_speeds = 1,
4408 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004409 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004410
4411 /* dynamic attributes the driver supports */
4412 .get_host_port_id = lpfc_get_host_port_id,
4413 .show_host_port_id = 1,
4414
4415 .get_host_port_type = lpfc_get_host_port_type,
4416 .show_host_port_type = 1,
4417
4418 .get_host_port_state = lpfc_get_host_port_state,
4419 .show_host_port_state = 1,
4420
4421 /* active_fc4s is shown but doesn't change (thus no get function) */
4422 .show_host_active_fc4s = 1,
4423
4424 .get_host_speed = lpfc_get_host_speed,
4425 .show_host_speed = 1,
4426
4427 .get_host_fabric_name = lpfc_get_host_fabric_name,
4428 .show_host_fabric_name = 1,
4429
4430 /*
4431 * The LPFC driver treats linkdown handling as target loss events
4432 * so there are no sysfs handlers for link_down_tmo.
4433 */
4434
4435 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004436 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004437
4438 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4439 .show_rport_maxframe_size = 1,
4440 .show_rport_supported_classes = 1,
4441
dea31012005-04-17 16:05:31 -05004442 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4443 .show_rport_dev_loss_tmo = 1,
4444
4445 .get_starget_port_id = lpfc_get_starget_port_id,
4446 .show_starget_port_id = 1,
4447
4448 .get_starget_node_name = lpfc_get_starget_node_name,
4449 .show_starget_node_name = 1,
4450
4451 .get_starget_port_name = lpfc_get_starget_port_name,
4452 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004453
4454 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004455 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4456 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004457
James Smart92d7f7b2007-06-17 19:56:38 -05004458 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004459
4460 .vport_disable = lpfc_vport_disable,
4461
4462 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004463
4464 .bsg_request = lpfc_bsg_request,
4465 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004466};
4467
James Smart98c9ea52007-10-27 13:37:33 -04004468struct fc_function_template lpfc_vport_transport_functions = {
4469 /* fixed attributes the driver supports */
4470 .show_host_node_name = 1,
4471 .show_host_port_name = 1,
4472 .show_host_supported_classes = 1,
4473 .show_host_supported_fc4s = 1,
4474 .show_host_supported_speeds = 1,
4475 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004476 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004477
4478 /* dynamic attributes the driver supports */
4479 .get_host_port_id = lpfc_get_host_port_id,
4480 .show_host_port_id = 1,
4481
4482 .get_host_port_type = lpfc_get_host_port_type,
4483 .show_host_port_type = 1,
4484
4485 .get_host_port_state = lpfc_get_host_port_state,
4486 .show_host_port_state = 1,
4487
4488 /* active_fc4s is shown but doesn't change (thus no get function) */
4489 .show_host_active_fc4s = 1,
4490
4491 .get_host_speed = lpfc_get_host_speed,
4492 .show_host_speed = 1,
4493
4494 .get_host_fabric_name = lpfc_get_host_fabric_name,
4495 .show_host_fabric_name = 1,
4496
4497 /*
4498 * The LPFC driver treats linkdown handling as target loss events
4499 * so there are no sysfs handlers for link_down_tmo.
4500 */
4501
4502 .get_fc_host_stats = lpfc_get_stats,
4503 .reset_fc_host_stats = lpfc_reset_stats,
4504
4505 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4506 .show_rport_maxframe_size = 1,
4507 .show_rport_supported_classes = 1,
4508
4509 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4510 .show_rport_dev_loss_tmo = 1,
4511
4512 .get_starget_port_id = lpfc_get_starget_port_id,
4513 .show_starget_port_id = 1,
4514
4515 .get_starget_node_name = lpfc_get_starget_node_name,
4516 .show_starget_node_name = 1,
4517
4518 .get_starget_port_name = lpfc_get_starget_port_name,
4519 .show_starget_port_name = 1,
4520
4521 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4522 .terminate_rport_io = lpfc_terminate_rport_io,
4523
4524 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004525
4526 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004527};
4528
James Smarte59058c2008-08-24 21:49:00 -04004529/**
James Smart3621a712009-04-06 18:47:14 -04004530 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004531 * @phba: lpfc_hba pointer.
4532 **/
dea31012005-04-17 16:05:31 -05004533void
4534lpfc_get_cfgparam(struct lpfc_hba *phba)
4535{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004536 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4537 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004538 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004539 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4540 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004541 lpfc_ack0_init(phba, lpfc_ack0);
4542 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004543 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004544 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004545 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004546 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004547 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4548 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4549 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004550 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4551 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004552 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004553 if (phba->sli_rev == LPFC_SLI_REV4)
4554 phba->cfg_poll = 0;
4555 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004556 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004557 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004558 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004559 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004560 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004561 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004562 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004563 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004564 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004565 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004566 return;
4567}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004568
James Smarte59058c2008-08-24 21:49:00 -04004569/**
James Smart3621a712009-04-06 18:47:14 -04004570 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004571 * @vport: lpfc_vport pointer.
4572 **/
James Smart3de2a652007-08-02 11:09:59 -04004573void
4574lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4575{
James Smarte8b62012007-08-02 11:10:09 -04004576 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004577 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4578 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4579 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4580 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4581 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4582 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4583 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004584 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004585 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4586 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4587 lpfc_max_luns_init(vport, lpfc_max_luns);
4588 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004589 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004590 return;
4591}