blob: fac26e4445f963a7b87d6d3d07993e9766131c62 [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 Smartbc739052010-08-04 16:11:18 -04001242 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1243 * @dev: class unused variable.
1244 * @attr: device attribute, not used.
1245 * @buf: on return contains the module description text.
1246 *
1247 * Returns: size of formatted string.
1248 **/
1249static ssize_t
1250lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1251 char *buf)
1252{
1253 struct Scsi_Host *shost = class_to_shost(dev);
1254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1255 struct lpfc_hba *phba = vport->phba;
1256
1257 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1258}
1259
1260/**
1261 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1262 * @dev: class unused variable.
1263 * @attr: device attribute, not used.
1264 * @buf: on return contains the module description text.
1265 *
1266 * Returns: size of formatted string.
1267 **/
1268static ssize_t
1269lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1270 char *buf)
1271{
1272 struct Scsi_Host *shost = class_to_shost(dev);
1273 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1274 struct lpfc_hba *phba = vport->phba;
1275
1276 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1277}
1278
1279/**
James Smart3621a712009-04-06 18:47:14 -04001280 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001281 *
1282 * Description:
1283 * Macro that given an attr e.g. hba_queue_depth expands
1284 * into a function with the name lpfc_hba_queue_depth_show.
1285 *
1286 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1287 * @dev: class device that is converted into a Scsi_host.
1288 * @attr: device attribute, not used.
1289 * @buf: on return contains the attribute value in decimal.
1290 *
1291 * Returns: size of formatted string.
1292 **/
dea31012005-04-17 16:05:31 -05001293#define lpfc_param_show(attr) \
1294static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001295lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1296 char *buf) \
dea31012005-04-17 16:05:31 -05001297{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001298 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001299 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1300 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001301 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001302 val = phba->cfg_##attr;\
1303 return snprintf(buf, PAGE_SIZE, "%d\n",\
1304 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001305}
1306
James Smarte59058c2008-08-24 21:49:00 -04001307/**
James Smart3621a712009-04-06 18:47:14 -04001308 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001309 *
1310 * Description:
1311 * Macro that given an attr e.g. hba_queue_depth expands
1312 * into a function with the name lpfc_hba_queue_depth_show
1313 *
1314 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1315 * @dev: class device that is converted into a Scsi_host.
1316 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001317 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001318 *
1319 * Returns: size of formatted string.
1320 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001321#define lpfc_param_hex_show(attr) \
1322static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001323lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1324 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001325{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001326 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001327 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1328 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001329 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001330 val = phba->cfg_##attr;\
1331 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1332 phba->cfg_##attr);\
1333}
1334
James Smarte59058c2008-08-24 21:49:00 -04001335/**
James Smart3621a712009-04-06 18:47:14 -04001336 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001337 *
1338 * Description:
1339 * Macro that given an attr e.g. hba_queue_depth expands
1340 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1341 * takes a default argument, a minimum and maximum argument.
1342 *
1343 * lpfc_##attr##_init: Initializes an attribute.
1344 * @phba: pointer the the adapter structure.
1345 * @val: integer attribute value.
1346 *
1347 * Validates the min and max values then sets the adapter config field
1348 * accordingly, or uses the default if out of range and prints an error message.
1349 *
1350 * Returns:
1351 * zero on success
1352 * -EINVAL if default used
1353 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001354#define lpfc_param_init(attr, default, minval, maxval) \
1355static int \
James Smart84d1b002010-02-12 14:42:33 -05001356lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001357{ \
1358 if (val >= minval && val <= maxval) {\
1359 phba->cfg_##attr = val;\
1360 return 0;\
1361 }\
1362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001363 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1364 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001365 phba->cfg_##attr = default;\
1366 return -EINVAL;\
1367}
1368
James Smarte59058c2008-08-24 21:49:00 -04001369/**
James Smart3621a712009-04-06 18:47:14 -04001370 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001371 *
1372 * Description:
1373 * Macro that given an attr e.g. hba_queue_depth expands
1374 * into a function with the name lpfc_hba_queue_depth_set
1375 *
1376 * lpfc_##attr##_set: Sets an attribute value.
1377 * @phba: pointer the the adapter structure.
1378 * @val: integer attribute value.
1379 *
1380 * Description:
1381 * Validates the min and max values then sets the
1382 * adapter config field if in the valid range. prints error message
1383 * and does not set the parameter if invalid.
1384 *
1385 * Returns:
1386 * zero on success
1387 * -EINVAL if val is invalid
1388 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001389#define lpfc_param_set(attr, default, minval, maxval) \
1390static int \
James Smart84d1b002010-02-12 14:42:33 -05001391lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001392{ \
1393 if (val >= minval && val <= maxval) {\
1394 phba->cfg_##attr = val;\
1395 return 0;\
1396 }\
1397 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001398 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1399 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001400 return -EINVAL;\
1401}
1402
James Smarte59058c2008-08-24 21:49:00 -04001403/**
James Smart3621a712009-04-06 18:47:14 -04001404 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001405 *
1406 * Description:
1407 * Macro that given an attr e.g. hba_queue_depth expands
1408 * into a function with the name lpfc_hba_queue_depth_store.
1409 *
1410 * lpfc_##attr##_store: Set an sttribute value.
1411 * @dev: class device that is converted into a Scsi_host.
1412 * @attr: device attribute, not used.
1413 * @buf: contains the attribute value in ascii.
1414 * @count: not used.
1415 *
1416 * Description:
1417 * Convert the ascii text number to an integer, then
1418 * use the lpfc_##attr##_set function to set the value.
1419 *
1420 * Returns:
1421 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1422 * length of buffer upon success.
1423 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001424#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001425static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001426lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1427 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001428{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001429 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001430 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1431 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001432 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001433 if (!isdigit(buf[0]))\
1434 return -EINVAL;\
1435 if (sscanf(buf, "%i", &val) != 1)\
1436 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001437 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001438 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001439 else \
1440 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001441}
1442
James Smarte59058c2008-08-24 21:49:00 -04001443/**
James Smart3621a712009-04-06 18:47:14 -04001444 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001445 *
1446 * Description:
1447 * Macro that given an attr e.g. hba_queue_depth expands
1448 * into a function with the name lpfc_hba_queue_depth_show
1449 *
1450 * lpfc_##attr##_show: prints the attribute value in decimal.
1451 * @dev: class device that is converted into a Scsi_host.
1452 * @attr: device attribute, not used.
1453 * @buf: on return contains the attribute value in decimal.
1454 *
1455 * Returns: length of formatted string.
1456 **/
James Smart3de2a652007-08-02 11:09:59 -04001457#define lpfc_vport_param_show(attr) \
1458static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001459lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1460 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001461{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001462 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001463 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001464 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001465 val = vport->cfg_##attr;\
1466 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1467}
1468
James Smarte59058c2008-08-24 21:49:00 -04001469/**
James Smart3621a712009-04-06 18:47:14 -04001470 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001471 *
1472 * Description:
1473 * Macro that given an attr e.g.
1474 * hba_queue_depth expands into a function with the name
1475 * lpfc_hba_queue_depth_show
1476 *
James Smart3621a712009-04-06 18:47:14 -04001477 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001478 * @dev: class device that is converted into a Scsi_host.
1479 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001480 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001481 *
1482 * Returns: length of formatted string.
1483 **/
James Smart3de2a652007-08-02 11:09:59 -04001484#define lpfc_vport_param_hex_show(attr) \
1485static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001486lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1487 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001488{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001489 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001490 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001491 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001492 val = vport->cfg_##attr;\
1493 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1494}
1495
James Smarte59058c2008-08-24 21:49:00 -04001496/**
James Smart3621a712009-04-06 18:47:14 -04001497 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001498 *
1499 * Description:
1500 * Macro that given an attr e.g. hba_queue_depth expands
1501 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1502 * takes a default argument, a minimum and maximum argument.
1503 *
1504 * lpfc_##attr##_init: validates the min and max values then sets the
1505 * adapter config field accordingly, or uses the default if out of range
1506 * and prints an error message.
1507 * @phba: pointer the the adapter structure.
1508 * @val: integer attribute value.
1509 *
1510 * Returns:
1511 * zero on success
1512 * -EINVAL if default used
1513 **/
James Smart3de2a652007-08-02 11:09:59 -04001514#define lpfc_vport_param_init(attr, default, minval, maxval) \
1515static int \
James Smart84d1b002010-02-12 14:42:33 -05001516lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001517{ \
1518 if (val >= minval && val <= maxval) {\
1519 vport->cfg_##attr = val;\
1520 return 0;\
1521 }\
James Smarte8b62012007-08-02 11:10:09 -04001522 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001523 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001524 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001525 vport->cfg_##attr = default;\
1526 return -EINVAL;\
1527}
1528
James Smarte59058c2008-08-24 21:49:00 -04001529/**
James Smart3621a712009-04-06 18:47:14 -04001530 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001531 *
1532 * Description:
1533 * Macro that given an attr e.g. hba_queue_depth expands
1534 * into a function with the name lpfc_hba_queue_depth_set
1535 *
1536 * lpfc_##attr##_set: validates the min and max values then sets the
1537 * adapter config field if in the valid range. prints error message
1538 * and does not set the parameter if invalid.
1539 * @phba: pointer the the adapter structure.
1540 * @val: integer attribute value.
1541 *
1542 * Returns:
1543 * zero on success
1544 * -EINVAL if val is invalid
1545 **/
James Smart3de2a652007-08-02 11:09:59 -04001546#define lpfc_vport_param_set(attr, default, minval, maxval) \
1547static int \
James Smart84d1b002010-02-12 14:42:33 -05001548lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001549{ \
1550 if (val >= minval && val <= maxval) {\
1551 vport->cfg_##attr = val;\
1552 return 0;\
1553 }\
James Smarte8b62012007-08-02 11:10:09 -04001554 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001555 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001556 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001557 return -EINVAL;\
1558}
1559
James Smarte59058c2008-08-24 21:49:00 -04001560/**
James Smart3621a712009-04-06 18:47:14 -04001561 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001562 *
1563 * Description:
1564 * Macro that given an attr e.g. hba_queue_depth
1565 * expands into a function with the name lpfc_hba_queue_depth_store
1566 *
1567 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1568 * use the lpfc_##attr##_set function to set the value.
1569 * @cdev: class device that is converted into a Scsi_host.
1570 * @buf: contains the attribute value in decimal.
1571 * @count: not used.
1572 *
1573 * Returns:
1574 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1575 * length of buffer upon success.
1576 **/
James Smart3de2a652007-08-02 11:09:59 -04001577#define lpfc_vport_param_store(attr) \
1578static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001579lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1580 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001581{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001582 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001584 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001585 if (!isdigit(buf[0]))\
1586 return -EINVAL;\
1587 if (sscanf(buf, "%i", &val) != 1)\
1588 return -EINVAL;\
1589 if (lpfc_##attr##_set(vport, val) == 0) \
1590 return strlen(buf);\
1591 else \
1592 return -EINVAL;\
1593}
1594
1595
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001596#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001597static uint lpfc_##name = defval;\
1598module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001599MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001600lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001601
1602#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001603static uint lpfc_##name = defval;\
1604module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001605MODULE_PARM_DESC(lpfc_##name, desc);\
1606lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001607lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001608static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001609
1610#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001611static uint lpfc_##name = defval;\
1612module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001613MODULE_PARM_DESC(lpfc_##name, desc);\
1614lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001615lpfc_param_init(name, defval, minval, maxval)\
1616lpfc_param_set(name, defval, minval, maxval)\
1617lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001618static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1619 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001620
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001621#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001622static uint lpfc_##name = defval;\
1623module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001624MODULE_PARM_DESC(lpfc_##name, desc);\
1625lpfc_param_hex_show(name)\
1626lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001627static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001628
1629#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001630static uint lpfc_##name = defval;\
1631module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001632MODULE_PARM_DESC(lpfc_##name, desc);\
1633lpfc_param_hex_show(name)\
1634lpfc_param_init(name, defval, minval, maxval)\
1635lpfc_param_set(name, defval, minval, maxval)\
1636lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001637static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1638 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001639
James Smart3de2a652007-08-02 11:09:59 -04001640#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001641static uint lpfc_##name = defval;\
1642module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001643MODULE_PARM_DESC(lpfc_##name, desc);\
1644lpfc_vport_param_init(name, defval, minval, maxval)
1645
1646#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001647static uint lpfc_##name = defval;\
1648module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001649MODULE_PARM_DESC(lpfc_##name, desc);\
1650lpfc_vport_param_show(name)\
1651lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001652static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001653
1654#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001655static uint lpfc_##name = defval;\
1656module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001657MODULE_PARM_DESC(lpfc_##name, desc);\
1658lpfc_vport_param_show(name)\
1659lpfc_vport_param_init(name, defval, minval, maxval)\
1660lpfc_vport_param_set(name, defval, minval, maxval)\
1661lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001662static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1663 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001664
1665#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001666static uint lpfc_##name = defval;\
1667module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001668MODULE_PARM_DESC(lpfc_##name, desc);\
1669lpfc_vport_param_hex_show(name)\
1670lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001671static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001672
1673#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001674static uint lpfc_##name = defval;\
1675module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001676MODULE_PARM_DESC(lpfc_##name, desc);\
1677lpfc_vport_param_hex_show(name)\
1678lpfc_vport_param_init(name, defval, minval, maxval)\
1679lpfc_vport_param_set(name, defval, minval, maxval)\
1680lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001681static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1682 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001683
James Smart81301a92008-12-04 22:39:46 -05001684static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1685static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1686static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1687static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001688static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1689static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1690static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1691static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1692static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1693static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1694static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1695static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001696static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1697 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001698static DEVICE_ATTR(option_rom_version, S_IRUGO,
1699 lpfc_option_rom_version_show, NULL);
1700static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1701 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001702static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001703static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1704static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001705static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001706static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1707 lpfc_board_mode_show, lpfc_board_mode_store);
1708static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1709static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1710static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1711static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1712static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1713static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1714static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1715static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1716static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001717static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1718static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
dea31012005-04-17 16:05:31 -05001719
James Smartc3f28af2006-08-18 17:47:18 -04001720
James Smarta12e07b2006-12-02 13:35:30 -05001721static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001722
James Smarte59058c2008-08-24 21:49:00 -04001723/**
James Smart3621a712009-04-06 18:47:14 -04001724 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001725 * @dev: class device that is converted into a Scsi_host.
1726 * @attr: device attribute, not used.
1727 * @buf: containing the string lpfc_soft_wwn_key.
1728 * @count: must be size of lpfc_soft_wwn_key.
1729 *
1730 * Returns:
1731 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1732 * length of buf indicates success
1733 **/
James Smartc3f28af2006-08-18 17:47:18 -04001734static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001735lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1736 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001737{
Tony Jonesee959b02008-02-22 00:13:36 +01001738 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1740 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001741 unsigned int cnt = count;
1742
1743 /*
1744 * We're doing a simple sanity check for soft_wwpn setting.
1745 * We require that the user write a specific key to enable
1746 * the soft_wwpn attribute to be settable. Once the attribute
1747 * is written, the enable key resets. If further updates are
1748 * desired, the key must be written again to re-enable the
1749 * attribute.
1750 *
1751 * The "key" is not secret - it is a hardcoded string shown
1752 * here. The intent is to protect against the random user or
1753 * application that is just writing attributes.
1754 */
1755
1756 /* count may include a LF at end of string */
1757 if (buf[cnt-1] == '\n')
1758 cnt--;
1759
James Smarta12e07b2006-12-02 13:35:30 -05001760 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1761 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001762 return -EINVAL;
1763
James Smarta12e07b2006-12-02 13:35:30 -05001764 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001765 return count;
1766}
Tony Jonesee959b02008-02-22 00:13:36 +01001767static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1768 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001769
James Smarte59058c2008-08-24 21:49:00 -04001770/**
James Smart3621a712009-04-06 18:47:14 -04001771 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001772 * @dev: class device that is converted into a Scsi_host.
1773 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001774 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001775 *
1776 * Returns: size of formatted string.
1777 **/
James Smartc3f28af2006-08-18 17:47:18 -04001778static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001779lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1780 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001781{
Tony Jonesee959b02008-02-22 00:13:36 +01001782 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001783 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1784 struct lpfc_hba *phba = vport->phba;
1785
Randy Dunlapafc071e2006-10-23 21:47:13 -07001786 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1787 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001788}
1789
James Smarte59058c2008-08-24 21:49:00 -04001790/**
James Smart3621a712009-04-06 18:47:14 -04001791 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001792 * @dev class device that is converted into a Scsi_host.
1793 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001794 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001795 * @count: number of wwpn bytes in buf
1796 *
1797 * Returns:
1798 * -EACCES hba reset not enabled, adapter over temp
1799 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1800 * -EIO error taking adapter offline or online
1801 * value of count on success
1802 **/
James Smartc3f28af2006-08-18 17:47:18 -04001803static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001804lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1805 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001806{
Tony Jonesee959b02008-02-22 00:13:36 +01001807 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001808 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1809 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001810 struct completion online_compl;
1811 int stat1=0, stat2=0;
1812 unsigned int i, j, cnt=count;
1813 u8 wwpn[8];
1814
James Smart13815c82008-01-11 01:52:48 -05001815 if (!phba->cfg_enable_hba_reset)
1816 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001817 spin_lock_irq(&phba->hbalock);
1818 if (phba->over_temp_state == HBA_OVER_TEMP) {
1819 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001820 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001821 }
1822 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001823 /* count may include a LF at end of string */
1824 if (buf[cnt-1] == '\n')
1825 cnt--;
1826
James Smarta12e07b2006-12-02 13:35:30 -05001827 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001828 ((cnt == 17) && (*buf++ != 'x')) ||
1829 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1830 return -EINVAL;
1831
James Smarta12e07b2006-12-02 13:35:30 -05001832 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001833
1834 memset(wwpn, 0, sizeof(wwpn));
1835
1836 /* Validate and store the new name */
1837 for (i=0, j=0; i < 16; i++) {
1838 if ((*buf >= 'a') && (*buf <= 'f'))
1839 j = ((j << 4) | ((*buf++ -'a') + 10));
1840 else if ((*buf >= 'A') && (*buf <= 'F'))
1841 j = ((j << 4) | ((*buf++ -'A') + 10));
1842 else if ((*buf >= '0') && (*buf <= '9'))
1843 j = ((j << 4) | (*buf++ -'0'));
1844 else
1845 return -EINVAL;
1846 if (i % 2) {
1847 wwpn[i/2] = j & 0xff;
1848 j = 0;
1849 }
1850 }
1851 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001852 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001853 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001854 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001855
1856 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1857 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1858
James Smart46fa3112007-04-25 09:51:45 -04001859 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001860 if (stat1)
1861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001862 "0463 lpfc_soft_wwpn attribute set failed to "
1863 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001864 init_completion(&online_compl);
1865 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1866 wait_for_completion(&online_compl);
1867 if (stat2)
1868 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001869 "0464 lpfc_soft_wwpn attribute set failed to "
1870 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001871 return (stat1 || stat2) ? -EIO : count;
1872}
Tony Jonesee959b02008-02-22 00:13:36 +01001873static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1874 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001875
James Smarte59058c2008-08-24 21:49:00 -04001876/**
James Smart3621a712009-04-06 18:47:14 -04001877 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001878 * @dev: class device that is converted into a Scsi_host.
1879 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001880 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001881 *
1882 * Returns: size of formatted string.
1883 **/
James Smarta12e07b2006-12-02 13:35:30 -05001884static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001885lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1886 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001887{
Tony Jonesee959b02008-02-22 00:13:36 +01001888 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001889 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001890 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1891 (unsigned long long)phba->cfg_soft_wwnn);
1892}
1893
James Smarte59058c2008-08-24 21:49:00 -04001894/**
James Smart3621a712009-04-06 18:47:14 -04001895 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001896 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001897 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001898 * @count: number of wwnn bytes in buf.
1899 *
1900 * Returns:
1901 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1902 * value of count on success
1903 **/
James Smarta12e07b2006-12-02 13:35:30 -05001904static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001905lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1906 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001907{
Tony Jonesee959b02008-02-22 00:13:36 +01001908 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001909 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001910 unsigned int i, j, cnt=count;
1911 u8 wwnn[8];
1912
1913 /* count may include a LF at end of string */
1914 if (buf[cnt-1] == '\n')
1915 cnt--;
1916
1917 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1918 ((cnt == 17) && (*buf++ != 'x')) ||
1919 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1920 return -EINVAL;
1921
1922 /*
1923 * Allow wwnn to be set many times, as long as the enable is set.
1924 * However, once the wwpn is set, everything locks.
1925 */
1926
1927 memset(wwnn, 0, sizeof(wwnn));
1928
1929 /* Validate and store the new name */
1930 for (i=0, j=0; i < 16; i++) {
1931 if ((*buf >= 'a') && (*buf <= 'f'))
1932 j = ((j << 4) | ((*buf++ -'a') + 10));
1933 else if ((*buf >= 'A') && (*buf <= 'F'))
1934 j = ((j << 4) | ((*buf++ -'A') + 10));
1935 else if ((*buf >= '0') && (*buf <= '9'))
1936 j = ((j << 4) | (*buf++ -'0'));
1937 else
1938 return -EINVAL;
1939 if (i % 2) {
1940 wwnn[i/2] = j & 0xff;
1941 j = 0;
1942 }
1943 }
1944 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1945
1946 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1947 "lpfc%d: soft_wwnn set. Value will take effect upon "
1948 "setting of the soft_wwpn\n", phba->brd_no);
1949
1950 return count;
1951}
Tony Jonesee959b02008-02-22 00:13:36 +01001952static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1953 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001954
James Smartc3f28af2006-08-18 17:47:18 -04001955
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001956static int lpfc_poll = 0;
1957module_param(lpfc_poll, int, 0);
1958MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1959 " 0 - none,"
1960 " 1 - poll with interrupts enabled"
1961 " 3 - poll and disable FCP ring interrupts");
1962
Tony Jonesee959b02008-02-22 00:13:36 +01001963static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1964 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001965
James Smart92d7f7b2007-06-17 19:56:38 -05001966int lpfc_sli_mode = 0;
1967module_param(lpfc_sli_mode, int, 0);
1968MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1969 " 0 - auto (SLI-3 if supported),"
1970 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1971 " 3 - select SLI-3");
1972
James Smart15672312010-04-06 14:49:03 -04001973int lpfc_enable_npiv = 1;
James Smart7ee5d432007-10-27 13:37:17 -04001974module_param(lpfc_enable_npiv, int, 0);
1975MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1976lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04001977lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04001978static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001979
dea31012005-04-17 16:05:31 -05001980/*
James Smart84d1b002010-02-12 14:42:33 -05001981# lpfc_suppress_link_up: Bring link up at initialization
1982# 0x0 = bring link up (issue MBX_INIT_LINK)
1983# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1984# 0x2 = never bring up link
1985# Default value is 0.
1986*/
James Smarte40a02c2010-02-26 14:13:54 -05001987LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1988 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1989 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04001990/*
1991# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1992# 1 - (1024)
1993# 2 - (2048)
1994# 3 - (3072)
1995# 4 - (4096)
1996# 5 - (5120)
1997*/
1998static ssize_t
1999lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2000{
2001 struct Scsi_Host *shost = class_to_shost(dev);
2002 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2003
2004 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2005}
2006
2007static DEVICE_ATTR(iocb_hw, S_IRUGO,
2008 lpfc_iocb_hw_show, NULL);
2009static ssize_t
2010lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2011{
2012 struct Scsi_Host *shost = class_to_shost(dev);
2013 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2014
2015 return snprintf(buf, PAGE_SIZE, "%d\n",
2016 phba->sli.ring[LPFC_ELS_RING].txq_max);
2017}
2018
2019static DEVICE_ATTR(txq_hw, S_IRUGO,
2020 lpfc_txq_hw_show, NULL);
2021static ssize_t
2022lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2023 char *buf)
2024{
2025 struct Scsi_Host *shost = class_to_shost(dev);
2026 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2027
2028 return snprintf(buf, PAGE_SIZE, "%d\n",
2029 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2030}
2031
2032static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2033 lpfc_txcmplq_hw_show, NULL);
2034
2035int lpfc_iocb_cnt = 2;
2036module_param(lpfc_iocb_cnt, int, 1);
2037MODULE_PARM_DESC(lpfc_iocb_cnt,
2038 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2039lpfc_param_show(iocb_cnt);
2040lpfc_param_init(iocb_cnt, 2, 1, 5);
2041static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2042 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002043
2044/*
James Smartc01f3202006-08-18 17:47:08 -04002045# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2046# until the timer expires. Value range is [0,255]. Default value is 30.
2047*/
2048static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2049static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2050module_param(lpfc_nodev_tmo, int, 0);
2051MODULE_PARM_DESC(lpfc_nodev_tmo,
2052 "Seconds driver will hold I/O waiting "
2053 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002054
2055/**
James Smart3621a712009-04-06 18:47:14 -04002056 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002057 * @dev: class converted to a Scsi_host structure.
2058 * @attr: device attribute, not used.
2059 * @buf: on return contains the dev loss timeout in decimal.
2060 *
2061 * Returns: size of formatted string.
2062 **/
James Smartc01f3202006-08-18 17:47:08 -04002063static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002064lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2065 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002066{
Tony Jonesee959b02008-02-22 00:13:36 +01002067 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002069
James Smart3de2a652007-08-02 11:09:59 -04002070 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002071}
2072
James Smarte59058c2008-08-24 21:49:00 -04002073/**
James Smart3621a712009-04-06 18:47:14 -04002074 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002075 * @vport: lpfc vport structure pointer.
2076 * @val: contains the nodev timeout value.
2077 *
2078 * Description:
2079 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2080 * a kernel error message is printed and zero is returned.
2081 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2082 * Otherwise nodev tmo is set to the default value.
2083 *
2084 * Returns:
2085 * zero if already set or if val is in range
2086 * -EINVAL val out of range
2087 **/
James Smartc01f3202006-08-18 17:47:08 -04002088static int
James Smart3de2a652007-08-02 11:09:59 -04002089lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002090{
James Smart3de2a652007-08-02 11:09:59 -04002091 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2092 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2093 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002094 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002095 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002096 "parameter because devloss_tmo is "
2097 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002098 return 0;
2099 }
2100
2101 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002102 vport->cfg_nodev_tmo = val;
2103 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002104 return 0;
2105 }
James Smarte8b62012007-08-02 11:10:09 -04002106 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2107 "0400 lpfc_nodev_tmo attribute cannot be set to"
2108 " %d, allowed range is [%d, %d]\n",
2109 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002110 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002111 return -EINVAL;
2112}
2113
James Smarte59058c2008-08-24 21:49:00 -04002114/**
James Smart3621a712009-04-06 18:47:14 -04002115 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002116 * @vport: lpfc vport structure pointer.
2117 *
2118 * Description:
2119 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2120 **/
James Smart7054a602007-04-25 09:52:34 -04002121static void
James Smart3de2a652007-08-02 11:09:59 -04002122lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002123{
James Smart858c9f62007-06-17 19:56:39 -05002124 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002125 struct lpfc_nodelist *ndlp;
2126
James Smart51ef4c22007-08-02 11:10:31 -04002127 shost = lpfc_shost_from_vport(vport);
2128 spin_lock_irq(shost->host_lock);
2129 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002130 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002131 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2132 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002133}
2134
James Smarte59058c2008-08-24 21:49:00 -04002135/**
James Smart3621a712009-04-06 18:47:14 -04002136 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002137 * @vport: lpfc vport structure pointer.
2138 * @val: contains the tmo value.
2139 *
2140 * Description:
2141 * If the devloss tmo is already set or the vport dev loss tmo has changed
2142 * then a kernel error message is printed and zero is returned.
2143 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2144 * Otherwise nodev tmo is set to the default value.
2145 *
2146 * Returns:
2147 * zero if already set or if val is in range
2148 * -EINVAL val out of range
2149 **/
James Smartc01f3202006-08-18 17:47:08 -04002150static int
James Smart3de2a652007-08-02 11:09:59 -04002151lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002152{
James Smart3de2a652007-08-02 11:09:59 -04002153 if (vport->dev_loss_tmo_changed ||
2154 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002155 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2156 "0401 Ignoring change to nodev_tmo "
2157 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002158 return 0;
2159 }
James Smartc01f3202006-08-18 17:47:08 -04002160 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002161 vport->cfg_nodev_tmo = val;
2162 vport->cfg_devloss_tmo = val;
2163 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002164 return 0;
2165 }
James Smarte8b62012007-08-02 11:10:09 -04002166 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2167 "0403 lpfc_nodev_tmo attribute cannot be set to"
2168 "%d, allowed range is [%d, %d]\n",
2169 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002170 return -EINVAL;
2171}
2172
James Smart3de2a652007-08-02 11:09:59 -04002173lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002174
Tony Jonesee959b02008-02-22 00:13:36 +01002175static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2176 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002177
2178/*
2179# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2180# disappear until the timer expires. Value range is [0,255]. Default
2181# value is 30.
2182*/
2183module_param(lpfc_devloss_tmo, int, 0);
2184MODULE_PARM_DESC(lpfc_devloss_tmo,
2185 "Seconds driver will hold I/O waiting "
2186 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002187lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2188 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2189lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002190
2191/**
James Smart3621a712009-04-06 18:47:14 -04002192 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002193 * @vport: lpfc vport structure pointer.
2194 * @val: contains the tmo value.
2195 *
2196 * Description:
2197 * If val is in a valid range then set the vport nodev tmo,
2198 * devloss tmo, also set the vport dev loss tmo changed flag.
2199 * Else a kernel error message is printed.
2200 *
2201 * Returns:
2202 * zero if val is in range
2203 * -EINVAL val out of range
2204 **/
James Smartc01f3202006-08-18 17:47:08 -04002205static int
James Smart3de2a652007-08-02 11:09:59 -04002206lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002207{
2208 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002209 vport->cfg_nodev_tmo = val;
2210 vport->cfg_devloss_tmo = val;
2211 vport->dev_loss_tmo_changed = 1;
2212 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002213 return 0;
2214 }
2215
James Smarte8b62012007-08-02 11:10:09 -04002216 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2217 "0404 lpfc_devloss_tmo attribute cannot be set to"
2218 " %d, allowed range is [%d, %d]\n",
2219 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002220 return -EINVAL;
2221}
2222
James Smart3de2a652007-08-02 11:09:59 -04002223lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002224static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2225 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002226
2227/*
dea31012005-04-17 16:05:31 -05002228# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2229# deluged with LOTS of information.
2230# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002231# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002232*/
James Smartf4b4c682009-05-22 14:53:12 -04002233LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002234 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002235
2236/*
James Smart7ee5d432007-10-27 13:37:17 -04002237# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2238# objects that have been registered with the nameserver after login.
2239*/
2240LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2241 "Deregister nameserver objects before LOGO");
2242
2243/*
dea31012005-04-17 16:05:31 -05002244# lun_queue_depth: This parameter is used to limit the number of outstanding
2245# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2246*/
James Smart3de2a652007-08-02 11:09:59 -04002247LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2248 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002249
2250/*
James Smart7dc517d2010-07-14 15:32:10 -04002251# tgt_queue_depth: This parameter is used to limit the number of outstanding
2252# commands per target port. Value range is [10,65535]. Default value is 65535.
2253*/
2254LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2255 "Max number of FCP commands we can queue to a specific target port");
2256
2257/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002258# hba_queue_depth: This parameter is used to limit the number of outstanding
2259# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2260# value is greater than the maximum number of exchanges supported by the HBA,
2261# then maximum number of exchanges supported by the HBA is used to determine
2262# the hba_queue_depth.
2263*/
2264LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2265 "Max number of FCP commands we can queue to a lpfc HBA");
2266
2267/*
James Smart92d7f7b2007-06-17 19:56:38 -05002268# peer_port_login: This parameter allows/prevents logins
2269# between peer ports hosted on the same physical port.
2270# When this parameter is set 0 peer ports of same physical port
2271# are not allowed to login to each other.
2272# When this parameter is set 1 peer ports of same physical port
2273# are allowed to login to each other.
2274# Default value of this parameter is 0.
2275*/
James Smart3de2a652007-08-02 11:09:59 -04002276LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2277 "Allow peer ports on the same physical port to login to each "
2278 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002279
2280/*
James Smart3de2a652007-08-02 11:09:59 -04002281# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002282# between Virtual Ports and remote initiators.
2283# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2284# other initiators and will attempt to PLOGI all remote ports.
2285# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2286# remote ports and will not attempt to PLOGI to other initiators.
2287# This parameter does not restrict to the physical port.
2288# This parameter does not restrict logins to Fabric resident remote ports.
2289# Default value of this parameter is 1.
2290*/
James Smart3de2a652007-08-02 11:09:59 -04002291static int lpfc_restrict_login = 1;
2292module_param(lpfc_restrict_login, int, 0);
2293MODULE_PARM_DESC(lpfc_restrict_login,
2294 "Restrict virtual ports login to remote initiators.");
2295lpfc_vport_param_show(restrict_login);
2296
James Smarte59058c2008-08-24 21:49:00 -04002297/**
James Smart3621a712009-04-06 18:47:14 -04002298 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002299 * @vport: lpfc vport structure pointer.
2300 * @val: contains the restrict login value.
2301 *
2302 * Description:
2303 * If val is not in a valid range then log a kernel error message and set
2304 * the vport restrict login to one.
2305 * If the port type is physical clear the restrict login flag and return.
2306 * Else set the restrict login flag to val.
2307 *
2308 * Returns:
2309 * zero if val is in range
2310 * -EINVAL val out of range
2311 **/
James Smart3de2a652007-08-02 11:09:59 -04002312static int
2313lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2314{
2315 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002316 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002317 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002318 "be set to %d, allowed range is [0, 1]\n",
2319 val);
James Smart3de2a652007-08-02 11:09:59 -04002320 vport->cfg_restrict_login = 1;
2321 return -EINVAL;
2322 }
2323 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2324 vport->cfg_restrict_login = 0;
2325 return 0;
2326 }
2327 vport->cfg_restrict_login = val;
2328 return 0;
2329}
2330
James Smarte59058c2008-08-24 21:49:00 -04002331/**
James Smart3621a712009-04-06 18:47:14 -04002332 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002333 * @vport: lpfc vport structure pointer.
2334 * @val: contains the restrict login value.
2335 *
2336 * Description:
2337 * If val is not in a valid range then log a kernel error message and set
2338 * the vport restrict login to one.
2339 * If the port type is physical and the val is not zero log a kernel
2340 * error message, clear the restrict login flag and return zero.
2341 * Else set the restrict login flag to val.
2342 *
2343 * Returns:
2344 * zero if val is in range
2345 * -EINVAL val out of range
2346 **/
James Smart3de2a652007-08-02 11:09:59 -04002347static int
2348lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2349{
2350 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002351 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002352 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002353 "be set to %d, allowed range is [0, 1]\n",
2354 val);
James Smart3de2a652007-08-02 11:09:59 -04002355 vport->cfg_restrict_login = 1;
2356 return -EINVAL;
2357 }
2358 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002359 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2360 "0468 lpfc_restrict_login must be 0 for "
2361 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002362 vport->cfg_restrict_login = 0;
2363 return 0;
2364 }
2365 vport->cfg_restrict_login = val;
2366 return 0;
2367}
2368lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002369static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2370 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002371
2372/*
dea31012005-04-17 16:05:31 -05002373# Some disk devices have a "select ID" or "select Target" capability.
2374# From a protocol standpoint "select ID" usually means select the
2375# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2376# annex" which contains a table that maps a "select ID" (a number
2377# between 0 and 7F) to an ALPA. By default, for compatibility with
2378# older drivers, the lpfc driver scans this table from low ALPA to high
2379# ALPA.
2380#
2381# Turning on the scan-down variable (on = 1, off = 0) will
2382# cause the lpfc driver to use an inverted table, effectively
2383# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2384#
2385# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2386# and will not work across a fabric. Also this parameter will take
2387# effect only in the case when ALPA map is not available.)
2388*/
James Smart3de2a652007-08-02 11:09:59 -04002389LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2390 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002391
2392/*
dea31012005-04-17 16:05:31 -05002393# lpfc_topology: link topology for init link
2394# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002395# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002396# 0x02 = attempt point-to-point mode only
2397# 0x04 = attempt loop mode only
2398# 0x06 = attempt point-to-point mode then loop
2399# Set point-to-point mode if you want to run as an N_Port.
2400# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2401# Default value is 0.
2402*/
James Smarte59058c2008-08-24 21:49:00 -04002403
2404/**
James Smart3621a712009-04-06 18:47:14 -04002405 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002406 * @phba: lpfc_hba pointer.
2407 * @val: topology value.
2408 *
2409 * Description:
2410 * If val is in a valid range then set the adapter's topology field and
2411 * issue a lip; if the lip fails reset the topology to the old value.
2412 *
2413 * If the value is not in range log a kernel error message and return an error.
2414 *
2415 * Returns:
2416 * zero if val is in range and lip okay
2417 * non-zero return value from lpfc_issue_lip()
2418 * -EINVAL val out of range
2419 **/
James Smarta257bf92009-04-06 18:48:10 -04002420static ssize_t
2421lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2422 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002423{
James Smarta257bf92009-04-06 18:48:10 -04002424 struct Scsi_Host *shost = class_to_shost(dev);
2425 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2426 struct lpfc_hba *phba = vport->phba;
2427 int val = 0;
2428 int nolip = 0;
2429 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002430 int err;
2431 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002432
2433 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2434 nolip = 1;
2435 val_buf = &buf[strlen("nolip ")];
2436 }
2437
2438 if (!isdigit(val_buf[0]))
2439 return -EINVAL;
2440 if (sscanf(val_buf, "%i", &val) != 1)
2441 return -EINVAL;
2442
James Smart83108bd2008-01-11 01:53:09 -05002443 if (val >= 0 && val <= 6) {
2444 prev_val = phba->cfg_topology;
2445 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002446 if (nolip)
2447 return strlen(buf);
2448
James Smart83108bd2008-01-11 01:53:09 -05002449 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002450 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002451 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002452 return -EINVAL;
2453 } else
2454 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002455 }
2456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2457 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2458 "allowed range is [0, 6]\n",
2459 phba->brd_no, val);
2460 return -EINVAL;
2461}
2462static int lpfc_topology = 0;
2463module_param(lpfc_topology, int, 0);
2464MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2465lpfc_param_show(topology)
2466lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002467static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002468 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002469
James Smart21e9a0a2009-05-22 14:53:21 -04002470/**
2471 * lpfc_static_vport_show: Read callback function for
2472 * lpfc_static_vport sysfs file.
2473 * @dev: Pointer to class device object.
2474 * @attr: device attribute structure.
2475 * @buf: Data buffer.
2476 *
2477 * This function is the read call back function for
2478 * lpfc_static_vport sysfs file. The lpfc_static_vport
2479 * sysfs file report the mageability of the vport.
2480 **/
2481static ssize_t
2482lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2483 char *buf)
2484{
2485 struct Scsi_Host *shost = class_to_shost(dev);
2486 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2487 if (vport->vport_flag & STATIC_VPORT)
2488 sprintf(buf, "1\n");
2489 else
2490 sprintf(buf, "0\n");
2491
2492 return strlen(buf);
2493}
2494
2495/*
2496 * Sysfs attribute to control the statistical data collection.
2497 */
2498static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2499 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002500
2501/**
James Smart3621a712009-04-06 18:47:14 -04002502 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002503 * @dev: Pointer to class device.
2504 * @buf: Data buffer.
2505 * @count: Size of the data buffer.
2506 *
2507 * This function get called when an user write to the lpfc_stat_data_ctrl
2508 * sysfs file. This function parse the command written to the sysfs file
2509 * and take appropriate action. These commands are used for controlling
2510 * driver statistical data collection.
2511 * Following are the command this function handles.
2512 *
2513 * setbucket <bucket_type> <base> <step>
2514 * = Set the latency buckets.
2515 * destroybucket = destroy all the buckets.
2516 * start = start data collection
2517 * stop = stop data collection
2518 * reset = reset the collected data
2519 **/
2520static ssize_t
2521lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2522 const char *buf, size_t count)
2523{
2524 struct Scsi_Host *shost = class_to_shost(dev);
2525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2526 struct lpfc_hba *phba = vport->phba;
2527#define LPFC_MAX_DATA_CTRL_LEN 1024
2528 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2529 unsigned long i;
2530 char *str_ptr, *token;
2531 struct lpfc_vport **vports;
2532 struct Scsi_Host *v_shost;
2533 char *bucket_type_str, *base_str, *step_str;
2534 unsigned long base, step, bucket_type;
2535
2536 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002537 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002538 return -EINVAL;
2539
2540 strcpy(bucket_data, buf);
2541 str_ptr = &bucket_data[0];
2542 /* Ignore this token - this is command token */
2543 token = strsep(&str_ptr, "\t ");
2544 if (!token)
2545 return -EINVAL;
2546
2547 bucket_type_str = strsep(&str_ptr, "\t ");
2548 if (!bucket_type_str)
2549 return -EINVAL;
2550
2551 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2552 bucket_type = LPFC_LINEAR_BUCKET;
2553 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2554 bucket_type = LPFC_POWER2_BUCKET;
2555 else
2556 return -EINVAL;
2557
2558 base_str = strsep(&str_ptr, "\t ");
2559 if (!base_str)
2560 return -EINVAL;
2561 base = simple_strtoul(base_str, NULL, 0);
2562
2563 step_str = strsep(&str_ptr, "\t ");
2564 if (!step_str)
2565 return -EINVAL;
2566 step = simple_strtoul(step_str, NULL, 0);
2567 if (!step)
2568 return -EINVAL;
2569
2570 /* Block the data collection for every vport */
2571 vports = lpfc_create_vport_work_array(phba);
2572 if (vports == NULL)
2573 return -ENOMEM;
2574
James Smartf4b4c682009-05-22 14:53:12 -04002575 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002576 v_shost = lpfc_shost_from_vport(vports[i]);
2577 spin_lock_irq(v_shost->host_lock);
2578 /* Block and reset data collection */
2579 vports[i]->stat_data_blocked = 1;
2580 if (vports[i]->stat_data_enabled)
2581 lpfc_vport_reset_stat_data(vports[i]);
2582 spin_unlock_irq(v_shost->host_lock);
2583 }
2584
2585 /* Set the bucket attributes */
2586 phba->bucket_type = bucket_type;
2587 phba->bucket_base = base;
2588 phba->bucket_step = step;
2589
James Smartf4b4c682009-05-22 14:53:12 -04002590 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002591 v_shost = lpfc_shost_from_vport(vports[i]);
2592
2593 /* Unblock data collection */
2594 spin_lock_irq(v_shost->host_lock);
2595 vports[i]->stat_data_blocked = 0;
2596 spin_unlock_irq(v_shost->host_lock);
2597 }
2598 lpfc_destroy_vport_work_array(phba, vports);
2599 return strlen(buf);
2600 }
2601
2602 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2603 vports = lpfc_create_vport_work_array(phba);
2604 if (vports == NULL)
2605 return -ENOMEM;
2606
James Smartf4b4c682009-05-22 14:53:12 -04002607 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002608 v_shost = lpfc_shost_from_vport(vports[i]);
2609 spin_lock_irq(shost->host_lock);
2610 vports[i]->stat_data_blocked = 1;
2611 lpfc_free_bucket(vport);
2612 vport->stat_data_enabled = 0;
2613 vports[i]->stat_data_blocked = 0;
2614 spin_unlock_irq(shost->host_lock);
2615 }
2616 lpfc_destroy_vport_work_array(phba, vports);
2617 phba->bucket_type = LPFC_NO_BUCKET;
2618 phba->bucket_base = 0;
2619 phba->bucket_step = 0;
2620 return strlen(buf);
2621 }
2622
2623 if (!strncmp(buf, "start", strlen("start"))) {
2624 /* If no buckets configured return error */
2625 if (phba->bucket_type == LPFC_NO_BUCKET)
2626 return -EINVAL;
2627 spin_lock_irq(shost->host_lock);
2628 if (vport->stat_data_enabled) {
2629 spin_unlock_irq(shost->host_lock);
2630 return strlen(buf);
2631 }
2632 lpfc_alloc_bucket(vport);
2633 vport->stat_data_enabled = 1;
2634 spin_unlock_irq(shost->host_lock);
2635 return strlen(buf);
2636 }
2637
2638 if (!strncmp(buf, "stop", strlen("stop"))) {
2639 spin_lock_irq(shost->host_lock);
2640 if (vport->stat_data_enabled == 0) {
2641 spin_unlock_irq(shost->host_lock);
2642 return strlen(buf);
2643 }
2644 lpfc_free_bucket(vport);
2645 vport->stat_data_enabled = 0;
2646 spin_unlock_irq(shost->host_lock);
2647 return strlen(buf);
2648 }
2649
2650 if (!strncmp(buf, "reset", strlen("reset"))) {
2651 if ((phba->bucket_type == LPFC_NO_BUCKET)
2652 || !vport->stat_data_enabled)
2653 return strlen(buf);
2654 spin_lock_irq(shost->host_lock);
2655 vport->stat_data_blocked = 1;
2656 lpfc_vport_reset_stat_data(vport);
2657 vport->stat_data_blocked = 0;
2658 spin_unlock_irq(shost->host_lock);
2659 return strlen(buf);
2660 }
2661 return -EINVAL;
2662}
2663
2664
2665/**
James Smart3621a712009-04-06 18:47:14 -04002666 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002667 * @dev: Pointer to class device object.
2668 * @buf: Data buffer.
2669 *
2670 * This function is the read call back function for
2671 * lpfc_stat_data_ctrl sysfs file. This function report the
2672 * current statistical data collection state.
2673 **/
2674static ssize_t
2675lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2676 char *buf)
2677{
2678 struct Scsi_Host *shost = class_to_shost(dev);
2679 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2680 struct lpfc_hba *phba = vport->phba;
2681 int index = 0;
2682 int i;
2683 char *bucket_type;
2684 unsigned long bucket_value;
2685
2686 switch (phba->bucket_type) {
2687 case LPFC_LINEAR_BUCKET:
2688 bucket_type = "linear";
2689 break;
2690 case LPFC_POWER2_BUCKET:
2691 bucket_type = "power2";
2692 break;
2693 default:
2694 bucket_type = "No Bucket";
2695 break;
2696 }
2697
2698 sprintf(&buf[index], "Statistical Data enabled :%d, "
2699 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2700 " Bucket step :%d\nLatency Ranges :",
2701 vport->stat_data_enabled, vport->stat_data_blocked,
2702 bucket_type, phba->bucket_base, phba->bucket_step);
2703 index = strlen(buf);
2704 if (phba->bucket_type != LPFC_NO_BUCKET) {
2705 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2706 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2707 bucket_value = phba->bucket_base +
2708 phba->bucket_step * i;
2709 else
2710 bucket_value = phba->bucket_base +
2711 (1 << i) * phba->bucket_step;
2712
2713 if (index + 10 > PAGE_SIZE)
2714 break;
2715 sprintf(&buf[index], "%08ld ", bucket_value);
2716 index = strlen(buf);
2717 }
2718 }
2719 sprintf(&buf[index], "\n");
2720 return strlen(buf);
2721}
2722
2723/*
2724 * Sysfs attribute to control the statistical data collection.
2725 */
2726static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2727 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2728
2729/*
2730 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2731 */
2732
2733/*
2734 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2735 * for each target.
2736 */
2737#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2738#define MAX_STAT_DATA_SIZE_PER_TARGET \
2739 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2740
2741
2742/**
James Smart3621a712009-04-06 18:47:14 -04002743 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002744 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002745 * @kobj: Pointer to the kernel object
2746 * @bin_attr: Attribute object
2747 * @buff: Buffer pointer
2748 * @off: File offset
2749 * @count: Buffer size
2750 *
2751 * This function is the read call back function for lpfc_drvr_stat_data
2752 * sysfs file. This function export the statistical data to user
2753 * applications.
2754 **/
2755static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002756sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2757 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002758 char *buf, loff_t off, size_t count)
2759{
2760 struct device *dev = container_of(kobj, struct device,
2761 kobj);
2762 struct Scsi_Host *shost = class_to_shost(dev);
2763 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2764 struct lpfc_hba *phba = vport->phba;
2765 int i = 0, index = 0;
2766 unsigned long nport_index;
2767 struct lpfc_nodelist *ndlp = NULL;
2768 nport_index = (unsigned long)off /
2769 MAX_STAT_DATA_SIZE_PER_TARGET;
2770
2771 if (!vport->stat_data_enabled || vport->stat_data_blocked
2772 || (phba->bucket_type == LPFC_NO_BUCKET))
2773 return 0;
2774
2775 spin_lock_irq(shost->host_lock);
2776 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2777 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2778 continue;
2779
2780 if (nport_index > 0) {
2781 nport_index--;
2782 continue;
2783 }
2784
2785 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2786 > count)
2787 break;
2788
2789 if (!ndlp->lat_data)
2790 continue;
2791
2792 /* Print the WWN */
2793 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2794 ndlp->nlp_portname.u.wwn[0],
2795 ndlp->nlp_portname.u.wwn[1],
2796 ndlp->nlp_portname.u.wwn[2],
2797 ndlp->nlp_portname.u.wwn[3],
2798 ndlp->nlp_portname.u.wwn[4],
2799 ndlp->nlp_portname.u.wwn[5],
2800 ndlp->nlp_portname.u.wwn[6],
2801 ndlp->nlp_portname.u.wwn[7]);
2802
2803 index = strlen(buf);
2804
2805 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2806 sprintf(&buf[index], "%010u,",
2807 ndlp->lat_data[i].cmd_count);
2808 index = strlen(buf);
2809 }
2810 sprintf(&buf[index], "\n");
2811 index = strlen(buf);
2812 }
2813 spin_unlock_irq(shost->host_lock);
2814 return index;
2815}
2816
2817static struct bin_attribute sysfs_drvr_stat_data_attr = {
2818 .attr = {
2819 .name = "lpfc_drvr_stat_data",
2820 .mode = S_IRUSR,
2821 .owner = THIS_MODULE,
2822 },
2823 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2824 .read = sysfs_drvr_stat_data_read,
2825 .write = NULL,
2826};
2827
dea31012005-04-17 16:05:31 -05002828/*
2829# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2830# connection.
2831# 0 = auto select (default)
2832# 1 = 1 Gigabaud
2833# 2 = 2 Gigabaud
2834# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002835# 8 = 8 Gigabaud
2836# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002837*/
James Smarte59058c2008-08-24 21:49:00 -04002838
2839/**
James Smart3621a712009-04-06 18:47:14 -04002840 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002841 * @phba: lpfc_hba pointer.
2842 * @val: link speed value.
2843 *
2844 * Description:
2845 * If val is in a valid range then set the adapter's link speed field and
2846 * issue a lip; if the lip fails reset the link speed to the old value.
2847 *
2848 * Notes:
2849 * If the value is not in range log a kernel error message and return an error.
2850 *
2851 * Returns:
2852 * zero if val is in range and lip okay.
2853 * non-zero return value from lpfc_issue_lip()
2854 * -EINVAL val out of range
2855 **/
James Smarta257bf92009-04-06 18:48:10 -04002856static ssize_t
2857lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2858 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002859{
James Smarta257bf92009-04-06 18:48:10 -04002860 struct Scsi_Host *shost = class_to_shost(dev);
2861 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2862 struct lpfc_hba *phba = vport->phba;
2863 int val = 0;
2864 int nolip = 0;
2865 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002866 int err;
2867 uint32_t prev_val;
2868
James Smarta257bf92009-04-06 18:48:10 -04002869 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2870 nolip = 1;
2871 val_buf = &buf[strlen("nolip ")];
2872 }
2873
2874 if (!isdigit(val_buf[0]))
2875 return -EINVAL;
2876 if (sscanf(val_buf, "%i", &val) != 1)
2877 return -EINVAL;
2878
James Smart83108bd2008-01-11 01:53:09 -05002879 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2880 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2881 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2882 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2883 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2884 return -EINVAL;
2885
James Smarta257bf92009-04-06 18:48:10 -04002886 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002887 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2888 prev_val = phba->cfg_link_speed;
2889 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002890 if (nolip)
2891 return strlen(buf);
2892
James Smart83108bd2008-01-11 01:53:09 -05002893 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002894 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002895 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002896 return -EINVAL;
2897 } else
2898 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002899 }
2900
2901 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2902 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2903 "allowed range is [0, 8]\n",
2904 phba->brd_no, val);
2905 return -EINVAL;
2906}
2907
2908static int lpfc_link_speed = 0;
2909module_param(lpfc_link_speed, int, 0);
2910MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2911lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002912
2913/**
James Smart3621a712009-04-06 18:47:14 -04002914 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002915 * @phba: lpfc_hba pointer.
2916 * @val: link speed value.
2917 *
2918 * Description:
2919 * If val is in a valid range then set the adapter's link speed field.
2920 *
2921 * Notes:
2922 * If the value is not in range log a kernel error message, clear the link
2923 * speed and return an error.
2924 *
2925 * Returns:
2926 * zero if val saved.
2927 * -EINVAL val out of range
2928 **/
James Smart83108bd2008-01-11 01:53:09 -05002929static int
2930lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2931{
2932 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2933 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2934 phba->cfg_link_speed = val;
2935 return 0;
2936 }
2937 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002938 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002939 "be set to %d, allowed values are "
2940 "["LPFC_LINK_SPEED_STRING"]\n", val);
2941 phba->cfg_link_speed = 0;
2942 return -EINVAL;
2943}
2944
Tony Jonesee959b02008-02-22 00:13:36 +01002945static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002946 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002947
2948/*
James Smart0d878412009-10-02 15:16:56 -04002949# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2950# 0 = aer disabled or not supported
2951# 1 = aer supported and enabled (default)
2952# Value range is [0,1]. Default value is 1.
2953*/
2954
2955/**
2956 * lpfc_aer_support_store - Set the adapter for aer support
2957 *
2958 * @dev: class device that is converted into a Scsi_host.
2959 * @attr: device attribute, not used.
2960 * @buf: containing the string "selective".
2961 * @count: unused variable.
2962 *
2963 * Description:
2964 * If the val is 1 and currently the device's AER capability was not
2965 * enabled, invoke the kernel's enable AER helper routine, trying to
2966 * enable the device's AER capability. If the helper routine enabling
2967 * AER returns success, update the device's cfg_aer_support flag to
2968 * indicate AER is supported by the device; otherwise, if the device
2969 * AER capability is already enabled to support AER, then do nothing.
2970 *
2971 * If the val is 0 and currently the device's AER support was enabled,
2972 * invoke the kernel's disable AER helper routine. After that, update
2973 * the device's cfg_aer_support flag to indicate AER is not supported
2974 * by the device; otherwise, if the device AER capability is already
2975 * disabled from supporting AER, then do nothing.
2976 *
2977 * Returns:
2978 * length of the buf on success if val is in range the intended mode
2979 * is supported.
2980 * -EINVAL if val out of range or intended mode is not supported.
2981 **/
2982static ssize_t
2983lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2984 const char *buf, size_t count)
2985{
2986 struct Scsi_Host *shost = class_to_shost(dev);
2987 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2988 struct lpfc_hba *phba = vport->phba;
2989 int val = 0, rc = -EINVAL;
2990
2991 if (!isdigit(buf[0]))
2992 return -EINVAL;
2993 if (sscanf(buf, "%i", &val) != 1)
2994 return -EINVAL;
2995
2996 switch (val) {
2997 case 0:
2998 if (phba->hba_flag & HBA_AER_ENABLED) {
2999 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3000 if (!rc) {
3001 spin_lock_irq(&phba->hbalock);
3002 phba->hba_flag &= ~HBA_AER_ENABLED;
3003 spin_unlock_irq(&phba->hbalock);
3004 phba->cfg_aer_support = 0;
3005 rc = strlen(buf);
3006 } else
James Smart891478a2009-11-18 15:40:23 -05003007 rc = -EPERM;
3008 } else {
James Smart0d878412009-10-02 15:16:56 -04003009 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003010 rc = strlen(buf);
3011 }
James Smart0d878412009-10-02 15:16:56 -04003012 break;
3013 case 1:
3014 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3015 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3016 if (!rc) {
3017 spin_lock_irq(&phba->hbalock);
3018 phba->hba_flag |= HBA_AER_ENABLED;
3019 spin_unlock_irq(&phba->hbalock);
3020 phba->cfg_aer_support = 1;
3021 rc = strlen(buf);
3022 } else
James Smart891478a2009-11-18 15:40:23 -05003023 rc = -EPERM;
3024 } else {
James Smart0d878412009-10-02 15:16:56 -04003025 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003026 rc = strlen(buf);
3027 }
James Smart0d878412009-10-02 15:16:56 -04003028 break;
3029 default:
3030 rc = -EINVAL;
3031 break;
3032 }
3033 return rc;
3034}
3035
3036static int lpfc_aer_support = 1;
3037module_param(lpfc_aer_support, int, 1);
3038MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3039lpfc_param_show(aer_support)
3040
3041/**
3042 * lpfc_aer_support_init - Set the initial adapters aer support flag
3043 * @phba: lpfc_hba pointer.
3044 * @val: link speed value.
3045 *
3046 * Description:
3047 * If val is in a valid range [0,1], then set the adapter's initial
3048 * cfg_aer_support field. It will be up to the driver's probe_one
3049 * routine to determine whether the device's AER support can be set
3050 * or not.
3051 *
3052 * Notes:
3053 * If the value is not in range log a kernel error message, and
3054 * choose the default value of setting AER support and return.
3055 *
3056 * Returns:
3057 * zero if val saved.
3058 * -EINVAL val out of range
3059 **/
3060static int
3061lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3062{
3063 if (val == 0 || val == 1) {
3064 phba->cfg_aer_support = val;
3065 return 0;
3066 }
3067 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3068 "2712 lpfc_aer_support attribute value %d out "
3069 "of range, allowed values are 0|1, setting it "
3070 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003071 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003072 phba->cfg_aer_support = 1;
3073 return -EINVAL;
3074}
3075
3076static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3077 lpfc_aer_support_show, lpfc_aer_support_store);
3078
3079/**
3080 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3081 * @dev: class device that is converted into a Scsi_host.
3082 * @attr: device attribute, not used.
3083 * @buf: containing the string "selective".
3084 * @count: unused variable.
3085 *
3086 * Description:
3087 * If the @buf contains 1 and the device currently has the AER support
3088 * enabled, then invokes the kernel AER helper routine
3089 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3090 * error status register.
3091 *
3092 * Notes:
3093 *
3094 * Returns:
3095 * -EINVAL if the buf does not contain the 1 or the device is not currently
3096 * enabled with the AER support.
3097 **/
3098static ssize_t
3099lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3100 const char *buf, size_t count)
3101{
3102 struct Scsi_Host *shost = class_to_shost(dev);
3103 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3104 struct lpfc_hba *phba = vport->phba;
3105 int val, rc = -1;
3106
3107 if (!isdigit(buf[0]))
3108 return -EINVAL;
3109 if (sscanf(buf, "%i", &val) != 1)
3110 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003111 if (val != 1)
3112 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003113
James Smart891478a2009-11-18 15:40:23 -05003114 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003115 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3116
3117 if (rc == 0)
3118 return strlen(buf);
3119 else
James Smart891478a2009-11-18 15:40:23 -05003120 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003121}
3122
3123static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3124 lpfc_aer_cleanup_state);
3125
3126/*
dea31012005-04-17 16:05:31 -05003127# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3128# Value range is [2,3]. Default value is 3.
3129*/
James Smart3de2a652007-08-02 11:09:59 -04003130LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3131 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003132
3133/*
3134# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3135# is [0,1]. Default value is 0.
3136*/
James Smart3de2a652007-08-02 11:09:59 -04003137LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3138 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003139
3140/*
James Smart977b5a02008-09-07 11:52:04 -04003141# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3142# depth. Default value is 0. When the value of this parameter is zero the
3143# SCSI command completion time is not used for controlling I/O queue depth. When
3144# the parameter is set to a non-zero value, the I/O queue depth is controlled
3145# to limit the I/O completion time to the parameter value.
3146# The value is set in milliseconds.
3147*/
3148static int lpfc_max_scsicmpl_time;
3149module_param(lpfc_max_scsicmpl_time, int, 0);
3150MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3151 "Use command completion time to control queue depth");
3152lpfc_vport_param_show(max_scsicmpl_time);
3153lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3154static int
3155lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3156{
3157 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3158 struct lpfc_nodelist *ndlp, *next_ndlp;
3159
3160 if (val == vport->cfg_max_scsicmpl_time)
3161 return 0;
3162 if ((val < 0) || (val > 60000))
3163 return -EINVAL;
3164 vport->cfg_max_scsicmpl_time = val;
3165
3166 spin_lock_irq(shost->host_lock);
3167 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3168 if (!NLP_CHK_NODE_ACT(ndlp))
3169 continue;
3170 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3171 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003172 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003173 }
3174 spin_unlock_irq(shost->host_lock);
3175 return 0;
3176}
3177lpfc_vport_param_store(max_scsicmpl_time);
3178static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3179 lpfc_max_scsicmpl_time_show,
3180 lpfc_max_scsicmpl_time_store);
3181
3182/*
dea31012005-04-17 16:05:31 -05003183# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3184# range is [0,1]. Default value is 0.
3185*/
3186LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3187
3188/*
3189# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3190# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003191# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003192# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3193# cr_delay is set to 0.
3194*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003195LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003196 "interrupt response is generated");
3197
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003198LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003199 "interrupt response is generated");
3200
3201/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003202# lpfc_multi_ring_support: Determines how many rings to spread available
3203# cmd/rsp IOCB entries across.
3204# Value range is [1,2]. Default value is 1.
3205*/
3206LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3207 "SLI rings to spread IOCB entries across");
3208
3209/*
James Smarta4bc3372006-12-02 13:34:16 -05003210# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3211# identifies what rctl value to configure the additional ring for.
3212# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3213*/
James Smart6a9c52c2009-10-02 15:16:51 -04003214LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003215 255, "Identifies RCTL for additional ring configuration");
3216
3217/*
3218# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3219# identifies what type value to configure the additional ring for.
3220# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3221*/
James Smart6a9c52c2009-10-02 15:16:51 -04003222LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003223 255, "Identifies TYPE for additional ring configuration");
3224
3225/*
dea31012005-04-17 16:05:31 -05003226# lpfc_fdmi_on: controls FDMI support.
3227# 0 = no FDMI support
3228# 1 = support FDMI without attribute of hostname
3229# 2 = support FDMI with attribute of hostname
3230# Value range [0,2]. Default value is 0.
3231*/
James Smart3de2a652007-08-02 11:09:59 -04003232LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003233
3234/*
3235# Specifies the maximum number of ELS cmds we can have outstanding (for
3236# discovery). Value range is [1,64]. Default value = 32.
3237*/
James Smart3de2a652007-08-02 11:09:59 -04003238LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003239 "during discovery");
3240
3241/*
James Smart65a29c12006-07-06 15:50:50 -04003242# lpfc_max_luns: maximum allowed LUN.
3243# Value range is [0,65535]. Default value is 255.
3244# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003245*/
James Smart3de2a652007-08-02 11:09:59 -04003246LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003247
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003248/*
3249# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3250# Value range is [1,255], default value is 10.
3251*/
3252LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3253 "Milliseconds driver will wait between polling FCP ring");
3254
James Smart4ff43242006-12-02 13:34:56 -05003255/*
3256# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3257# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003258# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003259# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003260# 2 = MSI-X enabled (default)
3261# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003262*/
George Kadianakis8605c462010-01-17 21:19:31 +02003263LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003264 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003265
James Smart13815c82008-01-11 01:52:48 -05003266/*
James Smartda0436e2009-05-22 14:51:39 -04003267# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3268#
3269# Value range is [636,651042]. Default value is 10000.
3270*/
3271LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3272 "Set the maximum number of fast-path FCP interrupts per second");
3273
3274/*
3275# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3276#
3277# Value range is [1,31]. Default value is 4.
3278*/
3279LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3280 "Set the number of fast-path FCP work queues, if possible");
3281
3282/*
3283# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3284#
3285# Value range is [1,7]. Default value is 1.
3286*/
3287LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3288 "Set the number of fast-path FCP event queues, if possible");
3289
3290/*
James Smart13815c82008-01-11 01:52:48 -05003291# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3292# 0 = HBA resets disabled
3293# 1 = HBA resets enabled (default)
3294# Value range is [0,1]. Default value is 1.
3295*/
3296LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003297
James Smart13815c82008-01-11 01:52:48 -05003298/*
3299# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3300# 0 = HBA Heartbeat disabled
3301# 1 = HBA Heartbeat enabled (default)
3302# Value range is [0,1]. Default value is 1.
3303*/
3304LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003305
James Smart83108bd2008-01-11 01:53:09 -05003306/*
James Smart81301a92008-12-04 22:39:46 -05003307# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3308# 0 = BlockGuard disabled (default)
3309# 1 = BlockGuard enabled
3310# Value range is [0,1]. Default value is 0.
3311*/
3312LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3313
James Smart6fb120a2009-05-22 14:52:59 -04003314/*
James Smart81301a92008-12-04 22:39:46 -05003315# lpfc_prot_mask: i
3316# - Bit mask of host protection capabilities used to register with the
3317# SCSI mid-layer
3318# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3319# - Allows you to ultimately specify which profiles to use
3320# - Default will result in registering capabilities for all profiles.
3321#
3322*/
James Smartbc739052010-08-04 16:11:18 -04003323unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003324
3325module_param(lpfc_prot_mask, uint, 0);
3326MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3327
3328/*
3329# lpfc_prot_guard: i
3330# - Bit mask of protection guard types to register with the SCSI mid-layer
3331# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3332# - Allows you to ultimately specify which profiles to use
3333# - Default will result in registering capabilities for all guard types
3334#
3335*/
3336unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3337module_param(lpfc_prot_guard, byte, 0);
3338MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3339
3340
3341/*
James Smart3621a712009-04-06 18:47:14 -04003342 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003343 * This value can be set to values between 64 and 256. The default value is
3344 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3345 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3346 */
3347LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3348 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3349
James Smart81301a92008-12-04 22:39:46 -05003350LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3351 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3352 "Max Protection Scatter Gather Segment Count");
3353
Tony Jonesee959b02008-02-22 00:13:36 +01003354struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003355 &dev_attr_bg_info,
3356 &dev_attr_bg_guard_err,
3357 &dev_attr_bg_apptag_err,
3358 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003359 &dev_attr_info,
3360 &dev_attr_serialnum,
3361 &dev_attr_modeldesc,
3362 &dev_attr_modelname,
3363 &dev_attr_programtype,
3364 &dev_attr_portnum,
3365 &dev_attr_fwrev,
3366 &dev_attr_hdw,
3367 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003368 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003369 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003370 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003371 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003372 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003373 &dev_attr_lpfc_temp_sensor,
3374 &dev_attr_lpfc_log_verbose,
3375 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003376 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003377 &dev_attr_lpfc_hba_queue_depth,
3378 &dev_attr_lpfc_peer_port_login,
3379 &dev_attr_lpfc_nodev_tmo,
3380 &dev_attr_lpfc_devloss_tmo,
3381 &dev_attr_lpfc_fcp_class,
3382 &dev_attr_lpfc_use_adisc,
3383 &dev_attr_lpfc_ack0,
3384 &dev_attr_lpfc_topology,
3385 &dev_attr_lpfc_scan_down,
3386 &dev_attr_lpfc_link_speed,
3387 &dev_attr_lpfc_cr_delay,
3388 &dev_attr_lpfc_cr_count,
3389 &dev_attr_lpfc_multi_ring_support,
3390 &dev_attr_lpfc_multi_ring_rctl,
3391 &dev_attr_lpfc_multi_ring_type,
3392 &dev_attr_lpfc_fdmi_on,
3393 &dev_attr_lpfc_max_luns,
3394 &dev_attr_lpfc_enable_npiv,
3395 &dev_attr_nport_evt_cnt,
3396 &dev_attr_board_mode,
3397 &dev_attr_max_vpi,
3398 &dev_attr_used_vpi,
3399 &dev_attr_max_rpi,
3400 &dev_attr_used_rpi,
3401 &dev_attr_max_xri,
3402 &dev_attr_used_xri,
3403 &dev_attr_npiv_info,
3404 &dev_attr_issue_reset,
3405 &dev_attr_lpfc_poll,
3406 &dev_attr_lpfc_poll_tmo,
3407 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003408 &dev_attr_lpfc_fcp_imax,
3409 &dev_attr_lpfc_fcp_wq_count,
3410 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003411 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003412 &dev_attr_lpfc_soft_wwnn,
3413 &dev_attr_lpfc_soft_wwpn,
3414 &dev_attr_lpfc_soft_wwn_enable,
3415 &dev_attr_lpfc_enable_hba_reset,
3416 &dev_attr_lpfc_enable_hba_heartbeat,
3417 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003418 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003419 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003420 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003421 &dev_attr_lpfc_aer_support,
3422 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003423 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003424 &dev_attr_lpfc_iocb_cnt,
3425 &dev_attr_iocb_hw,
3426 &dev_attr_txq_hw,
3427 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003428 &dev_attr_lpfc_fips_level,
3429 &dev_attr_lpfc_fips_rev,
dea31012005-04-17 16:05:31 -05003430 NULL,
3431};
3432
Tony Jonesee959b02008-02-22 00:13:36 +01003433struct device_attribute *lpfc_vport_attrs[] = {
3434 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003435 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003436 &dev_attr_num_discovered_ports,
3437 &dev_attr_lpfc_drvr_version,
3438 &dev_attr_lpfc_log_verbose,
3439 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003440 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003441 &dev_attr_lpfc_nodev_tmo,
3442 &dev_attr_lpfc_devloss_tmo,
3443 &dev_attr_lpfc_hba_queue_depth,
3444 &dev_attr_lpfc_peer_port_login,
3445 &dev_attr_lpfc_restrict_login,
3446 &dev_attr_lpfc_fcp_class,
3447 &dev_attr_lpfc_use_adisc,
3448 &dev_attr_lpfc_fdmi_on,
3449 &dev_attr_lpfc_max_luns,
3450 &dev_attr_nport_evt_cnt,
3451 &dev_attr_npiv_info,
3452 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003453 &dev_attr_lpfc_max_scsicmpl_time,
3454 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003455 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003456 &dev_attr_lpfc_fips_level,
3457 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003458 NULL,
3459};
3460
James Smarte59058c2008-08-24 21:49:00 -04003461/**
James Smart3621a712009-04-06 18:47:14 -04003462 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003463 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003464 * @kobj: kernel kobject that contains the kernel class device.
3465 * @bin_attr: kernel attributes passed to us.
3466 * @buf: contains the data to be written to the adapter IOREG space.
3467 * @off: offset into buffer to beginning of data.
3468 * @count: bytes to transfer.
3469 *
3470 * Description:
3471 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3472 * Uses the adapter io control registers to send buf contents to the adapter.
3473 *
3474 * Returns:
3475 * -ERANGE off and count combo out of range
3476 * -EINVAL off, count or buff address invalid
3477 * -EPERM adapter is offline
3478 * value of count, buf contents written
3479 **/
dea31012005-04-17 16:05:31 -05003480static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003481sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3482 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003483 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003484{
3485 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003486 struct device *dev = container_of(kobj, struct device, kobj);
3487 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003488 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3489 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003490
James Smartf1126682009-06-10 17:22:44 -04003491 if (phba->sli_rev >= LPFC_SLI_REV4)
3492 return -EPERM;
3493
dea31012005-04-17 16:05:31 -05003494 if ((off + count) > FF_REG_AREA_SIZE)
3495 return -ERANGE;
3496
3497 if (count == 0) return 0;
3498
3499 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3500 return -EINVAL;
3501
James Smart2e0fef82007-06-17 19:56:36 -05003502 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003503 return -EPERM;
3504 }
3505
James Smart2e0fef82007-06-17 19:56:36 -05003506 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003507 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3508 writel(*((uint32_t *)(buf + buf_off)),
3509 phba->ctrl_regs_memmap_p + off + buf_off);
3510
James Smart2e0fef82007-06-17 19:56:36 -05003511 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003512
3513 return count;
3514}
3515
James Smarte59058c2008-08-24 21:49:00 -04003516/**
James Smart3621a712009-04-06 18:47:14 -04003517 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003518 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003519 * @kobj: kernel kobject that contains the kernel class device.
3520 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003521 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003522 * @off: offset into buffer to beginning of data.
3523 * @count: bytes to transfer.
3524 *
3525 * Description:
3526 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3527 * Uses the adapter io control registers to read data into buf.
3528 *
3529 * Returns:
3530 * -ERANGE off and count combo out of range
3531 * -EINVAL off, count or buff address invalid
3532 * value of count, buf contents read
3533 **/
dea31012005-04-17 16:05:31 -05003534static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003535sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3536 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003537 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003538{
3539 size_t buf_off;
3540 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003541 struct device *dev = container_of(kobj, struct device, kobj);
3542 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003543 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3544 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003545
James Smartf1126682009-06-10 17:22:44 -04003546 if (phba->sli_rev >= LPFC_SLI_REV4)
3547 return -EPERM;
3548
dea31012005-04-17 16:05:31 -05003549 if (off > FF_REG_AREA_SIZE)
3550 return -ERANGE;
3551
3552 if ((off + count) > FF_REG_AREA_SIZE)
3553 count = FF_REG_AREA_SIZE - off;
3554
3555 if (count == 0) return 0;
3556
3557 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3558 return -EINVAL;
3559
James Smart2e0fef82007-06-17 19:56:36 -05003560 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003561
3562 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3563 tmp_ptr = (uint32_t *)(buf + buf_off);
3564 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3565 }
3566
James Smart2e0fef82007-06-17 19:56:36 -05003567 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003568
3569 return count;
3570}
3571
3572static struct bin_attribute sysfs_ctlreg_attr = {
3573 .attr = {
3574 .name = "ctlreg",
3575 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003576 },
3577 .size = 256,
3578 .read = sysfs_ctlreg_read,
3579 .write = sysfs_ctlreg_write,
3580};
3581
James Smarte59058c2008-08-24 21:49:00 -04003582/**
James Smart3621a712009-04-06 18:47:14 -04003583 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003584 * @phba: lpfc_hba pointer
3585 **/
dea31012005-04-17 16:05:31 -05003586static void
James Smart2e0fef82007-06-17 19:56:36 -05003587sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003588{
3589 phba->sysfs_mbox.state = SMBOX_IDLE;
3590 phba->sysfs_mbox.offset = 0;
3591
3592 if (phba->sysfs_mbox.mbox) {
3593 mempool_free(phba->sysfs_mbox.mbox,
3594 phba->mbox_mem_pool);
3595 phba->sysfs_mbox.mbox = NULL;
3596 }
3597}
3598
James Smarte59058c2008-08-24 21:49:00 -04003599/**
James Smart3621a712009-04-06 18:47:14 -04003600 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003601 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003602 * @kobj: kernel kobject that contains the kernel class device.
3603 * @bin_attr: kernel attributes passed to us.
3604 * @buf: contains the data to be written to sysfs mbox.
3605 * @off: offset into buffer to beginning of data.
3606 * @count: bytes to transfer.
3607 *
3608 * Description:
3609 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3610 * Uses the sysfs mbox to send buf contents to the adapter.
3611 *
3612 * Returns:
3613 * -ERANGE off and count combo out of range
3614 * -EINVAL off, count or buff address invalid
3615 * zero if count is zero
3616 * -EPERM adapter is offline
3617 * -ENOMEM failed to allocate memory for the mail box
3618 * -EAGAIN offset, state or mbox is NULL
3619 * count number of bytes transferred
3620 **/
dea31012005-04-17 16:05:31 -05003621static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003622sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3623 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003624 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003625{
Tony Jonesee959b02008-02-22 00:13:36 +01003626 struct device *dev = container_of(kobj, struct device, kobj);
3627 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3629 struct lpfc_hba *phba = vport->phba;
3630 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003631
3632 if ((count + off) > MAILBOX_CMD_SIZE)
3633 return -ERANGE;
3634
3635 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3636 return -EINVAL;
3637
3638 if (count == 0)
3639 return 0;
3640
3641 if (off == 0) {
3642 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3643 if (!mbox)
3644 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003645 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003646 }
3647
James Smart2e0fef82007-06-17 19:56:36 -05003648 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003649
3650 if (off == 0) {
3651 if (phba->sysfs_mbox.mbox)
3652 mempool_free(mbox, phba->mbox_mem_pool);
3653 else
3654 phba->sysfs_mbox.mbox = mbox;
3655 phba->sysfs_mbox.state = SMBOX_WRITING;
3656 } else {
3657 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3658 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003659 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003660 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003661 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003662 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003663 }
3664 }
3665
James Smart04c68492009-05-22 14:52:52 -04003666 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003667 buf, count);
3668
3669 phba->sysfs_mbox.offset = off + count;
3670
James Smart2e0fef82007-06-17 19:56:36 -05003671 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003672
3673 return count;
3674}
3675
James Smarte59058c2008-08-24 21:49:00 -04003676/**
James Smart3621a712009-04-06 18:47:14 -04003677 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003678 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003679 * @kobj: kernel kobject that contains the kernel class device.
3680 * @bin_attr: kernel attributes passed to us.
3681 * @buf: contains the data to be read from sysfs mbox.
3682 * @off: offset into buffer to beginning of data.
3683 * @count: bytes to transfer.
3684 *
3685 * Description:
3686 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3687 * Uses the sysfs mbox to receive data from to the adapter.
3688 *
3689 * Returns:
3690 * -ERANGE off greater than mailbox command size
3691 * -EINVAL off, count or buff address invalid
3692 * zero if off and count are zero
3693 * -EACCES adapter over temp
3694 * -EPERM garbage can value to catch a multitude of errors
3695 * -EAGAIN management IO not permitted, state or off error
3696 * -ETIME mailbox timeout
3697 * -ENODEV mailbox error
3698 * count number of bytes transferred
3699 **/
dea31012005-04-17 16:05:31 -05003700static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003701sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3702 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003703 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003704{
Tony Jonesee959b02008-02-22 00:13:36 +01003705 struct device *dev = container_of(kobj, struct device, kobj);
3706 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3708 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003709 int rc;
James Smart04c68492009-05-22 14:52:52 -04003710 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003711
James Smart1dcb58e2007-04-25 09:51:30 -04003712 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003713 return -ERANGE;
3714
James Smart1dcb58e2007-04-25 09:51:30 -04003715 if ((count + off) > MAILBOX_CMD_SIZE)
3716 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003717
3718 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3719 return -EINVAL;
3720
3721 if (off && count == 0)
3722 return 0;
3723
James Smart2e0fef82007-06-17 19:56:36 -05003724 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003725
James Smart7af67052007-10-27 13:38:11 -04003726 if (phba->over_temp_state == HBA_OVER_TEMP) {
3727 sysfs_mbox_idle(phba);
3728 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003729 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003730 }
3731
dea31012005-04-17 16:05:31 -05003732 if (off == 0 &&
3733 phba->sysfs_mbox.state == SMBOX_WRITING &&
3734 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003735 pmb = &phba->sysfs_mbox.mbox->u.mb;
3736 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003737 /* Offline only */
dea31012005-04-17 16:05:31 -05003738 case MBX_INIT_LINK:
3739 case MBX_DOWN_LINK:
3740 case MBX_CONFIG_LINK:
3741 case MBX_CONFIG_RING:
3742 case MBX_RESET_RING:
3743 case MBX_UNREG_LOGIN:
3744 case MBX_CLEAR_LA:
3745 case MBX_DUMP_CONTEXT:
3746 case MBX_RUN_DIAGS:
3747 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003748 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003749 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003750 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003751 printk(KERN_WARNING "mbox_read:Command 0x%x "
3752 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003753 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003754 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003755 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003756 return -EPERM;
3757 }
James Smarta8adb832007-10-27 13:37:53 -04003758 case MBX_WRITE_NV:
3759 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003760 case MBX_LOAD_SM:
3761 case MBX_READ_NV:
3762 case MBX_READ_CONFIG:
3763 case MBX_READ_RCONFIG:
3764 case MBX_READ_STATUS:
3765 case MBX_READ_XRI:
3766 case MBX_READ_REV:
3767 case MBX_READ_LNK_STAT:
3768 case MBX_DUMP_MEMORY:
3769 case MBX_DOWN_LOAD:
3770 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003771 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003772 case MBX_LOAD_AREA:
3773 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003774 case MBX_BEACON:
3775 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003776 case MBX_SET_VARIABLE:
3777 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003778 case MBX_PORT_CAPABILITIES:
3779 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003780 break;
3781 case MBX_READ_SPARM64:
3782 case MBX_READ_LA:
3783 case MBX_READ_LA64:
3784 case MBX_REG_LOGIN:
3785 case MBX_REG_LOGIN64:
3786 case MBX_CONFIG_PORT:
3787 case MBX_RUN_BIU_DIAG:
3788 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003789 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003790 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003791 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003792 return -EPERM;
3793 default:
3794 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003795 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003796 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003797 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003798 return -EPERM;
3799 }
3800
James Smart09372822008-01-11 01:52:54 -05003801 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003802 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003803 */
James Smartd7c255b2008-08-24 21:50:00 -04003804 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003805 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3806 pmb->mbxCommand != MBX_RESTART &&
3807 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3808 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003809 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3810 "1259 mbox: Issued mailbox cmd "
3811 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003812 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003813
James Smart92d7f7b2007-06-17 19:56:38 -05003814 phba->sysfs_mbox.mbox->vport = vport;
3815
James Smart58da1ff2008-04-07 10:15:56 -04003816 /* Don't allow mailbox commands to be sent when blocked
3817 * or when in the middle of discovery
3818 */
James Smart495a7142008-06-14 22:52:59 -04003819 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003820 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003821 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003822 return -EAGAIN;
3823 }
3824
James Smart2e0fef82007-06-17 19:56:36 -05003825 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003826 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003827
James Smart2e0fef82007-06-17 19:56:36 -05003828 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003829 rc = lpfc_sli_issue_mbox (phba,
3830 phba->sysfs_mbox.mbox,
3831 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003832 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003833
3834 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003835 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003836 rc = lpfc_sli_issue_mbox_wait (phba,
3837 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003838 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003839 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003840 }
3841
3842 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003843 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003844 phba->sysfs_mbox.mbox = NULL;
3845 }
dea31012005-04-17 16:05:31 -05003846 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003847 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003848 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003849 }
3850 phba->sysfs_mbox.state = SMBOX_READING;
3851 }
3852 else if (phba->sysfs_mbox.offset != off ||
3853 phba->sysfs_mbox.state != SMBOX_READING) {
3854 printk(KERN_WARNING "mbox_read: Bad State\n");
3855 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003856 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003857 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003858 }
3859
James Smart04c68492009-05-22 14:52:52 -04003860 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003861
3862 phba->sysfs_mbox.offset = off + count;
3863
James Smart1dcb58e2007-04-25 09:51:30 -04003864 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003865 sysfs_mbox_idle(phba);
3866
James Smart2e0fef82007-06-17 19:56:36 -05003867 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003868
3869 return count;
3870}
3871
3872static struct bin_attribute sysfs_mbox_attr = {
3873 .attr = {
3874 .name = "mbox",
3875 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003876 },
James Smart1dcb58e2007-04-25 09:51:30 -04003877 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003878 .read = sysfs_mbox_read,
3879 .write = sysfs_mbox_write,
3880};
3881
James Smarte59058c2008-08-24 21:49:00 -04003882/**
James Smart3621a712009-04-06 18:47:14 -04003883 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003884 * @vport: address of lpfc vport structure.
3885 *
3886 * Return codes:
3887 * zero on success
3888 * error return code from sysfs_create_bin_file()
3889 **/
dea31012005-04-17 16:05:31 -05003890int
James Smart2e0fef82007-06-17 19:56:36 -05003891lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003892{
James Smart2e0fef82007-06-17 19:56:36 -05003893 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003894 int error;
3895
Tony Jonesee959b02008-02-22 00:13:36 +01003896 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003897 &sysfs_drvr_stat_data_attr);
3898
3899 /* Virtual ports do not need ctrl_reg and mbox */
3900 if (error || vport->port_type == LPFC_NPIV_PORT)
3901 goto out;
3902
3903 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003904 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003905 if (error)
James Smarteada2722008-12-04 22:39:13 -05003906 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003907
Tony Jonesee959b02008-02-22 00:13:36 +01003908 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003909 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003910 if (error)
3911 goto out_remove_ctlreg_attr;
3912
3913 return 0;
3914out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003915 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003916out_remove_stat_attr:
3917 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3918 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003919out:
3920 return error;
3921}
3922
James Smarte59058c2008-08-24 21:49:00 -04003923/**
James Smart3621a712009-04-06 18:47:14 -04003924 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003925 * @vport: address of lpfc vport structure.
3926 **/
dea31012005-04-17 16:05:31 -05003927void
James Smart2e0fef82007-06-17 19:56:36 -05003928lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003929{
James Smart2e0fef82007-06-17 19:56:36 -05003930 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003931 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3932 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003933 /* Virtual ports do not need ctrl_reg and mbox */
3934 if (vport->port_type == LPFC_NPIV_PORT)
3935 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003936 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3937 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003938}
3939
3940
3941/*
3942 * Dynamic FC Host Attributes Support
3943 */
3944
James Smarte59058c2008-08-24 21:49:00 -04003945/**
James Smart3621a712009-04-06 18:47:14 -04003946 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003947 * @shost: kernel scsi host pointer.
3948 **/
dea31012005-04-17 16:05:31 -05003949static void
3950lpfc_get_host_port_id(struct Scsi_Host *shost)
3951{
James Smart2e0fef82007-06-17 19:56:36 -05003952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3953
dea31012005-04-17 16:05:31 -05003954 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003955 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003956}
3957
James Smarte59058c2008-08-24 21:49:00 -04003958/**
James Smart3621a712009-04-06 18:47:14 -04003959 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003960 * @shost: kernel scsi host pointer.
3961 **/
dea31012005-04-17 16:05:31 -05003962static void
3963lpfc_get_host_port_type(struct Scsi_Host *shost)
3964{
James Smart2e0fef82007-06-17 19:56:36 -05003965 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3966 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003967
3968 spin_lock_irq(shost->host_lock);
3969
James Smart92d7f7b2007-06-17 19:56:38 -05003970 if (vport->port_type == LPFC_NPIV_PORT) {
3971 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3972 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003973 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003974 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003975 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3976 else
3977 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3978 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003979 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003980 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3981 else
3982 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3983 }
3984 } else
3985 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3986
3987 spin_unlock_irq(shost->host_lock);
3988}
3989
James Smarte59058c2008-08-24 21:49:00 -04003990/**
James Smart3621a712009-04-06 18:47:14 -04003991 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003992 * @shost: kernel scsi host pointer.
3993 **/
dea31012005-04-17 16:05:31 -05003994static void
3995lpfc_get_host_port_state(struct Scsi_Host *shost)
3996{
James Smart2e0fef82007-06-17 19:56:36 -05003997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3998 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003999
4000 spin_lock_irq(shost->host_lock);
4001
James Smart2e0fef82007-06-17 19:56:36 -05004002 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004003 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4004 else {
James Smart2e0fef82007-06-17 19:56:36 -05004005 switch (phba->link_state) {
4006 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004007 case LPFC_LINK_DOWN:
4008 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4009 break;
4010 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004011 case LPFC_CLEAR_LA:
4012 case LPFC_HBA_READY:
4013 /* Links up, beyond this port_type reports state */
4014 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4015 break;
4016 case LPFC_HBA_ERROR:
4017 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4018 break;
4019 default:
4020 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4021 break;
4022 }
4023 }
4024
4025 spin_unlock_irq(shost->host_lock);
4026}
4027
James Smarte59058c2008-08-24 21:49:00 -04004028/**
James Smart3621a712009-04-06 18:47:14 -04004029 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004030 * @shost: kernel scsi host pointer.
4031 **/
dea31012005-04-17 16:05:31 -05004032static void
4033lpfc_get_host_speed(struct Scsi_Host *shost)
4034{
James Smart2e0fef82007-06-17 19:56:36 -05004035 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004037
4038 spin_lock_irq(shost->host_lock);
4039
James Smart2e0fef82007-06-17 19:56:36 -05004040 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004041 switch(phba->fc_linkspeed) {
4042 case LA_1GHZ_LINK:
4043 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4044 break;
4045 case LA_2GHZ_LINK:
4046 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4047 break;
4048 case LA_4GHZ_LINK:
4049 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4050 break;
James Smartb87eab32007-04-25 09:53:28 -04004051 case LA_8GHZ_LINK:
4052 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4053 break;
James Smartf4b4c682009-05-22 14:53:12 -04004054 case LA_10GHZ_LINK:
4055 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4056 break;
dea31012005-04-17 16:05:31 -05004057 default:
4058 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4059 break;
4060 }
James Smart09372822008-01-11 01:52:54 -05004061 } else
4062 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004063
4064 spin_unlock_irq(shost->host_lock);
4065}
4066
James Smarte59058c2008-08-24 21:49:00 -04004067/**
James Smart3621a712009-04-06 18:47:14 -04004068 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004069 * @shost: kernel scsi host pointer.
4070 **/
dea31012005-04-17 16:05:31 -05004071static void
4072lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4073{
James Smart2e0fef82007-06-17 19:56:36 -05004074 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4075 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004076 u64 node_name;
dea31012005-04-17 16:05:31 -05004077
4078 spin_lock_irq(shost->host_lock);
4079
James Smart2e0fef82007-06-17 19:56:36 -05004080 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05004081 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004082 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004083 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004084 else
4085 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004086 node_name = 0;
dea31012005-04-17 16:05:31 -05004087
4088 spin_unlock_irq(shost->host_lock);
4089
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004090 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004091}
4092
James Smarte59058c2008-08-24 21:49:00 -04004093/**
James Smart3621a712009-04-06 18:47:14 -04004094 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004095 * @shost: kernel scsi host pointer.
4096 *
4097 * Notes:
4098 * NULL on error for link down, no mbox pool, sli2 active,
4099 * management not allowed, memory allocation error, or mbox error.
4100 *
4101 * Returns:
4102 * NULL for error
4103 * address of the adapter host statistics
4104 **/
dea31012005-04-17 16:05:31 -05004105static struct fc_host_statistics *
4106lpfc_get_stats(struct Scsi_Host *shost)
4107{
James Smart2e0fef82007-06-17 19:56:36 -05004108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4109 struct lpfc_hba *phba = vport->phba;
4110 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004111 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004112 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004113 LPFC_MBOXQ_t *pmboxq;
4114 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004115 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004116 int rc = 0;
dea31012005-04-17 16:05:31 -05004117
James Smart92d7f7b2007-06-17 19:56:38 -05004118 /*
4119 * prevent udev from issuing mailbox commands until the port is
4120 * configured.
4121 */
James Smart2e0fef82007-06-17 19:56:36 -05004122 if (phba->link_state < LPFC_LINK_DOWN ||
4123 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004124 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004125 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004126
4127 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004128 return NULL;
4129
dea31012005-04-17 16:05:31 -05004130 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4131 if (!pmboxq)
4132 return NULL;
4133 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4134
James Smart04c68492009-05-22 14:52:52 -04004135 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004136 pmb->mbxCommand = MBX_READ_STATUS;
4137 pmb->mbxOwner = OWN_HOST;
4138 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004139 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004140
James Smart75baf692010-06-08 18:31:21 -04004141 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004142 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004143 else
dea31012005-04-17 16:05:31 -05004144 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4145
4146 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004147 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004148 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004149 return NULL;
4150 }
4151
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004152 memset(hs, 0, sizeof (struct fc_host_statistics));
4153
dea31012005-04-17 16:05:31 -05004154 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4155 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4156 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4157 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4158
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004159 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004160 pmb->mbxCommand = MBX_READ_LNK_STAT;
4161 pmb->mbxOwner = OWN_HOST;
4162 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004163 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004164
James Smart75baf692010-06-08 18:31:21 -04004165 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004166 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004167 else
dea31012005-04-17 16:05:31 -05004168 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4169
4170 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004171 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004172 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004173 return NULL;
4174 }
4175
4176 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4177 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4178 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4179 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4180 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4181 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4182 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4183
James Smart64ba8812006-08-02 15:24:34 -04004184 hs->link_failure_count -= lso->link_failure_count;
4185 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4186 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4187 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4188 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4189 hs->invalid_crc_count -= lso->invalid_crc_count;
4190 hs->error_frames -= lso->error_frames;
4191
James Smart4d9ab992009-10-02 15:16:39 -04004192 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4193 hs->lip_count = -1;
4194 hs->nos_count = (phba->link_events >> 1);
4195 hs->nos_count -= lso->link_events;
4196 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004197 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004198 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004199 hs->nos_count = -1;
4200 } else {
4201 hs->lip_count = -1;
4202 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004203 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004204 }
4205
4206 hs->dumped_frames = -1;
4207
James Smart64ba8812006-08-02 15:24:34 -04004208 seconds = get_seconds();
4209 if (seconds < psli->stats_start)
4210 hs->seconds_since_last_reset = seconds +
4211 ((unsigned long)-1 - psli->stats_start);
4212 else
4213 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004214
James Smart1dcb58e2007-04-25 09:51:30 -04004215 mempool_free(pmboxq, phba->mbox_mem_pool);
4216
dea31012005-04-17 16:05:31 -05004217 return hs;
4218}
4219
James Smarte59058c2008-08-24 21:49:00 -04004220/**
James Smart3621a712009-04-06 18:47:14 -04004221 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004222 * @shost: kernel scsi host pointer.
4223 **/
James Smart64ba8812006-08-02 15:24:34 -04004224static void
4225lpfc_reset_stats(struct Scsi_Host *shost)
4226{
James Smart2e0fef82007-06-17 19:56:36 -05004227 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4228 struct lpfc_hba *phba = vport->phba;
4229 struct lpfc_sli *psli = &phba->sli;
4230 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004231 LPFC_MBOXQ_t *pmboxq;
4232 MAILBOX_t *pmb;
4233 int rc = 0;
4234
James Smart2e0fef82007-06-17 19:56:36 -05004235 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004236 return;
4237
James Smart64ba8812006-08-02 15:24:34 -04004238 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4239 if (!pmboxq)
4240 return;
4241 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4242
James Smart04c68492009-05-22 14:52:52 -04004243 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004244 pmb->mbxCommand = MBX_READ_STATUS;
4245 pmb->mbxOwner = OWN_HOST;
4246 pmb->un.varWords[0] = 0x1; /* reset request */
4247 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004248 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004249
James Smart2e0fef82007-06-17 19:56:36 -05004250 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004251 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004252 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4253 else
4254 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4255
4256 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004257 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004258 mempool_free(pmboxq, phba->mbox_mem_pool);
4259 return;
4260 }
4261
4262 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4263 pmb->mbxCommand = MBX_READ_LNK_STAT;
4264 pmb->mbxOwner = OWN_HOST;
4265 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004266 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004267
James Smart2e0fef82007-06-17 19:56:36 -05004268 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004269 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004270 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4271 else
4272 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4273
4274 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004275 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004276 mempool_free( pmboxq, phba->mbox_mem_pool);
4277 return;
4278 }
4279
4280 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4281 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4282 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4283 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4284 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4285 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4286 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004287 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4288 lso->link_events = (phba->link_events >> 1);
4289 else
4290 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004291
4292 psli->stats_start = get_seconds();
4293
James Smart1dcb58e2007-04-25 09:51:30 -04004294 mempool_free(pmboxq, phba->mbox_mem_pool);
4295
James Smart64ba8812006-08-02 15:24:34 -04004296 return;
4297}
dea31012005-04-17 16:05:31 -05004298
4299/*
4300 * The LPFC driver treats linkdown handling as target loss events so there
4301 * are no sysfs handlers for link_down_tmo.
4302 */
James Smart685f0bf2007-04-25 09:53:08 -04004303
James Smarte59058c2008-08-24 21:49:00 -04004304/**
James Smart3621a712009-04-06 18:47:14 -04004305 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004306 * @starget: kernel scsi target pointer.
4307 *
4308 * Returns:
4309 * address of the node list if found
4310 * NULL target not found
4311 **/
James Smart685f0bf2007-04-25 09:53:08 -04004312static struct lpfc_nodelist *
4313lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004314{
James Smart2e0fef82007-06-17 19:56:36 -05004315 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004317 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004318
4319 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004320 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004321 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004322 if (NLP_CHK_NODE_ACT(ndlp) &&
4323 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004324 starget->id == ndlp->nlp_sid) {
4325 spin_unlock_irq(shost->host_lock);
4326 return ndlp;
dea31012005-04-17 16:05:31 -05004327 }
4328 }
4329 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004330 return NULL;
4331}
dea31012005-04-17 16:05:31 -05004332
James Smarte59058c2008-08-24 21:49:00 -04004333/**
James Smart3621a712009-04-06 18:47:14 -04004334 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004335 * @starget: kernel scsi target pointer.
4336 **/
James Smart685f0bf2007-04-25 09:53:08 -04004337static void
4338lpfc_get_starget_port_id(struct scsi_target *starget)
4339{
4340 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4341
4342 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004343}
4344
James Smarte59058c2008-08-24 21:49:00 -04004345/**
James Smart3621a712009-04-06 18:47:14 -04004346 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004347 * @starget: kernel scsi target pointer.
4348 *
4349 * Description: Set the target node name to the ndlp node name wwn or zero.
4350 **/
dea31012005-04-17 16:05:31 -05004351static void
4352lpfc_get_starget_node_name(struct scsi_target *starget)
4353{
James Smart685f0bf2007-04-25 09:53:08 -04004354 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004355
James Smart685f0bf2007-04-25 09:53:08 -04004356 fc_starget_node_name(starget) =
4357 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004358}
4359
James Smarte59058c2008-08-24 21:49:00 -04004360/**
James Smart3621a712009-04-06 18:47:14 -04004361 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004362 * @starget: kernel scsi target pointer.
4363 *
4364 * Description: set the target port name to the ndlp port name wwn or zero.
4365 **/
dea31012005-04-17 16:05:31 -05004366static void
4367lpfc_get_starget_port_name(struct scsi_target *starget)
4368{
James Smart685f0bf2007-04-25 09:53:08 -04004369 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004370
James Smart685f0bf2007-04-25 09:53:08 -04004371 fc_starget_port_name(starget) =
4372 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004373}
4374
James Smarte59058c2008-08-24 21:49:00 -04004375/**
James Smart3621a712009-04-06 18:47:14 -04004376 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004377 * @rport: fc rport address.
4378 * @timeout: new value for dev loss tmo.
4379 *
4380 * Description:
4381 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4382 * dev_loss_tmo to one.
4383 **/
dea31012005-04-17 16:05:31 -05004384static void
dea31012005-04-17 16:05:31 -05004385lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4386{
dea31012005-04-17 16:05:31 -05004387 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004388 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004389 else
James Smartc01f3202006-08-18 17:47:08 -04004390 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004391}
4392
James Smarte59058c2008-08-24 21:49:00 -04004393/**
James Smart3621a712009-04-06 18:47:14 -04004394 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004395 *
4396 * Description:
4397 * Macro that uses field to generate a function with the name lpfc_show_rport_
4398 *
4399 * lpfc_show_rport_##field: returns the bytes formatted in buf
4400 * @cdev: class converted to an fc_rport.
4401 * @buf: on return contains the target_field or zero.
4402 *
4403 * Returns: size of formatted string.
4404 **/
dea31012005-04-17 16:05:31 -05004405#define lpfc_rport_show_function(field, format_string, sz, cast) \
4406static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004407lpfc_show_rport_##field (struct device *dev, \
4408 struct device_attribute *attr, \
4409 char *buf) \
dea31012005-04-17 16:05:31 -05004410{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004411 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004412 struct lpfc_rport_data *rdata = rport->hostdata; \
4413 return snprintf(buf, sz, format_string, \
4414 (rdata->target) ? cast rdata->target->field : 0); \
4415}
4416
4417#define lpfc_rport_rd_attr(field, format_string, sz) \
4418 lpfc_rport_show_function(field, format_string, sz, ) \
4419static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4420
James Smarteada2722008-12-04 22:39:13 -05004421/**
James Smart3621a712009-04-06 18:47:14 -04004422 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004423 * @fc_vport: The fc_vport who's symbolic name has been changed.
4424 *
4425 * Description:
4426 * This function is called by the transport after the @fc_vport's symbolic name
4427 * has been changed. This function re-registers the symbolic name with the
4428 * switch to propogate the change into the fabric if the vport is active.
4429 **/
4430static void
4431lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4432{
4433 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4434
4435 if (vport->port_state == LPFC_VPORT_READY)
4436 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4437}
dea31012005-04-17 16:05:31 -05004438
James Smartf4b4c682009-05-22 14:53:12 -04004439/**
4440 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4441 * @phba: Pointer to lpfc_hba struct.
4442 *
4443 * This function is called by the lpfc_get_cfgparam() routine to set the
4444 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4445 * log messsage according to the module's lpfc_log_verbose parameter setting
4446 * before hba port or vport created.
4447 **/
4448static void
4449lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4450{
4451 phba->cfg_log_verbose = verbose;
4452}
4453
dea31012005-04-17 16:05:31 -05004454struct fc_function_template lpfc_transport_functions = {
4455 /* fixed attributes the driver supports */
4456 .show_host_node_name = 1,
4457 .show_host_port_name = 1,
4458 .show_host_supported_classes = 1,
4459 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004460 .show_host_supported_speeds = 1,
4461 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004462 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004463
4464 /* dynamic attributes the driver supports */
4465 .get_host_port_id = lpfc_get_host_port_id,
4466 .show_host_port_id = 1,
4467
4468 .get_host_port_type = lpfc_get_host_port_type,
4469 .show_host_port_type = 1,
4470
4471 .get_host_port_state = lpfc_get_host_port_state,
4472 .show_host_port_state = 1,
4473
4474 /* active_fc4s is shown but doesn't change (thus no get function) */
4475 .show_host_active_fc4s = 1,
4476
4477 .get_host_speed = lpfc_get_host_speed,
4478 .show_host_speed = 1,
4479
4480 .get_host_fabric_name = lpfc_get_host_fabric_name,
4481 .show_host_fabric_name = 1,
4482
4483 /*
4484 * The LPFC driver treats linkdown handling as target loss events
4485 * so there are no sysfs handlers for link_down_tmo.
4486 */
4487
4488 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004489 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004490
4491 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4492 .show_rport_maxframe_size = 1,
4493 .show_rport_supported_classes = 1,
4494
dea31012005-04-17 16:05:31 -05004495 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4496 .show_rport_dev_loss_tmo = 1,
4497
4498 .get_starget_port_id = lpfc_get_starget_port_id,
4499 .show_starget_port_id = 1,
4500
4501 .get_starget_node_name = lpfc_get_starget_node_name,
4502 .show_starget_node_name = 1,
4503
4504 .get_starget_port_name = lpfc_get_starget_port_name,
4505 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004506
4507 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004508 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4509 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004510
James Smart92d7f7b2007-06-17 19:56:38 -05004511 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004512
4513 .vport_disable = lpfc_vport_disable,
4514
4515 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004516
4517 .bsg_request = lpfc_bsg_request,
4518 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004519};
4520
James Smart98c9ea52007-10-27 13:37:33 -04004521struct fc_function_template lpfc_vport_transport_functions = {
4522 /* fixed attributes the driver supports */
4523 .show_host_node_name = 1,
4524 .show_host_port_name = 1,
4525 .show_host_supported_classes = 1,
4526 .show_host_supported_fc4s = 1,
4527 .show_host_supported_speeds = 1,
4528 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004529 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004530
4531 /* dynamic attributes the driver supports */
4532 .get_host_port_id = lpfc_get_host_port_id,
4533 .show_host_port_id = 1,
4534
4535 .get_host_port_type = lpfc_get_host_port_type,
4536 .show_host_port_type = 1,
4537
4538 .get_host_port_state = lpfc_get_host_port_state,
4539 .show_host_port_state = 1,
4540
4541 /* active_fc4s is shown but doesn't change (thus no get function) */
4542 .show_host_active_fc4s = 1,
4543
4544 .get_host_speed = lpfc_get_host_speed,
4545 .show_host_speed = 1,
4546
4547 .get_host_fabric_name = lpfc_get_host_fabric_name,
4548 .show_host_fabric_name = 1,
4549
4550 /*
4551 * The LPFC driver treats linkdown handling as target loss events
4552 * so there are no sysfs handlers for link_down_tmo.
4553 */
4554
4555 .get_fc_host_stats = lpfc_get_stats,
4556 .reset_fc_host_stats = lpfc_reset_stats,
4557
4558 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4559 .show_rport_maxframe_size = 1,
4560 .show_rport_supported_classes = 1,
4561
4562 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4563 .show_rport_dev_loss_tmo = 1,
4564
4565 .get_starget_port_id = lpfc_get_starget_port_id,
4566 .show_starget_port_id = 1,
4567
4568 .get_starget_node_name = lpfc_get_starget_node_name,
4569 .show_starget_node_name = 1,
4570
4571 .get_starget_port_name = lpfc_get_starget_port_name,
4572 .show_starget_port_name = 1,
4573
4574 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4575 .terminate_rport_io = lpfc_terminate_rport_io,
4576
4577 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004578
4579 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004580};
4581
James Smarte59058c2008-08-24 21:49:00 -04004582/**
James Smart3621a712009-04-06 18:47:14 -04004583 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004584 * @phba: lpfc_hba pointer.
4585 **/
dea31012005-04-17 16:05:31 -05004586void
4587lpfc_get_cfgparam(struct lpfc_hba *phba)
4588{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004589 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4590 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004591 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004592 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4593 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004594 lpfc_ack0_init(phba, lpfc_ack0);
4595 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004596 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004597 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004598 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004599 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004600 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4601 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4602 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004603 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4604 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004605 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004606 if (phba->sli_rev == LPFC_SLI_REV4)
4607 phba->cfg_poll = 0;
4608 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004609 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004610 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004611 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004612 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004613 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004614 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004615 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004616 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004617 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004618 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004619 return;
4620}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004621
James Smarte59058c2008-08-24 21:49:00 -04004622/**
James Smart3621a712009-04-06 18:47:14 -04004623 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004624 * @vport: lpfc_vport pointer.
4625 **/
James Smart3de2a652007-08-02 11:09:59 -04004626void
4627lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4628{
James Smarte8b62012007-08-02 11:10:09 -04004629 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004630 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004631 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004632 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4633 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4634 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4635 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4636 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4637 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004638 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004639 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4640 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4641 lpfc_max_luns_init(vport, lpfc_max_luns);
4642 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004643 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004644 return;
4645}