blob: 162704cf6a96eb805ca1f6d6bba008fe317c602c [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,
James Smartea2151b2008-09-07 11:52:10 -04002781 },
2782 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2783 .read = sysfs_drvr_stat_data_read,
2784 .write = NULL,
2785};
2786
dea31012005-04-17 16:05:31 -05002787/*
2788# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2789# connection.
2790# 0 = auto select (default)
2791# 1 = 1 Gigabaud
2792# 2 = 2 Gigabaud
2793# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002794# 8 = 8 Gigabaud
2795# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002796*/
James Smarte59058c2008-08-24 21:49:00 -04002797
2798/**
James Smart3621a712009-04-06 18:47:14 -04002799 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002800 * @phba: lpfc_hba pointer.
2801 * @val: link speed value.
2802 *
2803 * Description:
2804 * If val is in a valid range then set the adapter's link speed field and
2805 * issue a lip; if the lip fails reset the link speed to the old value.
2806 *
2807 * Notes:
2808 * If the value is not in range log a kernel error message and return an error.
2809 *
2810 * Returns:
2811 * zero if val is in range and lip okay.
2812 * non-zero return value from lpfc_issue_lip()
2813 * -EINVAL val out of range
2814 **/
James Smarta257bf92009-04-06 18:48:10 -04002815static ssize_t
2816lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2817 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002818{
James Smarta257bf92009-04-06 18:48:10 -04002819 struct Scsi_Host *shost = class_to_shost(dev);
2820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2821 struct lpfc_hba *phba = vport->phba;
2822 int val = 0;
2823 int nolip = 0;
2824 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002825 int err;
2826 uint32_t prev_val;
2827
James Smarta257bf92009-04-06 18:48:10 -04002828 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2829 nolip = 1;
2830 val_buf = &buf[strlen("nolip ")];
2831 }
2832
2833 if (!isdigit(val_buf[0]))
2834 return -EINVAL;
2835 if (sscanf(val_buf, "%i", &val) != 1)
2836 return -EINVAL;
2837
James Smart83108bd2008-01-11 01:53:09 -05002838 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2839 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2840 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2841 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2842 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2843 return -EINVAL;
2844
James Smarta257bf92009-04-06 18:48:10 -04002845 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002846 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2847 prev_val = phba->cfg_link_speed;
2848 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002849 if (nolip)
2850 return strlen(buf);
2851
James Smart83108bd2008-01-11 01:53:09 -05002852 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002853 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002854 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002855 return -EINVAL;
2856 } else
2857 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002858 }
2859
2860 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2861 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2862 "allowed range is [0, 8]\n",
2863 phba->brd_no, val);
2864 return -EINVAL;
2865}
2866
2867static int lpfc_link_speed = 0;
2868module_param(lpfc_link_speed, int, 0);
2869MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2870lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002871
2872/**
James Smart3621a712009-04-06 18:47:14 -04002873 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002874 * @phba: lpfc_hba pointer.
2875 * @val: link speed value.
2876 *
2877 * Description:
2878 * If val is in a valid range then set the adapter's link speed field.
2879 *
2880 * Notes:
2881 * If the value is not in range log a kernel error message, clear the link
2882 * speed and return an error.
2883 *
2884 * Returns:
2885 * zero if val saved.
2886 * -EINVAL val out of range
2887 **/
James Smart83108bd2008-01-11 01:53:09 -05002888static int
2889lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2890{
2891 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2892 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2893 phba->cfg_link_speed = val;
2894 return 0;
2895 }
2896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002897 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002898 "be set to %d, allowed values are "
2899 "["LPFC_LINK_SPEED_STRING"]\n", val);
2900 phba->cfg_link_speed = 0;
2901 return -EINVAL;
2902}
2903
Tony Jonesee959b02008-02-22 00:13:36 +01002904static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002905 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002906
2907/*
James Smart0d878412009-10-02 15:16:56 -04002908# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2909# 0 = aer disabled or not supported
2910# 1 = aer supported and enabled (default)
2911# Value range is [0,1]. Default value is 1.
2912*/
2913
2914/**
2915 * lpfc_aer_support_store - Set the adapter for aer support
2916 *
2917 * @dev: class device that is converted into a Scsi_host.
2918 * @attr: device attribute, not used.
2919 * @buf: containing the string "selective".
2920 * @count: unused variable.
2921 *
2922 * Description:
2923 * If the val is 1 and currently the device's AER capability was not
2924 * enabled, invoke the kernel's enable AER helper routine, trying to
2925 * enable the device's AER capability. If the helper routine enabling
2926 * AER returns success, update the device's cfg_aer_support flag to
2927 * indicate AER is supported by the device; otherwise, if the device
2928 * AER capability is already enabled to support AER, then do nothing.
2929 *
2930 * If the val is 0 and currently the device's AER support was enabled,
2931 * invoke the kernel's disable AER helper routine. After that, update
2932 * the device's cfg_aer_support flag to indicate AER is not supported
2933 * by the device; otherwise, if the device AER capability is already
2934 * disabled from supporting AER, then do nothing.
2935 *
2936 * Returns:
2937 * length of the buf on success if val is in range the intended mode
2938 * is supported.
2939 * -EINVAL if val out of range or intended mode is not supported.
2940 **/
2941static ssize_t
2942lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2943 const char *buf, size_t count)
2944{
2945 struct Scsi_Host *shost = class_to_shost(dev);
2946 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2947 struct lpfc_hba *phba = vport->phba;
2948 int val = 0, rc = -EINVAL;
2949
2950 if (!isdigit(buf[0]))
2951 return -EINVAL;
2952 if (sscanf(buf, "%i", &val) != 1)
2953 return -EINVAL;
2954
2955 switch (val) {
2956 case 0:
2957 if (phba->hba_flag & HBA_AER_ENABLED) {
2958 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2959 if (!rc) {
2960 spin_lock_irq(&phba->hbalock);
2961 phba->hba_flag &= ~HBA_AER_ENABLED;
2962 spin_unlock_irq(&phba->hbalock);
2963 phba->cfg_aer_support = 0;
2964 rc = strlen(buf);
2965 } else
James Smart891478a2009-11-18 15:40:23 -05002966 rc = -EPERM;
2967 } else {
James Smart0d878412009-10-02 15:16:56 -04002968 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05002969 rc = strlen(buf);
2970 }
James Smart0d878412009-10-02 15:16:56 -04002971 break;
2972 case 1:
2973 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2974 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2975 if (!rc) {
2976 spin_lock_irq(&phba->hbalock);
2977 phba->hba_flag |= HBA_AER_ENABLED;
2978 spin_unlock_irq(&phba->hbalock);
2979 phba->cfg_aer_support = 1;
2980 rc = strlen(buf);
2981 } else
James Smart891478a2009-11-18 15:40:23 -05002982 rc = -EPERM;
2983 } else {
James Smart0d878412009-10-02 15:16:56 -04002984 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05002985 rc = strlen(buf);
2986 }
James Smart0d878412009-10-02 15:16:56 -04002987 break;
2988 default:
2989 rc = -EINVAL;
2990 break;
2991 }
2992 return rc;
2993}
2994
2995static int lpfc_aer_support = 1;
2996module_param(lpfc_aer_support, int, 1);
2997MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2998lpfc_param_show(aer_support)
2999
3000/**
3001 * lpfc_aer_support_init - Set the initial adapters aer support flag
3002 * @phba: lpfc_hba pointer.
3003 * @val: link speed value.
3004 *
3005 * Description:
3006 * If val is in a valid range [0,1], then set the adapter's initial
3007 * cfg_aer_support field. It will be up to the driver's probe_one
3008 * routine to determine whether the device's AER support can be set
3009 * or not.
3010 *
3011 * Notes:
3012 * If the value is not in range log a kernel error message, and
3013 * choose the default value of setting AER support and return.
3014 *
3015 * Returns:
3016 * zero if val saved.
3017 * -EINVAL val out of range
3018 **/
3019static int
3020lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3021{
3022 if (val == 0 || val == 1) {
3023 phba->cfg_aer_support = val;
3024 return 0;
3025 }
3026 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3027 "2712 lpfc_aer_support attribute value %d out "
3028 "of range, allowed values are 0|1, setting it "
3029 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003030 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003031 phba->cfg_aer_support = 1;
3032 return -EINVAL;
3033}
3034
3035static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3036 lpfc_aer_support_show, lpfc_aer_support_store);
3037
3038/**
3039 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3040 * @dev: class device that is converted into a Scsi_host.
3041 * @attr: device attribute, not used.
3042 * @buf: containing the string "selective".
3043 * @count: unused variable.
3044 *
3045 * Description:
3046 * If the @buf contains 1 and the device currently has the AER support
3047 * enabled, then invokes the kernel AER helper routine
3048 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3049 * error status register.
3050 *
3051 * Notes:
3052 *
3053 * Returns:
3054 * -EINVAL if the buf does not contain the 1 or the device is not currently
3055 * enabled with the AER support.
3056 **/
3057static ssize_t
3058lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3059 const char *buf, size_t count)
3060{
3061 struct Scsi_Host *shost = class_to_shost(dev);
3062 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3063 struct lpfc_hba *phba = vport->phba;
3064 int val, rc = -1;
3065
3066 if (!isdigit(buf[0]))
3067 return -EINVAL;
3068 if (sscanf(buf, "%i", &val) != 1)
3069 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003070 if (val != 1)
3071 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003072
James Smart891478a2009-11-18 15:40:23 -05003073 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003074 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3075
3076 if (rc == 0)
3077 return strlen(buf);
3078 else
James Smart891478a2009-11-18 15:40:23 -05003079 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003080}
3081
3082static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3083 lpfc_aer_cleanup_state);
3084
3085/*
dea31012005-04-17 16:05:31 -05003086# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3087# Value range is [2,3]. Default value is 3.
3088*/
James Smart3de2a652007-08-02 11:09:59 -04003089LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3090 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003091
3092/*
3093# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3094# is [0,1]. Default value is 0.
3095*/
James Smart3de2a652007-08-02 11:09:59 -04003096LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3097 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003098
3099/*
James Smart977b5a02008-09-07 11:52:04 -04003100# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3101# depth. Default value is 0. When the value of this parameter is zero the
3102# SCSI command completion time is not used for controlling I/O queue depth. When
3103# the parameter is set to a non-zero value, the I/O queue depth is controlled
3104# to limit the I/O completion time to the parameter value.
3105# The value is set in milliseconds.
3106*/
3107static int lpfc_max_scsicmpl_time;
3108module_param(lpfc_max_scsicmpl_time, int, 0);
3109MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3110 "Use command completion time to control queue depth");
3111lpfc_vport_param_show(max_scsicmpl_time);
3112lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3113static int
3114lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3115{
3116 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3117 struct lpfc_nodelist *ndlp, *next_ndlp;
3118
3119 if (val == vport->cfg_max_scsicmpl_time)
3120 return 0;
3121 if ((val < 0) || (val > 60000))
3122 return -EINVAL;
3123 vport->cfg_max_scsicmpl_time = val;
3124
3125 spin_lock_irq(shost->host_lock);
3126 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3127 if (!NLP_CHK_NODE_ACT(ndlp))
3128 continue;
3129 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3130 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003131 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003132 }
3133 spin_unlock_irq(shost->host_lock);
3134 return 0;
3135}
3136lpfc_vport_param_store(max_scsicmpl_time);
3137static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3138 lpfc_max_scsicmpl_time_show,
3139 lpfc_max_scsicmpl_time_store);
3140
3141/*
dea31012005-04-17 16:05:31 -05003142# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3143# range is [0,1]. Default value is 0.
3144*/
3145LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3146
3147/*
3148# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3149# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003150# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003151# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3152# cr_delay is set to 0.
3153*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003154LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003155 "interrupt response is generated");
3156
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003157LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003158 "interrupt response is generated");
3159
3160/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003161# lpfc_multi_ring_support: Determines how many rings to spread available
3162# cmd/rsp IOCB entries across.
3163# Value range is [1,2]. Default value is 1.
3164*/
3165LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3166 "SLI rings to spread IOCB entries across");
3167
3168/*
James Smarta4bc3372006-12-02 13:34:16 -05003169# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3170# identifies what rctl value to configure the additional ring for.
3171# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3172*/
James Smart6a9c52c2009-10-02 15:16:51 -04003173LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003174 255, "Identifies RCTL for additional ring configuration");
3175
3176/*
3177# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3178# identifies what type value to configure the additional ring for.
3179# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3180*/
James Smart6a9c52c2009-10-02 15:16:51 -04003181LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003182 255, "Identifies TYPE for additional ring configuration");
3183
3184/*
dea31012005-04-17 16:05:31 -05003185# lpfc_fdmi_on: controls FDMI support.
3186# 0 = no FDMI support
3187# 1 = support FDMI without attribute of hostname
3188# 2 = support FDMI with attribute of hostname
3189# Value range [0,2]. Default value is 0.
3190*/
James Smart3de2a652007-08-02 11:09:59 -04003191LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003192
3193/*
3194# Specifies the maximum number of ELS cmds we can have outstanding (for
3195# discovery). Value range is [1,64]. Default value = 32.
3196*/
James Smart3de2a652007-08-02 11:09:59 -04003197LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003198 "during discovery");
3199
3200/*
James Smart65a29c12006-07-06 15:50:50 -04003201# lpfc_max_luns: maximum allowed LUN.
3202# Value range is [0,65535]. Default value is 255.
3203# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003204*/
James Smart3de2a652007-08-02 11:09:59 -04003205LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003206
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003207/*
3208# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3209# Value range is [1,255], default value is 10.
3210*/
3211LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3212 "Milliseconds driver will wait between polling FCP ring");
3213
James Smart4ff43242006-12-02 13:34:56 -05003214/*
3215# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3216# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003217# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003218# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003219# 2 = MSI-X enabled (default)
3220# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003221*/
George Kadianakis8605c462010-01-17 21:19:31 +02003222LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003223 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003224
James Smart13815c82008-01-11 01:52:48 -05003225/*
James Smartda0436e2009-05-22 14:51:39 -04003226# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3227#
3228# Value range is [636,651042]. Default value is 10000.
3229*/
3230LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3231 "Set the maximum number of fast-path FCP interrupts per second");
3232
3233/*
3234# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3235#
3236# Value range is [1,31]. Default value is 4.
3237*/
3238LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3239 "Set the number of fast-path FCP work queues, if possible");
3240
3241/*
3242# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3243#
3244# Value range is [1,7]. Default value is 1.
3245*/
3246LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3247 "Set the number of fast-path FCP event queues, if possible");
3248
3249/*
James Smart13815c82008-01-11 01:52:48 -05003250# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3251# 0 = HBA resets disabled
3252# 1 = HBA resets enabled (default)
3253# Value range is [0,1]. Default value is 1.
3254*/
3255LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003256
James Smart13815c82008-01-11 01:52:48 -05003257/*
3258# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3259# 0 = HBA Heartbeat disabled
3260# 1 = HBA Heartbeat enabled (default)
3261# Value range is [0,1]. Default value is 1.
3262*/
3263LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003264
James Smart83108bd2008-01-11 01:53:09 -05003265/*
James Smart81301a92008-12-04 22:39:46 -05003266# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3267# 0 = BlockGuard disabled (default)
3268# 1 = BlockGuard enabled
3269# Value range is [0,1]. Default value is 0.
3270*/
3271LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3272
James Smart6fb120a2009-05-22 14:52:59 -04003273/*
James Smart81301a92008-12-04 22:39:46 -05003274# lpfc_prot_mask: i
3275# - Bit mask of host protection capabilities used to register with the
3276# SCSI mid-layer
3277# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3278# - Allows you to ultimately specify which profiles to use
3279# - Default will result in registering capabilities for all profiles.
3280#
3281*/
3282unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3283
3284module_param(lpfc_prot_mask, uint, 0);
3285MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3286
3287/*
3288# lpfc_prot_guard: i
3289# - Bit mask of protection guard types to register with the SCSI mid-layer
3290# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3291# - Allows you to ultimately specify which profiles to use
3292# - Default will result in registering capabilities for all guard types
3293#
3294*/
3295unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3296module_param(lpfc_prot_guard, byte, 0);
3297MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3298
3299
3300/*
James Smart3621a712009-04-06 18:47:14 -04003301 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003302 * This value can be set to values between 64 and 256. The default value is
3303 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3304 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3305 */
3306LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3307 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3308
James Smart81301a92008-12-04 22:39:46 -05003309LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3310 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3311 "Max Protection Scatter Gather Segment Count");
3312
Tony Jonesee959b02008-02-22 00:13:36 +01003313struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003314 &dev_attr_bg_info,
3315 &dev_attr_bg_guard_err,
3316 &dev_attr_bg_apptag_err,
3317 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003318 &dev_attr_info,
3319 &dev_attr_serialnum,
3320 &dev_attr_modeldesc,
3321 &dev_attr_modelname,
3322 &dev_attr_programtype,
3323 &dev_attr_portnum,
3324 &dev_attr_fwrev,
3325 &dev_attr_hdw,
3326 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003327 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003328 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003329 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003330 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003331 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003332 &dev_attr_lpfc_temp_sensor,
3333 &dev_attr_lpfc_log_verbose,
3334 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003335 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003336 &dev_attr_lpfc_hba_queue_depth,
3337 &dev_attr_lpfc_peer_port_login,
3338 &dev_attr_lpfc_nodev_tmo,
3339 &dev_attr_lpfc_devloss_tmo,
3340 &dev_attr_lpfc_fcp_class,
3341 &dev_attr_lpfc_use_adisc,
3342 &dev_attr_lpfc_ack0,
3343 &dev_attr_lpfc_topology,
3344 &dev_attr_lpfc_scan_down,
3345 &dev_attr_lpfc_link_speed,
3346 &dev_attr_lpfc_cr_delay,
3347 &dev_attr_lpfc_cr_count,
3348 &dev_attr_lpfc_multi_ring_support,
3349 &dev_attr_lpfc_multi_ring_rctl,
3350 &dev_attr_lpfc_multi_ring_type,
3351 &dev_attr_lpfc_fdmi_on,
3352 &dev_attr_lpfc_max_luns,
3353 &dev_attr_lpfc_enable_npiv,
3354 &dev_attr_nport_evt_cnt,
3355 &dev_attr_board_mode,
3356 &dev_attr_max_vpi,
3357 &dev_attr_used_vpi,
3358 &dev_attr_max_rpi,
3359 &dev_attr_used_rpi,
3360 &dev_attr_max_xri,
3361 &dev_attr_used_xri,
3362 &dev_attr_npiv_info,
3363 &dev_attr_issue_reset,
3364 &dev_attr_lpfc_poll,
3365 &dev_attr_lpfc_poll_tmo,
3366 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003367 &dev_attr_lpfc_fcp_imax,
3368 &dev_attr_lpfc_fcp_wq_count,
3369 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003370 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003371 &dev_attr_lpfc_soft_wwnn,
3372 &dev_attr_lpfc_soft_wwpn,
3373 &dev_attr_lpfc_soft_wwn_enable,
3374 &dev_attr_lpfc_enable_hba_reset,
3375 &dev_attr_lpfc_enable_hba_heartbeat,
3376 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003377 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003378 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003379 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003380 &dev_attr_lpfc_aer_support,
3381 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003382 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003383 &dev_attr_lpfc_iocb_cnt,
3384 &dev_attr_iocb_hw,
3385 &dev_attr_txq_hw,
3386 &dev_attr_txcmplq_hw,
dea31012005-04-17 16:05:31 -05003387 NULL,
3388};
3389
Tony Jonesee959b02008-02-22 00:13:36 +01003390struct device_attribute *lpfc_vport_attrs[] = {
3391 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003392 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003393 &dev_attr_num_discovered_ports,
3394 &dev_attr_lpfc_drvr_version,
3395 &dev_attr_lpfc_log_verbose,
3396 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003397 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003398 &dev_attr_lpfc_nodev_tmo,
3399 &dev_attr_lpfc_devloss_tmo,
3400 &dev_attr_lpfc_hba_queue_depth,
3401 &dev_attr_lpfc_peer_port_login,
3402 &dev_attr_lpfc_restrict_login,
3403 &dev_attr_lpfc_fcp_class,
3404 &dev_attr_lpfc_use_adisc,
3405 &dev_attr_lpfc_fdmi_on,
3406 &dev_attr_lpfc_max_luns,
3407 &dev_attr_nport_evt_cnt,
3408 &dev_attr_npiv_info,
3409 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003410 &dev_attr_lpfc_max_scsicmpl_time,
3411 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003412 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003413 NULL,
3414};
3415
James Smarte59058c2008-08-24 21:49:00 -04003416/**
James Smart3621a712009-04-06 18:47:14 -04003417 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003418 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003419 * @kobj: kernel kobject that contains the kernel class device.
3420 * @bin_attr: kernel attributes passed to us.
3421 * @buf: contains the data to be written to the adapter IOREG space.
3422 * @off: offset into buffer to beginning of data.
3423 * @count: bytes to transfer.
3424 *
3425 * Description:
3426 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3427 * Uses the adapter io control registers to send buf contents to the adapter.
3428 *
3429 * Returns:
3430 * -ERANGE off and count combo out of range
3431 * -EINVAL off, count or buff address invalid
3432 * -EPERM adapter is offline
3433 * value of count, buf contents written
3434 **/
dea31012005-04-17 16:05:31 -05003435static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003436sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3437 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003438 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003439{
3440 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003441 struct device *dev = container_of(kobj, struct device, kobj);
3442 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003443 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3444 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003445
James Smartf1126682009-06-10 17:22:44 -04003446 if (phba->sli_rev >= LPFC_SLI_REV4)
3447 return -EPERM;
3448
dea31012005-04-17 16:05:31 -05003449 if ((off + count) > FF_REG_AREA_SIZE)
3450 return -ERANGE;
3451
3452 if (count == 0) return 0;
3453
3454 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3455 return -EINVAL;
3456
James Smart2e0fef82007-06-17 19:56:36 -05003457 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003458 return -EPERM;
3459 }
3460
James Smart2e0fef82007-06-17 19:56:36 -05003461 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003462 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3463 writel(*((uint32_t *)(buf + buf_off)),
3464 phba->ctrl_regs_memmap_p + off + buf_off);
3465
James Smart2e0fef82007-06-17 19:56:36 -05003466 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003467
3468 return count;
3469}
3470
James Smarte59058c2008-08-24 21:49:00 -04003471/**
James Smart3621a712009-04-06 18:47:14 -04003472 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003473 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003474 * @kobj: kernel kobject that contains the kernel class device.
3475 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003476 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003477 * @off: offset into buffer to beginning of data.
3478 * @count: bytes to transfer.
3479 *
3480 * Description:
3481 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3482 * Uses the adapter io control registers to read data into buf.
3483 *
3484 * Returns:
3485 * -ERANGE off and count combo out of range
3486 * -EINVAL off, count or buff address invalid
3487 * value of count, buf contents read
3488 **/
dea31012005-04-17 16:05:31 -05003489static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003490sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3491 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003492 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003493{
3494 size_t buf_off;
3495 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003496 struct device *dev = container_of(kobj, struct device, kobj);
3497 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003498 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3499 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003500
James Smartf1126682009-06-10 17:22:44 -04003501 if (phba->sli_rev >= LPFC_SLI_REV4)
3502 return -EPERM;
3503
dea31012005-04-17 16:05:31 -05003504 if (off > FF_REG_AREA_SIZE)
3505 return -ERANGE;
3506
3507 if ((off + count) > FF_REG_AREA_SIZE)
3508 count = FF_REG_AREA_SIZE - off;
3509
3510 if (count == 0) return 0;
3511
3512 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3513 return -EINVAL;
3514
James Smart2e0fef82007-06-17 19:56:36 -05003515 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003516
3517 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3518 tmp_ptr = (uint32_t *)(buf + buf_off);
3519 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3520 }
3521
James Smart2e0fef82007-06-17 19:56:36 -05003522 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003523
3524 return count;
3525}
3526
3527static struct bin_attribute sysfs_ctlreg_attr = {
3528 .attr = {
3529 .name = "ctlreg",
3530 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003531 },
3532 .size = 256,
3533 .read = sysfs_ctlreg_read,
3534 .write = sysfs_ctlreg_write,
3535};
3536
James Smarte59058c2008-08-24 21:49:00 -04003537/**
James Smart3621a712009-04-06 18:47:14 -04003538 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003539 * @phba: lpfc_hba pointer
3540 **/
dea31012005-04-17 16:05:31 -05003541static void
James Smart2e0fef82007-06-17 19:56:36 -05003542sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003543{
3544 phba->sysfs_mbox.state = SMBOX_IDLE;
3545 phba->sysfs_mbox.offset = 0;
3546
3547 if (phba->sysfs_mbox.mbox) {
3548 mempool_free(phba->sysfs_mbox.mbox,
3549 phba->mbox_mem_pool);
3550 phba->sysfs_mbox.mbox = NULL;
3551 }
3552}
3553
James Smarte59058c2008-08-24 21:49:00 -04003554/**
James Smart3621a712009-04-06 18:47:14 -04003555 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003556 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003557 * @kobj: kernel kobject that contains the kernel class device.
3558 * @bin_attr: kernel attributes passed to us.
3559 * @buf: contains the data to be written to sysfs mbox.
3560 * @off: offset into buffer to beginning of data.
3561 * @count: bytes to transfer.
3562 *
3563 * Description:
3564 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3565 * Uses the sysfs mbox to send buf contents to the adapter.
3566 *
3567 * Returns:
3568 * -ERANGE off and count combo out of range
3569 * -EINVAL off, count or buff address invalid
3570 * zero if count is zero
3571 * -EPERM adapter is offline
3572 * -ENOMEM failed to allocate memory for the mail box
3573 * -EAGAIN offset, state or mbox is NULL
3574 * count number of bytes transferred
3575 **/
dea31012005-04-17 16:05:31 -05003576static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003577sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3578 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003579 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003580{
Tony Jonesee959b02008-02-22 00:13:36 +01003581 struct device *dev = container_of(kobj, struct device, kobj);
3582 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3584 struct lpfc_hba *phba = vport->phba;
3585 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003586
3587 if ((count + off) > MAILBOX_CMD_SIZE)
3588 return -ERANGE;
3589
3590 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3591 return -EINVAL;
3592
3593 if (count == 0)
3594 return 0;
3595
3596 if (off == 0) {
3597 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3598 if (!mbox)
3599 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003600 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003601 }
3602
James Smart2e0fef82007-06-17 19:56:36 -05003603 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003604
3605 if (off == 0) {
3606 if (phba->sysfs_mbox.mbox)
3607 mempool_free(mbox, phba->mbox_mem_pool);
3608 else
3609 phba->sysfs_mbox.mbox = mbox;
3610 phba->sysfs_mbox.state = SMBOX_WRITING;
3611 } else {
3612 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3613 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003614 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003615 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003616 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003617 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003618 }
3619 }
3620
James Smart04c68492009-05-22 14:52:52 -04003621 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003622 buf, count);
3623
3624 phba->sysfs_mbox.offset = off + count;
3625
James Smart2e0fef82007-06-17 19:56:36 -05003626 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003627
3628 return count;
3629}
3630
James Smarte59058c2008-08-24 21:49:00 -04003631/**
James Smart3621a712009-04-06 18:47:14 -04003632 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003633 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003634 * @kobj: kernel kobject that contains the kernel class device.
3635 * @bin_attr: kernel attributes passed to us.
3636 * @buf: contains the data to be read from sysfs mbox.
3637 * @off: offset into buffer to beginning of data.
3638 * @count: bytes to transfer.
3639 *
3640 * Description:
3641 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3642 * Uses the sysfs mbox to receive data from to the adapter.
3643 *
3644 * Returns:
3645 * -ERANGE off greater than mailbox command size
3646 * -EINVAL off, count or buff address invalid
3647 * zero if off and count are zero
3648 * -EACCES adapter over temp
3649 * -EPERM garbage can value to catch a multitude of errors
3650 * -EAGAIN management IO not permitted, state or off error
3651 * -ETIME mailbox timeout
3652 * -ENODEV mailbox error
3653 * count number of bytes transferred
3654 **/
dea31012005-04-17 16:05:31 -05003655static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003656sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3657 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003658 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003659{
Tony Jonesee959b02008-02-22 00:13:36 +01003660 struct device *dev = container_of(kobj, struct device, kobj);
3661 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3663 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003664 int rc;
James Smart04c68492009-05-22 14:52:52 -04003665 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003666
James Smart1dcb58e2007-04-25 09:51:30 -04003667 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003668 return -ERANGE;
3669
James Smart1dcb58e2007-04-25 09:51:30 -04003670 if ((count + off) > MAILBOX_CMD_SIZE)
3671 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003672
3673 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3674 return -EINVAL;
3675
3676 if (off && count == 0)
3677 return 0;
3678
James Smart2e0fef82007-06-17 19:56:36 -05003679 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003680
James Smart7af67052007-10-27 13:38:11 -04003681 if (phba->over_temp_state == HBA_OVER_TEMP) {
3682 sysfs_mbox_idle(phba);
3683 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003684 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003685 }
3686
dea31012005-04-17 16:05:31 -05003687 if (off == 0 &&
3688 phba->sysfs_mbox.state == SMBOX_WRITING &&
3689 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003690 pmb = &phba->sysfs_mbox.mbox->u.mb;
3691 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003692 /* Offline only */
dea31012005-04-17 16:05:31 -05003693 case MBX_INIT_LINK:
3694 case MBX_DOWN_LINK:
3695 case MBX_CONFIG_LINK:
3696 case MBX_CONFIG_RING:
3697 case MBX_RESET_RING:
3698 case MBX_UNREG_LOGIN:
3699 case MBX_CLEAR_LA:
3700 case MBX_DUMP_CONTEXT:
3701 case MBX_RUN_DIAGS:
3702 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003703 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003704 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003705 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003706 printk(KERN_WARNING "mbox_read:Command 0x%x "
3707 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003708 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003709 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003710 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003711 return -EPERM;
3712 }
James Smarta8adb832007-10-27 13:37:53 -04003713 case MBX_WRITE_NV:
3714 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003715 case MBX_LOAD_SM:
3716 case MBX_READ_NV:
3717 case MBX_READ_CONFIG:
3718 case MBX_READ_RCONFIG:
3719 case MBX_READ_STATUS:
3720 case MBX_READ_XRI:
3721 case MBX_READ_REV:
3722 case MBX_READ_LNK_STAT:
3723 case MBX_DUMP_MEMORY:
3724 case MBX_DOWN_LOAD:
3725 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003726 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003727 case MBX_LOAD_AREA:
3728 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003729 case MBX_BEACON:
3730 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003731 case MBX_SET_VARIABLE:
3732 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003733 case MBX_PORT_CAPABILITIES:
3734 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003735 break;
3736 case MBX_READ_SPARM64:
3737 case MBX_READ_LA:
3738 case MBX_READ_LA64:
3739 case MBX_REG_LOGIN:
3740 case MBX_REG_LOGIN64:
3741 case MBX_CONFIG_PORT:
3742 case MBX_RUN_BIU_DIAG:
3743 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003744 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003745 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003746 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003747 return -EPERM;
3748 default:
3749 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003750 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003751 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003752 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003753 return -EPERM;
3754 }
3755
James Smart09372822008-01-11 01:52:54 -05003756 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003757 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003758 */
James Smartd7c255b2008-08-24 21:50:00 -04003759 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003760 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3761 pmb->mbxCommand != MBX_RESTART &&
3762 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3763 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003764 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3765 "1259 mbox: Issued mailbox cmd "
3766 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003767 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003768
James Smart92d7f7b2007-06-17 19:56:38 -05003769 phba->sysfs_mbox.mbox->vport = vport;
3770
James Smart58da1ff2008-04-07 10:15:56 -04003771 /* Don't allow mailbox commands to be sent when blocked
3772 * or when in the middle of discovery
3773 */
James Smart495a7142008-06-14 22:52:59 -04003774 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003775 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003776 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003777 return -EAGAIN;
3778 }
3779
James Smart2e0fef82007-06-17 19:56:36 -05003780 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003781 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003782
James Smart2e0fef82007-06-17 19:56:36 -05003783 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003784 rc = lpfc_sli_issue_mbox (phba,
3785 phba->sysfs_mbox.mbox,
3786 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003787 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003788
3789 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003790 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003791 rc = lpfc_sli_issue_mbox_wait (phba,
3792 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003793 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003794 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003795 }
3796
3797 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003798 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003799 phba->sysfs_mbox.mbox = NULL;
3800 }
dea31012005-04-17 16:05:31 -05003801 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003802 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003803 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003804 }
3805 phba->sysfs_mbox.state = SMBOX_READING;
3806 }
3807 else if (phba->sysfs_mbox.offset != off ||
3808 phba->sysfs_mbox.state != SMBOX_READING) {
3809 printk(KERN_WARNING "mbox_read: Bad State\n");
3810 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003811 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003812 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003813 }
3814
James Smart04c68492009-05-22 14:52:52 -04003815 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003816
3817 phba->sysfs_mbox.offset = off + count;
3818
James Smart1dcb58e2007-04-25 09:51:30 -04003819 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003820 sysfs_mbox_idle(phba);
3821
James Smart2e0fef82007-06-17 19:56:36 -05003822 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003823
3824 return count;
3825}
3826
3827static struct bin_attribute sysfs_mbox_attr = {
3828 .attr = {
3829 .name = "mbox",
3830 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003831 },
James Smart1dcb58e2007-04-25 09:51:30 -04003832 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003833 .read = sysfs_mbox_read,
3834 .write = sysfs_mbox_write,
3835};
3836
James Smarte59058c2008-08-24 21:49:00 -04003837/**
James Smart3621a712009-04-06 18:47:14 -04003838 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003839 * @vport: address of lpfc vport structure.
3840 *
3841 * Return codes:
3842 * zero on success
3843 * error return code from sysfs_create_bin_file()
3844 **/
dea31012005-04-17 16:05:31 -05003845int
James Smart2e0fef82007-06-17 19:56:36 -05003846lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003847{
James Smart2e0fef82007-06-17 19:56:36 -05003848 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003849 int error;
3850
Tony Jonesee959b02008-02-22 00:13:36 +01003851 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003852 &sysfs_drvr_stat_data_attr);
3853
3854 /* Virtual ports do not need ctrl_reg and mbox */
3855 if (error || vport->port_type == LPFC_NPIV_PORT)
3856 goto out;
3857
3858 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003859 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003860 if (error)
James Smarteada2722008-12-04 22:39:13 -05003861 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003862
Tony Jonesee959b02008-02-22 00:13:36 +01003863 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003864 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003865 if (error)
3866 goto out_remove_ctlreg_attr;
3867
3868 return 0;
3869out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003870 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003871out_remove_stat_attr:
3872 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3873 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003874out:
3875 return error;
3876}
3877
James Smarte59058c2008-08-24 21:49:00 -04003878/**
James Smart3621a712009-04-06 18:47:14 -04003879 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003880 * @vport: address of lpfc vport structure.
3881 **/
dea31012005-04-17 16:05:31 -05003882void
James Smart2e0fef82007-06-17 19:56:36 -05003883lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003884{
James Smart2e0fef82007-06-17 19:56:36 -05003885 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003886 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3887 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003888 /* Virtual ports do not need ctrl_reg and mbox */
3889 if (vport->port_type == LPFC_NPIV_PORT)
3890 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003891 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3892 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003893}
3894
3895
3896/*
3897 * Dynamic FC Host Attributes Support
3898 */
3899
James Smarte59058c2008-08-24 21:49:00 -04003900/**
James Smart3621a712009-04-06 18:47:14 -04003901 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003902 * @shost: kernel scsi host pointer.
3903 **/
dea31012005-04-17 16:05:31 -05003904static void
3905lpfc_get_host_port_id(struct Scsi_Host *shost)
3906{
James Smart2e0fef82007-06-17 19:56:36 -05003907 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3908
dea31012005-04-17 16:05:31 -05003909 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003910 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003911}
3912
James Smarte59058c2008-08-24 21:49:00 -04003913/**
James Smart3621a712009-04-06 18:47:14 -04003914 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003915 * @shost: kernel scsi host pointer.
3916 **/
dea31012005-04-17 16:05:31 -05003917static void
3918lpfc_get_host_port_type(struct Scsi_Host *shost)
3919{
James Smart2e0fef82007-06-17 19:56:36 -05003920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3921 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003922
3923 spin_lock_irq(shost->host_lock);
3924
James Smart92d7f7b2007-06-17 19:56:38 -05003925 if (vport->port_type == LPFC_NPIV_PORT) {
3926 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3927 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003928 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003929 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003930 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3931 else
3932 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3933 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003934 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003935 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3936 else
3937 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3938 }
3939 } else
3940 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3941
3942 spin_unlock_irq(shost->host_lock);
3943}
3944
James Smarte59058c2008-08-24 21:49:00 -04003945/**
James Smart3621a712009-04-06 18:47:14 -04003946 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003947 * @shost: kernel scsi host pointer.
3948 **/
dea31012005-04-17 16:05:31 -05003949static void
3950lpfc_get_host_port_state(struct Scsi_Host *shost)
3951{
James Smart2e0fef82007-06-17 19:56:36 -05003952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3953 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003954
3955 spin_lock_irq(shost->host_lock);
3956
James Smart2e0fef82007-06-17 19:56:36 -05003957 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003958 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3959 else {
James Smart2e0fef82007-06-17 19:56:36 -05003960 switch (phba->link_state) {
3961 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003962 case LPFC_LINK_DOWN:
3963 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3964 break;
3965 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003966 case LPFC_CLEAR_LA:
3967 case LPFC_HBA_READY:
3968 /* Links up, beyond this port_type reports state */
3969 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3970 break;
3971 case LPFC_HBA_ERROR:
3972 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3973 break;
3974 default:
3975 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3976 break;
3977 }
3978 }
3979
3980 spin_unlock_irq(shost->host_lock);
3981}
3982
James Smarte59058c2008-08-24 21:49:00 -04003983/**
James Smart3621a712009-04-06 18:47:14 -04003984 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003985 * @shost: kernel scsi host pointer.
3986 **/
dea31012005-04-17 16:05:31 -05003987static void
3988lpfc_get_host_speed(struct Scsi_Host *shost)
3989{
James Smart2e0fef82007-06-17 19:56:36 -05003990 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3991 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003992
3993 spin_lock_irq(shost->host_lock);
3994
James Smart2e0fef82007-06-17 19:56:36 -05003995 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003996 switch(phba->fc_linkspeed) {
3997 case LA_1GHZ_LINK:
3998 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3999 break;
4000 case LA_2GHZ_LINK:
4001 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4002 break;
4003 case LA_4GHZ_LINK:
4004 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4005 break;
James Smartb87eab32007-04-25 09:53:28 -04004006 case LA_8GHZ_LINK:
4007 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4008 break;
James Smartf4b4c682009-05-22 14:53:12 -04004009 case LA_10GHZ_LINK:
4010 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4011 break;
dea31012005-04-17 16:05:31 -05004012 default:
4013 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4014 break;
4015 }
James Smart09372822008-01-11 01:52:54 -05004016 } else
4017 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004018
4019 spin_unlock_irq(shost->host_lock);
4020}
4021
James Smarte59058c2008-08-24 21:49:00 -04004022/**
James Smart3621a712009-04-06 18:47:14 -04004023 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004024 * @shost: kernel scsi host pointer.
4025 **/
dea31012005-04-17 16:05:31 -05004026static void
4027lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4028{
James Smart2e0fef82007-06-17 19:56:36 -05004029 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4030 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004031 u64 node_name;
dea31012005-04-17 16:05:31 -05004032
4033 spin_lock_irq(shost->host_lock);
4034
James Smart2e0fef82007-06-17 19:56:36 -05004035 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05004036 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004037 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004038 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004039 else
4040 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004041 node_name = 0;
dea31012005-04-17 16:05:31 -05004042
4043 spin_unlock_irq(shost->host_lock);
4044
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004045 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004046}
4047
James Smarte59058c2008-08-24 21:49:00 -04004048/**
James Smart3621a712009-04-06 18:47:14 -04004049 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004050 * @shost: kernel scsi host pointer.
4051 *
4052 * Notes:
4053 * NULL on error for link down, no mbox pool, sli2 active,
4054 * management not allowed, memory allocation error, or mbox error.
4055 *
4056 * Returns:
4057 * NULL for error
4058 * address of the adapter host statistics
4059 **/
dea31012005-04-17 16:05:31 -05004060static struct fc_host_statistics *
4061lpfc_get_stats(struct Scsi_Host *shost)
4062{
James Smart2e0fef82007-06-17 19:56:36 -05004063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4064 struct lpfc_hba *phba = vport->phba;
4065 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004066 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004067 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004068 LPFC_MBOXQ_t *pmboxq;
4069 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004070 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004071 int rc = 0;
dea31012005-04-17 16:05:31 -05004072
James Smart92d7f7b2007-06-17 19:56:38 -05004073 /*
4074 * prevent udev from issuing mailbox commands until the port is
4075 * configured.
4076 */
James Smart2e0fef82007-06-17 19:56:36 -05004077 if (phba->link_state < LPFC_LINK_DOWN ||
4078 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004079 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004080 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004081
4082 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004083 return NULL;
4084
dea31012005-04-17 16:05:31 -05004085 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4086 if (!pmboxq)
4087 return NULL;
4088 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4089
James Smart04c68492009-05-22 14:52:52 -04004090 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004091 pmb->mbxCommand = MBX_READ_STATUS;
4092 pmb->mbxOwner = OWN_HOST;
4093 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004094 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004095
James Smart75baf692010-06-08 18:31:21 -04004096 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004097 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004098 else
dea31012005-04-17 16:05:31 -05004099 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4100
4101 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004102 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004103 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004104 return NULL;
4105 }
4106
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004107 memset(hs, 0, sizeof (struct fc_host_statistics));
4108
dea31012005-04-17 16:05:31 -05004109 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4110 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4111 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4112 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4113
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004114 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004115 pmb->mbxCommand = MBX_READ_LNK_STAT;
4116 pmb->mbxOwner = OWN_HOST;
4117 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004118 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004119
James Smart75baf692010-06-08 18:31:21 -04004120 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004121 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004122 else
dea31012005-04-17 16:05:31 -05004123 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4124
4125 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004126 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004127 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004128 return NULL;
4129 }
4130
4131 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4132 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4133 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4134 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4135 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4136 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4137 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4138
James Smart64ba8812006-08-02 15:24:34 -04004139 hs->link_failure_count -= lso->link_failure_count;
4140 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4141 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4142 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4143 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4144 hs->invalid_crc_count -= lso->invalid_crc_count;
4145 hs->error_frames -= lso->error_frames;
4146
James Smart4d9ab992009-10-02 15:16:39 -04004147 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4148 hs->lip_count = -1;
4149 hs->nos_count = (phba->link_events >> 1);
4150 hs->nos_count -= lso->link_events;
4151 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004152 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004153 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004154 hs->nos_count = -1;
4155 } else {
4156 hs->lip_count = -1;
4157 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004158 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004159 }
4160
4161 hs->dumped_frames = -1;
4162
James Smart64ba8812006-08-02 15:24:34 -04004163 seconds = get_seconds();
4164 if (seconds < psli->stats_start)
4165 hs->seconds_since_last_reset = seconds +
4166 ((unsigned long)-1 - psli->stats_start);
4167 else
4168 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004169
James Smart1dcb58e2007-04-25 09:51:30 -04004170 mempool_free(pmboxq, phba->mbox_mem_pool);
4171
dea31012005-04-17 16:05:31 -05004172 return hs;
4173}
4174
James Smarte59058c2008-08-24 21:49:00 -04004175/**
James Smart3621a712009-04-06 18:47:14 -04004176 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004177 * @shost: kernel scsi host pointer.
4178 **/
James Smart64ba8812006-08-02 15:24:34 -04004179static void
4180lpfc_reset_stats(struct Scsi_Host *shost)
4181{
James Smart2e0fef82007-06-17 19:56:36 -05004182 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4183 struct lpfc_hba *phba = vport->phba;
4184 struct lpfc_sli *psli = &phba->sli;
4185 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004186 LPFC_MBOXQ_t *pmboxq;
4187 MAILBOX_t *pmb;
4188 int rc = 0;
4189
James Smart2e0fef82007-06-17 19:56:36 -05004190 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004191 return;
4192
James Smart64ba8812006-08-02 15:24:34 -04004193 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4194 if (!pmboxq)
4195 return;
4196 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4197
James Smart04c68492009-05-22 14:52:52 -04004198 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004199 pmb->mbxCommand = MBX_READ_STATUS;
4200 pmb->mbxOwner = OWN_HOST;
4201 pmb->un.varWords[0] = 0x1; /* reset request */
4202 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004203 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004204
James Smart2e0fef82007-06-17 19:56:36 -05004205 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004206 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004207 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4208 else
4209 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4210
4211 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004212 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004213 mempool_free(pmboxq, phba->mbox_mem_pool);
4214 return;
4215 }
4216
4217 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4218 pmb->mbxCommand = MBX_READ_LNK_STAT;
4219 pmb->mbxOwner = OWN_HOST;
4220 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004221 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004222
James Smart2e0fef82007-06-17 19:56:36 -05004223 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004224 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004225 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4226 else
4227 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4228
4229 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004230 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004231 mempool_free( pmboxq, phba->mbox_mem_pool);
4232 return;
4233 }
4234
4235 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4236 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4237 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4238 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4239 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4240 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4241 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004242 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4243 lso->link_events = (phba->link_events >> 1);
4244 else
4245 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004246
4247 psli->stats_start = get_seconds();
4248
James Smart1dcb58e2007-04-25 09:51:30 -04004249 mempool_free(pmboxq, phba->mbox_mem_pool);
4250
James Smart64ba8812006-08-02 15:24:34 -04004251 return;
4252}
dea31012005-04-17 16:05:31 -05004253
4254/*
4255 * The LPFC driver treats linkdown handling as target loss events so there
4256 * are no sysfs handlers for link_down_tmo.
4257 */
James Smart685f0bf2007-04-25 09:53:08 -04004258
James Smarte59058c2008-08-24 21:49:00 -04004259/**
James Smart3621a712009-04-06 18:47:14 -04004260 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004261 * @starget: kernel scsi target pointer.
4262 *
4263 * Returns:
4264 * address of the node list if found
4265 * NULL target not found
4266 **/
James Smart685f0bf2007-04-25 09:53:08 -04004267static struct lpfc_nodelist *
4268lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004269{
James Smart2e0fef82007-06-17 19:56:36 -05004270 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004272 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004273
4274 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004275 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004276 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004277 if (NLP_CHK_NODE_ACT(ndlp) &&
4278 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004279 starget->id == ndlp->nlp_sid) {
4280 spin_unlock_irq(shost->host_lock);
4281 return ndlp;
dea31012005-04-17 16:05:31 -05004282 }
4283 }
4284 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004285 return NULL;
4286}
dea31012005-04-17 16:05:31 -05004287
James Smarte59058c2008-08-24 21:49:00 -04004288/**
James Smart3621a712009-04-06 18:47:14 -04004289 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004290 * @starget: kernel scsi target pointer.
4291 **/
James Smart685f0bf2007-04-25 09:53:08 -04004292static void
4293lpfc_get_starget_port_id(struct scsi_target *starget)
4294{
4295 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4296
4297 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004298}
4299
James Smarte59058c2008-08-24 21:49:00 -04004300/**
James Smart3621a712009-04-06 18:47:14 -04004301 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004302 * @starget: kernel scsi target pointer.
4303 *
4304 * Description: Set the target node name to the ndlp node name wwn or zero.
4305 **/
dea31012005-04-17 16:05:31 -05004306static void
4307lpfc_get_starget_node_name(struct scsi_target *starget)
4308{
James Smart685f0bf2007-04-25 09:53:08 -04004309 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004310
James Smart685f0bf2007-04-25 09:53:08 -04004311 fc_starget_node_name(starget) =
4312 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004313}
4314
James Smarte59058c2008-08-24 21:49:00 -04004315/**
James Smart3621a712009-04-06 18:47:14 -04004316 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004317 * @starget: kernel scsi target pointer.
4318 *
4319 * Description: set the target port name to the ndlp port name wwn or zero.
4320 **/
dea31012005-04-17 16:05:31 -05004321static void
4322lpfc_get_starget_port_name(struct scsi_target *starget)
4323{
James Smart685f0bf2007-04-25 09:53:08 -04004324 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004325
James Smart685f0bf2007-04-25 09:53:08 -04004326 fc_starget_port_name(starget) =
4327 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004328}
4329
James Smarte59058c2008-08-24 21:49:00 -04004330/**
James Smart3621a712009-04-06 18:47:14 -04004331 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004332 * @rport: fc rport address.
4333 * @timeout: new value for dev loss tmo.
4334 *
4335 * Description:
4336 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4337 * dev_loss_tmo to one.
4338 **/
dea31012005-04-17 16:05:31 -05004339static void
dea31012005-04-17 16:05:31 -05004340lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4341{
dea31012005-04-17 16:05:31 -05004342 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004343 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004344 else
James Smartc01f3202006-08-18 17:47:08 -04004345 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004346}
4347
James Smarte59058c2008-08-24 21:49:00 -04004348/**
James Smart3621a712009-04-06 18:47:14 -04004349 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004350 *
4351 * Description:
4352 * Macro that uses field to generate a function with the name lpfc_show_rport_
4353 *
4354 * lpfc_show_rport_##field: returns the bytes formatted in buf
4355 * @cdev: class converted to an fc_rport.
4356 * @buf: on return contains the target_field or zero.
4357 *
4358 * Returns: size of formatted string.
4359 **/
dea31012005-04-17 16:05:31 -05004360#define lpfc_rport_show_function(field, format_string, sz, cast) \
4361static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004362lpfc_show_rport_##field (struct device *dev, \
4363 struct device_attribute *attr, \
4364 char *buf) \
dea31012005-04-17 16:05:31 -05004365{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004366 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004367 struct lpfc_rport_data *rdata = rport->hostdata; \
4368 return snprintf(buf, sz, format_string, \
4369 (rdata->target) ? cast rdata->target->field : 0); \
4370}
4371
4372#define lpfc_rport_rd_attr(field, format_string, sz) \
4373 lpfc_rport_show_function(field, format_string, sz, ) \
4374static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4375
James Smarteada2722008-12-04 22:39:13 -05004376/**
James Smart3621a712009-04-06 18:47:14 -04004377 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004378 * @fc_vport: The fc_vport who's symbolic name has been changed.
4379 *
4380 * Description:
4381 * This function is called by the transport after the @fc_vport's symbolic name
4382 * has been changed. This function re-registers the symbolic name with the
4383 * switch to propogate the change into the fabric if the vport is active.
4384 **/
4385static void
4386lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4387{
4388 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4389
4390 if (vport->port_state == LPFC_VPORT_READY)
4391 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4392}
dea31012005-04-17 16:05:31 -05004393
James Smartf4b4c682009-05-22 14:53:12 -04004394/**
4395 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4396 * @phba: Pointer to lpfc_hba struct.
4397 *
4398 * This function is called by the lpfc_get_cfgparam() routine to set the
4399 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4400 * log messsage according to the module's lpfc_log_verbose parameter setting
4401 * before hba port or vport created.
4402 **/
4403static void
4404lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4405{
4406 phba->cfg_log_verbose = verbose;
4407}
4408
dea31012005-04-17 16:05:31 -05004409struct fc_function_template lpfc_transport_functions = {
4410 /* fixed attributes the driver supports */
4411 .show_host_node_name = 1,
4412 .show_host_port_name = 1,
4413 .show_host_supported_classes = 1,
4414 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004415 .show_host_supported_speeds = 1,
4416 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004417 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004418
4419 /* dynamic attributes the driver supports */
4420 .get_host_port_id = lpfc_get_host_port_id,
4421 .show_host_port_id = 1,
4422
4423 .get_host_port_type = lpfc_get_host_port_type,
4424 .show_host_port_type = 1,
4425
4426 .get_host_port_state = lpfc_get_host_port_state,
4427 .show_host_port_state = 1,
4428
4429 /* active_fc4s is shown but doesn't change (thus no get function) */
4430 .show_host_active_fc4s = 1,
4431
4432 .get_host_speed = lpfc_get_host_speed,
4433 .show_host_speed = 1,
4434
4435 .get_host_fabric_name = lpfc_get_host_fabric_name,
4436 .show_host_fabric_name = 1,
4437
4438 /*
4439 * The LPFC driver treats linkdown handling as target loss events
4440 * so there are no sysfs handlers for link_down_tmo.
4441 */
4442
4443 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004444 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004445
4446 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4447 .show_rport_maxframe_size = 1,
4448 .show_rport_supported_classes = 1,
4449
dea31012005-04-17 16:05:31 -05004450 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4451 .show_rport_dev_loss_tmo = 1,
4452
4453 .get_starget_port_id = lpfc_get_starget_port_id,
4454 .show_starget_port_id = 1,
4455
4456 .get_starget_node_name = lpfc_get_starget_node_name,
4457 .show_starget_node_name = 1,
4458
4459 .get_starget_port_name = lpfc_get_starget_port_name,
4460 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004461
4462 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004463 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4464 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004465
James Smart92d7f7b2007-06-17 19:56:38 -05004466 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004467
4468 .vport_disable = lpfc_vport_disable,
4469
4470 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004471
4472 .bsg_request = lpfc_bsg_request,
4473 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004474};
4475
James Smart98c9ea52007-10-27 13:37:33 -04004476struct fc_function_template lpfc_vport_transport_functions = {
4477 /* fixed attributes the driver supports */
4478 .show_host_node_name = 1,
4479 .show_host_port_name = 1,
4480 .show_host_supported_classes = 1,
4481 .show_host_supported_fc4s = 1,
4482 .show_host_supported_speeds = 1,
4483 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004484 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004485
4486 /* dynamic attributes the driver supports */
4487 .get_host_port_id = lpfc_get_host_port_id,
4488 .show_host_port_id = 1,
4489
4490 .get_host_port_type = lpfc_get_host_port_type,
4491 .show_host_port_type = 1,
4492
4493 .get_host_port_state = lpfc_get_host_port_state,
4494 .show_host_port_state = 1,
4495
4496 /* active_fc4s is shown but doesn't change (thus no get function) */
4497 .show_host_active_fc4s = 1,
4498
4499 .get_host_speed = lpfc_get_host_speed,
4500 .show_host_speed = 1,
4501
4502 .get_host_fabric_name = lpfc_get_host_fabric_name,
4503 .show_host_fabric_name = 1,
4504
4505 /*
4506 * The LPFC driver treats linkdown handling as target loss events
4507 * so there are no sysfs handlers for link_down_tmo.
4508 */
4509
4510 .get_fc_host_stats = lpfc_get_stats,
4511 .reset_fc_host_stats = lpfc_reset_stats,
4512
4513 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4514 .show_rport_maxframe_size = 1,
4515 .show_rport_supported_classes = 1,
4516
4517 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4518 .show_rport_dev_loss_tmo = 1,
4519
4520 .get_starget_port_id = lpfc_get_starget_port_id,
4521 .show_starget_port_id = 1,
4522
4523 .get_starget_node_name = lpfc_get_starget_node_name,
4524 .show_starget_node_name = 1,
4525
4526 .get_starget_port_name = lpfc_get_starget_port_name,
4527 .show_starget_port_name = 1,
4528
4529 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4530 .terminate_rport_io = lpfc_terminate_rport_io,
4531
4532 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004533
4534 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004535};
4536
James Smarte59058c2008-08-24 21:49:00 -04004537/**
James Smart3621a712009-04-06 18:47:14 -04004538 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004539 * @phba: lpfc_hba pointer.
4540 **/
dea31012005-04-17 16:05:31 -05004541void
4542lpfc_get_cfgparam(struct lpfc_hba *phba)
4543{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004544 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4545 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004546 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004547 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4548 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004549 lpfc_ack0_init(phba, lpfc_ack0);
4550 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004551 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004552 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004553 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004554 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004555 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4556 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4557 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004558 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4559 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004560 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004561 if (phba->sli_rev == LPFC_SLI_REV4)
4562 phba->cfg_poll = 0;
4563 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004564 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004565 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004566 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004567 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004568 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004569 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004570 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004571 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004572 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004573 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart3de2a652007-08-02 11:09:59 -04004574 return;
4575}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004576
James Smarte59058c2008-08-24 21:49:00 -04004577/**
James Smart3621a712009-04-06 18:47:14 -04004578 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004579 * @vport: lpfc_vport pointer.
4580 **/
James Smart3de2a652007-08-02 11:09:59 -04004581void
4582lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4583{
James Smarte8b62012007-08-02 11:10:09 -04004584 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004585 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004586 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004587 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4588 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4589 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4590 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4591 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4592 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004593 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004594 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4595 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4596 lpfc_max_luns_init(vport, lpfc_max_luns);
4597 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004598 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004599 return;
4600}