blob: 868874c28f99a6c0bf3ab89d0419f0698eff032d [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
James Smart0d878412009-10-02 15:16:56 -040026#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/gfp.h>
dea31012005-04-17 16:05:31 -050028
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050030#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_tcq.h>
33#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040034#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050035
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_logmsg.h"
45#include "lpfc_version.h"
46#include "lpfc_compat.h"
47#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050048#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050049
James Smartc01f3202006-08-18 17:47:08 -040050#define LPFC_DEF_DEVLOSS_TMO 30
51#define LPFC_MIN_DEVLOSS_TMO 1
52#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050053
James Smart83108bd2008-01-11 01:53:09 -050054#define LPFC_MAX_LINK_SPEED 8
55#define LPFC_LINK_SPEED_BITMAP 0x00000117
56#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
57
James Smarte59058c2008-08-24 21:49:00 -040058/**
James Smart3621a712009-04-06 18:47:14 -040059 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040060 * @incr: integer to convert.
61 * @hdw: ascii string holding converted integer plus a string terminator.
62 *
63 * Description:
64 * JEDEC Joint Electron Device Engineering Council.
65 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
66 * character string. The string is then terminated with a NULL in byte 9.
67 * Hex 0-9 becomes ascii '0' to '9'.
68 * Hex a-f becomes ascii '=' to 'B' capital B.
69 *
70 * Notes:
71 * Coded for 32 bit integers only.
72 **/
dea31012005-04-17 16:05:31 -050073static void
74lpfc_jedec_to_ascii(int incr, char hdw[])
75{
76 int i, j;
77 for (i = 0; i < 8; i++) {
78 j = (incr & 0xf);
79 if (j <= 9)
80 hdw[7 - i] = 0x30 + j;
81 else
82 hdw[7 - i] = 0x61 + j - 10;
83 incr = (incr >> 4);
84 }
85 hdw[8] = 0;
86 return;
87}
88
James Smarte59058c2008-08-24 21:49:00 -040089/**
James Smart3621a712009-04-06 18:47:14 -040090 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040091 * @dev: class unused variable.
92 * @attr: device attribute, not used.
93 * @buf: on return contains the module description text.
94 *
95 * Returns: size of formatted string.
96 **/
dea31012005-04-17 16:05:31 -050097static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010098lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
99 char *buf)
dea31012005-04-17 16:05:31 -0500100{
101 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
102}
103
James Smart45ed1192009-10-02 15:17:02 -0400104/**
105 * lpfc_enable_fip_show - Return the fip mode of the HBA
106 * @dev: class unused variable.
107 * @attr: device attribute, not used.
108 * @buf: on return contains the module description text.
109 *
110 * Returns: size of formatted string.
111 **/
112static ssize_t
113lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
114 char *buf)
115{
116 struct Scsi_Host *shost = class_to_shost(dev);
117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
118 struct lpfc_hba *phba = vport->phba;
119
120 if (phba->hba_flag & HBA_FIP_SUPPORT)
121 return snprintf(buf, PAGE_SIZE, "1\n");
122 else
123 return snprintf(buf, PAGE_SIZE, "0\n");
124}
125
James Smart81301a92008-12-04 22:39:46 -0500126static ssize_t
127lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
128 char *buf)
129{
130 struct Scsi_Host *shost = class_to_shost(dev);
131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
132 struct lpfc_hba *phba = vport->phba;
133
134 if (phba->cfg_enable_bg)
135 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
136 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Not Supported\n");
140 else
141 return snprintf(buf, PAGE_SIZE,
142 "BlockGuard Disabled\n");
143}
144
145static ssize_t
146lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
147 char *buf)
148{
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
152
James Smart87b5c322008-12-16 10:34:09 -0500153 return snprintf(buf, PAGE_SIZE, "%llu\n",
154 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500155}
156
157static ssize_t
158lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
159 char *buf)
160{
161 struct Scsi_Host *shost = class_to_shost(dev);
162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
163 struct lpfc_hba *phba = vport->phba;
164
James Smart87b5c322008-12-16 10:34:09 -0500165 return snprintf(buf, PAGE_SIZE, "%llu\n",
166 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500167}
168
169static ssize_t
170lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
171 char *buf)
172{
173 struct Scsi_Host *shost = class_to_shost(dev);
174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
175 struct lpfc_hba *phba = vport->phba;
176
James Smart87b5c322008-12-16 10:34:09 -0500177 return snprintf(buf, PAGE_SIZE, "%llu\n",
178 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500179}
180
James Smarte59058c2008-08-24 21:49:00 -0400181/**
James Smart3621a712009-04-06 18:47:14 -0400182 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400183 * @dev: class converted to a Scsi_host structure.
184 * @attr: device attribute, not used.
185 * @buf: on return contains the formatted text from lpfc_info().
186 *
187 * Returns: size of formatted string.
188 **/
dea31012005-04-17 16:05:31 -0500189static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100190lpfc_info_show(struct device *dev, struct device_attribute *attr,
191 char *buf)
dea31012005-04-17 16:05:31 -0500192{
Tony Jonesee959b02008-02-22 00:13:36 +0100193 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500194
dea31012005-04-17 16:05:31 -0500195 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
196}
197
James Smarte59058c2008-08-24 21:49:00 -0400198/**
James Smart3621a712009-04-06 18:47:14 -0400199 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400200 * @dev: class converted to a Scsi_host structure.
201 * @attr: device attribute, not used.
202 * @buf: on return contains the formatted text serial number.
203 *
204 * Returns: size of formatted string.
205 **/
dea31012005-04-17 16:05:31 -0500206static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100207lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
208 char *buf)
dea31012005-04-17 16:05:31 -0500209{
Tony Jonesee959b02008-02-22 00:13:36 +0100210 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500211 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
212 struct lpfc_hba *phba = vport->phba;
213
dea31012005-04-17 16:05:31 -0500214 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
215}
216
James Smarte59058c2008-08-24 21:49:00 -0400217/**
James Smart3621a712009-04-06 18:47:14 -0400218 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400219 * @dev: class converted to a Scsi_host structure.
220 * @attr: device attribute, not used.
221 * @buf: on return contains the formatted support level.
222 *
223 * Description:
224 * Returns a number indicating the temperature sensor level currently
225 * supported, zero or one in ascii.
226 *
227 * Returns: size of formatted string.
228 **/
dea31012005-04-17 16:05:31 -0500229static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100230lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
231 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400232{
Tony Jonesee959b02008-02-22 00:13:36 +0100233 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
235 struct lpfc_hba *phba = vport->phba;
236 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
237}
238
James Smarte59058c2008-08-24 21:49:00 -0400239/**
James Smart3621a712009-04-06 18:47:14 -0400240 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400241 * @dev: class converted to a Scsi_host structure.
242 * @attr: device attribute, not used.
243 * @buf: on return contains the scsi vpd model description.
244 *
245 * Returns: size of formatted string.
246 **/
James Smart57127f12007-10-27 13:37:05 -0400247static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100248lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
249 char *buf)
dea31012005-04-17 16:05:31 -0500250{
Tony Jonesee959b02008-02-22 00:13:36 +0100251 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500252 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
253 struct lpfc_hba *phba = vport->phba;
254
dea31012005-04-17 16:05:31 -0500255 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
256}
257
James Smarte59058c2008-08-24 21:49:00 -0400258/**
James Smart3621a712009-04-06 18:47:14 -0400259 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400260 * @dev: class converted to a Scsi_host structure.
261 * @attr: device attribute, not used.
262 * @buf: on return contains the scsi vpd model name.
263 *
264 * Returns: size of formatted string.
265 **/
dea31012005-04-17 16:05:31 -0500266static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100267lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
268 char *buf)
dea31012005-04-17 16:05:31 -0500269{
Tony Jonesee959b02008-02-22 00:13:36 +0100270 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
272 struct lpfc_hba *phba = vport->phba;
273
dea31012005-04-17 16:05:31 -0500274 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
275}
276
James Smarte59058c2008-08-24 21:49:00 -0400277/**
James Smart3621a712009-04-06 18:47:14 -0400278 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400279 * @dev: class converted to a Scsi_host structure.
280 * @attr: device attribute, not used.
281 * @buf: on return contains the scsi vpd program type.
282 *
283 * Returns: size of formatted string.
284 **/
dea31012005-04-17 16:05:31 -0500285static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100286lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
287 char *buf)
dea31012005-04-17 16:05:31 -0500288{
Tony Jonesee959b02008-02-22 00:13:36 +0100289 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
291 struct lpfc_hba *phba = vport->phba;
292
dea31012005-04-17 16:05:31 -0500293 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
294}
295
James Smarte59058c2008-08-24 21:49:00 -0400296/**
James Smart3621a712009-04-06 18:47:14 -0400297 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400298 * @dev: class converted to a Scsi_host structure.
299 * @attr: device attribute, not used.
300 * @buf: on return contains the Menlo Maintenance sli flag.
301 *
302 * Returns: size of formatted string.
303 **/
304static ssize_t
305lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
306{
307 struct Scsi_Host *shost = class_to_shost(dev);
308 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
309 struct lpfc_hba *phba = vport->phba;
310
311 return snprintf(buf, PAGE_SIZE, "%d\n",
312 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
313}
314
315/**
James Smart3621a712009-04-06 18:47:14 -0400316 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400317 * @dev: class converted to a Scsi_host structure.
318 * @attr: device attribute, not used.
319 * @buf: on return contains scsi vpd program type.
320 *
321 * Returns: size of formatted string.
322 **/
dea31012005-04-17 16:05:31 -0500323static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100324lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
325 char *buf)
dea31012005-04-17 16:05:31 -0500326{
Tony Jonesee959b02008-02-22 00:13:36 +0100327 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500328 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
329 struct lpfc_hba *phba = vport->phba;
330
dea31012005-04-17 16:05:31 -0500331 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
332}
333
James Smarte59058c2008-08-24 21:49:00 -0400334/**
James Smart3621a712009-04-06 18:47:14 -0400335 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400336 * @dev: class converted to a Scsi_host structure.
337 * @attr: device attribute, not used.
338 * @buf: on return contains the scsi vpd program type.
339 *
340 * Returns: size of formatted string.
341 **/
dea31012005-04-17 16:05:31 -0500342static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100343lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
344 char *buf)
dea31012005-04-17 16:05:31 -0500345{
Tony Jonesee959b02008-02-22 00:13:36 +0100346 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
348 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500349 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500350
dea31012005-04-17 16:05:31 -0500351 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500352 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500353}
354
James Smarte59058c2008-08-24 21:49:00 -0400355/**
James Smart3621a712009-04-06 18:47:14 -0400356 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400357 * @dev: class converted to a Scsi_host structure.
358 * @attr: device attribute, not used.
359 * @buf: on return contains the scsi vpd program type.
360 *
361 * Returns: size of formatted string.
362 **/
dea31012005-04-17 16:05:31 -0500363static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100364lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500365{
366 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100367 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
369 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500370 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500371
dea31012005-04-17 16:05:31 -0500372 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
373 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
374}
James Smarte59058c2008-08-24 21:49:00 -0400375
376/**
James Smart3621a712009-04-06 18:47:14 -0400377 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400378 * @dev: class converted to a Scsi_host structure.
379 * @attr: device attribute, not used.
380 * @buf: on return contains the ROM and FCode ascii strings.
381 *
382 * Returns: size of formatted string.
383 **/
dea31012005-04-17 16:05:31 -0500384static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100385lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
386 char *buf)
dea31012005-04-17 16:05:31 -0500387{
Tony Jonesee959b02008-02-22 00:13:36 +0100388 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
390 struct lpfc_hba *phba = vport->phba;
391
dea31012005-04-17 16:05:31 -0500392 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
393}
James Smarte59058c2008-08-24 21:49:00 -0400394
395/**
James Smart3621a712009-04-06 18:47:14 -0400396 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400397 * @dev: class converted to a Scsi_host structure.
398 * @attr: device attribute, not used.
399 * @buf: on return contains text describing the state of the link.
400 *
401 * Notes:
402 * The switch statement has no default so zero will be returned.
403 *
404 * Returns: size of formatted string.
405 **/
dea31012005-04-17 16:05:31 -0500406static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100407lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
408 char *buf)
dea31012005-04-17 16:05:31 -0500409{
Tony Jonesee959b02008-02-22 00:13:36 +0100410 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
412 struct lpfc_hba *phba = vport->phba;
413 int len = 0;
414
415 switch (phba->link_state) {
416 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500417 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500418 case LPFC_INIT_START:
419 case LPFC_INIT_MBX_CMDS:
420 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500421 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400422 if (phba->hba_flag & LINK_DISABLED)
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down - User disabled\n");
425 else
426 len += snprintf(buf + len, PAGE_SIZE-len,
427 "Link Down\n");
dea31012005-04-17 16:05:31 -0500428 break;
429 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500430 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500431 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400432 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500433
434 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500435 case LPFC_LOCAL_CFG_LINK:
436 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500437 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500438 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500439 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500440 case LPFC_FLOGI:
441 case LPFC_FABRIC_CFG_LINK:
442 case LPFC_NS_REG:
443 case LPFC_NS_QRY:
444 case LPFC_BUILD_DISC_LIST:
445 case LPFC_DISC_AUTH:
446 len += snprintf(buf + len, PAGE_SIZE - len,
447 "Discovery\n");
448 break;
449 case LPFC_VPORT_READY:
450 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
451 break;
452
James Smart92d7f7b2007-06-17 19:56:38 -0500453 case LPFC_VPORT_FAILED:
454 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
455 break;
456
457 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500458 len += snprintf(buf + len, PAGE_SIZE - len,
459 "Unknown\n");
460 break;
461 }
James Smart84774a42008-08-24 21:50:06 -0400462 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
463 len += snprintf(buf + len, PAGE_SIZE-len,
464 " Menlo Maint Mode\n");
465 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500466 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Public Loop\n");
469 else
470 len += snprintf(buf + len, PAGE_SIZE-len,
471 " Private Loop\n");
472 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500473 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Fabric\n");
476 else
477 len += snprintf(buf + len, PAGE_SIZE-len,
478 " Point-2-Point\n");
479 }
480 }
James Smart2e0fef82007-06-17 19:56:36 -0500481
dea31012005-04-17 16:05:31 -0500482 return len;
483}
484
James Smarte59058c2008-08-24 21:49:00 -0400485/**
James Smart84d1b002010-02-12 14:42:33 -0500486 * lpfc_link_state_store - Transition the link_state on an HBA port
487 * @dev: class device that is converted into a Scsi_host.
488 * @attr: device attribute, not used.
489 * @buf: one or more lpfc_polling_flags values.
490 * @count: not used.
491 *
492 * Returns:
493 * -EINVAL if the buffer is not "up" or "down"
494 * return from link state change function if non-zero
495 * length of the buf on success
496 **/
497static ssize_t
498lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
499 const char *buf, size_t count)
500{
501 struct Scsi_Host *shost = class_to_shost(dev);
502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 struct lpfc_hba *phba = vport->phba;
504
505 int status = -EINVAL;
506
507 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
508 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400509 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500510 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
511 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400512 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500513
514 if (status == 0)
515 return strlen(buf);
516 else
517 return status;
518}
519
520/**
James Smart3621a712009-04-06 18:47:14 -0400521 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400522 * @dev: class device that is converted into a Scsi_host.
523 * @attr: device attribute, not used.
524 * @buf: on return contains the sum of fc mapped and unmapped.
525 *
526 * Description:
527 * Returns the ascii text number of the sum of the fc mapped and unmapped
528 * vport counts.
529 *
530 * Returns: size of formatted string.
531 **/
dea31012005-04-17 16:05:31 -0500532static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100533lpfc_num_discovered_ports_show(struct device *dev,
534 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500535{
Tony Jonesee959b02008-02-22 00:13:36 +0100536 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500537 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
538
539 return snprintf(buf, PAGE_SIZE, "%d\n",
540 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500541}
542
James Smarte59058c2008-08-24 21:49:00 -0400543/**
James Smart3621a712009-04-06 18:47:14 -0400544 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400545 * @shost: Scsi_Host pointer.
546 *
547 * Description:
548 * Bring the link down gracefully then re-init the link. The firmware will
549 * re-init the fiber channel interface as required. Does not issue a LIP.
550 *
551 * Returns:
552 * -EPERM port offline or management commands are being blocked
553 * -ENOMEM cannot allocate memory for the mailbox command
554 * -EIO error sending the mailbox command
555 * zero for success
556 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700557static int
James Smart2e0fef82007-06-17 19:56:36 -0500558lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500559{
James Smart2e0fef82007-06-17 19:56:36 -0500560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
561 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500562 LPFC_MBOXQ_t *pmboxq;
563 int mbxstatus = MBXERR_ERROR;
564
James Smart2e0fef82007-06-17 19:56:36 -0500565 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500566 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500567 return -EPERM;
568
569 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
570
571 if (!pmboxq)
572 return -ENOMEM;
573
574 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400575 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
576 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400577
James Smart33ccf8d2006-08-17 11:57:58 -0400578 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500579
James Smart04c68492009-05-22 14:52:52 -0400580 if ((mbxstatus == MBX_SUCCESS) &&
581 (pmboxq->u.mb.mbxStatus == 0 ||
582 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400583 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
584 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
585 phba->cfg_link_speed);
586 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
587 phba->fc_ratov * 2);
588 }
589
James Smart5b8bd0c2007-04-25 09:52:49 -0400590 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500591 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400592 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500593
594 if (mbxstatus == MBXERR_ERROR)
595 return -EIO;
596
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700597 return 0;
dea31012005-04-17 16:05:31 -0500598}
599
James Smarte59058c2008-08-24 21:49:00 -0400600/**
James Smart3621a712009-04-06 18:47:14 -0400601 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400602 * @phba: lpfc_hba pointer.
603 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
604 *
605 * Notes:
606 * Assumes any error from lpfc_do_offline() will be negative.
607 * Can wait up to 5 seconds for the port ring buffers count
608 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400609 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400610 *
611 * Returns:
612 * -EIO error posting the event
613 * zero for success
614 **/
James Smart40496f02006-07-06 15:50:22 -0400615static int
James Smart46fa3112007-04-25 09:51:45 -0400616lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
617{
618 struct completion online_compl;
619 struct lpfc_sli_ring *pring;
620 struct lpfc_sli *psli;
621 int status = 0;
622 int cnt = 0;
623 int i;
624
625 init_completion(&online_compl);
626 lpfc_workq_post_event(phba, &status, &online_compl,
627 LPFC_EVT_OFFLINE_PREP);
628 wait_for_completion(&online_compl);
629
630 if (status != 0)
631 return -EIO;
632
633 psli = &phba->sli;
634
James Smart09372822008-01-11 01:52:54 -0500635 /* Wait a little for things to settle down, but not
636 * long enough for dev loss timeout to expire.
637 */
James Smart46fa3112007-04-25 09:51:45 -0400638 for (i = 0; i < psli->num_rings; i++) {
639 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400640 while (pring->txcmplq_cnt) {
641 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500642 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400643 lpfc_printf_log(phba,
644 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400645 "0466 Outstanding IO when "
646 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400647 break;
648 }
649 }
650 }
651
652 init_completion(&online_compl);
653 lpfc_workq_post_event(phba, &status, &online_compl, type);
654 wait_for_completion(&online_compl);
655
656 if (status != 0)
657 return -EIO;
658
659 return 0;
660}
661
James Smarte59058c2008-08-24 21:49:00 -0400662/**
James Smart3621a712009-04-06 18:47:14 -0400663 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400664 * @phba: lpfc_hba pointer.
665 *
666 * Description:
667 * If the port is configured to allow a reset then the hba is brought
668 * offline then online.
669 *
670 * Notes:
671 * Assumes any error from lpfc_do_offline() will be negative.
672 *
673 * Returns:
674 * lpfc_do_offline() return code if not zero
675 * -EIO reset not configured or error posting the event
676 * zero for success
677 **/
James Smart46fa3112007-04-25 09:51:45 -0400678static int
James Smart40496f02006-07-06 15:50:22 -0400679lpfc_selective_reset(struct lpfc_hba *phba)
680{
681 struct completion online_compl;
682 int status = 0;
683
James Smart13815c82008-01-11 01:52:48 -0500684 if (!phba->cfg_enable_hba_reset)
685 return -EIO;
686
James Smart46fa3112007-04-25 09:51:45 -0400687 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400688
689 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400690 return status;
James Smart40496f02006-07-06 15:50:22 -0400691
692 init_completion(&online_compl);
693 lpfc_workq_post_event(phba, &status, &online_compl,
694 LPFC_EVT_ONLINE);
695 wait_for_completion(&online_compl);
696
697 if (status != 0)
698 return -EIO;
699
700 return 0;
701}
702
James Smarte59058c2008-08-24 21:49:00 -0400703/**
James Smart3621a712009-04-06 18:47:14 -0400704 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400705 * @dev: class device that is converted into a Scsi_host.
706 * @attr: device attribute, not used.
707 * @buf: containing the string "selective".
708 * @count: unused variable.
709 *
710 * Description:
711 * If the buf contains the string "selective" then lpfc_selective_reset()
712 * is called to perform the reset.
713 *
714 * Notes:
715 * Assumes any error from lpfc_selective_reset() will be negative.
716 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200717 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400718 *
719 * Returns:
720 * -EINVAL if the buffer does not contain the string "selective"
721 * length of buf if lpfc-selective_reset() if the call succeeds
722 * return value of lpfc_selective_reset() if the call fails
723**/
James Smart40496f02006-07-06 15:50:22 -0400724static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100725lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
726 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400727{
Tony Jonesee959b02008-02-22 00:13:36 +0100728 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500729 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
730 struct lpfc_hba *phba = vport->phba;
731
James Smart40496f02006-07-06 15:50:22 -0400732 int status = -EINVAL;
733
734 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
735 status = lpfc_selective_reset(phba);
736
737 if (status == 0)
738 return strlen(buf);
739 else
740 return status;
741}
742
James Smarte59058c2008-08-24 21:49:00 -0400743/**
James Smart3621a712009-04-06 18:47:14 -0400744 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400745 * @dev: class device that is converted into a Scsi_host.
746 * @attr: device attribute, not used.
747 * @buf: on return contains the ascii number of nport events.
748 *
749 * Returns: size of formatted string.
750 **/
dea31012005-04-17 16:05:31 -0500751static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100752lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
753 char *buf)
dea31012005-04-17 16:05:31 -0500754{
Tony Jonesee959b02008-02-22 00:13:36 +0100755 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500756 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
757 struct lpfc_hba *phba = vport->phba;
758
dea31012005-04-17 16:05:31 -0500759 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
760}
761
James Smarte59058c2008-08-24 21:49:00 -0400762/**
James Smart3621a712009-04-06 18:47:14 -0400763 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400764 * @dev: class device that is converted into a Scsi_host.
765 * @attr: device attribute, not used.
766 * @buf: on return contains the state of the adapter.
767 *
768 * Returns: size of formatted string.
769 **/
dea31012005-04-17 16:05:31 -0500770static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100771lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
772 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500773{
Tony Jonesee959b02008-02-22 00:13:36 +0100774 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
776 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500777 char * state;
778
James Smart2e0fef82007-06-17 19:56:36 -0500779 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500780 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500781 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500782 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500783 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500784 state = "offline";
785 else
786 state = "online";
787
788 return snprintf(buf, PAGE_SIZE, "%s\n", state);
789}
790
James Smarte59058c2008-08-24 21:49:00 -0400791/**
James Smart3621a712009-04-06 18:47:14 -0400792 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400793 * @dev: class device that is converted into a Scsi_host.
794 * @attr: device attribute, not used.
795 * @buf: containing one of the strings "online", "offline", "warm" or "error".
796 * @count: unused variable.
797 *
798 * Returns:
799 * -EACCES if enable hba reset not enabled
800 * -EINVAL if the buffer does not contain a valid string (see above)
801 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
802 * buf length greater than zero indicates success
803 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500804static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100805lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
806 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500807{
Tony Jonesee959b02008-02-22 00:13:36 +0100808 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
810 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500811 struct completion online_compl;
812 int status=0;
813
James Smart13815c82008-01-11 01:52:48 -0500814 if (!phba->cfg_enable_hba_reset)
815 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500816 init_completion(&online_compl);
817
James Smart46fa3112007-04-25 09:51:45 -0400818 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500819 lpfc_workq_post_event(phba, &status, &online_compl,
820 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400821 wait_for_completion(&online_compl);
822 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
823 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500824 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400825 if (phba->sli_rev == LPFC_SLI_REV4)
826 return -EINVAL;
827 else
828 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400829 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400830 if (phba->sli_rev == LPFC_SLI_REV4)
831 return -EINVAL;
832 else
833 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500834 else
835 return -EINVAL;
836
Jamie Wellnitz41415862006-02-28 19:25:27 -0500837 if (!status)
838 return strlen(buf);
839 else
840 return -EIO;
841}
842
James Smarte59058c2008-08-24 21:49:00 -0400843/**
James Smart3621a712009-04-06 18:47:14 -0400844 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400845 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400846 * @mxri: max xri count.
847 * @axri: available xri count.
848 * @mrpi: max rpi count.
849 * @arpi: available rpi count.
850 * @mvpi: max vpi count.
851 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400852 *
853 * Description:
854 * If an integer pointer for an count is not null then the value for the
855 * count is returned.
856 *
857 * Returns:
858 * zero on error
859 * one for success
860 **/
James Smart311464e2007-08-02 11:10:37 -0400861static int
James Smart858c9f62007-06-17 19:56:39 -0500862lpfc_get_hba_info(struct lpfc_hba *phba,
863 uint32_t *mxri, uint32_t *axri,
864 uint32_t *mrpi, uint32_t *arpi,
865 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500866{
James Smart04c68492009-05-22 14:52:52 -0400867 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500868 LPFC_MBOXQ_t *pmboxq;
869 MAILBOX_t *pmb;
870 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400871 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500872
873 /*
874 * prevent udev from issuing mailbox commands until the port is
875 * configured.
876 */
877 if (phba->link_state < LPFC_LINK_DOWN ||
878 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400879 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500880 return 0;
881
882 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
883 return 0;
884
885 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
886 if (!pmboxq)
887 return 0;
888 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
889
James Smart04c68492009-05-22 14:52:52 -0400890 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500891 pmb->mbxCommand = MBX_READ_CONFIG;
892 pmb->mbxOwner = OWN_HOST;
893 pmboxq->context1 = NULL;
894
James Smart75baf692010-06-08 18:31:21 -0400895 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500896 rc = MBX_NOT_FINISHED;
897 else
898 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
899
900 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500901 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500902 mempool_free(pmboxq, phba->mbox_mem_pool);
903 return 0;
904 }
905
James Smartda0436e2009-05-22 14:51:39 -0400906 if (phba->sli_rev == LPFC_SLI_REV4) {
907 rd_config = &pmboxq->u.mqe.un.rd_config;
908 if (mrpi)
909 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
910 if (arpi)
911 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
912 phba->sli4_hba.max_cfg_param.rpi_used;
913 if (mxri)
914 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
915 if (axri)
916 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
917 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400918
919 /* Account for differences with SLI-3. Get vpi count from
920 * mailbox data and subtract one for max vpi value.
921 */
922 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
923 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
924
James Smartda0436e2009-05-22 14:51:39 -0400925 if (mvpi)
James Smart15672312010-04-06 14:49:03 -0400926 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -0400927 if (avpi)
James Smart15672312010-04-06 14:49:03 -0400928 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -0400929 } else {
930 if (mrpi)
931 *mrpi = pmb->un.varRdConfig.max_rpi;
932 if (arpi)
933 *arpi = pmb->un.varRdConfig.avail_rpi;
934 if (mxri)
935 *mxri = pmb->un.varRdConfig.max_xri;
936 if (axri)
937 *axri = pmb->un.varRdConfig.avail_xri;
938 if (mvpi)
939 *mvpi = pmb->un.varRdConfig.max_vpi;
940 if (avpi)
941 *avpi = pmb->un.varRdConfig.avail_vpi;
942 }
James Smart92d7f7b2007-06-17 19:56:38 -0500943
944 mempool_free(pmboxq, phba->mbox_mem_pool);
945 return 1;
946}
947
James Smarte59058c2008-08-24 21:49:00 -0400948/**
James Smart3621a712009-04-06 18:47:14 -0400949 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400950 * @dev: class device that is converted into a Scsi_host.
951 * @attr: device attribute, not used.
952 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
953 *
954 * Description:
955 * Calls lpfc_get_hba_info() asking for just the mrpi count.
956 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
957 * to "Unknown" and the buffer length is returned, therefore the caller
958 * must check for "Unknown" in the buffer to detect a failure.
959 *
960 * Returns: size of formatted string.
961 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500962static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100963lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
964 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500965{
Tony Jonesee959b02008-02-22 00:13:36 +0100966 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500967 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
968 struct lpfc_hba *phba = vport->phba;
969 uint32_t cnt;
970
James Smart858c9f62007-06-17 19:56:39 -0500971 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500972 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
973 return snprintf(buf, PAGE_SIZE, "Unknown\n");
974}
975
James Smarte59058c2008-08-24 21:49:00 -0400976/**
James Smart3621a712009-04-06 18:47:14 -0400977 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400978 * @dev: class device that is converted into a Scsi_host.
979 * @attr: device attribute, not used.
980 * @buf: containing the used rpi count in decimal or "Unknown".
981 *
982 * Description:
983 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
984 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
985 * to "Unknown" and the buffer length is returned, therefore the caller
986 * must check for "Unknown" in the buffer to detect a failure.
987 *
988 * Returns: size of formatted string.
989 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500990static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100991lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
992 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500993{
Tony Jonesee959b02008-02-22 00:13:36 +0100994 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500995 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
996 struct lpfc_hba *phba = vport->phba;
997 uint32_t cnt, acnt;
998
James Smart858c9f62007-06-17 19:56:39 -0500999 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001000 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1001 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1002}
1003
James Smarte59058c2008-08-24 21:49:00 -04001004/**
James Smart3621a712009-04-06 18:47:14 -04001005 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001006 * @dev: class device that is converted into a Scsi_host.
1007 * @attr: device attribute, not used.
1008 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1009 *
1010 * Description:
1011 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1012 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1013 * to "Unknown" and the buffer length is returned, therefore the caller
1014 * must check for "Unknown" in the buffer to detect a failure.
1015 *
1016 * Returns: size of formatted string.
1017 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001018static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001019lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1020 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001021{
Tony Jonesee959b02008-02-22 00:13:36 +01001022 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001023 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1024 struct lpfc_hba *phba = vport->phba;
1025 uint32_t cnt;
1026
James Smart858c9f62007-06-17 19:56:39 -05001027 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001028 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1029 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1030}
1031
James Smarte59058c2008-08-24 21:49:00 -04001032/**
James Smart3621a712009-04-06 18:47:14 -04001033 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001034 * @dev: class device that is converted into a Scsi_host.
1035 * @attr: device attribute, not used.
1036 * @buf: on return contains the used xri count in decimal or "Unknown".
1037 *
1038 * Description:
1039 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1040 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1041 * to "Unknown" and the buffer length is returned, therefore the caller
1042 * must check for "Unknown" in the buffer to detect a failure.
1043 *
1044 * Returns: size of formatted string.
1045 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001046static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001047lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1048 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001049{
Tony Jonesee959b02008-02-22 00:13:36 +01001050 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001051 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1052 struct lpfc_hba *phba = vport->phba;
1053 uint32_t cnt, acnt;
1054
James Smart858c9f62007-06-17 19:56:39 -05001055 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1056 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1057 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1058}
1059
James Smarte59058c2008-08-24 21:49:00 -04001060/**
James Smart3621a712009-04-06 18:47:14 -04001061 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001062 * @dev: class device that is converted into a Scsi_host.
1063 * @attr: device attribute, not used.
1064 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1065 *
1066 * Description:
1067 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1068 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1069 * to "Unknown" and the buffer length is returned, therefore the caller
1070 * must check for "Unknown" in the buffer to detect a failure.
1071 *
1072 * Returns: size of formatted string.
1073 **/
James Smart858c9f62007-06-17 19:56:39 -05001074static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001075lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1076 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001077{
Tony Jonesee959b02008-02-22 00:13:36 +01001078 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001079 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1080 struct lpfc_hba *phba = vport->phba;
1081 uint32_t cnt;
1082
1083 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1084 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1085 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1086}
1087
James Smarte59058c2008-08-24 21:49:00 -04001088/**
James Smart3621a712009-04-06 18:47:14 -04001089 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001090 * @dev: class device that is converted into a Scsi_host.
1091 * @attr: device attribute, not used.
1092 * @buf: on return contains the used vpi count in decimal or "Unknown".
1093 *
1094 * Description:
1095 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1096 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1097 * to "Unknown" and the buffer length is returned, therefore the caller
1098 * must check for "Unknown" in the buffer to detect a failure.
1099 *
1100 * Returns: size of formatted string.
1101 **/
James Smart858c9f62007-06-17 19:56:39 -05001102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001103lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1104 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001105{
Tony Jonesee959b02008-02-22 00:13:36 +01001106 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1108 struct lpfc_hba *phba = vport->phba;
1109 uint32_t cnt, acnt;
1110
1111 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001112 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1113 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1114}
1115
James Smarte59058c2008-08-24 21:49:00 -04001116/**
James Smart3621a712009-04-06 18:47:14 -04001117 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001118 * @dev: class device that is converted into a Scsi_host.
1119 * @attr: device attribute, not used.
1120 * @buf: text that must be interpreted to determine if npiv is supported.
1121 *
1122 * Description:
1123 * Buffer will contain text indicating npiv is not suppoerted on the port,
1124 * the port is an NPIV physical port, or it is an npiv virtual port with
1125 * the id of the vport.
1126 *
1127 * Returns: size of formatted string.
1128 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001129static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001130lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1131 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001132{
Tony Jonesee959b02008-02-22 00:13:36 +01001133 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1135 struct lpfc_hba *phba = vport->phba;
1136
1137 if (!(phba->max_vpi))
1138 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1139 if (vport->port_type == LPFC_PHYSICAL_PORT)
1140 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1141 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1142}
1143
James Smarte59058c2008-08-24 21:49:00 -04001144/**
James Smart3621a712009-04-06 18:47:14 -04001145 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001146 * @dev: class device that is converted into a Scsi_host.
1147 * @attr: device attribute, not used.
1148 * @buf: on return contains the cfg_poll in hex.
1149 *
1150 * Notes:
1151 * cfg_poll should be a lpfc_polling_flags type.
1152 *
1153 * Returns: size of formatted string.
1154 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001155static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001156lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1157 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001158{
Tony Jonesee959b02008-02-22 00:13:36 +01001159 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001160 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1161 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001162
1163 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1164}
1165
James Smarte59058c2008-08-24 21:49:00 -04001166/**
James Smart3621a712009-04-06 18:47:14 -04001167 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001168 * @dev: class device that is converted into a Scsi_host.
1169 * @attr: device attribute, not used.
1170 * @buf: one or more lpfc_polling_flags values.
1171 * @count: not used.
1172 *
1173 * Notes:
1174 * buf contents converted to integer and checked for a valid value.
1175 *
1176 * Returns:
1177 * -EINVAL if the buffer connot be converted or is out of range
1178 * length of the buf on success
1179 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001180static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001181lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1182 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001183{
Tony Jonesee959b02008-02-22 00:13:36 +01001184 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001185 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1186 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001187 uint32_t creg_val;
1188 uint32_t old_val;
1189 int val=0;
1190
1191 if (!isdigit(buf[0]))
1192 return -EINVAL;
1193
1194 if (sscanf(buf, "%i", &val) != 1)
1195 return -EINVAL;
1196
1197 if ((val & 0x3) != val)
1198 return -EINVAL;
1199
James Smart45ed1192009-10-02 15:17:02 -04001200 if (phba->sli_rev == LPFC_SLI_REV4)
1201 val = 0;
1202
James Smart2e0fef82007-06-17 19:56:36 -05001203 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001204
1205 old_val = phba->cfg_poll;
1206
1207 if (val & ENABLE_FCP_RING_POLLING) {
1208 if ((val & DISABLE_FCP_RING_INT) &&
1209 !(old_val & DISABLE_FCP_RING_INT)) {
1210 creg_val = readl(phba->HCregaddr);
1211 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1212 writel(creg_val, phba->HCregaddr);
1213 readl(phba->HCregaddr); /* flush */
1214
1215 lpfc_poll_start_timer(phba);
1216 }
1217 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001218 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001219 return -EINVAL;
1220 }
1221
1222 if (!(val & DISABLE_FCP_RING_INT) &&
1223 (old_val & DISABLE_FCP_RING_INT))
1224 {
James Smart2e0fef82007-06-17 19:56:36 -05001225 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001226 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001227 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001228 creg_val = readl(phba->HCregaddr);
1229 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1230 writel(creg_val, phba->HCregaddr);
1231 readl(phba->HCregaddr); /* flush */
1232 }
1233
1234 phba->cfg_poll = val;
1235
James Smart2e0fef82007-06-17 19:56:36 -05001236 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001237
1238 return strlen(buf);
1239}
dea31012005-04-17 16:05:31 -05001240
James Smarte59058c2008-08-24 21:49:00 -04001241/**
James Smart3621a712009-04-06 18:47:14 -04001242 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001243 *
1244 * Description:
1245 * Macro that given an attr e.g. hba_queue_depth expands
1246 * into a function with the name lpfc_hba_queue_depth_show.
1247 *
1248 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1249 * @dev: class device that is converted into a Scsi_host.
1250 * @attr: device attribute, not used.
1251 * @buf: on return contains the attribute value in decimal.
1252 *
1253 * Returns: size of formatted string.
1254 **/
dea31012005-04-17 16:05:31 -05001255#define lpfc_param_show(attr) \
1256static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001257lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1258 char *buf) \
dea31012005-04-17 16:05:31 -05001259{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001260 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1262 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001263 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001264 val = phba->cfg_##attr;\
1265 return snprintf(buf, PAGE_SIZE, "%d\n",\
1266 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001267}
1268
James Smarte59058c2008-08-24 21:49:00 -04001269/**
James Smart3621a712009-04-06 18:47:14 -04001270 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001271 *
1272 * Description:
1273 * Macro that given an attr e.g. hba_queue_depth expands
1274 * into a function with the name lpfc_hba_queue_depth_show
1275 *
1276 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1277 * @dev: class device that is converted into a Scsi_host.
1278 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001279 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001280 *
1281 * Returns: size of formatted string.
1282 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001283#define lpfc_param_hex_show(attr) \
1284static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001285lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1286 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001287{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001288 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1290 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001291 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001292 val = phba->cfg_##attr;\
1293 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1294 phba->cfg_##attr);\
1295}
1296
James Smarte59058c2008-08-24 21:49:00 -04001297/**
James Smart3621a712009-04-06 18:47:14 -04001298 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001299 *
1300 * Description:
1301 * Macro that given an attr e.g. hba_queue_depth expands
1302 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1303 * takes a default argument, a minimum and maximum argument.
1304 *
1305 * lpfc_##attr##_init: Initializes an attribute.
1306 * @phba: pointer the the adapter structure.
1307 * @val: integer attribute value.
1308 *
1309 * Validates the min and max values then sets the adapter config field
1310 * accordingly, or uses the default if out of range and prints an error message.
1311 *
1312 * Returns:
1313 * zero on success
1314 * -EINVAL if default used
1315 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001316#define lpfc_param_init(attr, default, minval, maxval) \
1317static int \
James Smart84d1b002010-02-12 14:42:33 -05001318lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001319{ \
1320 if (val >= minval && val <= maxval) {\
1321 phba->cfg_##attr = val;\
1322 return 0;\
1323 }\
1324 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001325 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1326 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001327 phba->cfg_##attr = default;\
1328 return -EINVAL;\
1329}
1330
James Smarte59058c2008-08-24 21:49:00 -04001331/**
James Smart3621a712009-04-06 18:47:14 -04001332 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001333 *
1334 * Description:
1335 * Macro that given an attr e.g. hba_queue_depth expands
1336 * into a function with the name lpfc_hba_queue_depth_set
1337 *
1338 * lpfc_##attr##_set: Sets an attribute value.
1339 * @phba: pointer the the adapter structure.
1340 * @val: integer attribute value.
1341 *
1342 * Description:
1343 * Validates the min and max values then sets the
1344 * adapter config field if in the valid range. prints error message
1345 * and does not set the parameter if invalid.
1346 *
1347 * Returns:
1348 * zero on success
1349 * -EINVAL if val is invalid
1350 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001351#define lpfc_param_set(attr, default, minval, maxval) \
1352static int \
James Smart84d1b002010-02-12 14:42:33 -05001353lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001354{ \
1355 if (val >= minval && val <= maxval) {\
1356 phba->cfg_##attr = val;\
1357 return 0;\
1358 }\
1359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001360 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1361 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001362 return -EINVAL;\
1363}
1364
James Smarte59058c2008-08-24 21:49:00 -04001365/**
James Smart3621a712009-04-06 18:47:14 -04001366 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001367 *
1368 * Description:
1369 * Macro that given an attr e.g. hba_queue_depth expands
1370 * into a function with the name lpfc_hba_queue_depth_store.
1371 *
1372 * lpfc_##attr##_store: Set an sttribute value.
1373 * @dev: class device that is converted into a Scsi_host.
1374 * @attr: device attribute, not used.
1375 * @buf: contains the attribute value in ascii.
1376 * @count: not used.
1377 *
1378 * Description:
1379 * Convert the ascii text number to an integer, then
1380 * use the lpfc_##attr##_set function to set the value.
1381 *
1382 * Returns:
1383 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1384 * length of buffer upon success.
1385 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001386#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001387static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001388lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1389 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001390{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001391 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001392 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1393 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001394 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001395 if (!isdigit(buf[0]))\
1396 return -EINVAL;\
1397 if (sscanf(buf, "%i", &val) != 1)\
1398 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001399 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001400 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001401 else \
1402 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001403}
1404
James Smarte59058c2008-08-24 21:49:00 -04001405/**
James Smart3621a712009-04-06 18:47:14 -04001406 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001407 *
1408 * Description:
1409 * Macro that given an attr e.g. hba_queue_depth expands
1410 * into a function with the name lpfc_hba_queue_depth_show
1411 *
1412 * lpfc_##attr##_show: prints the attribute value in decimal.
1413 * @dev: class device that is converted into a Scsi_host.
1414 * @attr: device attribute, not used.
1415 * @buf: on return contains the attribute value in decimal.
1416 *
1417 * Returns: length of formatted string.
1418 **/
James Smart3de2a652007-08-02 11:09:59 -04001419#define lpfc_vport_param_show(attr) \
1420static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001421lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1422 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001423{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001424 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001425 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001426 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001427 val = vport->cfg_##attr;\
1428 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1429}
1430
James Smarte59058c2008-08-24 21:49:00 -04001431/**
James Smart3621a712009-04-06 18:47:14 -04001432 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001433 *
1434 * Description:
1435 * Macro that given an attr e.g.
1436 * hba_queue_depth expands into a function with the name
1437 * lpfc_hba_queue_depth_show
1438 *
James Smart3621a712009-04-06 18:47:14 -04001439 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001440 * @dev: class device that is converted into a Scsi_host.
1441 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001442 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001443 *
1444 * Returns: length of formatted string.
1445 **/
James Smart3de2a652007-08-02 11:09:59 -04001446#define lpfc_vport_param_hex_show(attr) \
1447static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001448lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1449 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001450{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001451 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001452 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001453 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001454 val = vport->cfg_##attr;\
1455 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1456}
1457
James Smarte59058c2008-08-24 21:49:00 -04001458/**
James Smart3621a712009-04-06 18:47:14 -04001459 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001460 *
1461 * Description:
1462 * Macro that given an attr e.g. hba_queue_depth expands
1463 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1464 * takes a default argument, a minimum and maximum argument.
1465 *
1466 * lpfc_##attr##_init: validates the min and max values then sets the
1467 * adapter config field accordingly, or uses the default if out of range
1468 * and prints an error message.
1469 * @phba: pointer the the adapter structure.
1470 * @val: integer attribute value.
1471 *
1472 * Returns:
1473 * zero on success
1474 * -EINVAL if default used
1475 **/
James Smart3de2a652007-08-02 11:09:59 -04001476#define lpfc_vport_param_init(attr, default, minval, maxval) \
1477static int \
James Smart84d1b002010-02-12 14:42:33 -05001478lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001479{ \
1480 if (val >= minval && val <= maxval) {\
1481 vport->cfg_##attr = val;\
1482 return 0;\
1483 }\
James Smarte8b62012007-08-02 11:10:09 -04001484 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001485 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001486 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001487 vport->cfg_##attr = default;\
1488 return -EINVAL;\
1489}
1490
James Smarte59058c2008-08-24 21:49:00 -04001491/**
James Smart3621a712009-04-06 18:47:14 -04001492 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001493 *
1494 * Description:
1495 * Macro that given an attr e.g. hba_queue_depth expands
1496 * into a function with the name lpfc_hba_queue_depth_set
1497 *
1498 * lpfc_##attr##_set: validates the min and max values then sets the
1499 * adapter config field if in the valid range. prints error message
1500 * and does not set the parameter if invalid.
1501 * @phba: pointer the the adapter structure.
1502 * @val: integer attribute value.
1503 *
1504 * Returns:
1505 * zero on success
1506 * -EINVAL if val is invalid
1507 **/
James Smart3de2a652007-08-02 11:09:59 -04001508#define lpfc_vport_param_set(attr, default, minval, maxval) \
1509static int \
James Smart84d1b002010-02-12 14:42:33 -05001510lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001511{ \
1512 if (val >= minval && val <= maxval) {\
1513 vport->cfg_##attr = val;\
1514 return 0;\
1515 }\
James Smarte8b62012007-08-02 11:10:09 -04001516 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001517 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001518 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001519 return -EINVAL;\
1520}
1521
James Smarte59058c2008-08-24 21:49:00 -04001522/**
James Smart3621a712009-04-06 18:47:14 -04001523 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001524 *
1525 * Description:
1526 * Macro that given an attr e.g. hba_queue_depth
1527 * expands into a function with the name lpfc_hba_queue_depth_store
1528 *
1529 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1530 * use the lpfc_##attr##_set function to set the value.
1531 * @cdev: class device that is converted into a Scsi_host.
1532 * @buf: contains the attribute value in decimal.
1533 * @count: not used.
1534 *
1535 * Returns:
1536 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1537 * length of buffer upon success.
1538 **/
James Smart3de2a652007-08-02 11:09:59 -04001539#define lpfc_vport_param_store(attr) \
1540static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001541lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1542 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001543{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001544 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001545 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001546 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001547 if (!isdigit(buf[0]))\
1548 return -EINVAL;\
1549 if (sscanf(buf, "%i", &val) != 1)\
1550 return -EINVAL;\
1551 if (lpfc_##attr##_set(vport, val) == 0) \
1552 return strlen(buf);\
1553 else \
1554 return -EINVAL;\
1555}
1556
1557
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001558#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001559static uint lpfc_##name = defval;\
1560module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001561MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001562lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001563
1564#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001565static uint lpfc_##name = defval;\
1566module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001567MODULE_PARM_DESC(lpfc_##name, desc);\
1568lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001569lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001570static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001571
1572#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001573static uint lpfc_##name = defval;\
1574module_param(lpfc_##name, uint, 0);\
dea31012005-04-17 16:05:31 -05001575MODULE_PARM_DESC(lpfc_##name, desc);\
1576lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001577lpfc_param_init(name, defval, minval, maxval)\
1578lpfc_param_set(name, defval, minval, maxval)\
1579lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001580static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1581 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001582
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001583#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001584static uint lpfc_##name = defval;\
1585module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001586MODULE_PARM_DESC(lpfc_##name, desc);\
1587lpfc_param_hex_show(name)\
1588lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001589static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001590
1591#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001592static uint lpfc_##name = defval;\
1593module_param(lpfc_##name, uint, 0);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001594MODULE_PARM_DESC(lpfc_##name, desc);\
1595lpfc_param_hex_show(name)\
1596lpfc_param_init(name, defval, minval, maxval)\
1597lpfc_param_set(name, defval, minval, maxval)\
1598lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001599static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1600 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001601
James Smart3de2a652007-08-02 11:09:59 -04001602#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001603static uint lpfc_##name = defval;\
1604module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001605MODULE_PARM_DESC(lpfc_##name, desc);\
1606lpfc_vport_param_init(name, defval, minval, maxval)
1607
1608#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001609static uint lpfc_##name = defval;\
1610module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001611MODULE_PARM_DESC(lpfc_##name, desc);\
1612lpfc_vport_param_show(name)\
1613lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001614static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001615
1616#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001617static uint lpfc_##name = defval;\
1618module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001619MODULE_PARM_DESC(lpfc_##name, desc);\
1620lpfc_vport_param_show(name)\
1621lpfc_vport_param_init(name, defval, minval, maxval)\
1622lpfc_vport_param_set(name, defval, minval, maxval)\
1623lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001624static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1625 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001626
1627#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001628static uint lpfc_##name = defval;\
1629module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001630MODULE_PARM_DESC(lpfc_##name, desc);\
1631lpfc_vport_param_hex_show(name)\
1632lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001633static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001634
1635#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001636static uint lpfc_##name = defval;\
1637module_param(lpfc_##name, uint, 0);\
James Smart3de2a652007-08-02 11:09:59 -04001638MODULE_PARM_DESC(lpfc_##name, desc);\
1639lpfc_vport_param_hex_show(name)\
1640lpfc_vport_param_init(name, defval, minval, maxval)\
1641lpfc_vport_param_set(name, defval, minval, maxval)\
1642lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001643static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1644 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001645
James Smart81301a92008-12-04 22:39:46 -05001646static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1647static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1648static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1649static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001650static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1651static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1652static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1653static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1654static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1655static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1656static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1657static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001658static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1659 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001660static DEVICE_ATTR(option_rom_version, S_IRUGO,
1661 lpfc_option_rom_version_show, NULL);
1662static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1663 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001664static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001665static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1666static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001667static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001668static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1669 lpfc_board_mode_show, lpfc_board_mode_store);
1670static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1671static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1672static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1673static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1674static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1675static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1676static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1677static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1678static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001679
James Smartc3f28af2006-08-18 17:47:18 -04001680
James Smarta12e07b2006-12-02 13:35:30 -05001681static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001682
James Smarte59058c2008-08-24 21:49:00 -04001683/**
James Smart3621a712009-04-06 18:47:14 -04001684 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001685 * @dev: class device that is converted into a Scsi_host.
1686 * @attr: device attribute, not used.
1687 * @buf: containing the string lpfc_soft_wwn_key.
1688 * @count: must be size of lpfc_soft_wwn_key.
1689 *
1690 * Returns:
1691 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1692 * length of buf indicates success
1693 **/
James Smartc3f28af2006-08-18 17:47:18 -04001694static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001695lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1696 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001697{
Tony Jonesee959b02008-02-22 00:13:36 +01001698 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1700 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001701 unsigned int cnt = count;
1702
1703 /*
1704 * We're doing a simple sanity check for soft_wwpn setting.
1705 * We require that the user write a specific key to enable
1706 * the soft_wwpn attribute to be settable. Once the attribute
1707 * is written, the enable key resets. If further updates are
1708 * desired, the key must be written again to re-enable the
1709 * attribute.
1710 *
1711 * The "key" is not secret - it is a hardcoded string shown
1712 * here. The intent is to protect against the random user or
1713 * application that is just writing attributes.
1714 */
1715
1716 /* count may include a LF at end of string */
1717 if (buf[cnt-1] == '\n')
1718 cnt--;
1719
James Smarta12e07b2006-12-02 13:35:30 -05001720 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1721 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001722 return -EINVAL;
1723
James Smarta12e07b2006-12-02 13:35:30 -05001724 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001725 return count;
1726}
Tony Jonesee959b02008-02-22 00:13:36 +01001727static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1728 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001729
James Smarte59058c2008-08-24 21:49:00 -04001730/**
James Smart3621a712009-04-06 18:47:14 -04001731 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001732 * @dev: class device that is converted into a Scsi_host.
1733 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001734 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001735 *
1736 * Returns: size of formatted string.
1737 **/
James Smartc3f28af2006-08-18 17:47:18 -04001738static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001739lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1740 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001741{
Tony Jonesee959b02008-02-22 00:13:36 +01001742 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1744 struct lpfc_hba *phba = vport->phba;
1745
Randy Dunlapafc071e2006-10-23 21:47:13 -07001746 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1747 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001748}
1749
James Smarte59058c2008-08-24 21:49:00 -04001750/**
James Smart3621a712009-04-06 18:47:14 -04001751 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001752 * @dev class device that is converted into a Scsi_host.
1753 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001754 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001755 * @count: number of wwpn bytes in buf
1756 *
1757 * Returns:
1758 * -EACCES hba reset not enabled, adapter over temp
1759 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1760 * -EIO error taking adapter offline or online
1761 * value of count on success
1762 **/
James Smartc3f28af2006-08-18 17:47:18 -04001763static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001764lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1765 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001766{
Tony Jonesee959b02008-02-22 00:13:36 +01001767 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001768 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1769 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001770 struct completion online_compl;
1771 int stat1=0, stat2=0;
1772 unsigned int i, j, cnt=count;
1773 u8 wwpn[8];
1774
James Smart13815c82008-01-11 01:52:48 -05001775 if (!phba->cfg_enable_hba_reset)
1776 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001777 spin_lock_irq(&phba->hbalock);
1778 if (phba->over_temp_state == HBA_OVER_TEMP) {
1779 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001780 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001781 }
1782 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001783 /* count may include a LF at end of string */
1784 if (buf[cnt-1] == '\n')
1785 cnt--;
1786
James Smarta12e07b2006-12-02 13:35:30 -05001787 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001788 ((cnt == 17) && (*buf++ != 'x')) ||
1789 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1790 return -EINVAL;
1791
James Smarta12e07b2006-12-02 13:35:30 -05001792 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001793
1794 memset(wwpn, 0, sizeof(wwpn));
1795
1796 /* Validate and store the new name */
1797 for (i=0, j=0; i < 16; i++) {
1798 if ((*buf >= 'a') && (*buf <= 'f'))
1799 j = ((j << 4) | ((*buf++ -'a') + 10));
1800 else if ((*buf >= 'A') && (*buf <= 'F'))
1801 j = ((j << 4) | ((*buf++ -'A') + 10));
1802 else if ((*buf >= '0') && (*buf <= '9'))
1803 j = ((j << 4) | (*buf++ -'0'));
1804 else
1805 return -EINVAL;
1806 if (i % 2) {
1807 wwpn[i/2] = j & 0xff;
1808 j = 0;
1809 }
1810 }
1811 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001812 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001813 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001814 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001815
1816 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1817 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1818
James Smart46fa3112007-04-25 09:51:45 -04001819 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001820 if (stat1)
1821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001822 "0463 lpfc_soft_wwpn attribute set failed to "
1823 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001824 init_completion(&online_compl);
1825 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1826 wait_for_completion(&online_compl);
1827 if (stat2)
1828 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001829 "0464 lpfc_soft_wwpn attribute set failed to "
1830 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001831 return (stat1 || stat2) ? -EIO : count;
1832}
Tony Jonesee959b02008-02-22 00:13:36 +01001833static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1834 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001835
James Smarte59058c2008-08-24 21:49:00 -04001836/**
James Smart3621a712009-04-06 18:47:14 -04001837 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001838 * @dev: class device that is converted into a Scsi_host.
1839 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001840 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001841 *
1842 * Returns: size of formatted string.
1843 **/
James Smarta12e07b2006-12-02 13:35:30 -05001844static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001845lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1846 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001847{
Tony Jonesee959b02008-02-22 00:13:36 +01001848 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001849 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001850 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1851 (unsigned long long)phba->cfg_soft_wwnn);
1852}
1853
James Smarte59058c2008-08-24 21:49:00 -04001854/**
James Smart3621a712009-04-06 18:47:14 -04001855 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001856 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001857 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001858 * @count: number of wwnn bytes in buf.
1859 *
1860 * Returns:
1861 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1862 * value of count on success
1863 **/
James Smarta12e07b2006-12-02 13:35:30 -05001864static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001865lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1866 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001867{
Tony Jonesee959b02008-02-22 00:13:36 +01001868 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001869 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001870 unsigned int i, j, cnt=count;
1871 u8 wwnn[8];
1872
1873 /* count may include a LF at end of string */
1874 if (buf[cnt-1] == '\n')
1875 cnt--;
1876
1877 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1878 ((cnt == 17) && (*buf++ != 'x')) ||
1879 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1880 return -EINVAL;
1881
1882 /*
1883 * Allow wwnn to be set many times, as long as the enable is set.
1884 * However, once the wwpn is set, everything locks.
1885 */
1886
1887 memset(wwnn, 0, sizeof(wwnn));
1888
1889 /* Validate and store the new name */
1890 for (i=0, j=0; i < 16; i++) {
1891 if ((*buf >= 'a') && (*buf <= 'f'))
1892 j = ((j << 4) | ((*buf++ -'a') + 10));
1893 else if ((*buf >= 'A') && (*buf <= 'F'))
1894 j = ((j << 4) | ((*buf++ -'A') + 10));
1895 else if ((*buf >= '0') && (*buf <= '9'))
1896 j = ((j << 4) | (*buf++ -'0'));
1897 else
1898 return -EINVAL;
1899 if (i % 2) {
1900 wwnn[i/2] = j & 0xff;
1901 j = 0;
1902 }
1903 }
1904 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1905
1906 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1907 "lpfc%d: soft_wwnn set. Value will take effect upon "
1908 "setting of the soft_wwpn\n", phba->brd_no);
1909
1910 return count;
1911}
Tony Jonesee959b02008-02-22 00:13:36 +01001912static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1913 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001914
James Smartc3f28af2006-08-18 17:47:18 -04001915
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001916static int lpfc_poll = 0;
1917module_param(lpfc_poll, int, 0);
1918MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1919 " 0 - none,"
1920 " 1 - poll with interrupts enabled"
1921 " 3 - poll and disable FCP ring interrupts");
1922
Tony Jonesee959b02008-02-22 00:13:36 +01001923static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1924 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001925
James Smart92d7f7b2007-06-17 19:56:38 -05001926int lpfc_sli_mode = 0;
1927module_param(lpfc_sli_mode, int, 0);
1928MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1929 " 0 - auto (SLI-3 if supported),"
1930 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1931 " 3 - select SLI-3");
1932
James Smart15672312010-04-06 14:49:03 -04001933int lpfc_enable_npiv = 1;
James Smart7ee5d432007-10-27 13:37:17 -04001934module_param(lpfc_enable_npiv, int, 0);
1935MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1936lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04001937lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04001938static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001939
dea31012005-04-17 16:05:31 -05001940/*
James Smart84d1b002010-02-12 14:42:33 -05001941# lpfc_suppress_link_up: Bring link up at initialization
1942# 0x0 = bring link up (issue MBX_INIT_LINK)
1943# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1944# 0x2 = never bring up link
1945# Default value is 0.
1946*/
James Smarte40a02c2010-02-26 14:13:54 -05001947LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1948 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1949 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04001950/*
1951# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1952# 1 - (1024)
1953# 2 - (2048)
1954# 3 - (3072)
1955# 4 - (4096)
1956# 5 - (5120)
1957*/
1958static ssize_t
1959lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1960{
1961 struct Scsi_Host *shost = class_to_shost(dev);
1962 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1963
1964 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
1965}
1966
1967static DEVICE_ATTR(iocb_hw, S_IRUGO,
1968 lpfc_iocb_hw_show, NULL);
1969static ssize_t
1970lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1971{
1972 struct Scsi_Host *shost = class_to_shost(dev);
1973 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1974
1975 return snprintf(buf, PAGE_SIZE, "%d\n",
1976 phba->sli.ring[LPFC_ELS_RING].txq_max);
1977}
1978
1979static DEVICE_ATTR(txq_hw, S_IRUGO,
1980 lpfc_txq_hw_show, NULL);
1981static ssize_t
1982lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
1983 char *buf)
1984{
1985 struct Scsi_Host *shost = class_to_shost(dev);
1986 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1987
1988 return snprintf(buf, PAGE_SIZE, "%d\n",
1989 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
1990}
1991
1992static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
1993 lpfc_txcmplq_hw_show, NULL);
1994
1995int lpfc_iocb_cnt = 2;
1996module_param(lpfc_iocb_cnt, int, 1);
1997MODULE_PARM_DESC(lpfc_iocb_cnt,
1998 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
1999lpfc_param_show(iocb_cnt);
2000lpfc_param_init(iocb_cnt, 2, 1, 5);
2001static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2002 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002003
2004/*
James Smartc01f3202006-08-18 17:47:08 -04002005# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2006# until the timer expires. Value range is [0,255]. Default value is 30.
2007*/
2008static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2009static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2010module_param(lpfc_nodev_tmo, int, 0);
2011MODULE_PARM_DESC(lpfc_nodev_tmo,
2012 "Seconds driver will hold I/O waiting "
2013 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002014
2015/**
James Smart3621a712009-04-06 18:47:14 -04002016 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002017 * @dev: class converted to a Scsi_host structure.
2018 * @attr: device attribute, not used.
2019 * @buf: on return contains the dev loss timeout in decimal.
2020 *
2021 * Returns: size of formatted string.
2022 **/
James Smartc01f3202006-08-18 17:47:08 -04002023static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002024lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2025 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002026{
Tony Jonesee959b02008-02-22 00:13:36 +01002027 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002028 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002029
James Smart3de2a652007-08-02 11:09:59 -04002030 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002031}
2032
James Smarte59058c2008-08-24 21:49:00 -04002033/**
James Smart3621a712009-04-06 18:47:14 -04002034 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002035 * @vport: lpfc vport structure pointer.
2036 * @val: contains the nodev timeout value.
2037 *
2038 * Description:
2039 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2040 * a kernel error message is printed and zero is returned.
2041 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2042 * Otherwise nodev tmo is set to the default value.
2043 *
2044 * Returns:
2045 * zero if already set or if val is in range
2046 * -EINVAL val out of range
2047 **/
James Smartc01f3202006-08-18 17:47:08 -04002048static int
James Smart3de2a652007-08-02 11:09:59 -04002049lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002050{
James Smart3de2a652007-08-02 11:09:59 -04002051 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2052 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2053 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002055 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002056 "parameter because devloss_tmo is "
2057 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002058 return 0;
2059 }
2060
2061 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002062 vport->cfg_nodev_tmo = val;
2063 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002064 return 0;
2065 }
James Smarte8b62012007-08-02 11:10:09 -04002066 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2067 "0400 lpfc_nodev_tmo attribute cannot be set to"
2068 " %d, allowed range is [%d, %d]\n",
2069 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002070 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002071 return -EINVAL;
2072}
2073
James Smarte59058c2008-08-24 21:49:00 -04002074/**
James Smart3621a712009-04-06 18:47:14 -04002075 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002076 * @vport: lpfc vport structure pointer.
2077 *
2078 * Description:
2079 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2080 **/
James Smart7054a602007-04-25 09:52:34 -04002081static void
James Smart3de2a652007-08-02 11:09:59 -04002082lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002083{
James Smart858c9f62007-06-17 19:56:39 -05002084 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002085 struct lpfc_nodelist *ndlp;
2086
James Smart51ef4c22007-08-02 11:10:31 -04002087 shost = lpfc_shost_from_vport(vport);
2088 spin_lock_irq(shost->host_lock);
2089 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002090 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002091 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2092 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002093}
2094
James Smarte59058c2008-08-24 21:49:00 -04002095/**
James Smart3621a712009-04-06 18:47:14 -04002096 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002097 * @vport: lpfc vport structure pointer.
2098 * @val: contains the tmo value.
2099 *
2100 * Description:
2101 * If the devloss tmo is already set or the vport dev loss tmo has changed
2102 * then a kernel error message is printed and zero is returned.
2103 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2104 * Otherwise nodev tmo is set to the default value.
2105 *
2106 * Returns:
2107 * zero if already set or if val is in range
2108 * -EINVAL val out of range
2109 **/
James Smartc01f3202006-08-18 17:47:08 -04002110static int
James Smart3de2a652007-08-02 11:09:59 -04002111lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002112{
James Smart3de2a652007-08-02 11:09:59 -04002113 if (vport->dev_loss_tmo_changed ||
2114 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002115 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2116 "0401 Ignoring change to nodev_tmo "
2117 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002118 return 0;
2119 }
James Smartc01f3202006-08-18 17:47:08 -04002120 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002121 vport->cfg_nodev_tmo = val;
2122 vport->cfg_devloss_tmo = val;
2123 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002124 return 0;
2125 }
James Smarte8b62012007-08-02 11:10:09 -04002126 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2127 "0403 lpfc_nodev_tmo attribute cannot be set to"
2128 "%d, allowed range is [%d, %d]\n",
2129 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002130 return -EINVAL;
2131}
2132
James Smart3de2a652007-08-02 11:09:59 -04002133lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002134
Tony Jonesee959b02008-02-22 00:13:36 +01002135static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2136 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002137
2138/*
2139# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2140# disappear until the timer expires. Value range is [0,255]. Default
2141# value is 30.
2142*/
2143module_param(lpfc_devloss_tmo, int, 0);
2144MODULE_PARM_DESC(lpfc_devloss_tmo,
2145 "Seconds driver will hold I/O waiting "
2146 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002147lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2148 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2149lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002150
2151/**
James Smart3621a712009-04-06 18:47:14 -04002152 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002153 * @vport: lpfc vport structure pointer.
2154 * @val: contains the tmo value.
2155 *
2156 * Description:
2157 * If val is in a valid range then set the vport nodev tmo,
2158 * devloss tmo, also set the vport dev loss tmo changed flag.
2159 * Else a kernel error message is printed.
2160 *
2161 * Returns:
2162 * zero if val is in range
2163 * -EINVAL val out of range
2164 **/
James Smartc01f3202006-08-18 17:47:08 -04002165static int
James Smart3de2a652007-08-02 11:09:59 -04002166lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002167{
2168 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002169 vport->cfg_nodev_tmo = val;
2170 vport->cfg_devloss_tmo = val;
2171 vport->dev_loss_tmo_changed = 1;
2172 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002173 return 0;
2174 }
2175
James Smarte8b62012007-08-02 11:10:09 -04002176 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2177 "0404 lpfc_devloss_tmo attribute cannot be set to"
2178 " %d, allowed range is [%d, %d]\n",
2179 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002180 return -EINVAL;
2181}
2182
James Smart3de2a652007-08-02 11:09:59 -04002183lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002184static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2185 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002186
2187/*
dea31012005-04-17 16:05:31 -05002188# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2189# deluged with LOTS of information.
2190# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002191# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002192*/
James Smartf4b4c682009-05-22 14:53:12 -04002193LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002194 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002195
2196/*
James Smart7ee5d432007-10-27 13:37:17 -04002197# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2198# objects that have been registered with the nameserver after login.
2199*/
2200LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2201 "Deregister nameserver objects before LOGO");
2202
2203/*
dea31012005-04-17 16:05:31 -05002204# lun_queue_depth: This parameter is used to limit the number of outstanding
2205# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2206*/
James Smart3de2a652007-08-02 11:09:59 -04002207LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2208 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002209
2210/*
James Smart7dc517d2010-07-14 15:32:10 -04002211# tgt_queue_depth: This parameter is used to limit the number of outstanding
2212# commands per target port. Value range is [10,65535]. Default value is 65535.
2213*/
2214LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2215 "Max number of FCP commands we can queue to a specific target port");
2216
2217/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002218# hba_queue_depth: This parameter is used to limit the number of outstanding
2219# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2220# value is greater than the maximum number of exchanges supported by the HBA,
2221# then maximum number of exchanges supported by the HBA is used to determine
2222# the hba_queue_depth.
2223*/
2224LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2225 "Max number of FCP commands we can queue to a lpfc HBA");
2226
2227/*
James Smart92d7f7b2007-06-17 19:56:38 -05002228# peer_port_login: This parameter allows/prevents logins
2229# between peer ports hosted on the same physical port.
2230# When this parameter is set 0 peer ports of same physical port
2231# are not allowed to login to each other.
2232# When this parameter is set 1 peer ports of same physical port
2233# are allowed to login to each other.
2234# Default value of this parameter is 0.
2235*/
James Smart3de2a652007-08-02 11:09:59 -04002236LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2237 "Allow peer ports on the same physical port to login to each "
2238 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002239
2240/*
James Smart3de2a652007-08-02 11:09:59 -04002241# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002242# between Virtual Ports and remote initiators.
2243# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2244# other initiators and will attempt to PLOGI all remote ports.
2245# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2246# remote ports and will not attempt to PLOGI to other initiators.
2247# This parameter does not restrict to the physical port.
2248# This parameter does not restrict logins to Fabric resident remote ports.
2249# Default value of this parameter is 1.
2250*/
James Smart3de2a652007-08-02 11:09:59 -04002251static int lpfc_restrict_login = 1;
2252module_param(lpfc_restrict_login, int, 0);
2253MODULE_PARM_DESC(lpfc_restrict_login,
2254 "Restrict virtual ports login to remote initiators.");
2255lpfc_vport_param_show(restrict_login);
2256
James Smarte59058c2008-08-24 21:49:00 -04002257/**
James Smart3621a712009-04-06 18:47:14 -04002258 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002259 * @vport: lpfc vport structure pointer.
2260 * @val: contains the restrict login value.
2261 *
2262 * Description:
2263 * If val is not in a valid range then log a kernel error message and set
2264 * the vport restrict login to one.
2265 * If the port type is physical clear the restrict login flag and return.
2266 * Else set the restrict login flag to val.
2267 *
2268 * Returns:
2269 * zero if val is in range
2270 * -EINVAL val out of range
2271 **/
James Smart3de2a652007-08-02 11:09:59 -04002272static int
2273lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2274{
2275 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002276 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002277 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002278 "be set to %d, allowed range is [0, 1]\n",
2279 val);
James Smart3de2a652007-08-02 11:09:59 -04002280 vport->cfg_restrict_login = 1;
2281 return -EINVAL;
2282 }
2283 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2284 vport->cfg_restrict_login = 0;
2285 return 0;
2286 }
2287 vport->cfg_restrict_login = val;
2288 return 0;
2289}
2290
James Smarte59058c2008-08-24 21:49:00 -04002291/**
James Smart3621a712009-04-06 18:47:14 -04002292 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002293 * @vport: lpfc vport structure pointer.
2294 * @val: contains the restrict login value.
2295 *
2296 * Description:
2297 * If val is not in a valid range then log a kernel error message and set
2298 * the vport restrict login to one.
2299 * If the port type is physical and the val is not zero log a kernel
2300 * error message, clear the restrict login flag and return zero.
2301 * Else set the restrict login flag to val.
2302 *
2303 * Returns:
2304 * zero if val is in range
2305 * -EINVAL val out of range
2306 **/
James Smart3de2a652007-08-02 11:09:59 -04002307static int
2308lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2309{
2310 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002311 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002312 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002313 "be set to %d, allowed range is [0, 1]\n",
2314 val);
James Smart3de2a652007-08-02 11:09:59 -04002315 vport->cfg_restrict_login = 1;
2316 return -EINVAL;
2317 }
2318 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002319 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2320 "0468 lpfc_restrict_login must be 0 for "
2321 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002322 vport->cfg_restrict_login = 0;
2323 return 0;
2324 }
2325 vport->cfg_restrict_login = val;
2326 return 0;
2327}
2328lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002329static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2330 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002331
2332/*
dea31012005-04-17 16:05:31 -05002333# Some disk devices have a "select ID" or "select Target" capability.
2334# From a protocol standpoint "select ID" usually means select the
2335# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2336# annex" which contains a table that maps a "select ID" (a number
2337# between 0 and 7F) to an ALPA. By default, for compatibility with
2338# older drivers, the lpfc driver scans this table from low ALPA to high
2339# ALPA.
2340#
2341# Turning on the scan-down variable (on = 1, off = 0) will
2342# cause the lpfc driver to use an inverted table, effectively
2343# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2344#
2345# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2346# and will not work across a fabric. Also this parameter will take
2347# effect only in the case when ALPA map is not available.)
2348*/
James Smart3de2a652007-08-02 11:09:59 -04002349LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2350 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002351
2352/*
dea31012005-04-17 16:05:31 -05002353# lpfc_topology: link topology for init link
2354# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002355# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002356# 0x02 = attempt point-to-point mode only
2357# 0x04 = attempt loop mode only
2358# 0x06 = attempt point-to-point mode then loop
2359# Set point-to-point mode if you want to run as an N_Port.
2360# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2361# Default value is 0.
2362*/
James Smarte59058c2008-08-24 21:49:00 -04002363
2364/**
James Smart3621a712009-04-06 18:47:14 -04002365 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002366 * @phba: lpfc_hba pointer.
2367 * @val: topology value.
2368 *
2369 * Description:
2370 * If val is in a valid range then set the adapter's topology field and
2371 * issue a lip; if the lip fails reset the topology to the old value.
2372 *
2373 * If the value is not in range log a kernel error message and return an error.
2374 *
2375 * Returns:
2376 * zero if val is in range and lip okay
2377 * non-zero return value from lpfc_issue_lip()
2378 * -EINVAL val out of range
2379 **/
James Smarta257bf92009-04-06 18:48:10 -04002380static ssize_t
2381lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2382 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002383{
James Smarta257bf92009-04-06 18:48:10 -04002384 struct Scsi_Host *shost = class_to_shost(dev);
2385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2386 struct lpfc_hba *phba = vport->phba;
2387 int val = 0;
2388 int nolip = 0;
2389 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002390 int err;
2391 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002392
2393 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2394 nolip = 1;
2395 val_buf = &buf[strlen("nolip ")];
2396 }
2397
2398 if (!isdigit(val_buf[0]))
2399 return -EINVAL;
2400 if (sscanf(val_buf, "%i", &val) != 1)
2401 return -EINVAL;
2402
James Smart83108bd2008-01-11 01:53:09 -05002403 if (val >= 0 && val <= 6) {
2404 prev_val = phba->cfg_topology;
2405 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002406 if (nolip)
2407 return strlen(buf);
2408
James Smart83108bd2008-01-11 01:53:09 -05002409 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002410 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002411 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002412 return -EINVAL;
2413 } else
2414 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002415 }
2416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2417 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2418 "allowed range is [0, 6]\n",
2419 phba->brd_no, val);
2420 return -EINVAL;
2421}
2422static int lpfc_topology = 0;
2423module_param(lpfc_topology, int, 0);
2424MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2425lpfc_param_show(topology)
2426lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002427static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002428 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002429
James Smart21e9a0a2009-05-22 14:53:21 -04002430/**
2431 * lpfc_static_vport_show: Read callback function for
2432 * lpfc_static_vport sysfs file.
2433 * @dev: Pointer to class device object.
2434 * @attr: device attribute structure.
2435 * @buf: Data buffer.
2436 *
2437 * This function is the read call back function for
2438 * lpfc_static_vport sysfs file. The lpfc_static_vport
2439 * sysfs file report the mageability of the vport.
2440 **/
2441static ssize_t
2442lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2443 char *buf)
2444{
2445 struct Scsi_Host *shost = class_to_shost(dev);
2446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2447 if (vport->vport_flag & STATIC_VPORT)
2448 sprintf(buf, "1\n");
2449 else
2450 sprintf(buf, "0\n");
2451
2452 return strlen(buf);
2453}
2454
2455/*
2456 * Sysfs attribute to control the statistical data collection.
2457 */
2458static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2459 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002460
2461/**
James Smart3621a712009-04-06 18:47:14 -04002462 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002463 * @dev: Pointer to class device.
2464 * @buf: Data buffer.
2465 * @count: Size of the data buffer.
2466 *
2467 * This function get called when an user write to the lpfc_stat_data_ctrl
2468 * sysfs file. This function parse the command written to the sysfs file
2469 * and take appropriate action. These commands are used for controlling
2470 * driver statistical data collection.
2471 * Following are the command this function handles.
2472 *
2473 * setbucket <bucket_type> <base> <step>
2474 * = Set the latency buckets.
2475 * destroybucket = destroy all the buckets.
2476 * start = start data collection
2477 * stop = stop data collection
2478 * reset = reset the collected data
2479 **/
2480static ssize_t
2481lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2482 const char *buf, size_t count)
2483{
2484 struct Scsi_Host *shost = class_to_shost(dev);
2485 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2486 struct lpfc_hba *phba = vport->phba;
2487#define LPFC_MAX_DATA_CTRL_LEN 1024
2488 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2489 unsigned long i;
2490 char *str_ptr, *token;
2491 struct lpfc_vport **vports;
2492 struct Scsi_Host *v_shost;
2493 char *bucket_type_str, *base_str, *step_str;
2494 unsigned long base, step, bucket_type;
2495
2496 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002497 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002498 return -EINVAL;
2499
2500 strcpy(bucket_data, buf);
2501 str_ptr = &bucket_data[0];
2502 /* Ignore this token - this is command token */
2503 token = strsep(&str_ptr, "\t ");
2504 if (!token)
2505 return -EINVAL;
2506
2507 bucket_type_str = strsep(&str_ptr, "\t ");
2508 if (!bucket_type_str)
2509 return -EINVAL;
2510
2511 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2512 bucket_type = LPFC_LINEAR_BUCKET;
2513 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2514 bucket_type = LPFC_POWER2_BUCKET;
2515 else
2516 return -EINVAL;
2517
2518 base_str = strsep(&str_ptr, "\t ");
2519 if (!base_str)
2520 return -EINVAL;
2521 base = simple_strtoul(base_str, NULL, 0);
2522
2523 step_str = strsep(&str_ptr, "\t ");
2524 if (!step_str)
2525 return -EINVAL;
2526 step = simple_strtoul(step_str, NULL, 0);
2527 if (!step)
2528 return -EINVAL;
2529
2530 /* Block the data collection for every vport */
2531 vports = lpfc_create_vport_work_array(phba);
2532 if (vports == NULL)
2533 return -ENOMEM;
2534
James Smartf4b4c682009-05-22 14:53:12 -04002535 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002536 v_shost = lpfc_shost_from_vport(vports[i]);
2537 spin_lock_irq(v_shost->host_lock);
2538 /* Block and reset data collection */
2539 vports[i]->stat_data_blocked = 1;
2540 if (vports[i]->stat_data_enabled)
2541 lpfc_vport_reset_stat_data(vports[i]);
2542 spin_unlock_irq(v_shost->host_lock);
2543 }
2544
2545 /* Set the bucket attributes */
2546 phba->bucket_type = bucket_type;
2547 phba->bucket_base = base;
2548 phba->bucket_step = step;
2549
James Smartf4b4c682009-05-22 14:53:12 -04002550 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002551 v_shost = lpfc_shost_from_vport(vports[i]);
2552
2553 /* Unblock data collection */
2554 spin_lock_irq(v_shost->host_lock);
2555 vports[i]->stat_data_blocked = 0;
2556 spin_unlock_irq(v_shost->host_lock);
2557 }
2558 lpfc_destroy_vport_work_array(phba, vports);
2559 return strlen(buf);
2560 }
2561
2562 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2563 vports = lpfc_create_vport_work_array(phba);
2564 if (vports == NULL)
2565 return -ENOMEM;
2566
James Smartf4b4c682009-05-22 14:53:12 -04002567 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002568 v_shost = lpfc_shost_from_vport(vports[i]);
2569 spin_lock_irq(shost->host_lock);
2570 vports[i]->stat_data_blocked = 1;
2571 lpfc_free_bucket(vport);
2572 vport->stat_data_enabled = 0;
2573 vports[i]->stat_data_blocked = 0;
2574 spin_unlock_irq(shost->host_lock);
2575 }
2576 lpfc_destroy_vport_work_array(phba, vports);
2577 phba->bucket_type = LPFC_NO_BUCKET;
2578 phba->bucket_base = 0;
2579 phba->bucket_step = 0;
2580 return strlen(buf);
2581 }
2582
2583 if (!strncmp(buf, "start", strlen("start"))) {
2584 /* If no buckets configured return error */
2585 if (phba->bucket_type == LPFC_NO_BUCKET)
2586 return -EINVAL;
2587 spin_lock_irq(shost->host_lock);
2588 if (vport->stat_data_enabled) {
2589 spin_unlock_irq(shost->host_lock);
2590 return strlen(buf);
2591 }
2592 lpfc_alloc_bucket(vport);
2593 vport->stat_data_enabled = 1;
2594 spin_unlock_irq(shost->host_lock);
2595 return strlen(buf);
2596 }
2597
2598 if (!strncmp(buf, "stop", strlen("stop"))) {
2599 spin_lock_irq(shost->host_lock);
2600 if (vport->stat_data_enabled == 0) {
2601 spin_unlock_irq(shost->host_lock);
2602 return strlen(buf);
2603 }
2604 lpfc_free_bucket(vport);
2605 vport->stat_data_enabled = 0;
2606 spin_unlock_irq(shost->host_lock);
2607 return strlen(buf);
2608 }
2609
2610 if (!strncmp(buf, "reset", strlen("reset"))) {
2611 if ((phba->bucket_type == LPFC_NO_BUCKET)
2612 || !vport->stat_data_enabled)
2613 return strlen(buf);
2614 spin_lock_irq(shost->host_lock);
2615 vport->stat_data_blocked = 1;
2616 lpfc_vport_reset_stat_data(vport);
2617 vport->stat_data_blocked = 0;
2618 spin_unlock_irq(shost->host_lock);
2619 return strlen(buf);
2620 }
2621 return -EINVAL;
2622}
2623
2624
2625/**
James Smart3621a712009-04-06 18:47:14 -04002626 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002627 * @dev: Pointer to class device object.
2628 * @buf: Data buffer.
2629 *
2630 * This function is the read call back function for
2631 * lpfc_stat_data_ctrl sysfs file. This function report the
2632 * current statistical data collection state.
2633 **/
2634static ssize_t
2635lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2636 char *buf)
2637{
2638 struct Scsi_Host *shost = class_to_shost(dev);
2639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2640 struct lpfc_hba *phba = vport->phba;
2641 int index = 0;
2642 int i;
2643 char *bucket_type;
2644 unsigned long bucket_value;
2645
2646 switch (phba->bucket_type) {
2647 case LPFC_LINEAR_BUCKET:
2648 bucket_type = "linear";
2649 break;
2650 case LPFC_POWER2_BUCKET:
2651 bucket_type = "power2";
2652 break;
2653 default:
2654 bucket_type = "No Bucket";
2655 break;
2656 }
2657
2658 sprintf(&buf[index], "Statistical Data enabled :%d, "
2659 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2660 " Bucket step :%d\nLatency Ranges :",
2661 vport->stat_data_enabled, vport->stat_data_blocked,
2662 bucket_type, phba->bucket_base, phba->bucket_step);
2663 index = strlen(buf);
2664 if (phba->bucket_type != LPFC_NO_BUCKET) {
2665 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2666 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2667 bucket_value = phba->bucket_base +
2668 phba->bucket_step * i;
2669 else
2670 bucket_value = phba->bucket_base +
2671 (1 << i) * phba->bucket_step;
2672
2673 if (index + 10 > PAGE_SIZE)
2674 break;
2675 sprintf(&buf[index], "%08ld ", bucket_value);
2676 index = strlen(buf);
2677 }
2678 }
2679 sprintf(&buf[index], "\n");
2680 return strlen(buf);
2681}
2682
2683/*
2684 * Sysfs attribute to control the statistical data collection.
2685 */
2686static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2687 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2688
2689/*
2690 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2691 */
2692
2693/*
2694 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2695 * for each target.
2696 */
2697#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2698#define MAX_STAT_DATA_SIZE_PER_TARGET \
2699 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2700
2701
2702/**
James Smart3621a712009-04-06 18:47:14 -04002703 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002704 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002705 * @kobj: Pointer to the kernel object
2706 * @bin_attr: Attribute object
2707 * @buff: Buffer pointer
2708 * @off: File offset
2709 * @count: Buffer size
2710 *
2711 * This function is the read call back function for lpfc_drvr_stat_data
2712 * sysfs file. This function export the statistical data to user
2713 * applications.
2714 **/
2715static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002716sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2717 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002718 char *buf, loff_t off, size_t count)
2719{
2720 struct device *dev = container_of(kobj, struct device,
2721 kobj);
2722 struct Scsi_Host *shost = class_to_shost(dev);
2723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2724 struct lpfc_hba *phba = vport->phba;
2725 int i = 0, index = 0;
2726 unsigned long nport_index;
2727 struct lpfc_nodelist *ndlp = NULL;
2728 nport_index = (unsigned long)off /
2729 MAX_STAT_DATA_SIZE_PER_TARGET;
2730
2731 if (!vport->stat_data_enabled || vport->stat_data_blocked
2732 || (phba->bucket_type == LPFC_NO_BUCKET))
2733 return 0;
2734
2735 spin_lock_irq(shost->host_lock);
2736 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2737 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2738 continue;
2739
2740 if (nport_index > 0) {
2741 nport_index--;
2742 continue;
2743 }
2744
2745 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2746 > count)
2747 break;
2748
2749 if (!ndlp->lat_data)
2750 continue;
2751
2752 /* Print the WWN */
2753 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2754 ndlp->nlp_portname.u.wwn[0],
2755 ndlp->nlp_portname.u.wwn[1],
2756 ndlp->nlp_portname.u.wwn[2],
2757 ndlp->nlp_portname.u.wwn[3],
2758 ndlp->nlp_portname.u.wwn[4],
2759 ndlp->nlp_portname.u.wwn[5],
2760 ndlp->nlp_portname.u.wwn[6],
2761 ndlp->nlp_portname.u.wwn[7]);
2762
2763 index = strlen(buf);
2764
2765 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2766 sprintf(&buf[index], "%010u,",
2767 ndlp->lat_data[i].cmd_count);
2768 index = strlen(buf);
2769 }
2770 sprintf(&buf[index], "\n");
2771 index = strlen(buf);
2772 }
2773 spin_unlock_irq(shost->host_lock);
2774 return index;
2775}
2776
2777static struct bin_attribute sysfs_drvr_stat_data_attr = {
2778 .attr = {
2779 .name = "lpfc_drvr_stat_data",
2780 .mode = S_IRUSR,
2781 .owner = THIS_MODULE,
2782 },
2783 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2784 .read = sysfs_drvr_stat_data_read,
2785 .write = NULL,
2786};
2787
dea31012005-04-17 16:05:31 -05002788/*
2789# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2790# connection.
2791# 0 = auto select (default)
2792# 1 = 1 Gigabaud
2793# 2 = 2 Gigabaud
2794# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002795# 8 = 8 Gigabaud
2796# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002797*/
James Smarte59058c2008-08-24 21:49:00 -04002798
2799/**
James Smart3621a712009-04-06 18:47:14 -04002800 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002801 * @phba: lpfc_hba pointer.
2802 * @val: link speed value.
2803 *
2804 * Description:
2805 * If val is in a valid range then set the adapter's link speed field and
2806 * issue a lip; if the lip fails reset the link speed to the old value.
2807 *
2808 * Notes:
2809 * If the value is not in range log a kernel error message and return an error.
2810 *
2811 * Returns:
2812 * zero if val is in range and lip okay.
2813 * non-zero return value from lpfc_issue_lip()
2814 * -EINVAL val out of range
2815 **/
James Smarta257bf92009-04-06 18:48:10 -04002816static ssize_t
2817lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2818 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002819{
James Smarta257bf92009-04-06 18:48:10 -04002820 struct Scsi_Host *shost = class_to_shost(dev);
2821 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2822 struct lpfc_hba *phba = vport->phba;
2823 int val = 0;
2824 int nolip = 0;
2825 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002826 int err;
2827 uint32_t prev_val;
2828
James Smarta257bf92009-04-06 18:48:10 -04002829 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2830 nolip = 1;
2831 val_buf = &buf[strlen("nolip ")];
2832 }
2833
2834 if (!isdigit(val_buf[0]))
2835 return -EINVAL;
2836 if (sscanf(val_buf, "%i", &val) != 1)
2837 return -EINVAL;
2838
James Smart83108bd2008-01-11 01:53:09 -05002839 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2840 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2841 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2842 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2843 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2844 return -EINVAL;
2845
James Smarta257bf92009-04-06 18:48:10 -04002846 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002847 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2848 prev_val = phba->cfg_link_speed;
2849 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002850 if (nolip)
2851 return strlen(buf);
2852
James Smart83108bd2008-01-11 01:53:09 -05002853 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002854 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002855 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002856 return -EINVAL;
2857 } else
2858 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002859 }
2860
2861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2862 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2863 "allowed range is [0, 8]\n",
2864 phba->brd_no, val);
2865 return -EINVAL;
2866}
2867
2868static int lpfc_link_speed = 0;
2869module_param(lpfc_link_speed, int, 0);
2870MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2871lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002872
2873/**
James Smart3621a712009-04-06 18:47:14 -04002874 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002875 * @phba: lpfc_hba pointer.
2876 * @val: link speed value.
2877 *
2878 * Description:
2879 * If val is in a valid range then set the adapter's link speed field.
2880 *
2881 * Notes:
2882 * If the value is not in range log a kernel error message, clear the link
2883 * speed and return an error.
2884 *
2885 * Returns:
2886 * zero if val saved.
2887 * -EINVAL val out of range
2888 **/
James Smart83108bd2008-01-11 01:53:09 -05002889static int
2890lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2891{
2892 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2893 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2894 phba->cfg_link_speed = val;
2895 return 0;
2896 }
2897 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002898 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002899 "be set to %d, allowed values are "
2900 "["LPFC_LINK_SPEED_STRING"]\n", val);
2901 phba->cfg_link_speed = 0;
2902 return -EINVAL;
2903}
2904
Tony Jonesee959b02008-02-22 00:13:36 +01002905static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002906 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002907
2908/*
James Smart0d878412009-10-02 15:16:56 -04002909# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2910# 0 = aer disabled or not supported
2911# 1 = aer supported and enabled (default)
2912# Value range is [0,1]. Default value is 1.
2913*/
2914
2915/**
2916 * lpfc_aer_support_store - Set the adapter for aer support
2917 *
2918 * @dev: class device that is converted into a Scsi_host.
2919 * @attr: device attribute, not used.
2920 * @buf: containing the string "selective".
2921 * @count: unused variable.
2922 *
2923 * Description:
2924 * If the val is 1 and currently the device's AER capability was not
2925 * enabled, invoke the kernel's enable AER helper routine, trying to
2926 * enable the device's AER capability. If the helper routine enabling
2927 * AER returns success, update the device's cfg_aer_support flag to
2928 * indicate AER is supported by the device; otherwise, if the device
2929 * AER capability is already enabled to support AER, then do nothing.
2930 *
2931 * If the val is 0 and currently the device's AER support was enabled,
2932 * invoke the kernel's disable AER helper routine. After that, update
2933 * the device's cfg_aer_support flag to indicate AER is not supported
2934 * by the device; otherwise, if the device AER capability is already
2935 * disabled from supporting AER, then do nothing.
2936 *
2937 * Returns:
2938 * length of the buf on success if val is in range the intended mode
2939 * is supported.
2940 * -EINVAL if val out of range or intended mode is not supported.
2941 **/
2942static ssize_t
2943lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2944 const char *buf, size_t count)
2945{
2946 struct Scsi_Host *shost = class_to_shost(dev);
2947 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2948 struct lpfc_hba *phba = vport->phba;
2949 int val = 0, rc = -EINVAL;
2950
2951 if (!isdigit(buf[0]))
2952 return -EINVAL;
2953 if (sscanf(buf, "%i", &val) != 1)
2954 return -EINVAL;
2955
2956 switch (val) {
2957 case 0:
2958 if (phba->hba_flag & HBA_AER_ENABLED) {
2959 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2960 if (!rc) {
2961 spin_lock_irq(&phba->hbalock);
2962 phba->hba_flag &= ~HBA_AER_ENABLED;
2963 spin_unlock_irq(&phba->hbalock);
2964 phba->cfg_aer_support = 0;
2965 rc = strlen(buf);
2966 } else
James Smart891478a2009-11-18 15:40:23 -05002967 rc = -EPERM;
2968 } else {
James Smart0d878412009-10-02 15:16:56 -04002969 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05002970 rc = strlen(buf);
2971 }
James Smart0d878412009-10-02 15:16:56 -04002972 break;
2973 case 1:
2974 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2975 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2976 if (!rc) {
2977 spin_lock_irq(&phba->hbalock);
2978 phba->hba_flag |= HBA_AER_ENABLED;
2979 spin_unlock_irq(&phba->hbalock);
2980 phba->cfg_aer_support = 1;
2981 rc = strlen(buf);
2982 } else
James Smart891478a2009-11-18 15:40:23 -05002983 rc = -EPERM;
2984 } else {
James Smart0d878412009-10-02 15:16:56 -04002985 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05002986 rc = strlen(buf);
2987 }
James Smart0d878412009-10-02 15:16:56 -04002988 break;
2989 default:
2990 rc = -EINVAL;
2991 break;
2992 }
2993 return rc;
2994}
2995
2996static int lpfc_aer_support = 1;
2997module_param(lpfc_aer_support, int, 1);
2998MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2999lpfc_param_show(aer_support)
3000
3001/**
3002 * lpfc_aer_support_init - Set the initial adapters aer support flag
3003 * @phba: lpfc_hba pointer.
3004 * @val: link speed value.
3005 *
3006 * Description:
3007 * If val is in a valid range [0,1], then set the adapter's initial
3008 * cfg_aer_support field. It will be up to the driver's probe_one
3009 * routine to determine whether the device's AER support can be set
3010 * or not.
3011 *
3012 * Notes:
3013 * If the value is not in range log a kernel error message, and
3014 * choose the default value of setting AER support and return.
3015 *
3016 * Returns:
3017 * zero if val saved.
3018 * -EINVAL val out of range
3019 **/
3020static int
3021lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3022{
3023 if (val == 0 || val == 1) {
3024 phba->cfg_aer_support = val;
3025 return 0;
3026 }
3027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3028 "2712 lpfc_aer_support attribute value %d out "
3029 "of range, allowed values are 0|1, setting it "
3030 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003031 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003032 phba->cfg_aer_support = 1;
3033 return -EINVAL;
3034}
3035
3036static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3037 lpfc_aer_support_show, lpfc_aer_support_store);
3038
3039/**
3040 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3041 * @dev: class device that is converted into a Scsi_host.
3042 * @attr: device attribute, not used.
3043 * @buf: containing the string "selective".
3044 * @count: unused variable.
3045 *
3046 * Description:
3047 * If the @buf contains 1 and the device currently has the AER support
3048 * enabled, then invokes the kernel AER helper routine
3049 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3050 * error status register.
3051 *
3052 * Notes:
3053 *
3054 * Returns:
3055 * -EINVAL if the buf does not contain the 1 or the device is not currently
3056 * enabled with the AER support.
3057 **/
3058static ssize_t
3059lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3060 const char *buf, size_t count)
3061{
3062 struct Scsi_Host *shost = class_to_shost(dev);
3063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3064 struct lpfc_hba *phba = vport->phba;
3065 int val, rc = -1;
3066
3067 if (!isdigit(buf[0]))
3068 return -EINVAL;
3069 if (sscanf(buf, "%i", &val) != 1)
3070 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003071 if (val != 1)
3072 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003073
James Smart891478a2009-11-18 15:40:23 -05003074 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003075 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3076
3077 if (rc == 0)
3078 return strlen(buf);
3079 else
James Smart891478a2009-11-18 15:40:23 -05003080 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003081}
3082
3083static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3084 lpfc_aer_cleanup_state);
3085
3086/*
dea31012005-04-17 16:05:31 -05003087# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3088# Value range is [2,3]. Default value is 3.
3089*/
James Smart3de2a652007-08-02 11:09:59 -04003090LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3091 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003092
3093/*
3094# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3095# is [0,1]. Default value is 0.
3096*/
James Smart3de2a652007-08-02 11:09:59 -04003097LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3098 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003099
3100/*
James Smart977b5a02008-09-07 11:52:04 -04003101# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3102# depth. Default value is 0. When the value of this parameter is zero the
3103# SCSI command completion time is not used for controlling I/O queue depth. When
3104# the parameter is set to a non-zero value, the I/O queue depth is controlled
3105# to limit the I/O completion time to the parameter value.
3106# The value is set in milliseconds.
3107*/
3108static int lpfc_max_scsicmpl_time;
3109module_param(lpfc_max_scsicmpl_time, int, 0);
3110MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3111 "Use command completion time to control queue depth");
3112lpfc_vport_param_show(max_scsicmpl_time);
3113lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3114static int
3115lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3116{
3117 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3118 struct lpfc_nodelist *ndlp, *next_ndlp;
3119
3120 if (val == vport->cfg_max_scsicmpl_time)
3121 return 0;
3122 if ((val < 0) || (val > 60000))
3123 return -EINVAL;
3124 vport->cfg_max_scsicmpl_time = val;
3125
3126 spin_lock_irq(shost->host_lock);
3127 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3128 if (!NLP_CHK_NODE_ACT(ndlp))
3129 continue;
3130 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3131 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003132 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003133 }
3134 spin_unlock_irq(shost->host_lock);
3135 return 0;
3136}
3137lpfc_vport_param_store(max_scsicmpl_time);
3138static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3139 lpfc_max_scsicmpl_time_show,
3140 lpfc_max_scsicmpl_time_store);
3141
3142/*
dea31012005-04-17 16:05:31 -05003143# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3144# range is [0,1]. Default value is 0.
3145*/
3146LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3147
3148/*
3149# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3150# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003151# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003152# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3153# cr_delay is set to 0.
3154*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003155LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003156 "interrupt response is generated");
3157
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003158LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003159 "interrupt response is generated");
3160
3161/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003162# lpfc_multi_ring_support: Determines how many rings to spread available
3163# cmd/rsp IOCB entries across.
3164# Value range is [1,2]. Default value is 1.
3165*/
3166LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3167 "SLI rings to spread IOCB entries across");
3168
3169/*
James Smarta4bc3372006-12-02 13:34:16 -05003170# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3171# identifies what rctl value to configure the additional ring for.
3172# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3173*/
James Smart6a9c52c2009-10-02 15:16:51 -04003174LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003175 255, "Identifies RCTL for additional ring configuration");
3176
3177/*
3178# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3179# identifies what type value to configure the additional ring for.
3180# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3181*/
James Smart6a9c52c2009-10-02 15:16:51 -04003182LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003183 255, "Identifies TYPE for additional ring configuration");
3184
3185/*
dea31012005-04-17 16:05:31 -05003186# lpfc_fdmi_on: controls FDMI support.
3187# 0 = no FDMI support
3188# 1 = support FDMI without attribute of hostname
3189# 2 = support FDMI with attribute of hostname
3190# Value range [0,2]. Default value is 0.
3191*/
James Smart3de2a652007-08-02 11:09:59 -04003192LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003193
3194/*
3195# Specifies the maximum number of ELS cmds we can have outstanding (for
3196# discovery). Value range is [1,64]. Default value = 32.
3197*/
James Smart3de2a652007-08-02 11:09:59 -04003198LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003199 "during discovery");
3200
3201/*
James Smart65a29c12006-07-06 15:50:50 -04003202# lpfc_max_luns: maximum allowed LUN.
3203# Value range is [0,65535]. Default value is 255.
3204# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003205*/
James Smart3de2a652007-08-02 11:09:59 -04003206LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003207
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003208/*
3209# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3210# Value range is [1,255], default value is 10.
3211*/
3212LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3213 "Milliseconds driver will wait between polling FCP ring");
3214
James Smart4ff43242006-12-02 13:34:56 -05003215/*
3216# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3217# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003218# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003219# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003220# 2 = MSI-X enabled (default)
3221# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003222*/
George Kadianakis8605c462010-01-17 21:19:31 +02003223LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003224 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003225
James Smart13815c82008-01-11 01:52:48 -05003226/*
James Smartda0436e2009-05-22 14:51:39 -04003227# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3228#
3229# Value range is [636,651042]. Default value is 10000.
3230*/
3231LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3232 "Set the maximum number of fast-path FCP interrupts per second");
3233
3234/*
3235# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3236#
3237# Value range is [1,31]. Default value is 4.
3238*/
3239LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3240 "Set the number of fast-path FCP work queues, if possible");
3241
3242/*
3243# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3244#
3245# Value range is [1,7]. Default value is 1.
3246*/
3247LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3248 "Set the number of fast-path FCP event queues, if possible");
3249
3250/*
James Smart13815c82008-01-11 01:52:48 -05003251# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3252# 0 = HBA resets disabled
3253# 1 = HBA resets enabled (default)
3254# Value range is [0,1]. Default value is 1.
3255*/
3256LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003257
James Smart13815c82008-01-11 01:52:48 -05003258/*
3259# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3260# 0 = HBA Heartbeat disabled
3261# 1 = HBA Heartbeat enabled (default)
3262# Value range is [0,1]. Default value is 1.
3263*/
3264LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003265
James Smart83108bd2008-01-11 01:53:09 -05003266/*
James Smart81301a92008-12-04 22:39:46 -05003267# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3268# 0 = BlockGuard disabled (default)
3269# 1 = BlockGuard enabled
3270# Value range is [0,1]. Default value is 0.
3271*/
3272LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3273
James Smart6fb120a2009-05-22 14:52:59 -04003274/*
James Smart81301a92008-12-04 22:39:46 -05003275# lpfc_prot_mask: i
3276# - Bit mask of host protection capabilities used to register with the
3277# SCSI mid-layer
3278# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3279# - Allows you to ultimately specify which profiles to use
3280# - Default will result in registering capabilities for all profiles.
3281#
3282*/
3283unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3284
3285module_param(lpfc_prot_mask, uint, 0);
3286MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3287
3288/*
3289# lpfc_prot_guard: i
3290# - Bit mask of protection guard types to register with the SCSI mid-layer
3291# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3292# - Allows you to ultimately specify which profiles to use
3293# - Default will result in registering capabilities for all guard types
3294#
3295*/
3296unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3297module_param(lpfc_prot_guard, byte, 0);
3298MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3299
3300
3301/*
James Smart3621a712009-04-06 18:47:14 -04003302 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003303 * This value can be set to values between 64 and 256. The default value is
3304 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3305 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3306 */
3307LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3308 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3309
James Smart81301a92008-12-04 22:39:46 -05003310LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3311 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3312 "Max Protection Scatter Gather Segment Count");
3313
Tony Jonesee959b02008-02-22 00:13:36 +01003314struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003315 &dev_attr_bg_info,
3316 &dev_attr_bg_guard_err,
3317 &dev_attr_bg_apptag_err,
3318 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003319 &dev_attr_info,
3320 &dev_attr_serialnum,
3321 &dev_attr_modeldesc,
3322 &dev_attr_modelname,
3323 &dev_attr_programtype,
3324 &dev_attr_portnum,
3325 &dev_attr_fwrev,
3326 &dev_attr_hdw,
3327 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003328 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003329 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003330 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003331 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003332 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003333 &dev_attr_lpfc_temp_sensor,
3334 &dev_attr_lpfc_log_verbose,
3335 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003336 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003337 &dev_attr_lpfc_hba_queue_depth,
3338 &dev_attr_lpfc_peer_port_login,
3339 &dev_attr_lpfc_nodev_tmo,
3340 &dev_attr_lpfc_devloss_tmo,
3341 &dev_attr_lpfc_fcp_class,
3342 &dev_attr_lpfc_use_adisc,
3343 &dev_attr_lpfc_ack0,
3344 &dev_attr_lpfc_topology,
3345 &dev_attr_lpfc_scan_down,
3346 &dev_attr_lpfc_link_speed,
3347 &dev_attr_lpfc_cr_delay,
3348 &dev_attr_lpfc_cr_count,
3349 &dev_attr_lpfc_multi_ring_support,
3350 &dev_attr_lpfc_multi_ring_rctl,
3351 &dev_attr_lpfc_multi_ring_type,
3352 &dev_attr_lpfc_fdmi_on,
3353 &dev_attr_lpfc_max_luns,
3354 &dev_attr_lpfc_enable_npiv,
3355 &dev_attr_nport_evt_cnt,
3356 &dev_attr_board_mode,
3357 &dev_attr_max_vpi,
3358 &dev_attr_used_vpi,
3359 &dev_attr_max_rpi,
3360 &dev_attr_used_rpi,
3361 &dev_attr_max_xri,
3362 &dev_attr_used_xri,
3363 &dev_attr_npiv_info,
3364 &dev_attr_issue_reset,
3365 &dev_attr_lpfc_poll,
3366 &dev_attr_lpfc_poll_tmo,
3367 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003368 &dev_attr_lpfc_fcp_imax,
3369 &dev_attr_lpfc_fcp_wq_count,
3370 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003371 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003372 &dev_attr_lpfc_soft_wwnn,
3373 &dev_attr_lpfc_soft_wwpn,
3374 &dev_attr_lpfc_soft_wwn_enable,
3375 &dev_attr_lpfc_enable_hba_reset,
3376 &dev_attr_lpfc_enable_hba_heartbeat,
3377 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003378 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003379 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003380 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003381 &dev_attr_lpfc_aer_support,
3382 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003383 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003384 &dev_attr_lpfc_iocb_cnt,
3385 &dev_attr_iocb_hw,
3386 &dev_attr_txq_hw,
3387 &dev_attr_txcmplq_hw,
dea31012005-04-17 16:05:31 -05003388 NULL,
3389};
3390
Tony Jonesee959b02008-02-22 00:13:36 +01003391struct device_attribute *lpfc_vport_attrs[] = {
3392 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003393 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003394 &dev_attr_num_discovered_ports,
3395 &dev_attr_lpfc_drvr_version,
3396 &dev_attr_lpfc_log_verbose,
3397 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003398 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003399 &dev_attr_lpfc_nodev_tmo,
3400 &dev_attr_lpfc_devloss_tmo,
3401 &dev_attr_lpfc_hba_queue_depth,
3402 &dev_attr_lpfc_peer_port_login,
3403 &dev_attr_lpfc_restrict_login,
3404 &dev_attr_lpfc_fcp_class,
3405 &dev_attr_lpfc_use_adisc,
3406 &dev_attr_lpfc_fdmi_on,
3407 &dev_attr_lpfc_max_luns,
3408 &dev_attr_nport_evt_cnt,
3409 &dev_attr_npiv_info,
3410 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003411 &dev_attr_lpfc_max_scsicmpl_time,
3412 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003413 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003414 NULL,
3415};
3416
James Smarte59058c2008-08-24 21:49:00 -04003417/**
James Smart3621a712009-04-06 18:47:14 -04003418 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003419 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003420 * @kobj: kernel kobject that contains the kernel class device.
3421 * @bin_attr: kernel attributes passed to us.
3422 * @buf: contains the data to be written to the adapter IOREG space.
3423 * @off: offset into buffer to beginning of data.
3424 * @count: bytes to transfer.
3425 *
3426 * Description:
3427 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3428 * Uses the adapter io control registers to send buf contents to the adapter.
3429 *
3430 * Returns:
3431 * -ERANGE off and count combo out of range
3432 * -EINVAL off, count or buff address invalid
3433 * -EPERM adapter is offline
3434 * value of count, buf contents written
3435 **/
dea31012005-04-17 16:05:31 -05003436static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003437sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3438 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003439 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003440{
3441 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003442 struct device *dev = container_of(kobj, struct device, kobj);
3443 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003444 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3445 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003446
James Smartf1126682009-06-10 17:22:44 -04003447 if (phba->sli_rev >= LPFC_SLI_REV4)
3448 return -EPERM;
3449
dea31012005-04-17 16:05:31 -05003450 if ((off + count) > FF_REG_AREA_SIZE)
3451 return -ERANGE;
3452
3453 if (count == 0) return 0;
3454
3455 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3456 return -EINVAL;
3457
James Smart2e0fef82007-06-17 19:56:36 -05003458 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003459 return -EPERM;
3460 }
3461
James Smart2e0fef82007-06-17 19:56:36 -05003462 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003463 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3464 writel(*((uint32_t *)(buf + buf_off)),
3465 phba->ctrl_regs_memmap_p + off + buf_off);
3466
James Smart2e0fef82007-06-17 19:56:36 -05003467 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003468
3469 return count;
3470}
3471
James Smarte59058c2008-08-24 21:49:00 -04003472/**
James Smart3621a712009-04-06 18:47:14 -04003473 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003474 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003475 * @kobj: kernel kobject that contains the kernel class device.
3476 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003477 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003478 * @off: offset into buffer to beginning of data.
3479 * @count: bytes to transfer.
3480 *
3481 * Description:
3482 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3483 * Uses the adapter io control registers to read data into buf.
3484 *
3485 * Returns:
3486 * -ERANGE off and count combo out of range
3487 * -EINVAL off, count or buff address invalid
3488 * value of count, buf contents read
3489 **/
dea31012005-04-17 16:05:31 -05003490static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003491sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3492 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003493 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003494{
3495 size_t buf_off;
3496 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003497 struct device *dev = container_of(kobj, struct device, kobj);
3498 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3500 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003501
James Smartf1126682009-06-10 17:22:44 -04003502 if (phba->sli_rev >= LPFC_SLI_REV4)
3503 return -EPERM;
3504
dea31012005-04-17 16:05:31 -05003505 if (off > FF_REG_AREA_SIZE)
3506 return -ERANGE;
3507
3508 if ((off + count) > FF_REG_AREA_SIZE)
3509 count = FF_REG_AREA_SIZE - off;
3510
3511 if (count == 0) return 0;
3512
3513 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3514 return -EINVAL;
3515
James Smart2e0fef82007-06-17 19:56:36 -05003516 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003517
3518 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3519 tmp_ptr = (uint32_t *)(buf + buf_off);
3520 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3521 }
3522
James Smart2e0fef82007-06-17 19:56:36 -05003523 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003524
3525 return count;
3526}
3527
3528static struct bin_attribute sysfs_ctlreg_attr = {
3529 .attr = {
3530 .name = "ctlreg",
3531 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003532 },
3533 .size = 256,
3534 .read = sysfs_ctlreg_read,
3535 .write = sysfs_ctlreg_write,
3536};
3537
James Smarte59058c2008-08-24 21:49:00 -04003538/**
James Smart3621a712009-04-06 18:47:14 -04003539 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003540 * @phba: lpfc_hba pointer
3541 **/
dea31012005-04-17 16:05:31 -05003542static void
James Smart2e0fef82007-06-17 19:56:36 -05003543sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003544{
3545 phba->sysfs_mbox.state = SMBOX_IDLE;
3546 phba->sysfs_mbox.offset = 0;
3547
3548 if (phba->sysfs_mbox.mbox) {
3549 mempool_free(phba->sysfs_mbox.mbox,
3550 phba->mbox_mem_pool);
3551 phba->sysfs_mbox.mbox = NULL;
3552 }
3553}
3554
James Smarte59058c2008-08-24 21:49:00 -04003555/**
James Smart3621a712009-04-06 18:47:14 -04003556 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003557 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003558 * @kobj: kernel kobject that contains the kernel class device.
3559 * @bin_attr: kernel attributes passed to us.
3560 * @buf: contains the data to be written to sysfs mbox.
3561 * @off: offset into buffer to beginning of data.
3562 * @count: bytes to transfer.
3563 *
3564 * Description:
3565 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3566 * Uses the sysfs mbox to send buf contents to the adapter.
3567 *
3568 * Returns:
3569 * -ERANGE off and count combo out of range
3570 * -EINVAL off, count or buff address invalid
3571 * zero if count is zero
3572 * -EPERM adapter is offline
3573 * -ENOMEM failed to allocate memory for the mail box
3574 * -EAGAIN offset, state or mbox is NULL
3575 * count number of bytes transferred
3576 **/
dea31012005-04-17 16:05:31 -05003577static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003578sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3579 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003580 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003581{
Tony Jonesee959b02008-02-22 00:13:36 +01003582 struct device *dev = container_of(kobj, struct device, kobj);
3583 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3585 struct lpfc_hba *phba = vport->phba;
3586 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003587
3588 if ((count + off) > MAILBOX_CMD_SIZE)
3589 return -ERANGE;
3590
3591 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3592 return -EINVAL;
3593
3594 if (count == 0)
3595 return 0;
3596
3597 if (off == 0) {
3598 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3599 if (!mbox)
3600 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003601 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003602 }
3603
James Smart2e0fef82007-06-17 19:56:36 -05003604 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003605
3606 if (off == 0) {
3607 if (phba->sysfs_mbox.mbox)
3608 mempool_free(mbox, phba->mbox_mem_pool);
3609 else
3610 phba->sysfs_mbox.mbox = mbox;
3611 phba->sysfs_mbox.state = SMBOX_WRITING;
3612 } else {
3613 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3614 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003615 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003616 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003617 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003618 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003619 }
3620 }
3621
James Smart04c68492009-05-22 14:52:52 -04003622 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003623 buf, count);
3624
3625 phba->sysfs_mbox.offset = off + count;
3626
James Smart2e0fef82007-06-17 19:56:36 -05003627 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003628
3629 return count;
3630}
3631
James Smarte59058c2008-08-24 21:49:00 -04003632/**
James Smart3621a712009-04-06 18:47:14 -04003633 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003634 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003635 * @kobj: kernel kobject that contains the kernel class device.
3636 * @bin_attr: kernel attributes passed to us.
3637 * @buf: contains the data to be read from sysfs mbox.
3638 * @off: offset into buffer to beginning of data.
3639 * @count: bytes to transfer.
3640 *
3641 * Description:
3642 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3643 * Uses the sysfs mbox to receive data from to the adapter.
3644 *
3645 * Returns:
3646 * -ERANGE off greater than mailbox command size
3647 * -EINVAL off, count or buff address invalid
3648 * zero if off and count are zero
3649 * -EACCES adapter over temp
3650 * -EPERM garbage can value to catch a multitude of errors
3651 * -EAGAIN management IO not permitted, state or off error
3652 * -ETIME mailbox timeout
3653 * -ENODEV mailbox error
3654 * count number of bytes transferred
3655 **/
dea31012005-04-17 16:05:31 -05003656static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003657sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3658 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003659 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003660{
Tony Jonesee959b02008-02-22 00:13:36 +01003661 struct device *dev = container_of(kobj, struct device, kobj);
3662 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003663 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3664 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003665 int rc;
James Smart04c68492009-05-22 14:52:52 -04003666 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003667
James Smart1dcb58e2007-04-25 09:51:30 -04003668 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003669 return -ERANGE;
3670
James Smart1dcb58e2007-04-25 09:51:30 -04003671 if ((count + off) > MAILBOX_CMD_SIZE)
3672 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003673
3674 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3675 return -EINVAL;
3676
3677 if (off && count == 0)
3678 return 0;
3679
James Smart2e0fef82007-06-17 19:56:36 -05003680 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003681
James Smart7af67052007-10-27 13:38:11 -04003682 if (phba->over_temp_state == HBA_OVER_TEMP) {
3683 sysfs_mbox_idle(phba);
3684 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003685 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003686 }
3687
dea31012005-04-17 16:05:31 -05003688 if (off == 0 &&
3689 phba->sysfs_mbox.state == SMBOX_WRITING &&
3690 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003691 pmb = &phba->sysfs_mbox.mbox->u.mb;
3692 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003693 /* Offline only */
dea31012005-04-17 16:05:31 -05003694 case MBX_INIT_LINK:
3695 case MBX_DOWN_LINK:
3696 case MBX_CONFIG_LINK:
3697 case MBX_CONFIG_RING:
3698 case MBX_RESET_RING:
3699 case MBX_UNREG_LOGIN:
3700 case MBX_CLEAR_LA:
3701 case MBX_DUMP_CONTEXT:
3702 case MBX_RUN_DIAGS:
3703 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003704 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003705 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003706 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003707 printk(KERN_WARNING "mbox_read:Command 0x%x "
3708 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003709 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003710 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003711 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003712 return -EPERM;
3713 }
James Smarta8adb832007-10-27 13:37:53 -04003714 case MBX_WRITE_NV:
3715 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003716 case MBX_LOAD_SM:
3717 case MBX_READ_NV:
3718 case MBX_READ_CONFIG:
3719 case MBX_READ_RCONFIG:
3720 case MBX_READ_STATUS:
3721 case MBX_READ_XRI:
3722 case MBX_READ_REV:
3723 case MBX_READ_LNK_STAT:
3724 case MBX_DUMP_MEMORY:
3725 case MBX_DOWN_LOAD:
3726 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003727 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003728 case MBX_LOAD_AREA:
3729 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003730 case MBX_BEACON:
3731 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003732 case MBX_SET_VARIABLE:
3733 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003734 case MBX_PORT_CAPABILITIES:
3735 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003736 break;
3737 case MBX_READ_SPARM64:
3738 case MBX_READ_LA:
3739 case MBX_READ_LA64:
3740 case MBX_REG_LOGIN:
3741 case MBX_REG_LOGIN64:
3742 case MBX_CONFIG_PORT:
3743 case MBX_RUN_BIU_DIAG:
3744 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003745 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003746 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003747 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003748 return -EPERM;
3749 default:
3750 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003751 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003752 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003753 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003754 return -EPERM;
3755 }
3756
James Smart09372822008-01-11 01:52:54 -05003757 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003758 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003759 */
James Smartd7c255b2008-08-24 21:50:00 -04003760 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003761 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3762 pmb->mbxCommand != MBX_RESTART &&
3763 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3764 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003765 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3766 "1259 mbox: Issued mailbox cmd "
3767 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003768 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003769
James Smart92d7f7b2007-06-17 19:56:38 -05003770 phba->sysfs_mbox.mbox->vport = vport;
3771
James Smart58da1ff2008-04-07 10:15:56 -04003772 /* Don't allow mailbox commands to be sent when blocked
3773 * or when in the middle of discovery
3774 */
James Smart495a7142008-06-14 22:52:59 -04003775 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003776 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003777 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003778 return -EAGAIN;
3779 }
3780
James Smart2e0fef82007-06-17 19:56:36 -05003781 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003782 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003783
James Smart2e0fef82007-06-17 19:56:36 -05003784 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003785 rc = lpfc_sli_issue_mbox (phba,
3786 phba->sysfs_mbox.mbox,
3787 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003788 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003789
3790 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003791 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003792 rc = lpfc_sli_issue_mbox_wait (phba,
3793 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003794 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003795 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003796 }
3797
3798 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003799 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003800 phba->sysfs_mbox.mbox = NULL;
3801 }
dea31012005-04-17 16:05:31 -05003802 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003803 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003804 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003805 }
3806 phba->sysfs_mbox.state = SMBOX_READING;
3807 }
3808 else if (phba->sysfs_mbox.offset != off ||
3809 phba->sysfs_mbox.state != SMBOX_READING) {
3810 printk(KERN_WARNING "mbox_read: Bad State\n");
3811 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003812 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003813 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003814 }
3815
James Smart04c68492009-05-22 14:52:52 -04003816 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003817
3818 phba->sysfs_mbox.offset = off + count;
3819
James Smart1dcb58e2007-04-25 09:51:30 -04003820 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003821 sysfs_mbox_idle(phba);
3822
James Smart2e0fef82007-06-17 19:56:36 -05003823 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003824
3825 return count;
3826}
3827
3828static struct bin_attribute sysfs_mbox_attr = {
3829 .attr = {
3830 .name = "mbox",
3831 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003832 },
James Smart1dcb58e2007-04-25 09:51:30 -04003833 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003834 .read = sysfs_mbox_read,
3835 .write = sysfs_mbox_write,
3836};
3837
James Smarte59058c2008-08-24 21:49:00 -04003838/**
James Smart3621a712009-04-06 18:47:14 -04003839 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003840 * @vport: address of lpfc vport structure.
3841 *
3842 * Return codes:
3843 * zero on success
3844 * error return code from sysfs_create_bin_file()
3845 **/
dea31012005-04-17 16:05:31 -05003846int
James Smart2e0fef82007-06-17 19:56:36 -05003847lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003848{
James Smart2e0fef82007-06-17 19:56:36 -05003849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003850 int error;
3851
Tony Jonesee959b02008-02-22 00:13:36 +01003852 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003853 &sysfs_drvr_stat_data_attr);
3854
3855 /* Virtual ports do not need ctrl_reg and mbox */
3856 if (error || vport->port_type == LPFC_NPIV_PORT)
3857 goto out;
3858
3859 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003860 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003861 if (error)
James Smarteada2722008-12-04 22:39:13 -05003862 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003863
Tony Jonesee959b02008-02-22 00:13:36 +01003864 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003865 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003866 if (error)
3867 goto out_remove_ctlreg_attr;
3868
3869 return 0;
3870out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003871 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003872out_remove_stat_attr:
3873 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3874 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003875out:
3876 return error;
3877}
3878
James Smarte59058c2008-08-24 21:49:00 -04003879/**
James Smart3621a712009-04-06 18:47:14 -04003880 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003881 * @vport: address of lpfc vport structure.
3882 **/
dea31012005-04-17 16:05:31 -05003883void
James Smart2e0fef82007-06-17 19:56:36 -05003884lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003885{
James Smart2e0fef82007-06-17 19:56:36 -05003886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003887 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3888 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003889 /* Virtual ports do not need ctrl_reg and mbox */
3890 if (vport->port_type == LPFC_NPIV_PORT)
3891 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003892 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3893 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003894}
3895
3896
3897/*
3898 * Dynamic FC Host Attributes Support
3899 */
3900
James Smarte59058c2008-08-24 21:49:00 -04003901/**
James Smart3621a712009-04-06 18:47:14 -04003902 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003903 * @shost: kernel scsi host pointer.
3904 **/
dea31012005-04-17 16:05:31 -05003905static void
3906lpfc_get_host_port_id(struct Scsi_Host *shost)
3907{
James Smart2e0fef82007-06-17 19:56:36 -05003908 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3909
dea31012005-04-17 16:05:31 -05003910 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003911 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003912}
3913
James Smarte59058c2008-08-24 21:49:00 -04003914/**
James Smart3621a712009-04-06 18:47:14 -04003915 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003916 * @shost: kernel scsi host pointer.
3917 **/
dea31012005-04-17 16:05:31 -05003918static void
3919lpfc_get_host_port_type(struct Scsi_Host *shost)
3920{
James Smart2e0fef82007-06-17 19:56:36 -05003921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3922 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003923
3924 spin_lock_irq(shost->host_lock);
3925
James Smart92d7f7b2007-06-17 19:56:38 -05003926 if (vport->port_type == LPFC_NPIV_PORT) {
3927 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3928 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003929 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003930 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003931 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3932 else
3933 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3934 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003935 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003936 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3937 else
3938 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3939 }
3940 } else
3941 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3942
3943 spin_unlock_irq(shost->host_lock);
3944}
3945
James Smarte59058c2008-08-24 21:49:00 -04003946/**
James Smart3621a712009-04-06 18:47:14 -04003947 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003948 * @shost: kernel scsi host pointer.
3949 **/
dea31012005-04-17 16:05:31 -05003950static void
3951lpfc_get_host_port_state(struct Scsi_Host *shost)
3952{
James Smart2e0fef82007-06-17 19:56:36 -05003953 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3954 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003955
3956 spin_lock_irq(shost->host_lock);
3957
James Smart2e0fef82007-06-17 19:56:36 -05003958 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003959 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3960 else {
James Smart2e0fef82007-06-17 19:56:36 -05003961 switch (phba->link_state) {
3962 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003963 case LPFC_LINK_DOWN:
3964 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3965 break;
3966 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003967 case LPFC_CLEAR_LA:
3968 case LPFC_HBA_READY:
3969 /* Links up, beyond this port_type reports state */
3970 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3971 break;
3972 case LPFC_HBA_ERROR:
3973 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3974 break;
3975 default:
3976 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3977 break;
3978 }
3979 }
3980
3981 spin_unlock_irq(shost->host_lock);
3982}
3983
James Smarte59058c2008-08-24 21:49:00 -04003984/**
James Smart3621a712009-04-06 18:47:14 -04003985 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003986 * @shost: kernel scsi host pointer.
3987 **/
dea31012005-04-17 16:05:31 -05003988static void
3989lpfc_get_host_speed(struct Scsi_Host *shost)
3990{
James Smart2e0fef82007-06-17 19:56:36 -05003991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3992 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003993
3994 spin_lock_irq(shost->host_lock);
3995
James Smart2e0fef82007-06-17 19:56:36 -05003996 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003997 switch(phba->fc_linkspeed) {
3998 case LA_1GHZ_LINK:
3999 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4000 break;
4001 case LA_2GHZ_LINK:
4002 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4003 break;
4004 case LA_4GHZ_LINK:
4005 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4006 break;
James Smartb87eab32007-04-25 09:53:28 -04004007 case LA_8GHZ_LINK:
4008 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4009 break;
James Smartf4b4c682009-05-22 14:53:12 -04004010 case LA_10GHZ_LINK:
4011 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4012 break;
dea31012005-04-17 16:05:31 -05004013 default:
4014 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4015 break;
4016 }
James Smart09372822008-01-11 01:52:54 -05004017 } else
4018 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004019
4020 spin_unlock_irq(shost->host_lock);
4021}
4022
James Smarte59058c2008-08-24 21:49:00 -04004023/**
James Smart3621a712009-04-06 18:47:14 -04004024 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004025 * @shost: kernel scsi host pointer.
4026 **/
dea31012005-04-17 16:05:31 -05004027static void
4028lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4029{
James Smart2e0fef82007-06-17 19:56:36 -05004030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4031 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004032 u64 node_name;
dea31012005-04-17 16:05:31 -05004033
4034 spin_lock_irq(shost->host_lock);
4035
James Smart2e0fef82007-06-17 19:56:36 -05004036 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05004037 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004038 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004039 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004040 else
4041 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004042 node_name = 0;
dea31012005-04-17 16:05:31 -05004043
4044 spin_unlock_irq(shost->host_lock);
4045
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004046 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004047}
4048
James Smarte59058c2008-08-24 21:49:00 -04004049/**
James Smart3621a712009-04-06 18:47:14 -04004050 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004051 * @shost: kernel scsi host pointer.
4052 *
4053 * Notes:
4054 * NULL on error for link down, no mbox pool, sli2 active,
4055 * management not allowed, memory allocation error, or mbox error.
4056 *
4057 * Returns:
4058 * NULL for error
4059 * address of the adapter host statistics
4060 **/
dea31012005-04-17 16:05:31 -05004061static struct fc_host_statistics *
4062lpfc_get_stats(struct Scsi_Host *shost)
4063{
James Smart2e0fef82007-06-17 19:56:36 -05004064 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4065 struct lpfc_hba *phba = vport->phba;
4066 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004067 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004068 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004069 LPFC_MBOXQ_t *pmboxq;
4070 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004071 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004072 int rc = 0;
dea31012005-04-17 16:05:31 -05004073
James Smart92d7f7b2007-06-17 19:56:38 -05004074 /*
4075 * prevent udev from issuing mailbox commands until the port is
4076 * configured.
4077 */
James Smart2e0fef82007-06-17 19:56:36 -05004078 if (phba->link_state < LPFC_LINK_DOWN ||
4079 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004080 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004081 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004082
4083 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004084 return NULL;
4085
dea31012005-04-17 16:05:31 -05004086 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4087 if (!pmboxq)
4088 return NULL;
4089 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4090
James Smart04c68492009-05-22 14:52:52 -04004091 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004092 pmb->mbxCommand = MBX_READ_STATUS;
4093 pmb->mbxOwner = OWN_HOST;
4094 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004095 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004096
James Smart75baf692010-06-08 18:31:21 -04004097 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004098 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004099 else
dea31012005-04-17 16:05:31 -05004100 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4101
4102 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004103 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004104 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004105 return NULL;
4106 }
4107
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004108 memset(hs, 0, sizeof (struct fc_host_statistics));
4109
dea31012005-04-17 16:05:31 -05004110 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4111 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4112 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4113 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4114
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004115 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004116 pmb->mbxCommand = MBX_READ_LNK_STAT;
4117 pmb->mbxOwner = OWN_HOST;
4118 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004119 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004120
James Smart75baf692010-06-08 18:31:21 -04004121 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004122 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004123 else
dea31012005-04-17 16:05:31 -05004124 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4125
4126 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004127 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004128 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004129 return NULL;
4130 }
4131
4132 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4133 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4134 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4135 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4136 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4137 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4138 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4139
James Smart64ba8812006-08-02 15:24:34 -04004140 hs->link_failure_count -= lso->link_failure_count;
4141 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4142 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4143 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4144 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4145 hs->invalid_crc_count -= lso->invalid_crc_count;
4146 hs->error_frames -= lso->error_frames;
4147
James Smart4d9ab992009-10-02 15:16:39 -04004148 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4149 hs->lip_count = -1;
4150 hs->nos_count = (phba->link_events >> 1);
4151 hs->nos_count -= lso->link_events;
4152 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004153 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004154 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004155 hs->nos_count = -1;
4156 } else {
4157 hs->lip_count = -1;
4158 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004159 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004160 }
4161
4162 hs->dumped_frames = -1;
4163
James Smart64ba8812006-08-02 15:24:34 -04004164 seconds = get_seconds();
4165 if (seconds < psli->stats_start)
4166 hs->seconds_since_last_reset = seconds +
4167 ((unsigned long)-1 - psli->stats_start);
4168 else
4169 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004170
James Smart1dcb58e2007-04-25 09:51:30 -04004171 mempool_free(pmboxq, phba->mbox_mem_pool);
4172
dea31012005-04-17 16:05:31 -05004173 return hs;
4174}
4175
James Smarte59058c2008-08-24 21:49:00 -04004176/**
James Smart3621a712009-04-06 18:47:14 -04004177 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004178 * @shost: kernel scsi host pointer.
4179 **/
James Smart64ba8812006-08-02 15:24:34 -04004180static void
4181lpfc_reset_stats(struct Scsi_Host *shost)
4182{
James Smart2e0fef82007-06-17 19:56:36 -05004183 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4184 struct lpfc_hba *phba = vport->phba;
4185 struct lpfc_sli *psli = &phba->sli;
4186 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004187 LPFC_MBOXQ_t *pmboxq;
4188 MAILBOX_t *pmb;
4189 int rc = 0;
4190
James Smart2e0fef82007-06-17 19:56:36 -05004191 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004192 return;
4193
James Smart64ba8812006-08-02 15:24:34 -04004194 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4195 if (!pmboxq)
4196 return;
4197 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4198
James Smart04c68492009-05-22 14:52:52 -04004199 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004200 pmb->mbxCommand = MBX_READ_STATUS;
4201 pmb->mbxOwner = OWN_HOST;
4202 pmb->un.varWords[0] = 0x1; /* reset request */
4203 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004204 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004205
James Smart2e0fef82007-06-17 19:56:36 -05004206 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004207 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004208 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4209 else
4210 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4211
4212 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004213 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004214 mempool_free(pmboxq, phba->mbox_mem_pool);
4215 return;
4216 }
4217
4218 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4219 pmb->mbxCommand = MBX_READ_LNK_STAT;
4220 pmb->mbxOwner = OWN_HOST;
4221 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004222 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004223
James Smart2e0fef82007-06-17 19:56:36 -05004224 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004225 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004226 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4227 else
4228 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4229
4230 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004231 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004232 mempool_free( pmboxq, phba->mbox_mem_pool);
4233 return;
4234 }
4235
4236 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4237 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4238 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4239 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4240 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4241 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4242 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004243 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4244 lso->link_events = (phba->link_events >> 1);
4245 else
4246 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004247
4248 psli->stats_start = get_seconds();
4249
James Smart1dcb58e2007-04-25 09:51:30 -04004250 mempool_free(pmboxq, phba->mbox_mem_pool);
4251
James Smart64ba8812006-08-02 15:24:34 -04004252 return;
4253}
dea31012005-04-17 16:05:31 -05004254
4255/*
4256 * The LPFC driver treats linkdown handling as target loss events so there
4257 * are no sysfs handlers for link_down_tmo.
4258 */
James Smart685f0bf2007-04-25 09:53:08 -04004259
James Smarte59058c2008-08-24 21:49:00 -04004260/**
James Smart3621a712009-04-06 18:47:14 -04004261 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004262 * @starget: kernel scsi target pointer.
4263 *
4264 * Returns:
4265 * address of the node list if found
4266 * NULL target not found
4267 **/
James Smart685f0bf2007-04-25 09:53:08 -04004268static struct lpfc_nodelist *
4269lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004270{
James Smart2e0fef82007-06-17 19:56:36 -05004271 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004273 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004274
4275 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004276 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004277 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004278 if (NLP_CHK_NODE_ACT(ndlp) &&
4279 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004280 starget->id == ndlp->nlp_sid) {
4281 spin_unlock_irq(shost->host_lock);
4282 return ndlp;
dea31012005-04-17 16:05:31 -05004283 }
4284 }
4285 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004286 return NULL;
4287}
dea31012005-04-17 16:05:31 -05004288
James Smarte59058c2008-08-24 21:49:00 -04004289/**
James Smart3621a712009-04-06 18:47:14 -04004290 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004291 * @starget: kernel scsi target pointer.
4292 **/
James Smart685f0bf2007-04-25 09:53:08 -04004293static void
4294lpfc_get_starget_port_id(struct scsi_target *starget)
4295{
4296 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4297
4298 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004299}
4300
James Smarte59058c2008-08-24 21:49:00 -04004301/**
James Smart3621a712009-04-06 18:47:14 -04004302 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004303 * @starget: kernel scsi target pointer.
4304 *
4305 * Description: Set the target node name to the ndlp node name wwn or zero.
4306 **/
dea31012005-04-17 16:05:31 -05004307static void
4308lpfc_get_starget_node_name(struct scsi_target *starget)
4309{
James Smart685f0bf2007-04-25 09:53:08 -04004310 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004311
James Smart685f0bf2007-04-25 09:53:08 -04004312 fc_starget_node_name(starget) =
4313 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004314}
4315
James Smarte59058c2008-08-24 21:49:00 -04004316/**
James Smart3621a712009-04-06 18:47:14 -04004317 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004318 * @starget: kernel scsi target pointer.
4319 *
4320 * Description: set the target port name to the ndlp port name wwn or zero.
4321 **/
dea31012005-04-17 16:05:31 -05004322static void
4323lpfc_get_starget_port_name(struct scsi_target *starget)
4324{
James Smart685f0bf2007-04-25 09:53:08 -04004325 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004326
James Smart685f0bf2007-04-25 09:53:08 -04004327 fc_starget_port_name(starget) =
4328 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004329}
4330
James Smarte59058c2008-08-24 21:49:00 -04004331/**
James Smart3621a712009-04-06 18:47:14 -04004332 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004333 * @rport: fc rport address.
4334 * @timeout: new value for dev loss tmo.
4335 *
4336 * Description:
4337 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4338 * dev_loss_tmo to one.
4339 **/
dea31012005-04-17 16:05:31 -05004340static void
dea31012005-04-17 16:05:31 -05004341lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4342{
dea31012005-04-17 16:05:31 -05004343 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004344 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004345 else
James Smartc01f3202006-08-18 17:47:08 -04004346 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004347}
4348
James Smarte59058c2008-08-24 21:49:00 -04004349/**
James Smart3621a712009-04-06 18:47:14 -04004350 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004351 *
4352 * Description:
4353 * Macro that uses field to generate a function with the name lpfc_show_rport_
4354 *
4355 * lpfc_show_rport_##field: returns the bytes formatted in buf
4356 * @cdev: class converted to an fc_rport.
4357 * @buf: on return contains the target_field or zero.
4358 *
4359 * Returns: size of formatted string.
4360 **/
dea31012005-04-17 16:05:31 -05004361#define lpfc_rport_show_function(field, format_string, sz, cast) \
4362static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004363lpfc_show_rport_##field (struct device *dev, \
4364 struct device_attribute *attr, \
4365 char *buf) \
dea31012005-04-17 16:05:31 -05004366{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004367 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004368 struct lpfc_rport_data *rdata = rport->hostdata; \
4369 return snprintf(buf, sz, format_string, \
4370 (rdata->target) ? cast rdata->target->field : 0); \
4371}
4372
4373#define lpfc_rport_rd_attr(field, format_string, sz) \
4374 lpfc_rport_show_function(field, format_string, sz, ) \
4375static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4376
James Smarteada2722008-12-04 22:39:13 -05004377/**
James Smart3621a712009-04-06 18:47:14 -04004378 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004379 * @fc_vport: The fc_vport who's symbolic name has been changed.
4380 *
4381 * Description:
4382 * This function is called by the transport after the @fc_vport's symbolic name
4383 * has been changed. This function re-registers the symbolic name with the
4384 * switch to propogate the change into the fabric if the vport is active.
4385 **/
4386static void
4387lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4388{
4389 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4390
4391 if (vport->port_state == LPFC_VPORT_READY)
4392 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4393}
dea31012005-04-17 16:05:31 -05004394
James Smartf4b4c682009-05-22 14:53:12 -04004395/**
4396 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4397 * @phba: Pointer to lpfc_hba struct.
4398 *
4399 * This function is called by the lpfc_get_cfgparam() routine to set the
4400 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4401 * log messsage according to the module's lpfc_log_verbose parameter setting
4402 * before hba port or vport created.
4403 **/
4404static void
4405lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4406{
4407 phba->cfg_log_verbose = verbose;
4408}
4409
dea31012005-04-17 16:05:31 -05004410struct fc_function_template lpfc_transport_functions = {
4411 /* fixed attributes the driver supports */
4412 .show_host_node_name = 1,
4413 .show_host_port_name = 1,
4414 .show_host_supported_classes = 1,
4415 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004416 .show_host_supported_speeds = 1,
4417 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004418 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004419
4420 /* dynamic attributes the driver supports */
4421 .get_host_port_id = lpfc_get_host_port_id,
4422 .show_host_port_id = 1,
4423
4424 .get_host_port_type = lpfc_get_host_port_type,
4425 .show_host_port_type = 1,
4426
4427 .get_host_port_state = lpfc_get_host_port_state,
4428 .show_host_port_state = 1,
4429
4430 /* active_fc4s is shown but doesn't change (thus no get function) */
4431 .show_host_active_fc4s = 1,
4432
4433 .get_host_speed = lpfc_get_host_speed,
4434 .show_host_speed = 1,
4435
4436 .get_host_fabric_name = lpfc_get_host_fabric_name,
4437 .show_host_fabric_name = 1,
4438
4439 /*
4440 * The LPFC driver treats linkdown handling as target loss events
4441 * so there are no sysfs handlers for link_down_tmo.
4442 */
4443
4444 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004445 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004446
4447 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4448 .show_rport_maxframe_size = 1,
4449 .show_rport_supported_classes = 1,
4450
dea31012005-04-17 16:05:31 -05004451 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4452 .show_rport_dev_loss_tmo = 1,
4453
4454 .get_starget_port_id = lpfc_get_starget_port_id,
4455 .show_starget_port_id = 1,
4456
4457 .get_starget_node_name = lpfc_get_starget_node_name,
4458 .show_starget_node_name = 1,
4459
4460 .get_starget_port_name = lpfc_get_starget_port_name,
4461 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004462
4463 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004464 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4465 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004466
James Smart92d7f7b2007-06-17 19:56:38 -05004467 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004468
4469 .vport_disable = lpfc_vport_disable,
4470
4471 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004472
4473 .bsg_request = lpfc_bsg_request,
4474 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004475};
4476
James Smart98c9ea52007-10-27 13:37:33 -04004477struct fc_function_template lpfc_vport_transport_functions = {
4478 /* fixed attributes the driver supports */
4479 .show_host_node_name = 1,
4480 .show_host_port_name = 1,
4481 .show_host_supported_classes = 1,
4482 .show_host_supported_fc4s = 1,
4483 .show_host_supported_speeds = 1,
4484 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004485 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004486
4487 /* dynamic attributes the driver supports */
4488 .get_host_port_id = lpfc_get_host_port_id,
4489 .show_host_port_id = 1,
4490
4491 .get_host_port_type = lpfc_get_host_port_type,
4492 .show_host_port_type = 1,
4493
4494 .get_host_port_state = lpfc_get_host_port_state,
4495 .show_host_port_state = 1,
4496
4497 /* active_fc4s is shown but doesn't change (thus no get function) */
4498 .show_host_active_fc4s = 1,
4499
4500 .get_host_speed = lpfc_get_host_speed,
4501 .show_host_speed = 1,
4502
4503 .get_host_fabric_name = lpfc_get_host_fabric_name,
4504 .show_host_fabric_name = 1,
4505
4506 /*
4507 * The LPFC driver treats linkdown handling as target loss events
4508 * so there are no sysfs handlers for link_down_tmo.
4509 */
4510
4511 .get_fc_host_stats = lpfc_get_stats,
4512 .reset_fc_host_stats = lpfc_reset_stats,
4513
4514 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4515 .show_rport_maxframe_size = 1,
4516 .show_rport_supported_classes = 1,
4517
4518 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4519 .show_rport_dev_loss_tmo = 1,
4520
4521 .get_starget_port_id = lpfc_get_starget_port_id,
4522 .show_starget_port_id = 1,
4523
4524 .get_starget_node_name = lpfc_get_starget_node_name,
4525 .show_starget_node_name = 1,
4526
4527 .get_starget_port_name = lpfc_get_starget_port_name,
4528 .show_starget_port_name = 1,
4529
4530 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4531 .terminate_rport_io = lpfc_terminate_rport_io,
4532
4533 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004534
4535 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004536};
4537
James Smarte59058c2008-08-24 21:49:00 -04004538/**
James Smart3621a712009-04-06 18:47:14 -04004539 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004540 * @phba: lpfc_hba pointer.
4541 **/
dea31012005-04-17 16:05:31 -05004542void
4543lpfc_get_cfgparam(struct lpfc_hba *phba)
4544{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004545 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4546 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004547 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004548 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4549 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004550 lpfc_ack0_init(phba, lpfc_ack0);
4551 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004552 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004553 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004554 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004555 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004556 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4557 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4558 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004559 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4560 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004561 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004562 if (phba->sli_rev == LPFC_SLI_REV4)
4563 phba->cfg_poll = 0;
4564 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004565 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004566 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004567 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004568 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004569 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004570 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004571 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004572 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004573 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004574 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004575 return;
4576}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004577
James Smarte59058c2008-08-24 21:49:00 -04004578/**
James Smart3621a712009-04-06 18:47:14 -04004579 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004580 * @vport: lpfc_vport pointer.
4581 **/
James Smart3de2a652007-08-02 11:09:59 -04004582void
4583lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4584{
James Smarte8b62012007-08-02 11:10:09 -04004585 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004586 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004587 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004588 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4589 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4590 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4591 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4592 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4593 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004594 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004595 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4596 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4597 lpfc_max_luns_init(vport, lpfc_max_luns);
4598 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004599 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004600 return;
4601}