blob: 39b0760c438d0dba811a22bee032348699b836b1 [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_sli *psli = &phba->sli;
868 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500869 LPFC_MBOXQ_t *pmboxq;
870 MAILBOX_t *pmb;
871 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400872 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500873
874 /*
875 * prevent udev from issuing mailbox commands until the port is
876 * configured.
877 */
878 if (phba->link_state < LPFC_LINK_DOWN ||
879 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400880 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500881 return 0;
882
883 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
884 return 0;
885
886 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
887 if (!pmboxq)
888 return 0;
889 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
890
James Smart04c68492009-05-22 14:52:52 -0400891 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500892 pmb->mbxCommand = MBX_READ_CONFIG;
893 pmb->mbxOwner = OWN_HOST;
894 pmboxq->context1 = NULL;
895
896 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -0400897 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart92d7f7b2007-06-17 19:56:38 -0500898 rc = MBX_NOT_FINISHED;
899 else
900 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
901
902 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500903 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500904 mempool_free(pmboxq, phba->mbox_mem_pool);
905 return 0;
906 }
907
James Smartda0436e2009-05-22 14:51:39 -0400908 if (phba->sli_rev == LPFC_SLI_REV4) {
909 rd_config = &pmboxq->u.mqe.un.rd_config;
910 if (mrpi)
911 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
912 if (arpi)
913 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
914 phba->sli4_hba.max_cfg_param.rpi_used;
915 if (mxri)
916 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
917 if (axri)
918 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
919 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400920
921 /* Account for differences with SLI-3. Get vpi count from
922 * mailbox data and subtract one for max vpi value.
923 */
924 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
925 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
926
James Smartda0436e2009-05-22 14:51:39 -0400927 if (mvpi)
James Smart15672312010-04-06 14:49:03 -0400928 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -0400929 if (avpi)
James Smart15672312010-04-06 14:49:03 -0400930 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -0400931 } else {
932 if (mrpi)
933 *mrpi = pmb->un.varRdConfig.max_rpi;
934 if (arpi)
935 *arpi = pmb->un.varRdConfig.avail_rpi;
936 if (mxri)
937 *mxri = pmb->un.varRdConfig.max_xri;
938 if (axri)
939 *axri = pmb->un.varRdConfig.avail_xri;
940 if (mvpi)
941 *mvpi = pmb->un.varRdConfig.max_vpi;
942 if (avpi)
943 *avpi = pmb->un.varRdConfig.avail_vpi;
944 }
James Smart92d7f7b2007-06-17 19:56:38 -0500945
946 mempool_free(pmboxq, phba->mbox_mem_pool);
947 return 1;
948}
949
James Smarte59058c2008-08-24 21:49:00 -0400950/**
James Smart3621a712009-04-06 18:47:14 -0400951 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400952 * @dev: class device that is converted into a Scsi_host.
953 * @attr: device attribute, not used.
954 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
955 *
956 * Description:
957 * Calls lpfc_get_hba_info() asking for just the mrpi count.
958 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
959 * to "Unknown" and the buffer length is returned, therefore the caller
960 * must check for "Unknown" in the buffer to detect a failure.
961 *
962 * Returns: size of formatted string.
963 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500964static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100965lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
966 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500967{
Tony Jonesee959b02008-02-22 00:13:36 +0100968 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
970 struct lpfc_hba *phba = vport->phba;
971 uint32_t cnt;
972
James Smart858c9f62007-06-17 19:56:39 -0500973 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500974 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
975 return snprintf(buf, PAGE_SIZE, "Unknown\n");
976}
977
James Smarte59058c2008-08-24 21:49:00 -0400978/**
James Smart3621a712009-04-06 18:47:14 -0400979 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400980 * @dev: class device that is converted into a Scsi_host.
981 * @attr: device attribute, not used.
982 * @buf: containing the used rpi count in decimal or "Unknown".
983 *
984 * Description:
985 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
986 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
987 * to "Unknown" and the buffer length is returned, therefore the caller
988 * must check for "Unknown" in the buffer to detect a failure.
989 *
990 * Returns: size of formatted string.
991 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500992static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100993lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
994 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500995{
Tony Jonesee959b02008-02-22 00:13:36 +0100996 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
998 struct lpfc_hba *phba = vport->phba;
999 uint32_t cnt, acnt;
1000
James Smart858c9f62007-06-17 19:56:39 -05001001 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001002 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1003 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1004}
1005
James Smarte59058c2008-08-24 21:49:00 -04001006/**
James Smart3621a712009-04-06 18:47:14 -04001007 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001008 * @dev: class device that is converted into a Scsi_host.
1009 * @attr: device attribute, not used.
1010 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1011 *
1012 * Description:
1013 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1014 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1015 * to "Unknown" and the buffer length is returned, therefore the caller
1016 * must check for "Unknown" in the buffer to detect a failure.
1017 *
1018 * Returns: size of formatted string.
1019 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001020static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001021lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1022 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001023{
Tony Jonesee959b02008-02-22 00:13:36 +01001024 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001025 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1026 struct lpfc_hba *phba = vport->phba;
1027 uint32_t cnt;
1028
James Smart858c9f62007-06-17 19:56:39 -05001029 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001030 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1031 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1032}
1033
James Smarte59058c2008-08-24 21:49:00 -04001034/**
James Smart3621a712009-04-06 18:47:14 -04001035 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001036 * @dev: class device that is converted into a Scsi_host.
1037 * @attr: device attribute, not used.
1038 * @buf: on return contains the used xri count in decimal or "Unknown".
1039 *
1040 * Description:
1041 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1042 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1043 * to "Unknown" and the buffer length is returned, therefore the caller
1044 * must check for "Unknown" in the buffer to detect a failure.
1045 *
1046 * Returns: size of formatted string.
1047 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001048static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001049lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1050 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001051{
Tony Jonesee959b02008-02-22 00:13:36 +01001052 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1054 struct lpfc_hba *phba = vport->phba;
1055 uint32_t cnt, acnt;
1056
James Smart858c9f62007-06-17 19:56:39 -05001057 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1058 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1059 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1060}
1061
James Smarte59058c2008-08-24 21:49:00 -04001062/**
James Smart3621a712009-04-06 18:47:14 -04001063 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001064 * @dev: class device that is converted into a Scsi_host.
1065 * @attr: device attribute, not used.
1066 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1067 *
1068 * Description:
1069 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1070 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1071 * to "Unknown" and the buffer length is returned, therefore the caller
1072 * must check for "Unknown" in the buffer to detect a failure.
1073 *
1074 * Returns: size of formatted string.
1075 **/
James Smart858c9f62007-06-17 19:56:39 -05001076static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001077lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1078 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001079{
Tony Jonesee959b02008-02-22 00:13:36 +01001080 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1082 struct lpfc_hba *phba = vport->phba;
1083 uint32_t cnt;
1084
1085 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1086 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1087 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1088}
1089
James Smarte59058c2008-08-24 21:49:00 -04001090/**
James Smart3621a712009-04-06 18:47:14 -04001091 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001092 * @dev: class device that is converted into a Scsi_host.
1093 * @attr: device attribute, not used.
1094 * @buf: on return contains the used vpi count in decimal or "Unknown".
1095 *
1096 * Description:
1097 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1098 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1099 * to "Unknown" and the buffer length is returned, therefore the caller
1100 * must check for "Unknown" in the buffer to detect a failure.
1101 *
1102 * Returns: size of formatted string.
1103 **/
James Smart858c9f62007-06-17 19:56:39 -05001104static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001105lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1106 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001107{
Tony Jonesee959b02008-02-22 00:13:36 +01001108 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1110 struct lpfc_hba *phba = vport->phba;
1111 uint32_t cnt, acnt;
1112
1113 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001114 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1115 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1116}
1117
James Smarte59058c2008-08-24 21:49:00 -04001118/**
James Smart3621a712009-04-06 18:47:14 -04001119 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001120 * @dev: class device that is converted into a Scsi_host.
1121 * @attr: device attribute, not used.
1122 * @buf: text that must be interpreted to determine if npiv is supported.
1123 *
1124 * Description:
1125 * Buffer will contain text indicating npiv is not suppoerted on the port,
1126 * the port is an NPIV physical port, or it is an npiv virtual port with
1127 * the id of the vport.
1128 *
1129 * Returns: size of formatted string.
1130 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001131static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001132lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1133 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001134{
Tony Jonesee959b02008-02-22 00:13:36 +01001135 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1137 struct lpfc_hba *phba = vport->phba;
1138
1139 if (!(phba->max_vpi))
1140 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1141 if (vport->port_type == LPFC_PHYSICAL_PORT)
1142 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1143 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1144}
1145
James Smarte59058c2008-08-24 21:49:00 -04001146/**
James Smart3621a712009-04-06 18:47:14 -04001147 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001148 * @dev: class device that is converted into a Scsi_host.
1149 * @attr: device attribute, not used.
1150 * @buf: on return contains the cfg_poll in hex.
1151 *
1152 * Notes:
1153 * cfg_poll should be a lpfc_polling_flags type.
1154 *
1155 * Returns: size of formatted string.
1156 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001157static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001158lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1159 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001160{
Tony Jonesee959b02008-02-22 00:13:36 +01001161 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1163 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001164
1165 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1166}
1167
James Smarte59058c2008-08-24 21:49:00 -04001168/**
James Smart3621a712009-04-06 18:47:14 -04001169 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001170 * @dev: class device that is converted into a Scsi_host.
1171 * @attr: device attribute, not used.
1172 * @buf: one or more lpfc_polling_flags values.
1173 * @count: not used.
1174 *
1175 * Notes:
1176 * buf contents converted to integer and checked for a valid value.
1177 *
1178 * Returns:
1179 * -EINVAL if the buffer connot be converted or is out of range
1180 * length of the buf on success
1181 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001182static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001183lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1184 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001185{
Tony Jonesee959b02008-02-22 00:13:36 +01001186 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001187 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1188 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001189 uint32_t creg_val;
1190 uint32_t old_val;
1191 int val=0;
1192
1193 if (!isdigit(buf[0]))
1194 return -EINVAL;
1195
1196 if (sscanf(buf, "%i", &val) != 1)
1197 return -EINVAL;
1198
1199 if ((val & 0x3) != val)
1200 return -EINVAL;
1201
James Smart45ed1192009-10-02 15:17:02 -04001202 if (phba->sli_rev == LPFC_SLI_REV4)
1203 val = 0;
1204
James Smart2e0fef82007-06-17 19:56:36 -05001205 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001206
1207 old_val = phba->cfg_poll;
1208
1209 if (val & ENABLE_FCP_RING_POLLING) {
1210 if ((val & DISABLE_FCP_RING_INT) &&
1211 !(old_val & DISABLE_FCP_RING_INT)) {
1212 creg_val = readl(phba->HCregaddr);
1213 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1214 writel(creg_val, phba->HCregaddr);
1215 readl(phba->HCregaddr); /* flush */
1216
1217 lpfc_poll_start_timer(phba);
1218 }
1219 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001220 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001221 return -EINVAL;
1222 }
1223
1224 if (!(val & DISABLE_FCP_RING_INT) &&
1225 (old_val & DISABLE_FCP_RING_INT))
1226 {
James Smart2e0fef82007-06-17 19:56:36 -05001227 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001228 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001229 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001230 creg_val = readl(phba->HCregaddr);
1231 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1232 writel(creg_val, phba->HCregaddr);
1233 readl(phba->HCregaddr); /* flush */
1234 }
1235
1236 phba->cfg_poll = val;
1237
James Smart2e0fef82007-06-17 19:56:36 -05001238 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001239
1240 return strlen(buf);
1241}
dea31012005-04-17 16:05:31 -05001242
James Smarte59058c2008-08-24 21:49:00 -04001243/**
James Smart3621a712009-04-06 18:47:14 -04001244 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001245 *
1246 * Description:
1247 * Macro that given an attr e.g. hba_queue_depth expands
1248 * into a function with the name lpfc_hba_queue_depth_show.
1249 *
1250 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1251 * @dev: class device that is converted into a Scsi_host.
1252 * @attr: device attribute, not used.
1253 * @buf: on return contains the attribute value in decimal.
1254 *
1255 * Returns: size of formatted string.
1256 **/
dea31012005-04-17 16:05:31 -05001257#define lpfc_param_show(attr) \
1258static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001259lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1260 char *buf) \
dea31012005-04-17 16:05:31 -05001261{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001262 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001263 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1264 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001265 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001266 val = phba->cfg_##attr;\
1267 return snprintf(buf, PAGE_SIZE, "%d\n",\
1268 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001269}
1270
James Smarte59058c2008-08-24 21:49:00 -04001271/**
James Smart3621a712009-04-06 18:47:14 -04001272 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001273 *
1274 * Description:
1275 * Macro that given an attr e.g. hba_queue_depth expands
1276 * into a function with the name lpfc_hba_queue_depth_show
1277 *
1278 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1279 * @dev: class device that is converted into a Scsi_host.
1280 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001281 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001282 *
1283 * Returns: size of formatted string.
1284 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001285#define lpfc_param_hex_show(attr) \
1286static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001287lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1288 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001289{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001290 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001291 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1292 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001293 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001294 val = phba->cfg_##attr;\
1295 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1296 phba->cfg_##attr);\
1297}
1298
James Smarte59058c2008-08-24 21:49:00 -04001299/**
James Smart3621a712009-04-06 18:47:14 -04001300 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001301 *
1302 * Description:
1303 * Macro that given an attr e.g. hba_queue_depth expands
1304 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1305 * takes a default argument, a minimum and maximum argument.
1306 *
1307 * lpfc_##attr##_init: Initializes an attribute.
1308 * @phba: pointer the the adapter structure.
1309 * @val: integer attribute value.
1310 *
1311 * Validates the min and max values then sets the adapter config field
1312 * accordingly, or uses the default if out of range and prints an error message.
1313 *
1314 * Returns:
1315 * zero on success
1316 * -EINVAL if default used
1317 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001318#define lpfc_param_init(attr, default, minval, maxval) \
1319static int \
James Smart84d1b002010-02-12 14:42:33 -05001320lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001321{ \
1322 if (val >= minval && val <= maxval) {\
1323 phba->cfg_##attr = val;\
1324 return 0;\
1325 }\
1326 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001327 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1328 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001329 phba->cfg_##attr = default;\
1330 return -EINVAL;\
1331}
1332
James Smarte59058c2008-08-24 21:49:00 -04001333/**
James Smart3621a712009-04-06 18:47:14 -04001334 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001335 *
1336 * Description:
1337 * Macro that given an attr e.g. hba_queue_depth expands
1338 * into a function with the name lpfc_hba_queue_depth_set
1339 *
1340 * lpfc_##attr##_set: Sets an attribute value.
1341 * @phba: pointer the the adapter structure.
1342 * @val: integer attribute value.
1343 *
1344 * Description:
1345 * Validates the min and max values then sets the
1346 * adapter config field if in the valid range. prints error message
1347 * and does not set the parameter if invalid.
1348 *
1349 * Returns:
1350 * zero on success
1351 * -EINVAL if val is invalid
1352 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001353#define lpfc_param_set(attr, default, minval, maxval) \
1354static int \
James Smart84d1b002010-02-12 14:42:33 -05001355lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001356{ \
1357 if (val >= minval && val <= maxval) {\
1358 phba->cfg_##attr = val;\
1359 return 0;\
1360 }\
1361 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001362 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1363 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001364 return -EINVAL;\
1365}
1366
James Smarte59058c2008-08-24 21:49:00 -04001367/**
James Smart3621a712009-04-06 18:47:14 -04001368 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001369 *
1370 * Description:
1371 * Macro that given an attr e.g. hba_queue_depth expands
1372 * into a function with the name lpfc_hba_queue_depth_store.
1373 *
1374 * lpfc_##attr##_store: Set an sttribute value.
1375 * @dev: class device that is converted into a Scsi_host.
1376 * @attr: device attribute, not used.
1377 * @buf: contains the attribute value in ascii.
1378 * @count: not used.
1379 *
1380 * Description:
1381 * Convert the ascii text number to an integer, then
1382 * use the lpfc_##attr##_set function to set the value.
1383 *
1384 * Returns:
1385 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1386 * length of buffer upon success.
1387 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001388#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001389static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001390lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1391 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001392{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001393 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001394 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1395 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001396 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001397 if (!isdigit(buf[0]))\
1398 return -EINVAL;\
1399 if (sscanf(buf, "%i", &val) != 1)\
1400 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001401 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001402 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001403 else \
1404 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001405}
1406
James Smarte59058c2008-08-24 21:49:00 -04001407/**
James Smart3621a712009-04-06 18:47:14 -04001408 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001409 *
1410 * Description:
1411 * Macro that given an attr e.g. hba_queue_depth expands
1412 * into a function with the name lpfc_hba_queue_depth_show
1413 *
1414 * lpfc_##attr##_show: prints the attribute value in decimal.
1415 * @dev: class device that is converted into a Scsi_host.
1416 * @attr: device attribute, not used.
1417 * @buf: on return contains the attribute value in decimal.
1418 *
1419 * Returns: length of formatted string.
1420 **/
James Smart3de2a652007-08-02 11:09:59 -04001421#define lpfc_vport_param_show(attr) \
1422static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001423lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1424 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001425{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001426 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001427 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001428 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001429 val = vport->cfg_##attr;\
1430 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1431}
1432
James Smarte59058c2008-08-24 21:49:00 -04001433/**
James Smart3621a712009-04-06 18:47:14 -04001434 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001435 *
1436 * Description:
1437 * Macro that given an attr e.g.
1438 * hba_queue_depth expands into a function with the name
1439 * lpfc_hba_queue_depth_show
1440 *
James Smart3621a712009-04-06 18:47:14 -04001441 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001442 * @dev: class device that is converted into a Scsi_host.
1443 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001444 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001445 *
1446 * Returns: length of formatted string.
1447 **/
James Smart3de2a652007-08-02 11:09:59 -04001448#define lpfc_vport_param_hex_show(attr) \
1449static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001450lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1451 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001452{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001453 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001455 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001456 val = vport->cfg_##attr;\
1457 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1458}
1459
James Smarte59058c2008-08-24 21:49:00 -04001460/**
James Smart3621a712009-04-06 18:47:14 -04001461 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001462 *
1463 * Description:
1464 * Macro that given an attr e.g. hba_queue_depth expands
1465 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1466 * takes a default argument, a minimum and maximum argument.
1467 *
1468 * lpfc_##attr##_init: validates the min and max values then sets the
1469 * adapter config field accordingly, or uses the default if out of range
1470 * and prints an error message.
1471 * @phba: pointer the the adapter structure.
1472 * @val: integer attribute value.
1473 *
1474 * Returns:
1475 * zero on success
1476 * -EINVAL if default used
1477 **/
James Smart3de2a652007-08-02 11:09:59 -04001478#define lpfc_vport_param_init(attr, default, minval, maxval) \
1479static int \
James Smart84d1b002010-02-12 14:42:33 -05001480lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001481{ \
1482 if (val >= minval && val <= maxval) {\
1483 vport->cfg_##attr = val;\
1484 return 0;\
1485 }\
James Smarte8b62012007-08-02 11:10:09 -04001486 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001487 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001488 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001489 vport->cfg_##attr = default;\
1490 return -EINVAL;\
1491}
1492
James Smarte59058c2008-08-24 21:49:00 -04001493/**
James Smart3621a712009-04-06 18:47:14 -04001494 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001495 *
1496 * Description:
1497 * Macro that given an attr e.g. hba_queue_depth expands
1498 * into a function with the name lpfc_hba_queue_depth_set
1499 *
1500 * lpfc_##attr##_set: validates the min and max values then sets the
1501 * adapter config field if in the valid range. prints error message
1502 * and does not set the parameter if invalid.
1503 * @phba: pointer the the adapter structure.
1504 * @val: integer attribute value.
1505 *
1506 * Returns:
1507 * zero on success
1508 * -EINVAL if val is invalid
1509 **/
James Smart3de2a652007-08-02 11:09:59 -04001510#define lpfc_vport_param_set(attr, default, minval, maxval) \
1511static int \
James Smart84d1b002010-02-12 14:42:33 -05001512lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001513{ \
1514 if (val >= minval && val <= maxval) {\
1515 vport->cfg_##attr = val;\
1516 return 0;\
1517 }\
James Smarte8b62012007-08-02 11:10:09 -04001518 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001519 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001520 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001521 return -EINVAL;\
1522}
1523
James Smarte59058c2008-08-24 21:49:00 -04001524/**
James Smart3621a712009-04-06 18:47:14 -04001525 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001526 *
1527 * Description:
1528 * Macro that given an attr e.g. hba_queue_depth
1529 * expands into a function with the name lpfc_hba_queue_depth_store
1530 *
1531 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1532 * use the lpfc_##attr##_set function to set the value.
1533 * @cdev: class device that is converted into a Scsi_host.
1534 * @buf: contains the attribute value in decimal.
1535 * @count: not used.
1536 *
1537 * Returns:
1538 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1539 * length of buffer upon success.
1540 **/
James Smart3de2a652007-08-02 11:09:59 -04001541#define lpfc_vport_param_store(attr) \
1542static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001543lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1544 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001545{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001546 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001548 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001549 if (!isdigit(buf[0]))\
1550 return -EINVAL;\
1551 if (sscanf(buf, "%i", &val) != 1)\
1552 return -EINVAL;\
1553 if (lpfc_##attr##_set(vport, val) == 0) \
1554 return strlen(buf);\
1555 else \
1556 return -EINVAL;\
1557}
1558
1559
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001560#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001561static uint lpfc_##name = defval;\
1562module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001563MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001564lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001565
1566#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001567static uint lpfc_##name = defval;\
1568module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001569MODULE_PARM_DESC(lpfc_##name, desc);\
1570lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001571lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001572static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001573
1574#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001575static uint lpfc_##name = defval;\
1576module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001577MODULE_PARM_DESC(lpfc_##name, desc);\
1578lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001579lpfc_param_init(name, defval, minval, maxval)\
1580lpfc_param_set(name, defval, minval, maxval)\
1581lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001582static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1583 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001584
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001585#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001586static uint lpfc_##name = defval;\
1587module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001588MODULE_PARM_DESC(lpfc_##name, desc);\
1589lpfc_param_hex_show(name)\
1590lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001591static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001592
1593#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001594static uint lpfc_##name = defval;\
1595module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001596MODULE_PARM_DESC(lpfc_##name, desc);\
1597lpfc_param_hex_show(name)\
1598lpfc_param_init(name, defval, minval, maxval)\
1599lpfc_param_set(name, defval, minval, maxval)\
1600lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001601static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1602 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001603
James Smart3de2a652007-08-02 11:09:59 -04001604#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001605static uint lpfc_##name = defval;\
1606module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001607MODULE_PARM_DESC(lpfc_##name, desc);\
1608lpfc_vport_param_init(name, defval, minval, maxval)
1609
1610#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001611static uint lpfc_##name = defval;\
1612module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001613MODULE_PARM_DESC(lpfc_##name, desc);\
1614lpfc_vport_param_show(name)\
1615lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001616static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001617
1618#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001619static uint lpfc_##name = defval;\
1620module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001621MODULE_PARM_DESC(lpfc_##name, desc);\
1622lpfc_vport_param_show(name)\
1623lpfc_vport_param_init(name, defval, minval, maxval)\
1624lpfc_vport_param_set(name, defval, minval, maxval)\
1625lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001626static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1627 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001628
1629#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001630static uint lpfc_##name = defval;\
1631module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001632MODULE_PARM_DESC(lpfc_##name, desc);\
1633lpfc_vport_param_hex_show(name)\
1634lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001635static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001636
1637#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001638static uint lpfc_##name = defval;\
1639module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001640MODULE_PARM_DESC(lpfc_##name, desc);\
1641lpfc_vport_param_hex_show(name)\
1642lpfc_vport_param_init(name, defval, minval, maxval)\
1643lpfc_vport_param_set(name, defval, minval, maxval)\
1644lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001645static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1646 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001647
James Smart81301a92008-12-04 22:39:46 -05001648static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1649static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1650static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1651static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001652static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1653static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1654static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1655static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1656static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1657static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1658static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1659static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001660static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1661 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001662static DEVICE_ATTR(option_rom_version, S_IRUGO,
1663 lpfc_option_rom_version_show, NULL);
1664static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1665 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001666static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001667static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1668static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001669static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001670static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1671 lpfc_board_mode_show, lpfc_board_mode_store);
1672static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1673static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1674static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1675static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1676static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1677static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1678static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1679static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1680static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001681
James Smartc3f28af2006-08-18 17:47:18 -04001682
James Smarta12e07b2006-12-02 13:35:30 -05001683static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001684
James Smarte59058c2008-08-24 21:49:00 -04001685/**
James Smart3621a712009-04-06 18:47:14 -04001686 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001687 * @dev: class device that is converted into a Scsi_host.
1688 * @attr: device attribute, not used.
1689 * @buf: containing the string lpfc_soft_wwn_key.
1690 * @count: must be size of lpfc_soft_wwn_key.
1691 *
1692 * Returns:
1693 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1694 * length of buf indicates success
1695 **/
James Smartc3f28af2006-08-18 17:47:18 -04001696static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001697lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1698 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001699{
Tony Jonesee959b02008-02-22 00:13:36 +01001700 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1702 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001703 unsigned int cnt = count;
1704
1705 /*
1706 * We're doing a simple sanity check for soft_wwpn setting.
1707 * We require that the user write a specific key to enable
1708 * the soft_wwpn attribute to be settable. Once the attribute
1709 * is written, the enable key resets. If further updates are
1710 * desired, the key must be written again to re-enable the
1711 * attribute.
1712 *
1713 * The "key" is not secret - it is a hardcoded string shown
1714 * here. The intent is to protect against the random user or
1715 * application that is just writing attributes.
1716 */
1717
1718 /* count may include a LF at end of string */
1719 if (buf[cnt-1] == '\n')
1720 cnt--;
1721
James Smarta12e07b2006-12-02 13:35:30 -05001722 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1723 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001724 return -EINVAL;
1725
James Smarta12e07b2006-12-02 13:35:30 -05001726 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001727 return count;
1728}
Tony Jonesee959b02008-02-22 00:13:36 +01001729static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1730 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001731
James Smarte59058c2008-08-24 21:49:00 -04001732/**
James Smart3621a712009-04-06 18:47:14 -04001733 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001734 * @dev: class device that is converted into a Scsi_host.
1735 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001736 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001737 *
1738 * Returns: size of formatted string.
1739 **/
James Smartc3f28af2006-08-18 17:47:18 -04001740static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001741lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1742 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001743{
Tony Jonesee959b02008-02-22 00:13:36 +01001744 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001745 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1746 struct lpfc_hba *phba = vport->phba;
1747
Randy Dunlapafc071e2006-10-23 21:47:13 -07001748 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1749 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001750}
1751
James Smarte59058c2008-08-24 21:49:00 -04001752/**
James Smart3621a712009-04-06 18:47:14 -04001753 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001754 * @dev class device that is converted into a Scsi_host.
1755 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001756 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001757 * @count: number of wwpn bytes in buf
1758 *
1759 * Returns:
1760 * -EACCES hba reset not enabled, adapter over temp
1761 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1762 * -EIO error taking adapter offline or online
1763 * value of count on success
1764 **/
James Smartc3f28af2006-08-18 17:47:18 -04001765static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001766lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1767 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001768{
Tony Jonesee959b02008-02-22 00:13:36 +01001769 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1771 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001772 struct completion online_compl;
1773 int stat1=0, stat2=0;
1774 unsigned int i, j, cnt=count;
1775 u8 wwpn[8];
1776
James Smart13815c82008-01-11 01:52:48 -05001777 if (!phba->cfg_enable_hba_reset)
1778 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001779 spin_lock_irq(&phba->hbalock);
1780 if (phba->over_temp_state == HBA_OVER_TEMP) {
1781 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001782 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001783 }
1784 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001785 /* count may include a LF at end of string */
1786 if (buf[cnt-1] == '\n')
1787 cnt--;
1788
James Smarta12e07b2006-12-02 13:35:30 -05001789 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001790 ((cnt == 17) && (*buf++ != 'x')) ||
1791 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1792 return -EINVAL;
1793
James Smarta12e07b2006-12-02 13:35:30 -05001794 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001795
1796 memset(wwpn, 0, sizeof(wwpn));
1797
1798 /* Validate and store the new name */
1799 for (i=0, j=0; i < 16; i++) {
1800 if ((*buf >= 'a') && (*buf <= 'f'))
1801 j = ((j << 4) | ((*buf++ -'a') + 10));
1802 else if ((*buf >= 'A') && (*buf <= 'F'))
1803 j = ((j << 4) | ((*buf++ -'A') + 10));
1804 else if ((*buf >= '0') && (*buf <= '9'))
1805 j = ((j << 4) | (*buf++ -'0'));
1806 else
1807 return -EINVAL;
1808 if (i % 2) {
1809 wwpn[i/2] = j & 0xff;
1810 j = 0;
1811 }
1812 }
1813 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001814 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001815 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001816 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001817
1818 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1819 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1820
James Smart46fa3112007-04-25 09:51:45 -04001821 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001822 if (stat1)
1823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001824 "0463 lpfc_soft_wwpn attribute set failed to "
1825 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001826 init_completion(&online_compl);
1827 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1828 wait_for_completion(&online_compl);
1829 if (stat2)
1830 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001831 "0464 lpfc_soft_wwpn attribute set failed to "
1832 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001833 return (stat1 || stat2) ? -EIO : count;
1834}
Tony Jonesee959b02008-02-22 00:13:36 +01001835static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1836 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001837
James Smarte59058c2008-08-24 21:49:00 -04001838/**
James Smart3621a712009-04-06 18:47:14 -04001839 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001840 * @dev: class device that is converted into a Scsi_host.
1841 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001842 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001843 *
1844 * Returns: size of formatted string.
1845 **/
James Smarta12e07b2006-12-02 13:35:30 -05001846static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001847lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1848 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001849{
Tony Jonesee959b02008-02-22 00:13:36 +01001850 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001851 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001852 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1853 (unsigned long long)phba->cfg_soft_wwnn);
1854}
1855
James Smarte59058c2008-08-24 21:49:00 -04001856/**
James Smart3621a712009-04-06 18:47:14 -04001857 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001858 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001859 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001860 * @count: number of wwnn bytes in buf.
1861 *
1862 * Returns:
1863 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1864 * value of count on success
1865 **/
James Smarta12e07b2006-12-02 13:35:30 -05001866static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001867lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1868 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001869{
Tony Jonesee959b02008-02-22 00:13:36 +01001870 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001871 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001872 unsigned int i, j, cnt=count;
1873 u8 wwnn[8];
1874
1875 /* count may include a LF at end of string */
1876 if (buf[cnt-1] == '\n')
1877 cnt--;
1878
1879 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1880 ((cnt == 17) && (*buf++ != 'x')) ||
1881 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1882 return -EINVAL;
1883
1884 /*
1885 * Allow wwnn to be set many times, as long as the enable is set.
1886 * However, once the wwpn is set, everything locks.
1887 */
1888
1889 memset(wwnn, 0, sizeof(wwnn));
1890
1891 /* Validate and store the new name */
1892 for (i=0, j=0; i < 16; i++) {
1893 if ((*buf >= 'a') && (*buf <= 'f'))
1894 j = ((j << 4) | ((*buf++ -'a') + 10));
1895 else if ((*buf >= 'A') && (*buf <= 'F'))
1896 j = ((j << 4) | ((*buf++ -'A') + 10));
1897 else if ((*buf >= '0') && (*buf <= '9'))
1898 j = ((j << 4) | (*buf++ -'0'));
1899 else
1900 return -EINVAL;
1901 if (i % 2) {
1902 wwnn[i/2] = j & 0xff;
1903 j = 0;
1904 }
1905 }
1906 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1907
1908 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1909 "lpfc%d: soft_wwnn set. Value will take effect upon "
1910 "setting of the soft_wwpn\n", phba->brd_no);
1911
1912 return count;
1913}
Tony Jonesee959b02008-02-22 00:13:36 +01001914static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1915 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001916
James Smartc3f28af2006-08-18 17:47:18 -04001917
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001918static int lpfc_poll = 0;
1919module_param(lpfc_poll, int, 0);
1920MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1921 " 0 - none,"
1922 " 1 - poll with interrupts enabled"
1923 " 3 - poll and disable FCP ring interrupts");
1924
Tony Jonesee959b02008-02-22 00:13:36 +01001925static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1926 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001927
James Smart92d7f7b2007-06-17 19:56:38 -05001928int lpfc_sli_mode = 0;
1929module_param(lpfc_sli_mode, int, 0);
1930MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1931 " 0 - auto (SLI-3 if supported),"
1932 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1933 " 3 - select SLI-3");
1934
James Smart15672312010-04-06 14:49:03 -04001935int lpfc_enable_npiv = 1;
James Smart7ee5d432007-10-27 13:37:17 -04001936module_param(lpfc_enable_npiv, int, 0);
1937MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1938lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04001939lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04001940static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001941
dea31012005-04-17 16:05:31 -05001942/*
James Smart84d1b002010-02-12 14:42:33 -05001943# lpfc_suppress_link_up: Bring link up at initialization
1944# 0x0 = bring link up (issue MBX_INIT_LINK)
1945# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1946# 0x2 = never bring up link
1947# Default value is 0.
1948*/
James Smarte40a02c2010-02-26 14:13:54 -05001949LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1950 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1951 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04001952/*
1953# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1954# 1 - (1024)
1955# 2 - (2048)
1956# 3 - (3072)
1957# 4 - (4096)
1958# 5 - (5120)
1959*/
1960static ssize_t
1961lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1962{
1963 struct Scsi_Host *shost = class_to_shost(dev);
1964 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1965
1966 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
1967}
1968
1969static DEVICE_ATTR(iocb_hw, S_IRUGO,
1970 lpfc_iocb_hw_show, NULL);
1971static ssize_t
1972lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1973{
1974 struct Scsi_Host *shost = class_to_shost(dev);
1975 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1976
1977 return snprintf(buf, PAGE_SIZE, "%d\n",
1978 phba->sli.ring[LPFC_ELS_RING].txq_max);
1979}
1980
1981static DEVICE_ATTR(txq_hw, S_IRUGO,
1982 lpfc_txq_hw_show, NULL);
1983static ssize_t
1984lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
1985 char *buf)
1986{
1987 struct Scsi_Host *shost = class_to_shost(dev);
1988 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1989
1990 return snprintf(buf, PAGE_SIZE, "%d\n",
1991 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
1992}
1993
1994static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
1995 lpfc_txcmplq_hw_show, NULL);
1996
1997int lpfc_iocb_cnt = 2;
1998module_param(lpfc_iocb_cnt, int, 1);
1999MODULE_PARM_DESC(lpfc_iocb_cnt,
2000 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2001lpfc_param_show(iocb_cnt);
2002lpfc_param_init(iocb_cnt, 2, 1, 5);
2003static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2004 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002005
2006/*
James Smartc01f3202006-08-18 17:47:08 -04002007# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2008# until the timer expires. Value range is [0,255]. Default value is 30.
2009*/
2010static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2011static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2012module_param(lpfc_nodev_tmo, int, 0);
2013MODULE_PARM_DESC(lpfc_nodev_tmo,
2014 "Seconds driver will hold I/O waiting "
2015 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002016
2017/**
James Smart3621a712009-04-06 18:47:14 -04002018 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002019 * @dev: class converted to a Scsi_host structure.
2020 * @attr: device attribute, not used.
2021 * @buf: on return contains the dev loss timeout in decimal.
2022 *
2023 * Returns: size of formatted string.
2024 **/
James Smartc01f3202006-08-18 17:47:08 -04002025static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002026lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2027 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002028{
Tony Jonesee959b02008-02-22 00:13:36 +01002029 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002031
James Smart3de2a652007-08-02 11:09:59 -04002032 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002033}
2034
James Smarte59058c2008-08-24 21:49:00 -04002035/**
James Smart3621a712009-04-06 18:47:14 -04002036 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002037 * @vport: lpfc vport structure pointer.
2038 * @val: contains the nodev timeout value.
2039 *
2040 * Description:
2041 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2042 * a kernel error message is printed and zero is returned.
2043 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2044 * Otherwise nodev tmo is set to the default value.
2045 *
2046 * Returns:
2047 * zero if already set or if val is in range
2048 * -EINVAL val out of range
2049 **/
James Smartc01f3202006-08-18 17:47:08 -04002050static int
James Smart3de2a652007-08-02 11:09:59 -04002051lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002052{
James Smart3de2a652007-08-02 11:09:59 -04002053 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2054 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2055 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002056 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002057 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002058 "parameter because devloss_tmo is "
2059 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002060 return 0;
2061 }
2062
2063 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002064 vport->cfg_nodev_tmo = val;
2065 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002066 return 0;
2067 }
James Smarte8b62012007-08-02 11:10:09 -04002068 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2069 "0400 lpfc_nodev_tmo attribute cannot be set to"
2070 " %d, allowed range is [%d, %d]\n",
2071 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002072 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002073 return -EINVAL;
2074}
2075
James Smarte59058c2008-08-24 21:49:00 -04002076/**
James Smart3621a712009-04-06 18:47:14 -04002077 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002078 * @vport: lpfc vport structure pointer.
2079 *
2080 * Description:
2081 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2082 **/
James Smart7054a602007-04-25 09:52:34 -04002083static void
James Smart3de2a652007-08-02 11:09:59 -04002084lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002085{
James Smart858c9f62007-06-17 19:56:39 -05002086 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002087 struct lpfc_nodelist *ndlp;
2088
James Smart51ef4c22007-08-02 11:10:31 -04002089 shost = lpfc_shost_from_vport(vport);
2090 spin_lock_irq(shost->host_lock);
2091 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002092 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002093 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2094 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002095}
2096
James Smarte59058c2008-08-24 21:49:00 -04002097/**
James Smart3621a712009-04-06 18:47:14 -04002098 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002099 * @vport: lpfc vport structure pointer.
2100 * @val: contains the tmo value.
2101 *
2102 * Description:
2103 * If the devloss tmo is already set or the vport dev loss tmo has changed
2104 * then a kernel error message is printed and zero is returned.
2105 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2106 * Otherwise nodev tmo is set to the default value.
2107 *
2108 * Returns:
2109 * zero if already set or if val is in range
2110 * -EINVAL val out of range
2111 **/
James Smartc01f3202006-08-18 17:47:08 -04002112static int
James Smart3de2a652007-08-02 11:09:59 -04002113lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002114{
James Smart3de2a652007-08-02 11:09:59 -04002115 if (vport->dev_loss_tmo_changed ||
2116 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002117 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2118 "0401 Ignoring change to nodev_tmo "
2119 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002120 return 0;
2121 }
James Smartc01f3202006-08-18 17:47:08 -04002122 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002123 vport->cfg_nodev_tmo = val;
2124 vport->cfg_devloss_tmo = val;
2125 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002126 return 0;
2127 }
James Smarte8b62012007-08-02 11:10:09 -04002128 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2129 "0403 lpfc_nodev_tmo attribute cannot be set to"
2130 "%d, allowed range is [%d, %d]\n",
2131 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002132 return -EINVAL;
2133}
2134
James Smart3de2a652007-08-02 11:09:59 -04002135lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002136
Tony Jonesee959b02008-02-22 00:13:36 +01002137static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2138 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002139
2140/*
2141# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2142# disappear until the timer expires. Value range is [0,255]. Default
2143# value is 30.
2144*/
2145module_param(lpfc_devloss_tmo, int, 0);
2146MODULE_PARM_DESC(lpfc_devloss_tmo,
2147 "Seconds driver will hold I/O waiting "
2148 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002149lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2150 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2151lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002152
2153/**
James Smart3621a712009-04-06 18:47:14 -04002154 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002155 * @vport: lpfc vport structure pointer.
2156 * @val: contains the tmo value.
2157 *
2158 * Description:
2159 * If val is in a valid range then set the vport nodev tmo,
2160 * devloss tmo, also set the vport dev loss tmo changed flag.
2161 * Else a kernel error message is printed.
2162 *
2163 * Returns:
2164 * zero if val is in range
2165 * -EINVAL val out of range
2166 **/
James Smartc01f3202006-08-18 17:47:08 -04002167static int
James Smart3de2a652007-08-02 11:09:59 -04002168lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002169{
2170 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002171 vport->cfg_nodev_tmo = val;
2172 vport->cfg_devloss_tmo = val;
2173 vport->dev_loss_tmo_changed = 1;
2174 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002175 return 0;
2176 }
2177
James Smarte8b62012007-08-02 11:10:09 -04002178 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2179 "0404 lpfc_devloss_tmo attribute cannot be set to"
2180 " %d, allowed range is [%d, %d]\n",
2181 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002182 return -EINVAL;
2183}
2184
James Smart3de2a652007-08-02 11:09:59 -04002185lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002186static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2187 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002188
2189/*
dea31012005-04-17 16:05:31 -05002190# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2191# deluged with LOTS of information.
2192# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002193# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002194*/
James Smartf4b4c682009-05-22 14:53:12 -04002195LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002196 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002197
2198/*
James Smart7ee5d432007-10-27 13:37:17 -04002199# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2200# objects that have been registered with the nameserver after login.
2201*/
2202LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2203 "Deregister nameserver objects before LOGO");
2204
2205/*
dea31012005-04-17 16:05:31 -05002206# lun_queue_depth: This parameter is used to limit the number of outstanding
2207# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2208*/
James Smart3de2a652007-08-02 11:09:59 -04002209LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2210 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002211
2212/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002213# hba_queue_depth: This parameter is used to limit the number of outstanding
2214# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2215# value is greater than the maximum number of exchanges supported by the HBA,
2216# then maximum number of exchanges supported by the HBA is used to determine
2217# the hba_queue_depth.
2218*/
2219LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2220 "Max number of FCP commands we can queue to a lpfc HBA");
2221
2222/*
James Smart92d7f7b2007-06-17 19:56:38 -05002223# peer_port_login: This parameter allows/prevents logins
2224# between peer ports hosted on the same physical port.
2225# When this parameter is set 0 peer ports of same physical port
2226# are not allowed to login to each other.
2227# When this parameter is set 1 peer ports of same physical port
2228# are allowed to login to each other.
2229# Default value of this parameter is 0.
2230*/
James Smart3de2a652007-08-02 11:09:59 -04002231LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2232 "Allow peer ports on the same physical port to login to each "
2233 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002234
2235/*
James Smart3de2a652007-08-02 11:09:59 -04002236# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002237# between Virtual Ports and remote initiators.
2238# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2239# other initiators and will attempt to PLOGI all remote ports.
2240# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2241# remote ports and will not attempt to PLOGI to other initiators.
2242# This parameter does not restrict to the physical port.
2243# This parameter does not restrict logins to Fabric resident remote ports.
2244# Default value of this parameter is 1.
2245*/
James Smart3de2a652007-08-02 11:09:59 -04002246static int lpfc_restrict_login = 1;
2247module_param(lpfc_restrict_login, int, 0);
2248MODULE_PARM_DESC(lpfc_restrict_login,
2249 "Restrict virtual ports login to remote initiators.");
2250lpfc_vport_param_show(restrict_login);
2251
James Smarte59058c2008-08-24 21:49:00 -04002252/**
James Smart3621a712009-04-06 18:47:14 -04002253 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002254 * @vport: lpfc vport structure pointer.
2255 * @val: contains the restrict login value.
2256 *
2257 * Description:
2258 * If val is not in a valid range then log a kernel error message and set
2259 * the vport restrict login to one.
2260 * If the port type is physical clear the restrict login flag and return.
2261 * Else set the restrict login flag to val.
2262 *
2263 * Returns:
2264 * zero if val is in range
2265 * -EINVAL val out of range
2266 **/
James Smart3de2a652007-08-02 11:09:59 -04002267static int
2268lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2269{
2270 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002271 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002272 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002273 "be set to %d, allowed range is [0, 1]\n",
2274 val);
James Smart3de2a652007-08-02 11:09:59 -04002275 vport->cfg_restrict_login = 1;
2276 return -EINVAL;
2277 }
2278 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2279 vport->cfg_restrict_login = 0;
2280 return 0;
2281 }
2282 vport->cfg_restrict_login = val;
2283 return 0;
2284}
2285
James Smarte59058c2008-08-24 21:49:00 -04002286/**
James Smart3621a712009-04-06 18:47:14 -04002287 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002288 * @vport: lpfc vport structure pointer.
2289 * @val: contains the restrict login value.
2290 *
2291 * Description:
2292 * If val is not in a valid range then log a kernel error message and set
2293 * the vport restrict login to one.
2294 * If the port type is physical and the val is not zero log a kernel
2295 * error message, clear the restrict login flag and return zero.
2296 * Else set the restrict login flag to val.
2297 *
2298 * Returns:
2299 * zero if val is in range
2300 * -EINVAL val out of range
2301 **/
James Smart3de2a652007-08-02 11:09:59 -04002302static int
2303lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2304{
2305 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002306 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002307 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002308 "be set to %d, allowed range is [0, 1]\n",
2309 val);
James Smart3de2a652007-08-02 11:09:59 -04002310 vport->cfg_restrict_login = 1;
2311 return -EINVAL;
2312 }
2313 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002314 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2315 "0468 lpfc_restrict_login must be 0 for "
2316 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002317 vport->cfg_restrict_login = 0;
2318 return 0;
2319 }
2320 vport->cfg_restrict_login = val;
2321 return 0;
2322}
2323lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002324static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2325 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002326
2327/*
dea31012005-04-17 16:05:31 -05002328# Some disk devices have a "select ID" or "select Target" capability.
2329# From a protocol standpoint "select ID" usually means select the
2330# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2331# annex" which contains a table that maps a "select ID" (a number
2332# between 0 and 7F) to an ALPA. By default, for compatibility with
2333# older drivers, the lpfc driver scans this table from low ALPA to high
2334# ALPA.
2335#
2336# Turning on the scan-down variable (on = 1, off = 0) will
2337# cause the lpfc driver to use an inverted table, effectively
2338# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2339#
2340# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2341# and will not work across a fabric. Also this parameter will take
2342# effect only in the case when ALPA map is not available.)
2343*/
James Smart3de2a652007-08-02 11:09:59 -04002344LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2345 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002346
2347/*
dea31012005-04-17 16:05:31 -05002348# lpfc_topology: link topology for init link
2349# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002350# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002351# 0x02 = attempt point-to-point mode only
2352# 0x04 = attempt loop mode only
2353# 0x06 = attempt point-to-point mode then loop
2354# Set point-to-point mode if you want to run as an N_Port.
2355# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2356# Default value is 0.
2357*/
James Smarte59058c2008-08-24 21:49:00 -04002358
2359/**
James Smart3621a712009-04-06 18:47:14 -04002360 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002361 * @phba: lpfc_hba pointer.
2362 * @val: topology value.
2363 *
2364 * Description:
2365 * If val is in a valid range then set the adapter's topology field and
2366 * issue a lip; if the lip fails reset the topology to the old value.
2367 *
2368 * If the value is not in range log a kernel error message and return an error.
2369 *
2370 * Returns:
2371 * zero if val is in range and lip okay
2372 * non-zero return value from lpfc_issue_lip()
2373 * -EINVAL val out of range
2374 **/
James Smarta257bf92009-04-06 18:48:10 -04002375static ssize_t
2376lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2377 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002378{
James Smarta257bf92009-04-06 18:48:10 -04002379 struct Scsi_Host *shost = class_to_shost(dev);
2380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2381 struct lpfc_hba *phba = vport->phba;
2382 int val = 0;
2383 int nolip = 0;
2384 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002385 int err;
2386 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002387
2388 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2389 nolip = 1;
2390 val_buf = &buf[strlen("nolip ")];
2391 }
2392
2393 if (!isdigit(val_buf[0]))
2394 return -EINVAL;
2395 if (sscanf(val_buf, "%i", &val) != 1)
2396 return -EINVAL;
2397
James Smart83108bd2008-01-11 01:53:09 -05002398 if (val >= 0 && val <= 6) {
2399 prev_val = phba->cfg_topology;
2400 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002401 if (nolip)
2402 return strlen(buf);
2403
James Smart83108bd2008-01-11 01:53:09 -05002404 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002405 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002406 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002407 return -EINVAL;
2408 } else
2409 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002410 }
2411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2412 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2413 "allowed range is [0, 6]\n",
2414 phba->brd_no, val);
2415 return -EINVAL;
2416}
2417static int lpfc_topology = 0;
2418module_param(lpfc_topology, int, 0);
2419MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2420lpfc_param_show(topology)
2421lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002422static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002423 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002424
James Smart21e9a0a2009-05-22 14:53:21 -04002425/**
2426 * lpfc_static_vport_show: Read callback function for
2427 * lpfc_static_vport sysfs file.
2428 * @dev: Pointer to class device object.
2429 * @attr: device attribute structure.
2430 * @buf: Data buffer.
2431 *
2432 * This function is the read call back function for
2433 * lpfc_static_vport sysfs file. The lpfc_static_vport
2434 * sysfs file report the mageability of the vport.
2435 **/
2436static ssize_t
2437lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2438 char *buf)
2439{
2440 struct Scsi_Host *shost = class_to_shost(dev);
2441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2442 if (vport->vport_flag & STATIC_VPORT)
2443 sprintf(buf, "1\n");
2444 else
2445 sprintf(buf, "0\n");
2446
2447 return strlen(buf);
2448}
2449
2450/*
2451 * Sysfs attribute to control the statistical data collection.
2452 */
2453static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2454 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002455
2456/**
James Smart3621a712009-04-06 18:47:14 -04002457 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002458 * @dev: Pointer to class device.
2459 * @buf: Data buffer.
2460 * @count: Size of the data buffer.
2461 *
2462 * This function get called when an user write to the lpfc_stat_data_ctrl
2463 * sysfs file. This function parse the command written to the sysfs file
2464 * and take appropriate action. These commands are used for controlling
2465 * driver statistical data collection.
2466 * Following are the command this function handles.
2467 *
2468 * setbucket <bucket_type> <base> <step>
2469 * = Set the latency buckets.
2470 * destroybucket = destroy all the buckets.
2471 * start = start data collection
2472 * stop = stop data collection
2473 * reset = reset the collected data
2474 **/
2475static ssize_t
2476lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2477 const char *buf, size_t count)
2478{
2479 struct Scsi_Host *shost = class_to_shost(dev);
2480 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2481 struct lpfc_hba *phba = vport->phba;
2482#define LPFC_MAX_DATA_CTRL_LEN 1024
2483 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2484 unsigned long i;
2485 char *str_ptr, *token;
2486 struct lpfc_vport **vports;
2487 struct Scsi_Host *v_shost;
2488 char *bucket_type_str, *base_str, *step_str;
2489 unsigned long base, step, bucket_type;
2490
2491 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002492 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002493 return -EINVAL;
2494
2495 strcpy(bucket_data, buf);
2496 str_ptr = &bucket_data[0];
2497 /* Ignore this token - this is command token */
2498 token = strsep(&str_ptr, "\t ");
2499 if (!token)
2500 return -EINVAL;
2501
2502 bucket_type_str = strsep(&str_ptr, "\t ");
2503 if (!bucket_type_str)
2504 return -EINVAL;
2505
2506 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2507 bucket_type = LPFC_LINEAR_BUCKET;
2508 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2509 bucket_type = LPFC_POWER2_BUCKET;
2510 else
2511 return -EINVAL;
2512
2513 base_str = strsep(&str_ptr, "\t ");
2514 if (!base_str)
2515 return -EINVAL;
2516 base = simple_strtoul(base_str, NULL, 0);
2517
2518 step_str = strsep(&str_ptr, "\t ");
2519 if (!step_str)
2520 return -EINVAL;
2521 step = simple_strtoul(step_str, NULL, 0);
2522 if (!step)
2523 return -EINVAL;
2524
2525 /* Block the data collection for every vport */
2526 vports = lpfc_create_vport_work_array(phba);
2527 if (vports == NULL)
2528 return -ENOMEM;
2529
James Smartf4b4c682009-05-22 14:53:12 -04002530 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002531 v_shost = lpfc_shost_from_vport(vports[i]);
2532 spin_lock_irq(v_shost->host_lock);
2533 /* Block and reset data collection */
2534 vports[i]->stat_data_blocked = 1;
2535 if (vports[i]->stat_data_enabled)
2536 lpfc_vport_reset_stat_data(vports[i]);
2537 spin_unlock_irq(v_shost->host_lock);
2538 }
2539
2540 /* Set the bucket attributes */
2541 phba->bucket_type = bucket_type;
2542 phba->bucket_base = base;
2543 phba->bucket_step = step;
2544
James Smartf4b4c682009-05-22 14:53:12 -04002545 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002546 v_shost = lpfc_shost_from_vport(vports[i]);
2547
2548 /* Unblock data collection */
2549 spin_lock_irq(v_shost->host_lock);
2550 vports[i]->stat_data_blocked = 0;
2551 spin_unlock_irq(v_shost->host_lock);
2552 }
2553 lpfc_destroy_vport_work_array(phba, vports);
2554 return strlen(buf);
2555 }
2556
2557 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2558 vports = lpfc_create_vport_work_array(phba);
2559 if (vports == NULL)
2560 return -ENOMEM;
2561
James Smartf4b4c682009-05-22 14:53:12 -04002562 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002563 v_shost = lpfc_shost_from_vport(vports[i]);
2564 spin_lock_irq(shost->host_lock);
2565 vports[i]->stat_data_blocked = 1;
2566 lpfc_free_bucket(vport);
2567 vport->stat_data_enabled = 0;
2568 vports[i]->stat_data_blocked = 0;
2569 spin_unlock_irq(shost->host_lock);
2570 }
2571 lpfc_destroy_vport_work_array(phba, vports);
2572 phba->bucket_type = LPFC_NO_BUCKET;
2573 phba->bucket_base = 0;
2574 phba->bucket_step = 0;
2575 return strlen(buf);
2576 }
2577
2578 if (!strncmp(buf, "start", strlen("start"))) {
2579 /* If no buckets configured return error */
2580 if (phba->bucket_type == LPFC_NO_BUCKET)
2581 return -EINVAL;
2582 spin_lock_irq(shost->host_lock);
2583 if (vport->stat_data_enabled) {
2584 spin_unlock_irq(shost->host_lock);
2585 return strlen(buf);
2586 }
2587 lpfc_alloc_bucket(vport);
2588 vport->stat_data_enabled = 1;
2589 spin_unlock_irq(shost->host_lock);
2590 return strlen(buf);
2591 }
2592
2593 if (!strncmp(buf, "stop", strlen("stop"))) {
2594 spin_lock_irq(shost->host_lock);
2595 if (vport->stat_data_enabled == 0) {
2596 spin_unlock_irq(shost->host_lock);
2597 return strlen(buf);
2598 }
2599 lpfc_free_bucket(vport);
2600 vport->stat_data_enabled = 0;
2601 spin_unlock_irq(shost->host_lock);
2602 return strlen(buf);
2603 }
2604
2605 if (!strncmp(buf, "reset", strlen("reset"))) {
2606 if ((phba->bucket_type == LPFC_NO_BUCKET)
2607 || !vport->stat_data_enabled)
2608 return strlen(buf);
2609 spin_lock_irq(shost->host_lock);
2610 vport->stat_data_blocked = 1;
2611 lpfc_vport_reset_stat_data(vport);
2612 vport->stat_data_blocked = 0;
2613 spin_unlock_irq(shost->host_lock);
2614 return strlen(buf);
2615 }
2616 return -EINVAL;
2617}
2618
2619
2620/**
James Smart3621a712009-04-06 18:47:14 -04002621 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002622 * @dev: Pointer to class device object.
2623 * @buf: Data buffer.
2624 *
2625 * This function is the read call back function for
2626 * lpfc_stat_data_ctrl sysfs file. This function report the
2627 * current statistical data collection state.
2628 **/
2629static ssize_t
2630lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2631 char *buf)
2632{
2633 struct Scsi_Host *shost = class_to_shost(dev);
2634 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2635 struct lpfc_hba *phba = vport->phba;
2636 int index = 0;
2637 int i;
2638 char *bucket_type;
2639 unsigned long bucket_value;
2640
2641 switch (phba->bucket_type) {
2642 case LPFC_LINEAR_BUCKET:
2643 bucket_type = "linear";
2644 break;
2645 case LPFC_POWER2_BUCKET:
2646 bucket_type = "power2";
2647 break;
2648 default:
2649 bucket_type = "No Bucket";
2650 break;
2651 }
2652
2653 sprintf(&buf[index], "Statistical Data enabled :%d, "
2654 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2655 " Bucket step :%d\nLatency Ranges :",
2656 vport->stat_data_enabled, vport->stat_data_blocked,
2657 bucket_type, phba->bucket_base, phba->bucket_step);
2658 index = strlen(buf);
2659 if (phba->bucket_type != LPFC_NO_BUCKET) {
2660 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2661 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2662 bucket_value = phba->bucket_base +
2663 phba->bucket_step * i;
2664 else
2665 bucket_value = phba->bucket_base +
2666 (1 << i) * phba->bucket_step;
2667
2668 if (index + 10 > PAGE_SIZE)
2669 break;
2670 sprintf(&buf[index], "%08ld ", bucket_value);
2671 index = strlen(buf);
2672 }
2673 }
2674 sprintf(&buf[index], "\n");
2675 return strlen(buf);
2676}
2677
2678/*
2679 * Sysfs attribute to control the statistical data collection.
2680 */
2681static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2682 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2683
2684/*
2685 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2686 */
2687
2688/*
2689 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2690 * for each target.
2691 */
2692#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2693#define MAX_STAT_DATA_SIZE_PER_TARGET \
2694 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2695
2696
2697/**
James Smart3621a712009-04-06 18:47:14 -04002698 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002699 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002700 * @kobj: Pointer to the kernel object
2701 * @bin_attr: Attribute object
2702 * @buff: Buffer pointer
2703 * @off: File offset
2704 * @count: Buffer size
2705 *
2706 * This function is the read call back function for lpfc_drvr_stat_data
2707 * sysfs file. This function export the statistical data to user
2708 * applications.
2709 **/
2710static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002711sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2712 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002713 char *buf, loff_t off, size_t count)
2714{
2715 struct device *dev = container_of(kobj, struct device,
2716 kobj);
2717 struct Scsi_Host *shost = class_to_shost(dev);
2718 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2719 struct lpfc_hba *phba = vport->phba;
2720 int i = 0, index = 0;
2721 unsigned long nport_index;
2722 struct lpfc_nodelist *ndlp = NULL;
2723 nport_index = (unsigned long)off /
2724 MAX_STAT_DATA_SIZE_PER_TARGET;
2725
2726 if (!vport->stat_data_enabled || vport->stat_data_blocked
2727 || (phba->bucket_type == LPFC_NO_BUCKET))
2728 return 0;
2729
2730 spin_lock_irq(shost->host_lock);
2731 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2732 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2733 continue;
2734
2735 if (nport_index > 0) {
2736 nport_index--;
2737 continue;
2738 }
2739
2740 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2741 > count)
2742 break;
2743
2744 if (!ndlp->lat_data)
2745 continue;
2746
2747 /* Print the WWN */
2748 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2749 ndlp->nlp_portname.u.wwn[0],
2750 ndlp->nlp_portname.u.wwn[1],
2751 ndlp->nlp_portname.u.wwn[2],
2752 ndlp->nlp_portname.u.wwn[3],
2753 ndlp->nlp_portname.u.wwn[4],
2754 ndlp->nlp_portname.u.wwn[5],
2755 ndlp->nlp_portname.u.wwn[6],
2756 ndlp->nlp_portname.u.wwn[7]);
2757
2758 index = strlen(buf);
2759
2760 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2761 sprintf(&buf[index], "%010u,",
2762 ndlp->lat_data[i].cmd_count);
2763 index = strlen(buf);
2764 }
2765 sprintf(&buf[index], "\n");
2766 index = strlen(buf);
2767 }
2768 spin_unlock_irq(shost->host_lock);
2769 return index;
2770}
2771
2772static struct bin_attribute sysfs_drvr_stat_data_attr = {
2773 .attr = {
2774 .name = "lpfc_drvr_stat_data",
2775 .mode = S_IRUSR,
2776 .owner = THIS_MODULE,
2777 },
2778 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2779 .read = sysfs_drvr_stat_data_read,
2780 .write = NULL,
2781};
2782
dea31012005-04-17 16:05:31 -05002783/*
2784# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2785# connection.
2786# 0 = auto select (default)
2787# 1 = 1 Gigabaud
2788# 2 = 2 Gigabaud
2789# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002790# 8 = 8 Gigabaud
2791# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002792*/
James Smarte59058c2008-08-24 21:49:00 -04002793
2794/**
James Smart3621a712009-04-06 18:47:14 -04002795 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002796 * @phba: lpfc_hba pointer.
2797 * @val: link speed value.
2798 *
2799 * Description:
2800 * If val is in a valid range then set the adapter's link speed field and
2801 * issue a lip; if the lip fails reset the link speed to the old value.
2802 *
2803 * Notes:
2804 * If the value is not in range log a kernel error message and return an error.
2805 *
2806 * Returns:
2807 * zero if val is in range and lip okay.
2808 * non-zero return value from lpfc_issue_lip()
2809 * -EINVAL val out of range
2810 **/
James Smarta257bf92009-04-06 18:48:10 -04002811static ssize_t
2812lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2813 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002814{
James Smarta257bf92009-04-06 18:48:10 -04002815 struct Scsi_Host *shost = class_to_shost(dev);
2816 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2817 struct lpfc_hba *phba = vport->phba;
2818 int val = 0;
2819 int nolip = 0;
2820 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002821 int err;
2822 uint32_t prev_val;
2823
James Smarta257bf92009-04-06 18:48:10 -04002824 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2825 nolip = 1;
2826 val_buf = &buf[strlen("nolip ")];
2827 }
2828
2829 if (!isdigit(val_buf[0]))
2830 return -EINVAL;
2831 if (sscanf(val_buf, "%i", &val) != 1)
2832 return -EINVAL;
2833
James Smart83108bd2008-01-11 01:53:09 -05002834 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2835 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2836 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2837 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2838 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2839 return -EINVAL;
2840
James Smarta257bf92009-04-06 18:48:10 -04002841 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002842 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2843 prev_val = phba->cfg_link_speed;
2844 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002845 if (nolip)
2846 return strlen(buf);
2847
James Smart83108bd2008-01-11 01:53:09 -05002848 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002849 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002850 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002851 return -EINVAL;
2852 } else
2853 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002854 }
2855
2856 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2857 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2858 "allowed range is [0, 8]\n",
2859 phba->brd_no, val);
2860 return -EINVAL;
2861}
2862
2863static int lpfc_link_speed = 0;
2864module_param(lpfc_link_speed, int, 0);
2865MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2866lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002867
2868/**
James Smart3621a712009-04-06 18:47:14 -04002869 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002870 * @phba: lpfc_hba pointer.
2871 * @val: link speed value.
2872 *
2873 * Description:
2874 * If val is in a valid range then set the adapter's link speed field.
2875 *
2876 * Notes:
2877 * If the value is not in range log a kernel error message, clear the link
2878 * speed and return an error.
2879 *
2880 * Returns:
2881 * zero if val saved.
2882 * -EINVAL val out of range
2883 **/
James Smart83108bd2008-01-11 01:53:09 -05002884static int
2885lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2886{
2887 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2888 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2889 phba->cfg_link_speed = val;
2890 return 0;
2891 }
2892 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002893 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002894 "be set to %d, allowed values are "
2895 "["LPFC_LINK_SPEED_STRING"]\n", val);
2896 phba->cfg_link_speed = 0;
2897 return -EINVAL;
2898}
2899
Tony Jonesee959b02008-02-22 00:13:36 +01002900static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002901 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002902
2903/*
James Smart0d878412009-10-02 15:16:56 -04002904# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2905# 0 = aer disabled or not supported
2906# 1 = aer supported and enabled (default)
2907# Value range is [0,1]. Default value is 1.
2908*/
2909
2910/**
2911 * lpfc_aer_support_store - Set the adapter for aer support
2912 *
2913 * @dev: class device that is converted into a Scsi_host.
2914 * @attr: device attribute, not used.
2915 * @buf: containing the string "selective".
2916 * @count: unused variable.
2917 *
2918 * Description:
2919 * If the val is 1 and currently the device's AER capability was not
2920 * enabled, invoke the kernel's enable AER helper routine, trying to
2921 * enable the device's AER capability. If the helper routine enabling
2922 * AER returns success, update the device's cfg_aer_support flag to
2923 * indicate AER is supported by the device; otherwise, if the device
2924 * AER capability is already enabled to support AER, then do nothing.
2925 *
2926 * If the val is 0 and currently the device's AER support was enabled,
2927 * invoke the kernel's disable AER helper routine. After that, update
2928 * the device's cfg_aer_support flag to indicate AER is not supported
2929 * by the device; otherwise, if the device AER capability is already
2930 * disabled from supporting AER, then do nothing.
2931 *
2932 * Returns:
2933 * length of the buf on success if val is in range the intended mode
2934 * is supported.
2935 * -EINVAL if val out of range or intended mode is not supported.
2936 **/
2937static ssize_t
2938lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2939 const char *buf, size_t count)
2940{
2941 struct Scsi_Host *shost = class_to_shost(dev);
2942 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2943 struct lpfc_hba *phba = vport->phba;
2944 int val = 0, rc = -EINVAL;
2945
James Smart891478a2009-11-18 15:40:23 -05002946 /* AER not supported on OC devices yet */
2947 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
2948 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04002949 if (!isdigit(buf[0]))
2950 return -EINVAL;
2951 if (sscanf(buf, "%i", &val) != 1)
2952 return -EINVAL;
2953
2954 switch (val) {
2955 case 0:
2956 if (phba->hba_flag & HBA_AER_ENABLED) {
2957 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2958 if (!rc) {
2959 spin_lock_irq(&phba->hbalock);
2960 phba->hba_flag &= ~HBA_AER_ENABLED;
2961 spin_unlock_irq(&phba->hbalock);
2962 phba->cfg_aer_support = 0;
2963 rc = strlen(buf);
2964 } else
James Smart891478a2009-11-18 15:40:23 -05002965 rc = -EPERM;
2966 } else {
James Smart0d878412009-10-02 15:16:56 -04002967 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05002968 rc = strlen(buf);
2969 }
James Smart0d878412009-10-02 15:16:56 -04002970 break;
2971 case 1:
2972 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2973 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2974 if (!rc) {
2975 spin_lock_irq(&phba->hbalock);
2976 phba->hba_flag |= HBA_AER_ENABLED;
2977 spin_unlock_irq(&phba->hbalock);
2978 phba->cfg_aer_support = 1;
2979 rc = strlen(buf);
2980 } else
James Smart891478a2009-11-18 15:40:23 -05002981 rc = -EPERM;
2982 } else {
James Smart0d878412009-10-02 15:16:56 -04002983 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05002984 rc = strlen(buf);
2985 }
James Smart0d878412009-10-02 15:16:56 -04002986 break;
2987 default:
2988 rc = -EINVAL;
2989 break;
2990 }
2991 return rc;
2992}
2993
2994static int lpfc_aer_support = 1;
2995module_param(lpfc_aer_support, int, 1);
2996MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2997lpfc_param_show(aer_support)
2998
2999/**
3000 * lpfc_aer_support_init - Set the initial adapters aer support flag
3001 * @phba: lpfc_hba pointer.
3002 * @val: link speed value.
3003 *
3004 * Description:
3005 * If val is in a valid range [0,1], then set the adapter's initial
3006 * cfg_aer_support field. It will be up to the driver's probe_one
3007 * routine to determine whether the device's AER support can be set
3008 * or not.
3009 *
3010 * Notes:
3011 * If the value is not in range log a kernel error message, and
3012 * choose the default value of setting AER support and return.
3013 *
3014 * Returns:
3015 * zero if val saved.
3016 * -EINVAL val out of range
3017 **/
3018static int
3019lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3020{
James Smart891478a2009-11-18 15:40:23 -05003021 /* AER not supported on OC devices yet */
3022 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3023 phba->cfg_aer_support = 0;
3024 return -EPERM;
3025 }
3026
James Smart0d878412009-10-02 15:16:56 -04003027 if (val == 0 || val == 1) {
3028 phba->cfg_aer_support = val;
3029 return 0;
3030 }
3031 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3032 "2712 lpfc_aer_support attribute value %d out "
3033 "of range, allowed values are 0|1, setting it "
3034 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003035 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003036 phba->cfg_aer_support = 1;
3037 return -EINVAL;
3038}
3039
3040static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3041 lpfc_aer_support_show, lpfc_aer_support_store);
3042
3043/**
3044 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3045 * @dev: class device that is converted into a Scsi_host.
3046 * @attr: device attribute, not used.
3047 * @buf: containing the string "selective".
3048 * @count: unused variable.
3049 *
3050 * Description:
3051 * If the @buf contains 1 and the device currently has the AER support
3052 * enabled, then invokes the kernel AER helper routine
3053 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3054 * error status register.
3055 *
3056 * Notes:
3057 *
3058 * Returns:
3059 * -EINVAL if the buf does not contain the 1 or the device is not currently
3060 * enabled with the AER support.
3061 **/
3062static ssize_t
3063lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3064 const char *buf, size_t count)
3065{
3066 struct Scsi_Host *shost = class_to_shost(dev);
3067 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3068 struct lpfc_hba *phba = vport->phba;
3069 int val, rc = -1;
3070
James Smart891478a2009-11-18 15:40:23 -05003071 /* AER not supported on OC devices yet */
3072 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
3073 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003074 if (!isdigit(buf[0]))
3075 return -EINVAL;
3076 if (sscanf(buf, "%i", &val) != 1)
3077 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003078 if (val != 1)
3079 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003080
James Smart891478a2009-11-18 15:40:23 -05003081 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003082 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3083
3084 if (rc == 0)
3085 return strlen(buf);
3086 else
James Smart891478a2009-11-18 15:40:23 -05003087 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003088}
3089
3090static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3091 lpfc_aer_cleanup_state);
3092
3093/*
dea31012005-04-17 16:05:31 -05003094# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3095# Value range is [2,3]. Default value is 3.
3096*/
James Smart3de2a652007-08-02 11:09:59 -04003097LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3098 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003099
3100/*
3101# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3102# is [0,1]. Default value is 0.
3103*/
James Smart3de2a652007-08-02 11:09:59 -04003104LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3105 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003106
3107/*
James Smart977b5a02008-09-07 11:52:04 -04003108# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3109# depth. Default value is 0. When the value of this parameter is zero the
3110# SCSI command completion time is not used for controlling I/O queue depth. When
3111# the parameter is set to a non-zero value, the I/O queue depth is controlled
3112# to limit the I/O completion time to the parameter value.
3113# The value is set in milliseconds.
3114*/
3115static int lpfc_max_scsicmpl_time;
3116module_param(lpfc_max_scsicmpl_time, int, 0);
3117MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3118 "Use command completion time to control queue depth");
3119lpfc_vport_param_show(max_scsicmpl_time);
3120lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3121static int
3122lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3123{
3124 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3125 struct lpfc_nodelist *ndlp, *next_ndlp;
3126
3127 if (val == vport->cfg_max_scsicmpl_time)
3128 return 0;
3129 if ((val < 0) || (val > 60000))
3130 return -EINVAL;
3131 vport->cfg_max_scsicmpl_time = val;
3132
3133 spin_lock_irq(shost->host_lock);
3134 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3135 if (!NLP_CHK_NODE_ACT(ndlp))
3136 continue;
3137 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3138 continue;
3139 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
3140 }
3141 spin_unlock_irq(shost->host_lock);
3142 return 0;
3143}
3144lpfc_vport_param_store(max_scsicmpl_time);
3145static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3146 lpfc_max_scsicmpl_time_show,
3147 lpfc_max_scsicmpl_time_store);
3148
3149/*
dea31012005-04-17 16:05:31 -05003150# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3151# range is [0,1]. Default value is 0.
3152*/
3153LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3154
3155/*
3156# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3157# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003158# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003159# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3160# cr_delay is set to 0.
3161*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003162LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003163 "interrupt response is generated");
3164
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003165LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003166 "interrupt response is generated");
3167
3168/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003169# lpfc_multi_ring_support: Determines how many rings to spread available
3170# cmd/rsp IOCB entries across.
3171# Value range is [1,2]. Default value is 1.
3172*/
3173LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3174 "SLI rings to spread IOCB entries across");
3175
3176/*
James Smarta4bc3372006-12-02 13:34:16 -05003177# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3178# identifies what rctl value to configure the additional ring for.
3179# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3180*/
James Smart6a9c52c2009-10-02 15:16:51 -04003181LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003182 255, "Identifies RCTL for additional ring configuration");
3183
3184/*
3185# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3186# identifies what type value to configure the additional ring for.
3187# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3188*/
James Smart6a9c52c2009-10-02 15:16:51 -04003189LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003190 255, "Identifies TYPE for additional ring configuration");
3191
3192/*
dea31012005-04-17 16:05:31 -05003193# lpfc_fdmi_on: controls FDMI support.
3194# 0 = no FDMI support
3195# 1 = support FDMI without attribute of hostname
3196# 2 = support FDMI with attribute of hostname
3197# Value range [0,2]. Default value is 0.
3198*/
James Smart3de2a652007-08-02 11:09:59 -04003199LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003200
3201/*
3202# Specifies the maximum number of ELS cmds we can have outstanding (for
3203# discovery). Value range is [1,64]. Default value = 32.
3204*/
James Smart3de2a652007-08-02 11:09:59 -04003205LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003206 "during discovery");
3207
3208/*
James Smart65a29c12006-07-06 15:50:50 -04003209# lpfc_max_luns: maximum allowed LUN.
3210# Value range is [0,65535]. Default value is 255.
3211# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003212*/
James Smart3de2a652007-08-02 11:09:59 -04003213LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003214
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003215/*
3216# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3217# Value range is [1,255], default value is 10.
3218*/
3219LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3220 "Milliseconds driver will wait between polling FCP ring");
3221
James Smart4ff43242006-12-02 13:34:56 -05003222/*
3223# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3224# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003225# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003226# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003227# 2 = MSI-X enabled (default)
3228# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003229*/
George Kadianakis8605c462010-01-17 21:19:31 +02003230LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003231 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003232
James Smart13815c82008-01-11 01:52:48 -05003233/*
James Smartda0436e2009-05-22 14:51:39 -04003234# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3235#
3236# Value range is [636,651042]. Default value is 10000.
3237*/
3238LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3239 "Set the maximum number of fast-path FCP interrupts per second");
3240
3241/*
3242# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3243#
3244# Value range is [1,31]. Default value is 4.
3245*/
3246LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3247 "Set the number of fast-path FCP work queues, if possible");
3248
3249/*
3250# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3251#
3252# Value range is [1,7]. Default value is 1.
3253*/
3254LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3255 "Set the number of fast-path FCP event queues, if possible");
3256
3257/*
James Smart13815c82008-01-11 01:52:48 -05003258# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3259# 0 = HBA resets disabled
3260# 1 = HBA resets enabled (default)
3261# Value range is [0,1]. Default value is 1.
3262*/
3263LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003264
James Smart13815c82008-01-11 01:52:48 -05003265/*
3266# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3267# 0 = HBA Heartbeat disabled
3268# 1 = HBA Heartbeat enabled (default)
3269# Value range is [0,1]. Default value is 1.
3270*/
3271LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003272
James Smart83108bd2008-01-11 01:53:09 -05003273/*
James Smart81301a92008-12-04 22:39:46 -05003274# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3275# 0 = BlockGuard disabled (default)
3276# 1 = BlockGuard enabled
3277# Value range is [0,1]. Default value is 0.
3278*/
3279LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3280
James Smart6fb120a2009-05-22 14:52:59 -04003281/*
James Smart81301a92008-12-04 22:39:46 -05003282# lpfc_prot_mask: i
3283# - Bit mask of host protection capabilities used to register with the
3284# SCSI mid-layer
3285# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3286# - Allows you to ultimately specify which profiles to use
3287# - Default will result in registering capabilities for all profiles.
3288#
3289*/
3290unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3291
3292module_param(lpfc_prot_mask, uint, 0);
3293MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3294
3295/*
3296# lpfc_prot_guard: i
3297# - Bit mask of protection guard types to register with the SCSI mid-layer
3298# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3299# - Allows you to ultimately specify which profiles to use
3300# - Default will result in registering capabilities for all guard types
3301#
3302*/
3303unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3304module_param(lpfc_prot_guard, byte, 0);
3305MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3306
3307
3308/*
James Smart3621a712009-04-06 18:47:14 -04003309 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003310 * This value can be set to values between 64 and 256. The default value is
3311 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3312 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3313 */
3314LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3315 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3316
James Smart81301a92008-12-04 22:39:46 -05003317LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3318 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3319 "Max Protection Scatter Gather Segment Count");
3320
Tony Jonesee959b02008-02-22 00:13:36 +01003321struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003322 &dev_attr_bg_info,
3323 &dev_attr_bg_guard_err,
3324 &dev_attr_bg_apptag_err,
3325 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003326 &dev_attr_info,
3327 &dev_attr_serialnum,
3328 &dev_attr_modeldesc,
3329 &dev_attr_modelname,
3330 &dev_attr_programtype,
3331 &dev_attr_portnum,
3332 &dev_attr_fwrev,
3333 &dev_attr_hdw,
3334 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003335 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003336 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003337 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003338 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003339 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003340 &dev_attr_lpfc_temp_sensor,
3341 &dev_attr_lpfc_log_verbose,
3342 &dev_attr_lpfc_lun_queue_depth,
3343 &dev_attr_lpfc_hba_queue_depth,
3344 &dev_attr_lpfc_peer_port_login,
3345 &dev_attr_lpfc_nodev_tmo,
3346 &dev_attr_lpfc_devloss_tmo,
3347 &dev_attr_lpfc_fcp_class,
3348 &dev_attr_lpfc_use_adisc,
3349 &dev_attr_lpfc_ack0,
3350 &dev_attr_lpfc_topology,
3351 &dev_attr_lpfc_scan_down,
3352 &dev_attr_lpfc_link_speed,
3353 &dev_attr_lpfc_cr_delay,
3354 &dev_attr_lpfc_cr_count,
3355 &dev_attr_lpfc_multi_ring_support,
3356 &dev_attr_lpfc_multi_ring_rctl,
3357 &dev_attr_lpfc_multi_ring_type,
3358 &dev_attr_lpfc_fdmi_on,
3359 &dev_attr_lpfc_max_luns,
3360 &dev_attr_lpfc_enable_npiv,
3361 &dev_attr_nport_evt_cnt,
3362 &dev_attr_board_mode,
3363 &dev_attr_max_vpi,
3364 &dev_attr_used_vpi,
3365 &dev_attr_max_rpi,
3366 &dev_attr_used_rpi,
3367 &dev_attr_max_xri,
3368 &dev_attr_used_xri,
3369 &dev_attr_npiv_info,
3370 &dev_attr_issue_reset,
3371 &dev_attr_lpfc_poll,
3372 &dev_attr_lpfc_poll_tmo,
3373 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003374 &dev_attr_lpfc_fcp_imax,
3375 &dev_attr_lpfc_fcp_wq_count,
3376 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003377 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003378 &dev_attr_lpfc_soft_wwnn,
3379 &dev_attr_lpfc_soft_wwpn,
3380 &dev_attr_lpfc_soft_wwn_enable,
3381 &dev_attr_lpfc_enable_hba_reset,
3382 &dev_attr_lpfc_enable_hba_heartbeat,
3383 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003384 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003385 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003386 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003387 &dev_attr_lpfc_aer_support,
3388 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003389 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003390 &dev_attr_lpfc_iocb_cnt,
3391 &dev_attr_iocb_hw,
3392 &dev_attr_txq_hw,
3393 &dev_attr_txcmplq_hw,
dea31012005-04-17 16:05:31 -05003394 NULL,
3395};
3396
Tony Jonesee959b02008-02-22 00:13:36 +01003397struct device_attribute *lpfc_vport_attrs[] = {
3398 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003399 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003400 &dev_attr_num_discovered_ports,
3401 &dev_attr_lpfc_drvr_version,
3402 &dev_attr_lpfc_log_verbose,
3403 &dev_attr_lpfc_lun_queue_depth,
3404 &dev_attr_lpfc_nodev_tmo,
3405 &dev_attr_lpfc_devloss_tmo,
3406 &dev_attr_lpfc_hba_queue_depth,
3407 &dev_attr_lpfc_peer_port_login,
3408 &dev_attr_lpfc_restrict_login,
3409 &dev_attr_lpfc_fcp_class,
3410 &dev_attr_lpfc_use_adisc,
3411 &dev_attr_lpfc_fdmi_on,
3412 &dev_attr_lpfc_max_luns,
3413 &dev_attr_nport_evt_cnt,
3414 &dev_attr_npiv_info,
3415 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003416 &dev_attr_lpfc_max_scsicmpl_time,
3417 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003418 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003419 NULL,
3420};
3421
James Smarte59058c2008-08-24 21:49:00 -04003422/**
James Smart3621a712009-04-06 18:47:14 -04003423 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003424 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003425 * @kobj: kernel kobject that contains the kernel class device.
3426 * @bin_attr: kernel attributes passed to us.
3427 * @buf: contains the data to be written to the adapter IOREG space.
3428 * @off: offset into buffer to beginning of data.
3429 * @count: bytes to transfer.
3430 *
3431 * Description:
3432 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3433 * Uses the adapter io control registers to send buf contents to the adapter.
3434 *
3435 * Returns:
3436 * -ERANGE off and count combo out of range
3437 * -EINVAL off, count or buff address invalid
3438 * -EPERM adapter is offline
3439 * value of count, buf contents written
3440 **/
dea31012005-04-17 16:05:31 -05003441static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003442sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3443 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003444 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003445{
3446 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003447 struct device *dev = container_of(kobj, struct device, kobj);
3448 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003449 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3450 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003451
James Smartf1126682009-06-10 17:22:44 -04003452 if (phba->sli_rev >= LPFC_SLI_REV4)
3453 return -EPERM;
3454
dea31012005-04-17 16:05:31 -05003455 if ((off + count) > FF_REG_AREA_SIZE)
3456 return -ERANGE;
3457
3458 if (count == 0) return 0;
3459
3460 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3461 return -EINVAL;
3462
James Smart2e0fef82007-06-17 19:56:36 -05003463 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003464 return -EPERM;
3465 }
3466
James Smart2e0fef82007-06-17 19:56:36 -05003467 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003468 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3469 writel(*((uint32_t *)(buf + buf_off)),
3470 phba->ctrl_regs_memmap_p + off + buf_off);
3471
James Smart2e0fef82007-06-17 19:56:36 -05003472 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003473
3474 return count;
3475}
3476
James Smarte59058c2008-08-24 21:49:00 -04003477/**
James Smart3621a712009-04-06 18:47:14 -04003478 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003479 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003480 * @kobj: kernel kobject that contains the kernel class device.
3481 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003482 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003483 * @off: offset into buffer to beginning of data.
3484 * @count: bytes to transfer.
3485 *
3486 * Description:
3487 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3488 * Uses the adapter io control registers to read data into buf.
3489 *
3490 * Returns:
3491 * -ERANGE off and count combo out of range
3492 * -EINVAL off, count or buff address invalid
3493 * value of count, buf contents read
3494 **/
dea31012005-04-17 16:05:31 -05003495static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003496sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3497 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003498 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003499{
3500 size_t buf_off;
3501 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003502 struct device *dev = container_of(kobj, struct device, kobj);
3503 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3505 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003506
James Smartf1126682009-06-10 17:22:44 -04003507 if (phba->sli_rev >= LPFC_SLI_REV4)
3508 return -EPERM;
3509
dea31012005-04-17 16:05:31 -05003510 if (off > FF_REG_AREA_SIZE)
3511 return -ERANGE;
3512
3513 if ((off + count) > FF_REG_AREA_SIZE)
3514 count = FF_REG_AREA_SIZE - off;
3515
3516 if (count == 0) return 0;
3517
3518 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3519 return -EINVAL;
3520
James Smart2e0fef82007-06-17 19:56:36 -05003521 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003522
3523 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3524 tmp_ptr = (uint32_t *)(buf + buf_off);
3525 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3526 }
3527
James Smart2e0fef82007-06-17 19:56:36 -05003528 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003529
3530 return count;
3531}
3532
3533static struct bin_attribute sysfs_ctlreg_attr = {
3534 .attr = {
3535 .name = "ctlreg",
3536 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003537 },
3538 .size = 256,
3539 .read = sysfs_ctlreg_read,
3540 .write = sysfs_ctlreg_write,
3541};
3542
James Smarte59058c2008-08-24 21:49:00 -04003543/**
James Smart3621a712009-04-06 18:47:14 -04003544 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003545 * @phba: lpfc_hba pointer
3546 **/
dea31012005-04-17 16:05:31 -05003547static void
James Smart2e0fef82007-06-17 19:56:36 -05003548sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003549{
3550 phba->sysfs_mbox.state = SMBOX_IDLE;
3551 phba->sysfs_mbox.offset = 0;
3552
3553 if (phba->sysfs_mbox.mbox) {
3554 mempool_free(phba->sysfs_mbox.mbox,
3555 phba->mbox_mem_pool);
3556 phba->sysfs_mbox.mbox = NULL;
3557 }
3558}
3559
James Smarte59058c2008-08-24 21:49:00 -04003560/**
James Smart3621a712009-04-06 18:47:14 -04003561 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003562 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003563 * @kobj: kernel kobject that contains the kernel class device.
3564 * @bin_attr: kernel attributes passed to us.
3565 * @buf: contains the data to be written to sysfs mbox.
3566 * @off: offset into buffer to beginning of data.
3567 * @count: bytes to transfer.
3568 *
3569 * Description:
3570 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3571 * Uses the sysfs mbox to send buf contents to the adapter.
3572 *
3573 * Returns:
3574 * -ERANGE off and count combo out of range
3575 * -EINVAL off, count or buff address invalid
3576 * zero if count is zero
3577 * -EPERM adapter is offline
3578 * -ENOMEM failed to allocate memory for the mail box
3579 * -EAGAIN offset, state or mbox is NULL
3580 * count number of bytes transferred
3581 **/
dea31012005-04-17 16:05:31 -05003582static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003583sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3584 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003585 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003586{
Tony Jonesee959b02008-02-22 00:13:36 +01003587 struct device *dev = container_of(kobj, struct device, kobj);
3588 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3590 struct lpfc_hba *phba = vport->phba;
3591 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003592
3593 if ((count + off) > MAILBOX_CMD_SIZE)
3594 return -ERANGE;
3595
3596 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3597 return -EINVAL;
3598
3599 if (count == 0)
3600 return 0;
3601
3602 if (off == 0) {
3603 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3604 if (!mbox)
3605 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003606 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003607 }
3608
James Smart2e0fef82007-06-17 19:56:36 -05003609 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003610
3611 if (off == 0) {
3612 if (phba->sysfs_mbox.mbox)
3613 mempool_free(mbox, phba->mbox_mem_pool);
3614 else
3615 phba->sysfs_mbox.mbox = mbox;
3616 phba->sysfs_mbox.state = SMBOX_WRITING;
3617 } else {
3618 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3619 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003620 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003621 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003622 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003623 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003624 }
3625 }
3626
James Smart04c68492009-05-22 14:52:52 -04003627 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003628 buf, count);
3629
3630 phba->sysfs_mbox.offset = off + count;
3631
James Smart2e0fef82007-06-17 19:56:36 -05003632 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003633
3634 return count;
3635}
3636
James Smarte59058c2008-08-24 21:49:00 -04003637/**
James Smart3621a712009-04-06 18:47:14 -04003638 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003639 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003640 * @kobj: kernel kobject that contains the kernel class device.
3641 * @bin_attr: kernel attributes passed to us.
3642 * @buf: contains the data to be read from sysfs mbox.
3643 * @off: offset into buffer to beginning of data.
3644 * @count: bytes to transfer.
3645 *
3646 * Description:
3647 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3648 * Uses the sysfs mbox to receive data from to the adapter.
3649 *
3650 * Returns:
3651 * -ERANGE off greater than mailbox command size
3652 * -EINVAL off, count or buff address invalid
3653 * zero if off and count are zero
3654 * -EACCES adapter over temp
3655 * -EPERM garbage can value to catch a multitude of errors
3656 * -EAGAIN management IO not permitted, state or off error
3657 * -ETIME mailbox timeout
3658 * -ENODEV mailbox error
3659 * count number of bytes transferred
3660 **/
dea31012005-04-17 16:05:31 -05003661static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003662sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3663 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003664 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003665{
Tony Jonesee959b02008-02-22 00:13:36 +01003666 struct device *dev = container_of(kobj, struct device, kobj);
3667 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003668 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3669 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003670 int rc;
James Smart04c68492009-05-22 14:52:52 -04003671 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003672
James Smart1dcb58e2007-04-25 09:51:30 -04003673 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003674 return -ERANGE;
3675
James Smart1dcb58e2007-04-25 09:51:30 -04003676 if ((count + off) > MAILBOX_CMD_SIZE)
3677 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003678
3679 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3680 return -EINVAL;
3681
3682 if (off && count == 0)
3683 return 0;
3684
James Smart2e0fef82007-06-17 19:56:36 -05003685 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003686
James Smart7af67052007-10-27 13:38:11 -04003687 if (phba->over_temp_state == HBA_OVER_TEMP) {
3688 sysfs_mbox_idle(phba);
3689 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003690 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003691 }
3692
dea31012005-04-17 16:05:31 -05003693 if (off == 0 &&
3694 phba->sysfs_mbox.state == SMBOX_WRITING &&
3695 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003696 pmb = &phba->sysfs_mbox.mbox->u.mb;
3697 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003698 /* Offline only */
dea31012005-04-17 16:05:31 -05003699 case MBX_INIT_LINK:
3700 case MBX_DOWN_LINK:
3701 case MBX_CONFIG_LINK:
3702 case MBX_CONFIG_RING:
3703 case MBX_RESET_RING:
3704 case MBX_UNREG_LOGIN:
3705 case MBX_CLEAR_LA:
3706 case MBX_DUMP_CONTEXT:
3707 case MBX_RUN_DIAGS:
3708 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003709 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003710 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003711 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003712 printk(KERN_WARNING "mbox_read:Command 0x%x "
3713 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003714 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003715 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003716 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003717 return -EPERM;
3718 }
James Smarta8adb832007-10-27 13:37:53 -04003719 case MBX_WRITE_NV:
3720 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003721 case MBX_LOAD_SM:
3722 case MBX_READ_NV:
3723 case MBX_READ_CONFIG:
3724 case MBX_READ_RCONFIG:
3725 case MBX_READ_STATUS:
3726 case MBX_READ_XRI:
3727 case MBX_READ_REV:
3728 case MBX_READ_LNK_STAT:
3729 case MBX_DUMP_MEMORY:
3730 case MBX_DOWN_LOAD:
3731 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003732 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003733 case MBX_LOAD_AREA:
3734 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003735 case MBX_BEACON:
3736 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003737 case MBX_SET_VARIABLE:
3738 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003739 case MBX_PORT_CAPABILITIES:
3740 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003741 break;
3742 case MBX_READ_SPARM64:
3743 case MBX_READ_LA:
3744 case MBX_READ_LA64:
3745 case MBX_REG_LOGIN:
3746 case MBX_REG_LOGIN64:
3747 case MBX_CONFIG_PORT:
3748 case MBX_RUN_BIU_DIAG:
3749 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003750 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003751 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003752 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003753 return -EPERM;
3754 default:
3755 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003756 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003757 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003758 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003759 return -EPERM;
3760 }
3761
James Smart09372822008-01-11 01:52:54 -05003762 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003763 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003764 */
James Smartd7c255b2008-08-24 21:50:00 -04003765 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003766 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3767 pmb->mbxCommand != MBX_RESTART &&
3768 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3769 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003770 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3771 "1259 mbox: Issued mailbox cmd "
3772 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003773 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003774
James Smart92d7f7b2007-06-17 19:56:38 -05003775 phba->sysfs_mbox.mbox->vport = vport;
3776
James Smart58da1ff2008-04-07 10:15:56 -04003777 /* Don't allow mailbox commands to be sent when blocked
3778 * or when in the middle of discovery
3779 */
James Smart495a7142008-06-14 22:52:59 -04003780 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003781 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003782 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003783 return -EAGAIN;
3784 }
3785
James Smart2e0fef82007-06-17 19:56:36 -05003786 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003787 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003788
James Smart2e0fef82007-06-17 19:56:36 -05003789 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003790 rc = lpfc_sli_issue_mbox (phba,
3791 phba->sysfs_mbox.mbox,
3792 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003793 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003794
3795 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003796 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003797 rc = lpfc_sli_issue_mbox_wait (phba,
3798 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003799 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003800 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003801 }
3802
3803 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003804 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003805 phba->sysfs_mbox.mbox = NULL;
3806 }
dea31012005-04-17 16:05:31 -05003807 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003808 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003809 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003810 }
3811 phba->sysfs_mbox.state = SMBOX_READING;
3812 }
3813 else if (phba->sysfs_mbox.offset != off ||
3814 phba->sysfs_mbox.state != SMBOX_READING) {
3815 printk(KERN_WARNING "mbox_read: Bad State\n");
3816 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003817 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003818 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003819 }
3820
James Smart04c68492009-05-22 14:52:52 -04003821 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003822
3823 phba->sysfs_mbox.offset = off + count;
3824
James Smart1dcb58e2007-04-25 09:51:30 -04003825 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003826 sysfs_mbox_idle(phba);
3827
James Smart2e0fef82007-06-17 19:56:36 -05003828 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003829
3830 return count;
3831}
3832
3833static struct bin_attribute sysfs_mbox_attr = {
3834 .attr = {
3835 .name = "mbox",
3836 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003837 },
James Smart1dcb58e2007-04-25 09:51:30 -04003838 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003839 .read = sysfs_mbox_read,
3840 .write = sysfs_mbox_write,
3841};
3842
James Smarte59058c2008-08-24 21:49:00 -04003843/**
James Smart3621a712009-04-06 18:47:14 -04003844 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003845 * @vport: address of lpfc vport structure.
3846 *
3847 * Return codes:
3848 * zero on success
3849 * error return code from sysfs_create_bin_file()
3850 **/
dea31012005-04-17 16:05:31 -05003851int
James Smart2e0fef82007-06-17 19:56:36 -05003852lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003853{
James Smart2e0fef82007-06-17 19:56:36 -05003854 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003855 int error;
3856
Tony Jonesee959b02008-02-22 00:13:36 +01003857 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003858 &sysfs_drvr_stat_data_attr);
3859
3860 /* Virtual ports do not need ctrl_reg and mbox */
3861 if (error || vport->port_type == LPFC_NPIV_PORT)
3862 goto out;
3863
3864 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003865 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003866 if (error)
James Smarteada2722008-12-04 22:39:13 -05003867 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003868
Tony Jonesee959b02008-02-22 00:13:36 +01003869 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003870 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003871 if (error)
3872 goto out_remove_ctlreg_attr;
3873
3874 return 0;
3875out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003876 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003877out_remove_stat_attr:
3878 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3879 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003880out:
3881 return error;
3882}
3883
James Smarte59058c2008-08-24 21:49:00 -04003884/**
James Smart3621a712009-04-06 18:47:14 -04003885 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003886 * @vport: address of lpfc vport structure.
3887 **/
dea31012005-04-17 16:05:31 -05003888void
James Smart2e0fef82007-06-17 19:56:36 -05003889lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003890{
James Smart2e0fef82007-06-17 19:56:36 -05003891 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003892 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3893 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003894 /* Virtual ports do not need ctrl_reg and mbox */
3895 if (vport->port_type == LPFC_NPIV_PORT)
3896 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003897 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3898 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003899}
3900
3901
3902/*
3903 * Dynamic FC Host Attributes Support
3904 */
3905
James Smarte59058c2008-08-24 21:49:00 -04003906/**
James Smart3621a712009-04-06 18:47:14 -04003907 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003908 * @shost: kernel scsi host pointer.
3909 **/
dea31012005-04-17 16:05:31 -05003910static void
3911lpfc_get_host_port_id(struct Scsi_Host *shost)
3912{
James Smart2e0fef82007-06-17 19:56:36 -05003913 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3914
dea31012005-04-17 16:05:31 -05003915 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003916 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003917}
3918
James Smarte59058c2008-08-24 21:49:00 -04003919/**
James Smart3621a712009-04-06 18:47:14 -04003920 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003921 * @shost: kernel scsi host pointer.
3922 **/
dea31012005-04-17 16:05:31 -05003923static void
3924lpfc_get_host_port_type(struct Scsi_Host *shost)
3925{
James Smart2e0fef82007-06-17 19:56:36 -05003926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3927 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003928
3929 spin_lock_irq(shost->host_lock);
3930
James Smart92d7f7b2007-06-17 19:56:38 -05003931 if (vport->port_type == LPFC_NPIV_PORT) {
3932 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3933 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003934 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003935 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003936 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3937 else
3938 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3939 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003940 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003941 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3942 else
3943 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3944 }
3945 } else
3946 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3947
3948 spin_unlock_irq(shost->host_lock);
3949}
3950
James Smarte59058c2008-08-24 21:49:00 -04003951/**
James Smart3621a712009-04-06 18:47:14 -04003952 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003953 * @shost: kernel scsi host pointer.
3954 **/
dea31012005-04-17 16:05:31 -05003955static void
3956lpfc_get_host_port_state(struct Scsi_Host *shost)
3957{
James Smart2e0fef82007-06-17 19:56:36 -05003958 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003960
3961 spin_lock_irq(shost->host_lock);
3962
James Smart2e0fef82007-06-17 19:56:36 -05003963 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003964 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3965 else {
James Smart2e0fef82007-06-17 19:56:36 -05003966 switch (phba->link_state) {
3967 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003968 case LPFC_LINK_DOWN:
3969 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3970 break;
3971 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003972 case LPFC_CLEAR_LA:
3973 case LPFC_HBA_READY:
3974 /* Links up, beyond this port_type reports state */
3975 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3976 break;
3977 case LPFC_HBA_ERROR:
3978 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3979 break;
3980 default:
3981 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3982 break;
3983 }
3984 }
3985
3986 spin_unlock_irq(shost->host_lock);
3987}
3988
James Smarte59058c2008-08-24 21:49:00 -04003989/**
James Smart3621a712009-04-06 18:47:14 -04003990 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003991 * @shost: kernel scsi host pointer.
3992 **/
dea31012005-04-17 16:05:31 -05003993static void
3994lpfc_get_host_speed(struct Scsi_Host *shost)
3995{
James Smart2e0fef82007-06-17 19:56:36 -05003996 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3997 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003998
3999 spin_lock_irq(shost->host_lock);
4000
James Smart2e0fef82007-06-17 19:56:36 -05004001 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004002 switch(phba->fc_linkspeed) {
4003 case LA_1GHZ_LINK:
4004 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4005 break;
4006 case LA_2GHZ_LINK:
4007 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4008 break;
4009 case LA_4GHZ_LINK:
4010 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4011 break;
James Smartb87eab32007-04-25 09:53:28 -04004012 case LA_8GHZ_LINK:
4013 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4014 break;
James Smartf4b4c682009-05-22 14:53:12 -04004015 case LA_10GHZ_LINK:
4016 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4017 break;
dea31012005-04-17 16:05:31 -05004018 default:
4019 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4020 break;
4021 }
James Smart09372822008-01-11 01:52:54 -05004022 } else
4023 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004024
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_fabric_name - Set the value of the scsi host fabric name
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_fabric_name (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;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004037 u64 node_name;
dea31012005-04-17 16:05:31 -05004038
4039 spin_lock_irq(shost->host_lock);
4040
James Smart2e0fef82007-06-17 19:56:36 -05004041 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05004042 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004043 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004044 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004045 else
4046 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004047 node_name = 0;
dea31012005-04-17 16:05:31 -05004048
4049 spin_unlock_irq(shost->host_lock);
4050
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004051 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004052}
4053
James Smarte59058c2008-08-24 21:49:00 -04004054/**
James Smart3621a712009-04-06 18:47:14 -04004055 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004056 * @shost: kernel scsi host pointer.
4057 *
4058 * Notes:
4059 * NULL on error for link down, no mbox pool, sli2 active,
4060 * management not allowed, memory allocation error, or mbox error.
4061 *
4062 * Returns:
4063 * NULL for error
4064 * address of the adapter host statistics
4065 **/
dea31012005-04-17 16:05:31 -05004066static struct fc_host_statistics *
4067lpfc_get_stats(struct Scsi_Host *shost)
4068{
James Smart2e0fef82007-06-17 19:56:36 -05004069 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4070 struct lpfc_hba *phba = vport->phba;
4071 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004072 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004073 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004074 LPFC_MBOXQ_t *pmboxq;
4075 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004076 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004077 int rc = 0;
dea31012005-04-17 16:05:31 -05004078
James Smart92d7f7b2007-06-17 19:56:38 -05004079 /*
4080 * prevent udev from issuing mailbox commands until the port is
4081 * configured.
4082 */
James Smart2e0fef82007-06-17 19:56:36 -05004083 if (phba->link_state < LPFC_LINK_DOWN ||
4084 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004085 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004086 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004087
4088 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004089 return NULL;
4090
dea31012005-04-17 16:05:31 -05004091 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4092 if (!pmboxq)
4093 return NULL;
4094 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4095
James Smart04c68492009-05-22 14:52:52 -04004096 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004097 pmb->mbxCommand = MBX_READ_STATUS;
4098 pmb->mbxOwner = OWN_HOST;
4099 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004100 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004101
James Smart2e0fef82007-06-17 19:56:36 -05004102 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart04c68492009-05-22 14:52:52 -04004103 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05004104 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004105 else
dea31012005-04-17 16:05:31 -05004106 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4107
4108 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004109 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004110 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004111 return NULL;
4112 }
4113
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004114 memset(hs, 0, sizeof (struct fc_host_statistics));
4115
dea31012005-04-17 16:05:31 -05004116 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4117 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4118 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4119 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4120
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004121 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004122 pmb->mbxCommand = MBX_READ_LNK_STAT;
4123 pmb->mbxOwner = OWN_HOST;
4124 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004125 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004126
James Smart2e0fef82007-06-17 19:56:36 -05004127 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004128 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05004129 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004130 else
dea31012005-04-17 16:05:31 -05004131 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4132
4133 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004134 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004135 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004136 return NULL;
4137 }
4138
4139 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4140 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4141 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4142 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4143 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4144 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4145 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4146
James Smart64ba8812006-08-02 15:24:34 -04004147 hs->link_failure_count -= lso->link_failure_count;
4148 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4149 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4150 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4151 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4152 hs->invalid_crc_count -= lso->invalid_crc_count;
4153 hs->error_frames -= lso->error_frames;
4154
James Smart4d9ab992009-10-02 15:16:39 -04004155 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4156 hs->lip_count = -1;
4157 hs->nos_count = (phba->link_events >> 1);
4158 hs->nos_count -= lso->link_events;
4159 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004160 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004161 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004162 hs->nos_count = -1;
4163 } else {
4164 hs->lip_count = -1;
4165 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004166 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004167 }
4168
4169 hs->dumped_frames = -1;
4170
James Smart64ba8812006-08-02 15:24:34 -04004171 seconds = get_seconds();
4172 if (seconds < psli->stats_start)
4173 hs->seconds_since_last_reset = seconds +
4174 ((unsigned long)-1 - psli->stats_start);
4175 else
4176 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004177
James Smart1dcb58e2007-04-25 09:51:30 -04004178 mempool_free(pmboxq, phba->mbox_mem_pool);
4179
dea31012005-04-17 16:05:31 -05004180 return hs;
4181}
4182
James Smarte59058c2008-08-24 21:49:00 -04004183/**
James Smart3621a712009-04-06 18:47:14 -04004184 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004185 * @shost: kernel scsi host pointer.
4186 **/
James Smart64ba8812006-08-02 15:24:34 -04004187static void
4188lpfc_reset_stats(struct Scsi_Host *shost)
4189{
James Smart2e0fef82007-06-17 19:56:36 -05004190 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4191 struct lpfc_hba *phba = vport->phba;
4192 struct lpfc_sli *psli = &phba->sli;
4193 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004194 LPFC_MBOXQ_t *pmboxq;
4195 MAILBOX_t *pmb;
4196 int rc = 0;
4197
James Smart2e0fef82007-06-17 19:56:36 -05004198 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004199 return;
4200
James Smart64ba8812006-08-02 15:24:34 -04004201 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4202 if (!pmboxq)
4203 return;
4204 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4205
James Smart04c68492009-05-22 14:52:52 -04004206 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004207 pmb->mbxCommand = MBX_READ_STATUS;
4208 pmb->mbxOwner = OWN_HOST;
4209 pmb->un.varWords[0] = 0x1; /* reset request */
4210 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004211 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004212
James Smart2e0fef82007-06-17 19:56:36 -05004213 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004214 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004215 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4216 else
4217 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4218
4219 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004220 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004221 mempool_free(pmboxq, phba->mbox_mem_pool);
4222 return;
4223 }
4224
4225 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4226 pmb->mbxCommand = MBX_READ_LNK_STAT;
4227 pmb->mbxOwner = OWN_HOST;
4228 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004229 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004230
James Smart2e0fef82007-06-17 19:56:36 -05004231 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004232 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004233 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4234 else
4235 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4236
4237 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004238 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004239 mempool_free( pmboxq, phba->mbox_mem_pool);
4240 return;
4241 }
4242
4243 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4244 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4245 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4246 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4247 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4248 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4249 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004250 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4251 lso->link_events = (phba->link_events >> 1);
4252 else
4253 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004254
4255 psli->stats_start = get_seconds();
4256
James Smart1dcb58e2007-04-25 09:51:30 -04004257 mempool_free(pmboxq, phba->mbox_mem_pool);
4258
James Smart64ba8812006-08-02 15:24:34 -04004259 return;
4260}
dea31012005-04-17 16:05:31 -05004261
4262/*
4263 * The LPFC driver treats linkdown handling as target loss events so there
4264 * are no sysfs handlers for link_down_tmo.
4265 */
James Smart685f0bf2007-04-25 09:53:08 -04004266
James Smarte59058c2008-08-24 21:49:00 -04004267/**
James Smart3621a712009-04-06 18:47:14 -04004268 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004269 * @starget: kernel scsi target pointer.
4270 *
4271 * Returns:
4272 * address of the node list if found
4273 * NULL target not found
4274 **/
James Smart685f0bf2007-04-25 09:53:08 -04004275static struct lpfc_nodelist *
4276lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004277{
James Smart2e0fef82007-06-17 19:56:36 -05004278 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4279 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004280 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004281
4282 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004283 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004284 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004285 if (NLP_CHK_NODE_ACT(ndlp) &&
4286 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004287 starget->id == ndlp->nlp_sid) {
4288 spin_unlock_irq(shost->host_lock);
4289 return ndlp;
dea31012005-04-17 16:05:31 -05004290 }
4291 }
4292 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004293 return NULL;
4294}
dea31012005-04-17 16:05:31 -05004295
James Smarte59058c2008-08-24 21:49:00 -04004296/**
James Smart3621a712009-04-06 18:47:14 -04004297 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004298 * @starget: kernel scsi target pointer.
4299 **/
James Smart685f0bf2007-04-25 09:53:08 -04004300static void
4301lpfc_get_starget_port_id(struct scsi_target *starget)
4302{
4303 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4304
4305 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004306}
4307
James Smarte59058c2008-08-24 21:49:00 -04004308/**
James Smart3621a712009-04-06 18:47:14 -04004309 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004310 * @starget: kernel scsi target pointer.
4311 *
4312 * Description: Set the target node name to the ndlp node name wwn or zero.
4313 **/
dea31012005-04-17 16:05:31 -05004314static void
4315lpfc_get_starget_node_name(struct scsi_target *starget)
4316{
James Smart685f0bf2007-04-25 09:53:08 -04004317 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004318
James Smart685f0bf2007-04-25 09:53:08 -04004319 fc_starget_node_name(starget) =
4320 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004321}
4322
James Smarte59058c2008-08-24 21:49:00 -04004323/**
James Smart3621a712009-04-06 18:47:14 -04004324 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004325 * @starget: kernel scsi target pointer.
4326 *
4327 * Description: set the target port name to the ndlp port name wwn or zero.
4328 **/
dea31012005-04-17 16:05:31 -05004329static void
4330lpfc_get_starget_port_name(struct scsi_target *starget)
4331{
James Smart685f0bf2007-04-25 09:53:08 -04004332 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004333
James Smart685f0bf2007-04-25 09:53:08 -04004334 fc_starget_port_name(starget) =
4335 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004336}
4337
James Smarte59058c2008-08-24 21:49:00 -04004338/**
James Smart3621a712009-04-06 18:47:14 -04004339 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004340 * @rport: fc rport address.
4341 * @timeout: new value for dev loss tmo.
4342 *
4343 * Description:
4344 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4345 * dev_loss_tmo to one.
4346 **/
dea31012005-04-17 16:05:31 -05004347static void
dea31012005-04-17 16:05:31 -05004348lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4349{
dea31012005-04-17 16:05:31 -05004350 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004351 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004352 else
James Smartc01f3202006-08-18 17:47:08 -04004353 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004354}
4355
James Smarte59058c2008-08-24 21:49:00 -04004356/**
James Smart3621a712009-04-06 18:47:14 -04004357 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004358 *
4359 * Description:
4360 * Macro that uses field to generate a function with the name lpfc_show_rport_
4361 *
4362 * lpfc_show_rport_##field: returns the bytes formatted in buf
4363 * @cdev: class converted to an fc_rport.
4364 * @buf: on return contains the target_field or zero.
4365 *
4366 * Returns: size of formatted string.
4367 **/
dea31012005-04-17 16:05:31 -05004368#define lpfc_rport_show_function(field, format_string, sz, cast) \
4369static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004370lpfc_show_rport_##field (struct device *dev, \
4371 struct device_attribute *attr, \
4372 char *buf) \
dea31012005-04-17 16:05:31 -05004373{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004374 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004375 struct lpfc_rport_data *rdata = rport->hostdata; \
4376 return snprintf(buf, sz, format_string, \
4377 (rdata->target) ? cast rdata->target->field : 0); \
4378}
4379
4380#define lpfc_rport_rd_attr(field, format_string, sz) \
4381 lpfc_rport_show_function(field, format_string, sz, ) \
4382static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4383
James Smarteada2722008-12-04 22:39:13 -05004384/**
James Smart3621a712009-04-06 18:47:14 -04004385 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004386 * @fc_vport: The fc_vport who's symbolic name has been changed.
4387 *
4388 * Description:
4389 * This function is called by the transport after the @fc_vport's symbolic name
4390 * has been changed. This function re-registers the symbolic name with the
4391 * switch to propogate the change into the fabric if the vport is active.
4392 **/
4393static void
4394lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4395{
4396 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4397
4398 if (vport->port_state == LPFC_VPORT_READY)
4399 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4400}
dea31012005-04-17 16:05:31 -05004401
James Smartf4b4c682009-05-22 14:53:12 -04004402/**
4403 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4404 * @phba: Pointer to lpfc_hba struct.
4405 *
4406 * This function is called by the lpfc_get_cfgparam() routine to set the
4407 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4408 * log messsage according to the module's lpfc_log_verbose parameter setting
4409 * before hba port or vport created.
4410 **/
4411static void
4412lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4413{
4414 phba->cfg_log_verbose = verbose;
4415}
4416
dea31012005-04-17 16:05:31 -05004417struct fc_function_template lpfc_transport_functions = {
4418 /* fixed attributes the driver supports */
4419 .show_host_node_name = 1,
4420 .show_host_port_name = 1,
4421 .show_host_supported_classes = 1,
4422 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004423 .show_host_supported_speeds = 1,
4424 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004425 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004426
4427 /* dynamic attributes the driver supports */
4428 .get_host_port_id = lpfc_get_host_port_id,
4429 .show_host_port_id = 1,
4430
4431 .get_host_port_type = lpfc_get_host_port_type,
4432 .show_host_port_type = 1,
4433
4434 .get_host_port_state = lpfc_get_host_port_state,
4435 .show_host_port_state = 1,
4436
4437 /* active_fc4s is shown but doesn't change (thus no get function) */
4438 .show_host_active_fc4s = 1,
4439
4440 .get_host_speed = lpfc_get_host_speed,
4441 .show_host_speed = 1,
4442
4443 .get_host_fabric_name = lpfc_get_host_fabric_name,
4444 .show_host_fabric_name = 1,
4445
4446 /*
4447 * The LPFC driver treats linkdown handling as target loss events
4448 * so there are no sysfs handlers for link_down_tmo.
4449 */
4450
4451 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004452 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004453
4454 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4455 .show_rport_maxframe_size = 1,
4456 .show_rport_supported_classes = 1,
4457
dea31012005-04-17 16:05:31 -05004458 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4459 .show_rport_dev_loss_tmo = 1,
4460
4461 .get_starget_port_id = lpfc_get_starget_port_id,
4462 .show_starget_port_id = 1,
4463
4464 .get_starget_node_name = lpfc_get_starget_node_name,
4465 .show_starget_node_name = 1,
4466
4467 .get_starget_port_name = lpfc_get_starget_port_name,
4468 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004469
4470 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004471 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4472 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004473
James Smart92d7f7b2007-06-17 19:56:38 -05004474 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004475
4476 .vport_disable = lpfc_vport_disable,
4477
4478 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004479
4480 .bsg_request = lpfc_bsg_request,
4481 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004482};
4483
James Smart98c9ea52007-10-27 13:37:33 -04004484struct fc_function_template lpfc_vport_transport_functions = {
4485 /* fixed attributes the driver supports */
4486 .show_host_node_name = 1,
4487 .show_host_port_name = 1,
4488 .show_host_supported_classes = 1,
4489 .show_host_supported_fc4s = 1,
4490 .show_host_supported_speeds = 1,
4491 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004492 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004493
4494 /* dynamic attributes the driver supports */
4495 .get_host_port_id = lpfc_get_host_port_id,
4496 .show_host_port_id = 1,
4497
4498 .get_host_port_type = lpfc_get_host_port_type,
4499 .show_host_port_type = 1,
4500
4501 .get_host_port_state = lpfc_get_host_port_state,
4502 .show_host_port_state = 1,
4503
4504 /* active_fc4s is shown but doesn't change (thus no get function) */
4505 .show_host_active_fc4s = 1,
4506
4507 .get_host_speed = lpfc_get_host_speed,
4508 .show_host_speed = 1,
4509
4510 .get_host_fabric_name = lpfc_get_host_fabric_name,
4511 .show_host_fabric_name = 1,
4512
4513 /*
4514 * The LPFC driver treats linkdown handling as target loss events
4515 * so there are no sysfs handlers for link_down_tmo.
4516 */
4517
4518 .get_fc_host_stats = lpfc_get_stats,
4519 .reset_fc_host_stats = lpfc_reset_stats,
4520
4521 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4522 .show_rport_maxframe_size = 1,
4523 .show_rport_supported_classes = 1,
4524
4525 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4526 .show_rport_dev_loss_tmo = 1,
4527
4528 .get_starget_port_id = lpfc_get_starget_port_id,
4529 .show_starget_port_id = 1,
4530
4531 .get_starget_node_name = lpfc_get_starget_node_name,
4532 .show_starget_node_name = 1,
4533
4534 .get_starget_port_name = lpfc_get_starget_port_name,
4535 .show_starget_port_name = 1,
4536
4537 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4538 .terminate_rport_io = lpfc_terminate_rport_io,
4539
4540 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004541
4542 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004543};
4544
James Smarte59058c2008-08-24 21:49:00 -04004545/**
James Smart3621a712009-04-06 18:47:14 -04004546 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004547 * @phba: lpfc_hba pointer.
4548 **/
dea31012005-04-17 16:05:31 -05004549void
4550lpfc_get_cfgparam(struct lpfc_hba *phba)
4551{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004552 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4553 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004554 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004555 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4556 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004557 lpfc_ack0_init(phba, lpfc_ack0);
4558 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004559 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004560 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004561 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004562 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004563 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4564 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4565 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004566 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4567 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004568 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004569 if (phba->sli_rev == LPFC_SLI_REV4)
4570 phba->cfg_poll = 0;
4571 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004572 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004573 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004574 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004575 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004576 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004577 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004578 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004579 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004580 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004581 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004582 return;
4583}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004584
James Smarte59058c2008-08-24 21:49:00 -04004585/**
James Smart3621a712009-04-06 18:47:14 -04004586 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004587 * @vport: lpfc_vport pointer.
4588 **/
James Smart3de2a652007-08-02 11:09:59 -04004589void
4590lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4591{
James Smarte8b62012007-08-02 11:10:09 -04004592 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004593 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4594 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4595 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4596 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4597 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4598 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4599 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004600 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004601 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4602 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4603 lpfc_max_luns_init(vport, lpfc_max_luns);
4604 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004605 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004606 return;
4607}