blob: cf15b9754402b7e11e27bc7a06f8a139766a6f37 [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 Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 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>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040026#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040027#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070029#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050030
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_tcq.h>
35#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040036#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050037
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_hw.h"
40#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040041#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040042#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_disc.h"
44#include "lpfc_scsi.h"
45#include "lpfc.h"
46#include "lpfc_logmsg.h"
47#include "lpfc_version.h"
48#include "lpfc_compat.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
James Smart93dd1912016-07-06 12:36:10 -070051#include "lpfc_attr.h"
dea31012005-04-17 16:05:31 -050052
James Smartc01f3202006-08-18 17:47:08 -040053#define LPFC_DEF_DEVLOSS_TMO 30
54#define LPFC_MIN_DEVLOSS_TMO 1
55#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050056
James Smartf7a919b2011-08-21 21:49:16 -040057/*
58 * Write key size should be multiple of 4. If write key is changed
59 * make sure that library write key is also changed.
60 */
61#define LPFC_REG_WRITE_KEY_SIZE 4
62#define LPFC_REG_WRITE_KEY "EMLX"
63
James Smarte59058c2008-08-24 21:49:00 -040064/**
James Smart3621a712009-04-06 18:47:14 -040065 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040066 * @incr: integer to convert.
67 * @hdw: ascii string holding converted integer plus a string terminator.
68 *
69 * Description:
70 * JEDEC Joint Electron Device Engineering Council.
71 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
72 * character string. The string is then terminated with a NULL in byte 9.
73 * Hex 0-9 becomes ascii '0' to '9'.
74 * Hex a-f becomes ascii '=' to 'B' capital B.
75 *
76 * Notes:
77 * Coded for 32 bit integers only.
78 **/
dea31012005-04-17 16:05:31 -050079static void
80lpfc_jedec_to_ascii(int incr, char hdw[])
81{
82 int i, j;
83 for (i = 0; i < 8; i++) {
84 j = (incr & 0xf);
85 if (j <= 9)
86 hdw[7 - i] = 0x30 + j;
87 else
88 hdw[7 - i] = 0x61 + j - 10;
89 incr = (incr >> 4);
90 }
91 hdw[8] = 0;
92 return;
93}
94
James Smarte59058c2008-08-24 21:49:00 -040095/**
James Smart3621a712009-04-06 18:47:14 -040096 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040097 * @dev: class unused variable.
98 * @attr: device attribute, not used.
99 * @buf: on return contains the module description text.
100 *
101 * Returns: size of formatted string.
102 **/
dea31012005-04-17 16:05:31 -0500103static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100104lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
105 char *buf)
dea31012005-04-17 16:05:31 -0500106{
107 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
108}
109
James Smart45ed1192009-10-02 15:17:02 -0400110/**
111 * lpfc_enable_fip_show - Return the fip mode of the HBA
112 * @dev: class unused variable.
113 * @attr: device attribute, not used.
114 * @buf: on return contains the module description text.
115 *
116 * Returns: size of formatted string.
117 **/
118static ssize_t
119lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
120 char *buf)
121{
122 struct Scsi_Host *shost = class_to_shost(dev);
123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
124 struct lpfc_hba *phba = vport->phba;
125
126 if (phba->hba_flag & HBA_FIP_SUPPORT)
127 return snprintf(buf, PAGE_SIZE, "1\n");
128 else
129 return snprintf(buf, PAGE_SIZE, "0\n");
130}
131
James Smart81301a92008-12-04 22:39:46 -0500132static ssize_t
133lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
134 char *buf)
135{
136 struct Scsi_Host *shost = class_to_shost(dev);
137 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
138 struct lpfc_hba *phba = vport->phba;
139
140 if (phba->cfg_enable_bg)
141 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
142 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
143 else
144 return snprintf(buf, PAGE_SIZE,
145 "BlockGuard Not Supported\n");
146 else
147 return snprintf(buf, PAGE_SIZE,
148 "BlockGuard Disabled\n");
149}
150
151static ssize_t
152lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
153 char *buf)
154{
155 struct Scsi_Host *shost = class_to_shost(dev);
156 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
157 struct lpfc_hba *phba = vport->phba;
158
James Smart87b5c322008-12-16 10:34:09 -0500159 return snprintf(buf, PAGE_SIZE, "%llu\n",
160 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500161}
162
163static ssize_t
164lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
165 char *buf)
166{
167 struct Scsi_Host *shost = class_to_shost(dev);
168 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
169 struct lpfc_hba *phba = vport->phba;
170
James Smart87b5c322008-12-16 10:34:09 -0500171 return snprintf(buf, PAGE_SIZE, "%llu\n",
172 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500173}
174
175static ssize_t
176lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
177 char *buf)
178{
179 struct Scsi_Host *shost = class_to_shost(dev);
180 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
181 struct lpfc_hba *phba = vport->phba;
182
James Smart87b5c322008-12-16 10:34:09 -0500183 return snprintf(buf, PAGE_SIZE, "%llu\n",
184 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500185}
186
James Smarte59058c2008-08-24 21:49:00 -0400187/**
James Smart3621a712009-04-06 18:47:14 -0400188 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400189 * @dev: class converted to a Scsi_host structure.
190 * @attr: device attribute, not used.
191 * @buf: on return contains the formatted text from lpfc_info().
192 *
193 * Returns: size of formatted string.
194 **/
dea31012005-04-17 16:05:31 -0500195static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100196lpfc_info_show(struct device *dev, struct device_attribute *attr,
197 char *buf)
dea31012005-04-17 16:05:31 -0500198{
Tony Jonesee959b02008-02-22 00:13:36 +0100199 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500200
dea31012005-04-17 16:05:31 -0500201 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
202}
203
James Smarte59058c2008-08-24 21:49:00 -0400204/**
James Smart3621a712009-04-06 18:47:14 -0400205 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400206 * @dev: class converted to a Scsi_host structure.
207 * @attr: device attribute, not used.
208 * @buf: on return contains the formatted text serial number.
209 *
210 * Returns: size of formatted string.
211 **/
dea31012005-04-17 16:05:31 -0500212static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100213lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
214 char *buf)
dea31012005-04-17 16:05:31 -0500215{
Tony Jonesee959b02008-02-22 00:13:36 +0100216 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500217 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
218 struct lpfc_hba *phba = vport->phba;
219
dea31012005-04-17 16:05:31 -0500220 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
221}
222
James Smarte59058c2008-08-24 21:49:00 -0400223/**
James Smart3621a712009-04-06 18:47:14 -0400224 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400225 * @dev: class converted to a Scsi_host structure.
226 * @attr: device attribute, not used.
227 * @buf: on return contains the formatted support level.
228 *
229 * Description:
230 * Returns a number indicating the temperature sensor level currently
231 * supported, zero or one in ascii.
232 *
233 * Returns: size of formatted string.
234 **/
dea31012005-04-17 16:05:31 -0500235static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100236lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
237 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400238{
Tony Jonesee959b02008-02-22 00:13:36 +0100239 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400240 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
241 struct lpfc_hba *phba = vport->phba;
242 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
243}
244
James Smarte59058c2008-08-24 21:49:00 -0400245/**
James Smart3621a712009-04-06 18:47:14 -0400246 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400247 * @dev: class converted to a Scsi_host structure.
248 * @attr: device attribute, not used.
249 * @buf: on return contains the scsi vpd model description.
250 *
251 * Returns: size of formatted string.
252 **/
James Smart57127f12007-10-27 13:37:05 -0400253static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100254lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
255 char *buf)
dea31012005-04-17 16:05:31 -0500256{
Tony Jonesee959b02008-02-22 00:13:36 +0100257 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500258 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
259 struct lpfc_hba *phba = vport->phba;
260
dea31012005-04-17 16:05:31 -0500261 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
262}
263
James Smarte59058c2008-08-24 21:49:00 -0400264/**
James Smart3621a712009-04-06 18:47:14 -0400265 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400266 * @dev: class converted to a Scsi_host structure.
267 * @attr: device attribute, not used.
268 * @buf: on return contains the scsi vpd model name.
269 *
270 * Returns: size of formatted string.
271 **/
dea31012005-04-17 16:05:31 -0500272static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100273lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
274 char *buf)
dea31012005-04-17 16:05:31 -0500275{
Tony Jonesee959b02008-02-22 00:13:36 +0100276 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500277 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
278 struct lpfc_hba *phba = vport->phba;
279
dea31012005-04-17 16:05:31 -0500280 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
281}
282
James Smarte59058c2008-08-24 21:49:00 -0400283/**
James Smart3621a712009-04-06 18:47:14 -0400284 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400285 * @dev: class converted to a Scsi_host structure.
286 * @attr: device attribute, not used.
287 * @buf: on return contains the scsi vpd program type.
288 *
289 * Returns: size of formatted string.
290 **/
dea31012005-04-17 16:05:31 -0500291static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100292lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
293 char *buf)
dea31012005-04-17 16:05:31 -0500294{
Tony Jonesee959b02008-02-22 00:13:36 +0100295 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500296 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
297 struct lpfc_hba *phba = vport->phba;
298
dea31012005-04-17 16:05:31 -0500299 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
300}
301
James Smarte59058c2008-08-24 21:49:00 -0400302/**
James Smart3621a712009-04-06 18:47:14 -0400303 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400304 * @dev: class converted to a Scsi_host structure.
305 * @attr: device attribute, not used.
306 * @buf: on return contains the Menlo Maintenance sli flag.
307 *
308 * Returns: size of formatted string.
309 **/
310static ssize_t
311lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
312{
313 struct Scsi_Host *shost = class_to_shost(dev);
314 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
315 struct lpfc_hba *phba = vport->phba;
316
317 return snprintf(buf, PAGE_SIZE, "%d\n",
318 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
319}
320
321/**
James Smart3621a712009-04-06 18:47:14 -0400322 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400323 * @dev: class converted to a Scsi_host structure.
324 * @attr: device attribute, not used.
325 * @buf: on return contains scsi vpd program type.
326 *
327 * Returns: size of formatted string.
328 **/
dea31012005-04-17 16:05:31 -0500329static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100330lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
331 char *buf)
dea31012005-04-17 16:05:31 -0500332{
Tony Jonesee959b02008-02-22 00:13:36 +0100333 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
335 struct lpfc_hba *phba = vport->phba;
336
dea31012005-04-17 16:05:31 -0500337 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
338}
339
James Smarte59058c2008-08-24 21:49:00 -0400340/**
James Smart3621a712009-04-06 18:47:14 -0400341 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400342 * @dev: class converted to a Scsi_host structure.
343 * @attr: device attribute, not used.
344 * @buf: on return contains the scsi vpd program type.
345 *
346 * Returns: size of formatted string.
347 **/
dea31012005-04-17 16:05:31 -0500348static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100349lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
350 char *buf)
dea31012005-04-17 16:05:31 -0500351{
Tony Jonesee959b02008-02-22 00:13:36 +0100352 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500353 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
354 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500355 uint32_t if_type;
356 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500357 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500358 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500359
dea31012005-04-17 16:05:31 -0500360 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500361 if_type = phba->sli4_hba.pc_sli4_params.if_type;
362 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
363
364 if (phba->sli_rev < LPFC_SLI_REV4)
365 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
366 fwrev, phba->sli_rev);
367 else
368 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
369 fwrev, phba->sli_rev, if_type, sli_family);
370
371 return len;
dea31012005-04-17 16:05:31 -0500372}
373
James Smarte59058c2008-08-24 21:49:00 -0400374/**
James Smart3621a712009-04-06 18:47:14 -0400375 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400376 * @dev: class converted to a Scsi_host structure.
377 * @attr: device attribute, not used.
378 * @buf: on return contains the scsi vpd program type.
379 *
380 * Returns: size of formatted string.
381 **/
dea31012005-04-17 16:05:31 -0500382static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100383lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500384{
385 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100386 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
388 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500389 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500390
dea31012005-04-17 16:05:31 -0500391 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
392 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
393}
James Smarte59058c2008-08-24 21:49:00 -0400394
395/**
James Smart3621a712009-04-06 18:47:14 -0400396 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
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 the ROM and FCode ascii strings.
400 *
401 * Returns: size of formatted string.
402 **/
dea31012005-04-17 16:05:31 -0500403static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100404lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
dea31012005-04-17 16:05:31 -0500406{
Tony Jonesee959b02008-02-22 00:13:36 +0100407 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400410 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500411
James Smarta0683bf2015-04-07 15:07:16 -0400412 if (phba->sli_rev < LPFC_SLI_REV4)
413 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
414
415 lpfc_decode_firmware_rev(phba, fwrev, 1);
416 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500417}
James Smarte59058c2008-08-24 21:49:00 -0400418
419/**
James Smart3621a712009-04-06 18:47:14 -0400420 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400421 * @dev: class converted to a Scsi_host structure.
422 * @attr: device attribute, not used.
423 * @buf: on return contains text describing the state of the link.
424 *
425 * Notes:
426 * The switch statement has no default so zero will be returned.
427 *
428 * Returns: size of formatted string.
429 **/
dea31012005-04-17 16:05:31 -0500430static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100431lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
432 char *buf)
dea31012005-04-17 16:05:31 -0500433{
Tony Jonesee959b02008-02-22 00:13:36 +0100434 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500435 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
436 struct lpfc_hba *phba = vport->phba;
437 int len = 0;
438
439 switch (phba->link_state) {
440 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500441 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500442 case LPFC_INIT_START:
443 case LPFC_INIT_MBX_CMDS:
444 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500445 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400446 if (phba->hba_flag & LINK_DISABLED)
447 len += snprintf(buf + len, PAGE_SIZE-len,
448 "Link Down - User disabled\n");
449 else
450 len += snprintf(buf + len, PAGE_SIZE-len,
451 "Link Down\n");
dea31012005-04-17 16:05:31 -0500452 break;
453 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500454 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500455 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400456 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500457
458 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500459 case LPFC_LOCAL_CFG_LINK:
460 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500461 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500462 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500463 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500464 case LPFC_FLOGI:
465 case LPFC_FABRIC_CFG_LINK:
466 case LPFC_NS_REG:
467 case LPFC_NS_QRY:
468 case LPFC_BUILD_DISC_LIST:
469 case LPFC_DISC_AUTH:
470 len += snprintf(buf + len, PAGE_SIZE - len,
471 "Discovery\n");
472 break;
473 case LPFC_VPORT_READY:
474 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
475 break;
476
James Smart92d7f7b2007-06-17 19:56:38 -0500477 case LPFC_VPORT_FAILED:
478 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
479 break;
480
481 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500482 len += snprintf(buf + len, PAGE_SIZE - len,
483 "Unknown\n");
484 break;
485 }
James Smart84774a42008-08-24 21:50:06 -0400486 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
487 len += snprintf(buf + len, PAGE_SIZE-len,
488 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500489 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500490 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500491 len += snprintf(buf + len, PAGE_SIZE-len,
492 " Public Loop\n");
493 else
494 len += snprintf(buf + len, PAGE_SIZE-len,
495 " Private Loop\n");
496 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500497 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500498 len += snprintf(buf + len, PAGE_SIZE-len,
499 " Fabric\n");
500 else
501 len += snprintf(buf + len, PAGE_SIZE-len,
502 " Point-2-Point\n");
503 }
504 }
James Smart2e0fef82007-06-17 19:56:36 -0500505
dea31012005-04-17 16:05:31 -0500506 return len;
507}
508
James Smarte59058c2008-08-24 21:49:00 -0400509/**
James Smart026abb82011-12-13 13:20:45 -0500510 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
511 * @dev: class unused variable.
512 * @attr: device attribute, not used.
513 * @buf: on return contains the module description text.
514 *
515 * Returns: size of formatted string.
516 **/
517static ssize_t
518lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
519 char *buf)
520{
521 struct Scsi_Host *shost = class_to_shost(dev);
522 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
523 struct lpfc_hba *phba = vport->phba;
524
525 if (phba->sli_rev < LPFC_SLI_REV4)
526 return snprintf(buf, PAGE_SIZE, "fc\n");
527
528 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
529 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
530 return snprintf(buf, PAGE_SIZE, "fcoe\n");
531 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
532 return snprintf(buf, PAGE_SIZE, "fc\n");
533 }
534 return snprintf(buf, PAGE_SIZE, "unknown\n");
535}
536
537/**
James Smart1ba981f2014-02-20 09:56:45 -0500538 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
539 * (OAS) is supported.
540 * @dev: class unused variable.
541 * @attr: device attribute, not used.
542 * @buf: on return contains the module description text.
543 *
544 * Returns: size of formatted string.
545 **/
546static ssize_t
547lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
548 char *buf)
549{
550 struct Scsi_Host *shost = class_to_shost(dev);
551 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
552 struct lpfc_hba *phba = vport->phba;
553
554 return snprintf(buf, PAGE_SIZE, "%d\n",
555 phba->sli4_hba.pc_sli4_params.oas_supported);
556}
557
558/**
James Smart84d1b002010-02-12 14:42:33 -0500559 * lpfc_link_state_store - Transition the link_state on an HBA port
560 * @dev: class device that is converted into a Scsi_host.
561 * @attr: device attribute, not used.
562 * @buf: one or more lpfc_polling_flags values.
563 * @count: not used.
564 *
565 * Returns:
566 * -EINVAL if the buffer is not "up" or "down"
567 * return from link state change function if non-zero
568 * length of the buf on success
569 **/
570static ssize_t
571lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
572 const char *buf, size_t count)
573{
574 struct Scsi_Host *shost = class_to_shost(dev);
575 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
576 struct lpfc_hba *phba = vport->phba;
577
578 int status = -EINVAL;
579
580 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
581 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400582 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500583 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
584 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400585 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500586
587 if (status == 0)
588 return strlen(buf);
589 else
590 return status;
591}
592
593/**
James Smart3621a712009-04-06 18:47:14 -0400594 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400595 * @dev: class device that is converted into a Scsi_host.
596 * @attr: device attribute, not used.
597 * @buf: on return contains the sum of fc mapped and unmapped.
598 *
599 * Description:
600 * Returns the ascii text number of the sum of the fc mapped and unmapped
601 * vport counts.
602 *
603 * Returns: size of formatted string.
604 **/
dea31012005-04-17 16:05:31 -0500605static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100606lpfc_num_discovered_ports_show(struct device *dev,
607 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500608{
Tony Jonesee959b02008-02-22 00:13:36 +0100609 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
611
612 return snprintf(buf, PAGE_SIZE, "%d\n",
613 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500614}
615
James Smarte59058c2008-08-24 21:49:00 -0400616/**
James Smart3621a712009-04-06 18:47:14 -0400617 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400618 * @shost: Scsi_Host pointer.
619 *
620 * Description:
621 * Bring the link down gracefully then re-init the link. The firmware will
622 * re-init the fiber channel interface as required. Does not issue a LIP.
623 *
624 * Returns:
625 * -EPERM port offline or management commands are being blocked
626 * -ENOMEM cannot allocate memory for the mailbox command
627 * -EIO error sending the mailbox command
628 * zero for success
629 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700630static int
James Smart2e0fef82007-06-17 19:56:36 -0500631lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500632{
James Smart2e0fef82007-06-17 19:56:36 -0500633 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
634 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500635 LPFC_MBOXQ_t *pmboxq;
636 int mbxstatus = MBXERR_ERROR;
637
James Smarta3adc582018-01-30 15:58:55 -0800638 /*
639 * If the link is offline, disabled or BLOCK_MGMT_IO
640 * it doesn't make any sense to allow issue_lip
641 */
James Smart2e0fef82007-06-17 19:56:36 -0500642 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smarta3adc582018-01-30 15:58:55 -0800643 (phba->hba_flag & LINK_DISABLED) ||
James Smart83108bd2008-01-11 01:53:09 -0500644 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500645 return -EPERM;
646
647 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
648
649 if (!pmboxq)
650 return -ENOMEM;
651
652 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400653 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
654 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400655
James Smart33ccf8d2006-08-17 11:57:58 -0400656 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500657
James Smart04c68492009-05-22 14:52:52 -0400658 if ((mbxstatus == MBX_SUCCESS) &&
659 (pmboxq->u.mb.mbxStatus == 0 ||
660 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400661 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
662 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
663 phba->cfg_link_speed);
664 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
665 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400666 if ((mbxstatus == MBX_SUCCESS) &&
667 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
668 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
669 "2859 SLI authentication is required "
670 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400671 }
672
James Smart5b8bd0c2007-04-25 09:52:49 -0400673 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500674 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400675 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500676
677 if (mbxstatus == MBXERR_ERROR)
678 return -EIO;
679
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700680 return 0;
dea31012005-04-17 16:05:31 -0500681}
682
James Smarte59058c2008-08-24 21:49:00 -0400683/**
James Smart3621a712009-04-06 18:47:14 -0400684 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400685 * @phba: lpfc_hba pointer.
686 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
687 *
688 * Notes:
689 * Assumes any error from lpfc_do_offline() will be negative.
690 * Can wait up to 5 seconds for the port ring buffers count
691 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400692 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400693 *
694 * Returns:
695 * -EIO error posting the event
696 * zero for success
697 **/
James Smart40496f02006-07-06 15:50:22 -0400698static int
James Smart46fa3112007-04-25 09:51:45 -0400699lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
700{
701 struct completion online_compl;
702 struct lpfc_sli_ring *pring;
703 struct lpfc_sli *psli;
704 int status = 0;
705 int cnt = 0;
706 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500707 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400708
709 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500710 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400711 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500712 if (rc == 0)
713 return -ENOMEM;
714
James Smart46fa3112007-04-25 09:51:45 -0400715 wait_for_completion(&online_compl);
716
717 if (status != 0)
718 return -EIO;
719
720 psli = &phba->sli;
721
James Smart09372822008-01-11 01:52:54 -0500722 /* Wait a little for things to settle down, but not
723 * long enough for dev loss timeout to expire.
724 */
James Smart46fa3112007-04-25 09:51:45 -0400725 for (i = 0; i < psli->num_rings; i++) {
726 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500727 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400728 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500729 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400730 lpfc_printf_log(phba,
731 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400732 "0466 Outstanding IO when "
733 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400734 break;
735 }
736 }
737 }
738
739 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500740 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
741 if (rc == 0)
742 return -ENOMEM;
743
James Smart46fa3112007-04-25 09:51:45 -0400744 wait_for_completion(&online_compl);
745
746 if (status != 0)
747 return -EIO;
748
749 return 0;
750}
751
James Smarte59058c2008-08-24 21:49:00 -0400752/**
James Smart3621a712009-04-06 18:47:14 -0400753 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400754 * @phba: lpfc_hba pointer.
755 *
756 * Description:
757 * If the port is configured to allow a reset then the hba is brought
758 * offline then online.
759 *
760 * Notes:
761 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500762 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400763 *
764 * Returns:
765 * lpfc_do_offline() return code if not zero
766 * -EIO reset not configured or error posting the event
767 * zero for success
768 **/
James Smart7f860592011-03-11 16:05:52 -0500769int
James Smart40496f02006-07-06 15:50:22 -0400770lpfc_selective_reset(struct lpfc_hba *phba)
771{
772 struct completion online_compl;
773 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500774 int rc;
James Smart40496f02006-07-06 15:50:22 -0400775
James Smart71157c92013-07-15 18:34:36 -0400776 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400777 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500778
James Smart71157c92013-07-15 18:34:36 -0400779 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
780 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400781
James Smart71157c92013-07-15 18:34:36 -0400782 if (status != 0)
783 return status;
784 }
James Smart40496f02006-07-06 15:50:22 -0400785
786 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500787 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400788 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500789 if (rc == 0)
790 return -ENOMEM;
791
James Smart40496f02006-07-06 15:50:22 -0400792 wait_for_completion(&online_compl);
793
794 if (status != 0)
795 return -EIO;
796
797 return 0;
798}
799
James Smarte59058c2008-08-24 21:49:00 -0400800/**
James Smart3621a712009-04-06 18:47:14 -0400801 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400802 * @dev: class device that is converted into a Scsi_host.
803 * @attr: device attribute, not used.
804 * @buf: containing the string "selective".
805 * @count: unused variable.
806 *
807 * Description:
808 * If the buf contains the string "selective" then lpfc_selective_reset()
809 * is called to perform the reset.
810 *
811 * Notes:
812 * Assumes any error from lpfc_selective_reset() will be negative.
813 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200814 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400815 *
816 * Returns:
817 * -EINVAL if the buffer does not contain the string "selective"
818 * length of buf if lpfc-selective_reset() if the call succeeds
819 * return value of lpfc_selective_reset() if the call fails
820**/
James Smart40496f02006-07-06 15:50:22 -0400821static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100822lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
823 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400824{
Tony Jonesee959b02008-02-22 00:13:36 +0100825 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500826 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
827 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400828 int status = -EINVAL;
829
James Smart73d91e52011-10-10 21:32:10 -0400830 if (!phba->cfg_enable_hba_reset)
831 return -EACCES;
832
James Smart40496f02006-07-06 15:50:22 -0400833 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500834 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400835
836 if (status == 0)
837 return strlen(buf);
838 else
839 return status;
840}
841
James Smarte59058c2008-08-24 21:49:00 -0400842/**
James Smart88a2cfb2011-07-22 18:36:33 -0400843 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
844 * @phba: lpfc_hba pointer.
845 *
846 * Description:
847 * SLI4 interface type-2 device to wait on the sliport status register for
848 * the readyness after performing a firmware reset.
849 *
850 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +0900851 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -0500852 * reset, -EIO when port timeout from recovering from the reset.
853 *
854 * Note:
855 * As the caller will interpret the return code by value, be careful in making
856 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400857 **/
James Smart73d91e52011-10-10 21:32:10 -0400858int
James Smart88a2cfb2011-07-22 18:36:33 -0400859lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
860{
James Smartf7a919b2011-08-21 21:49:16 -0400861 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400862 int i;
863
James Smartf7a919b2011-08-21 21:49:16 -0400864 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400865 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
866 &portstat_reg.word0);
867
Masanari Iida0b1587b2013-07-17 04:37:44 +0900868 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -0400869 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
870 !bf_get(lpfc_sliport_status_err, &portstat_reg))
871 return -EPERM;
872
James Smart88a2cfb2011-07-22 18:36:33 -0400873 /* wait for the SLI port firmware ready after firmware reset */
874 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
875 msleep(10);
876 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
877 &portstat_reg.word0);
878 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
879 continue;
880 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
881 continue;
882 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
883 continue;
884 break;
885 }
886
887 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
888 return 0;
889 else
890 return -EIO;
891}
892
893/**
James Smart52d52442011-05-24 11:42:45 -0400894 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400895 * @phba: lpfc_hba pointer.
896 *
897 * Description:
James Smart52d52442011-05-24 11:42:45 -0400898 * Request SLI4 interface type-2 device to perform a physical register set
899 * access.
James Smartc0c11512011-05-24 11:41:34 -0400900 *
901 * Returns:
902 * zero for success
903 **/
904static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400905lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400906{
907 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400908 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500909 uint32_t before_fc_flag;
910 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400911 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500912 int status = 0, rc = 0;
913 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400914
915 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400916 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400917
James Smart52d52442011-05-24 11:42:45 -0400918 if ((phba->sli_rev < LPFC_SLI_REV4) ||
919 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
920 LPFC_SLI_INTF_IF_TYPE_2))
921 return -EPERM;
922
James Smart026abb82011-12-13 13:20:45 -0500923 /* Keep state if we need to restore back */
924 before_fc_flag = phba->pport->fc_flag;
925 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
926
James Smartb76f2dc2011-07-22 18:37:42 -0400927 /* Disable SR-IOV virtual functions if enabled */
928 if (phba->cfg_sriov_nr_virtfn) {
929 pci_disable_sriov(pdev);
930 phba->cfg_sriov_nr_virtfn = 0;
931 }
James Smart229adb02013-04-17 20:16:51 -0400932
James Smart02936352014-04-04 13:52:12 -0400933 if (opcode == LPFC_FW_DUMP)
934 phba->hba_flag |= HBA_FW_DUMP_OP;
935
James Smartc0c11512011-05-24 11:41:34 -0400936 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
937
James Smart02936352014-04-04 13:52:12 -0400938 if (status != 0) {
939 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -0400940 return status;
James Smart02936352014-04-04 13:52:12 -0400941 }
James Smartc0c11512011-05-24 11:41:34 -0400942
943 /* wait for the device to be quiesced before firmware reset */
944 msleep(100);
945
946 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
947 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400948
949 if (opcode == LPFC_FW_DUMP)
950 reg_val |= LPFC_FW_DUMP_REQUEST;
951 else if (opcode == LPFC_FW_RESET)
952 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
953 else if (opcode == LPFC_DV_RESET)
954 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
955
James Smartc0c11512011-05-24 11:41:34 -0400956 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
957 LPFC_CTL_PDEV_CTL_OFFSET);
958 /* flush */
959 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
960
961 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400962 rc = lpfc_sli4_pdev_status_reg_wait(phba);
963
James Smart026abb82011-12-13 13:20:45 -0500964 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +0900965 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -0500966 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +0900967 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -0500968 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500969 } else if (rc == -EIO) {
970 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500971 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
972 "3153 Fail to perform the requested "
973 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400974 return rc;
James Smart026abb82011-12-13 13:20:45 -0500975 }
976
977 /* keep the original port state */
978 if (before_fc_flag & FC_OFFLINE_MODE)
979 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400980
981 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500982 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
983 LPFC_EVT_ONLINE);
984 if (!job_posted)
985 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400986
987 wait_for_completion(&online_compl);
988
James Smart026abb82011-12-13 13:20:45 -0500989out:
990 /* in any case, restore the virtual functions enabled as before */
991 if (sriov_nr_virtfn) {
992 sriov_err =
993 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
994 if (!sriov_err)
995 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
996 }
James Smartc0c11512011-05-24 11:41:34 -0400997
James Smart026abb82011-12-13 13:20:45 -0500998 /* return proper error code */
999 if (!rc) {
1000 if (!job_posted)
1001 rc = -ENOMEM;
1002 else if (status)
1003 rc = -EIO;
1004 }
1005 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001006}
1007
1008/**
James Smart3621a712009-04-06 18:47:14 -04001009 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001010 * @dev: class device that is converted into a Scsi_host.
1011 * @attr: device attribute, not used.
1012 * @buf: on return contains the ascii number of nport events.
1013 *
1014 * Returns: size of formatted string.
1015 **/
dea31012005-04-17 16:05:31 -05001016static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001017lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1018 char *buf)
dea31012005-04-17 16:05:31 -05001019{
Tony Jonesee959b02008-02-22 00:13:36 +01001020 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001021 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1022 struct lpfc_hba *phba = vport->phba;
1023
dea31012005-04-17 16:05:31 -05001024 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1025}
1026
James Smarte59058c2008-08-24 21:49:00 -04001027/**
James Smart3621a712009-04-06 18:47:14 -04001028 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001029 * @dev: class device that is converted into a Scsi_host.
1030 * @attr: device attribute, not used.
1031 * @buf: on return contains the state of the adapter.
1032 *
1033 * Returns: size of formatted string.
1034 **/
dea31012005-04-17 16:05:31 -05001035static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001036lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1037 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001038{
Tony Jonesee959b02008-02-22 00:13:36 +01001039 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1041 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001042 char * state;
1043
James Smart2e0fef82007-06-17 19:56:36 -05001044 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001045 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001046 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001047 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001048 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001049 state = "offline";
1050 else
1051 state = "online";
1052
1053 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1054}
1055
James Smarte59058c2008-08-24 21:49:00 -04001056/**
James Smart3621a712009-04-06 18:47:14 -04001057 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001058 * @dev: class device that is converted into a Scsi_host.
1059 * @attr: device attribute, not used.
1060 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1061 * @count: unused variable.
1062 *
1063 * Returns:
1064 * -EACCES if enable hba reset not enabled
1065 * -EINVAL if the buffer does not contain a valid string (see above)
1066 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1067 * buf length greater than zero indicates success
1068 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001069static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001070lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1071 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001072{
Tony Jonesee959b02008-02-22 00:13:36 +01001073 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001074 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1075 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001076 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001077 char *board_mode_str = NULL;
1078 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001079 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001080
James Smart026abb82011-12-13 13:20:45 -05001081 if (!phba->cfg_enable_hba_reset) {
1082 status = -EACCES;
1083 goto board_mode_out;
1084 }
James Smart88a2cfb2011-07-22 18:36:33 -04001085
1086 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001087 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001088
Jamie Wellnitz41415862006-02-28 19:25:27 -05001089 init_completion(&online_compl);
1090
James Smart46fa3112007-04-25 09:51:45 -04001091 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001092 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001093 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001094 if (rc == 0) {
1095 status = -ENOMEM;
1096 goto board_mode_out;
1097 }
James Smart46fa3112007-04-25 09:51:45 -04001098 wait_for_completion(&online_compl);
1099 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1100 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001101 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001102 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001103 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001104 else
1105 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001106 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001107 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001108 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001109 else
1110 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001111 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001112 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1113 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1114 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1115 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1116 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001117 else
James Smart026abb82011-12-13 13:20:45 -05001118 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001119
James Smart026abb82011-12-13 13:20:45 -05001120board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001121 if (!status)
1122 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001123 else {
1124 board_mode_str = strchr(buf, '\n');
1125 if (board_mode_str)
1126 *board_mode_str = '\0';
1127 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1128 "3097 Failed \"%s\", status(%d), "
1129 "fc_flag(x%x)\n",
1130 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001131 return status;
James Smart026abb82011-12-13 13:20:45 -05001132 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001133}
1134
James Smarte59058c2008-08-24 21:49:00 -04001135/**
James Smart3621a712009-04-06 18:47:14 -04001136 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001137 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001138 * @mxri: max xri count.
1139 * @axri: available xri count.
1140 * @mrpi: max rpi count.
1141 * @arpi: available rpi count.
1142 * @mvpi: max vpi count.
1143 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001144 *
1145 * Description:
1146 * If an integer pointer for an count is not null then the value for the
1147 * count is returned.
1148 *
1149 * Returns:
1150 * zero on error
1151 * one for success
1152 **/
James Smart311464e2007-08-02 11:10:37 -04001153static int
James Smart858c9f62007-06-17 19:56:39 -05001154lpfc_get_hba_info(struct lpfc_hba *phba,
1155 uint32_t *mxri, uint32_t *axri,
1156 uint32_t *mrpi, uint32_t *arpi,
1157 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001158{
James Smart04c68492009-05-22 14:52:52 -04001159 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001160 LPFC_MBOXQ_t *pmboxq;
1161 MAILBOX_t *pmb;
1162 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001163 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001164
1165 /*
1166 * prevent udev from issuing mailbox commands until the port is
1167 * configured.
1168 */
1169 if (phba->link_state < LPFC_LINK_DOWN ||
1170 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001171 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001172 return 0;
1173
1174 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1175 return 0;
1176
1177 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1178 if (!pmboxq)
1179 return 0;
1180 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1181
James Smart04c68492009-05-22 14:52:52 -04001182 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001183 pmb->mbxCommand = MBX_READ_CONFIG;
1184 pmb->mbxOwner = OWN_HOST;
1185 pmboxq->context1 = NULL;
1186
James Smart75baf692010-06-08 18:31:21 -04001187 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001188 rc = MBX_NOT_FINISHED;
1189 else
1190 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1191
1192 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001193 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001194 mempool_free(pmboxq, phba->mbox_mem_pool);
1195 return 0;
1196 }
1197
James Smartda0436e2009-05-22 14:51:39 -04001198 if (phba->sli_rev == LPFC_SLI_REV4) {
1199 rd_config = &pmboxq->u.mqe.un.rd_config;
1200 if (mrpi)
1201 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1202 if (arpi)
1203 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1204 phba->sli4_hba.max_cfg_param.rpi_used;
1205 if (mxri)
1206 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1207 if (axri)
1208 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1209 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001210
1211 /* Account for differences with SLI-3. Get vpi count from
1212 * mailbox data and subtract one for max vpi value.
1213 */
1214 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1215 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1216
James Smartda0436e2009-05-22 14:51:39 -04001217 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001218 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001219 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001220 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001221 } else {
1222 if (mrpi)
1223 *mrpi = pmb->un.varRdConfig.max_rpi;
1224 if (arpi)
1225 *arpi = pmb->un.varRdConfig.avail_rpi;
1226 if (mxri)
1227 *mxri = pmb->un.varRdConfig.max_xri;
1228 if (axri)
1229 *axri = pmb->un.varRdConfig.avail_xri;
1230 if (mvpi)
1231 *mvpi = pmb->un.varRdConfig.max_vpi;
1232 if (avpi)
1233 *avpi = pmb->un.varRdConfig.avail_vpi;
1234 }
James Smart92d7f7b2007-06-17 19:56:38 -05001235
1236 mempool_free(pmboxq, phba->mbox_mem_pool);
1237 return 1;
1238}
1239
James Smarte59058c2008-08-24 21:49:00 -04001240/**
James Smart3621a712009-04-06 18:47:14 -04001241 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001242 * @dev: class device that is converted into a Scsi_host.
1243 * @attr: device attribute, not used.
1244 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1245 *
1246 * Description:
1247 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1248 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1249 * to "Unknown" and the buffer length is returned, therefore the caller
1250 * must check for "Unknown" in the buffer to detect a failure.
1251 *
1252 * Returns: size of formatted string.
1253 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001254static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001255lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1256 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001257{
Tony Jonesee959b02008-02-22 00:13:36 +01001258 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001259 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1260 struct lpfc_hba *phba = vport->phba;
1261 uint32_t cnt;
1262
James Smart858c9f62007-06-17 19:56:39 -05001263 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001264 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1265 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1266}
1267
James Smarte59058c2008-08-24 21:49:00 -04001268/**
James Smart3621a712009-04-06 18:47:14 -04001269 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001270 * @dev: class device that is converted into a Scsi_host.
1271 * @attr: device attribute, not used.
1272 * @buf: containing the used rpi count in decimal or "Unknown".
1273 *
1274 * Description:
1275 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1276 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1277 * to "Unknown" and the buffer length is returned, therefore the caller
1278 * must check for "Unknown" in the buffer to detect a failure.
1279 *
1280 * Returns: size of formatted string.
1281 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001282static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001283lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1284 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001285{
Tony Jonesee959b02008-02-22 00:13:36 +01001286 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1288 struct lpfc_hba *phba = vport->phba;
1289 uint32_t cnt, acnt;
1290
James Smart858c9f62007-06-17 19:56:39 -05001291 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001292 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1293 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1294}
1295
James Smarte59058c2008-08-24 21:49:00 -04001296/**
James Smart3621a712009-04-06 18:47:14 -04001297 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001298 * @dev: class device that is converted into a Scsi_host.
1299 * @attr: device attribute, not used.
1300 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1301 *
1302 * Description:
1303 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1304 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1305 * to "Unknown" and the buffer length is returned, therefore the caller
1306 * must check for "Unknown" in the buffer to detect a failure.
1307 *
1308 * Returns: size of formatted string.
1309 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001310static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001311lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1312 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001313{
Tony Jonesee959b02008-02-22 00:13:36 +01001314 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001315 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1316 struct lpfc_hba *phba = vport->phba;
1317 uint32_t cnt;
1318
James Smart858c9f62007-06-17 19:56:39 -05001319 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001320 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1321 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1322}
1323
James Smarte59058c2008-08-24 21:49:00 -04001324/**
James Smart3621a712009-04-06 18:47:14 -04001325 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001326 * @dev: class device that is converted into a Scsi_host.
1327 * @attr: device attribute, not used.
1328 * @buf: on return contains the used xri count in decimal or "Unknown".
1329 *
1330 * Description:
1331 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1332 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1333 * to "Unknown" and the buffer length is returned, therefore the caller
1334 * must check for "Unknown" in the buffer to detect a failure.
1335 *
1336 * Returns: size of formatted string.
1337 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001338static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001339lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1340 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001341{
Tony Jonesee959b02008-02-22 00:13:36 +01001342 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1344 struct lpfc_hba *phba = vport->phba;
1345 uint32_t cnt, acnt;
1346
James Smart858c9f62007-06-17 19:56:39 -05001347 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1348 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1349 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1350}
1351
James Smarte59058c2008-08-24 21:49:00 -04001352/**
James Smart3621a712009-04-06 18:47:14 -04001353 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001354 * @dev: class device that is converted into a Scsi_host.
1355 * @attr: device attribute, not used.
1356 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1357 *
1358 * Description:
1359 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1360 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1361 * to "Unknown" and the buffer length is returned, therefore the caller
1362 * must check for "Unknown" in the buffer to detect a failure.
1363 *
1364 * Returns: size of formatted string.
1365 **/
James Smart858c9f62007-06-17 19:56:39 -05001366static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001367lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1368 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001369{
Tony Jonesee959b02008-02-22 00:13:36 +01001370 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1372 struct lpfc_hba *phba = vport->phba;
1373 uint32_t cnt;
1374
1375 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1376 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1377 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1378}
1379
James Smarte59058c2008-08-24 21:49:00 -04001380/**
James Smart3621a712009-04-06 18:47:14 -04001381 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001382 * @dev: class device that is converted into a Scsi_host.
1383 * @attr: device attribute, not used.
1384 * @buf: on return contains the used vpi count in decimal or "Unknown".
1385 *
1386 * Description:
1387 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1388 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1389 * to "Unknown" and the buffer length is returned, therefore the caller
1390 * must check for "Unknown" in the buffer to detect a failure.
1391 *
1392 * Returns: size of formatted string.
1393 **/
James Smart858c9f62007-06-17 19:56:39 -05001394static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001395lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1396 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001397{
Tony Jonesee959b02008-02-22 00:13:36 +01001398 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001399 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1400 struct lpfc_hba *phba = vport->phba;
1401 uint32_t cnt, acnt;
1402
1403 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001404 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1405 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1406}
1407
James Smarte59058c2008-08-24 21:49:00 -04001408/**
James Smart3621a712009-04-06 18:47:14 -04001409 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001410 * @dev: class device that is converted into a Scsi_host.
1411 * @attr: device attribute, not used.
1412 * @buf: text that must be interpreted to determine if npiv is supported.
1413 *
1414 * Description:
1415 * Buffer will contain text indicating npiv is not suppoerted on the port,
1416 * the port is an NPIV physical port, or it is an npiv virtual port with
1417 * the id of the vport.
1418 *
1419 * Returns: size of formatted string.
1420 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001421static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001422lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1423 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001424{
Tony Jonesee959b02008-02-22 00:13:36 +01001425 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001426 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1427 struct lpfc_hba *phba = vport->phba;
1428
1429 if (!(phba->max_vpi))
1430 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1431 if (vport->port_type == LPFC_PHYSICAL_PORT)
1432 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1433 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1434}
1435
James Smarte59058c2008-08-24 21:49:00 -04001436/**
James Smart3621a712009-04-06 18:47:14 -04001437 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001438 * @dev: class device that is converted into a Scsi_host.
1439 * @attr: device attribute, not used.
1440 * @buf: on return contains the cfg_poll in hex.
1441 *
1442 * Notes:
1443 * cfg_poll should be a lpfc_polling_flags type.
1444 *
1445 * Returns: size of formatted string.
1446 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001447static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001448lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1449 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001450{
Tony Jonesee959b02008-02-22 00:13:36 +01001451 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001452 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1453 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001454
1455 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1456}
1457
James Smarte59058c2008-08-24 21:49:00 -04001458/**
James Smart3621a712009-04-06 18:47:14 -04001459 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001460 * @dev: class device that is converted into a Scsi_host.
1461 * @attr: device attribute, not used.
1462 * @buf: one or more lpfc_polling_flags values.
1463 * @count: not used.
1464 *
1465 * Notes:
1466 * buf contents converted to integer and checked for a valid value.
1467 *
1468 * Returns:
1469 * -EINVAL if the buffer connot be converted or is out of range
1470 * length of the buf on success
1471 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001472static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001473lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1474 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001475{
Tony Jonesee959b02008-02-22 00:13:36 +01001476 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001477 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1478 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001479 uint32_t creg_val;
1480 uint32_t old_val;
1481 int val=0;
1482
1483 if (!isdigit(buf[0]))
1484 return -EINVAL;
1485
1486 if (sscanf(buf, "%i", &val) != 1)
1487 return -EINVAL;
1488
1489 if ((val & 0x3) != val)
1490 return -EINVAL;
1491
James Smart45ed1192009-10-02 15:17:02 -04001492 if (phba->sli_rev == LPFC_SLI_REV4)
1493 val = 0;
1494
James Smart88a2cfb2011-07-22 18:36:33 -04001495 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1496 "3051 lpfc_poll changed from %d to %d\n",
1497 phba->cfg_poll, val);
1498
James Smart2e0fef82007-06-17 19:56:36 -05001499 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001500
1501 old_val = phba->cfg_poll;
1502
1503 if (val & ENABLE_FCP_RING_POLLING) {
1504 if ((val & DISABLE_FCP_RING_INT) &&
1505 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001506 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1507 spin_unlock_irq(&phba->hbalock);
1508 return -EINVAL;
1509 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001510 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1511 writel(creg_val, phba->HCregaddr);
1512 readl(phba->HCregaddr); /* flush */
1513
1514 lpfc_poll_start_timer(phba);
1515 }
1516 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001517 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001518 return -EINVAL;
1519 }
1520
1521 if (!(val & DISABLE_FCP_RING_INT) &&
1522 (old_val & DISABLE_FCP_RING_INT))
1523 {
James Smart2e0fef82007-06-17 19:56:36 -05001524 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001525 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001526 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001527 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1528 spin_unlock_irq(&phba->hbalock);
1529 return -EINVAL;
1530 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001531 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1532 writel(creg_val, phba->HCregaddr);
1533 readl(phba->HCregaddr); /* flush */
1534 }
1535
1536 phba->cfg_poll = val;
1537
James Smart2e0fef82007-06-17 19:56:36 -05001538 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001539
1540 return strlen(buf);
1541}
dea31012005-04-17 16:05:31 -05001542
James Smarte59058c2008-08-24 21:49:00 -04001543/**
James Smartbc739052010-08-04 16:11:18 -04001544 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1545 * @dev: class unused variable.
1546 * @attr: device attribute, not used.
1547 * @buf: on return contains the module description text.
1548 *
1549 * Returns: size of formatted string.
1550 **/
1551static ssize_t
1552lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1553 char *buf)
1554{
1555 struct Scsi_Host *shost = class_to_shost(dev);
1556 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1557 struct lpfc_hba *phba = vport->phba;
1558
1559 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1560}
1561
1562/**
1563 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1564 * @dev: class unused variable.
1565 * @attr: device attribute, not used.
1566 * @buf: on return contains the module description text.
1567 *
1568 * Returns: size of formatted string.
1569 **/
1570static ssize_t
1571lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1572 char *buf)
1573{
1574 struct Scsi_Host *shost = class_to_shost(dev);
1575 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1576 struct lpfc_hba *phba = vport->phba;
1577
1578 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1579}
1580
1581/**
James Smartab56dc22011-02-16 12:39:57 -05001582 * lpfc_dss_show - Return the current state of dss and the configured state
1583 * @dev: class converted to a Scsi_host structure.
1584 * @attr: device attribute, not used.
1585 * @buf: on return contains the formatted text.
1586 *
1587 * Returns: size of formatted string.
1588 **/
1589static ssize_t
1590lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1591 char *buf)
1592{
1593 struct Scsi_Host *shost = class_to_shost(dev);
1594 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1595 struct lpfc_hba *phba = vport->phba;
1596
1597 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1598 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1599 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1600 "" : "Not ");
1601}
1602
1603/**
James Smart912e3ac2011-05-24 11:42:11 -04001604 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1605 * @dev: class converted to a Scsi_host structure.
1606 * @attr: device attribute, not used.
1607 * @buf: on return contains the formatted support level.
1608 *
1609 * Description:
1610 * Returns the maximum number of virtual functions a physical function can
1611 * support, 0 will be returned if called on virtual function.
1612 *
1613 * Returns: size of formatted string.
1614 **/
1615static ssize_t
1616lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1617 struct device_attribute *attr,
1618 char *buf)
1619{
1620 struct Scsi_Host *shost = class_to_shost(dev);
1621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1622 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001623 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001624
James Smart0a96e972011-07-22 18:37:28 -04001625 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1626 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001627}
1628
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001629static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1630{
1631 return val >= min && val <= max;
1632}
1633
James Smart912e3ac2011-05-24 11:42:11 -04001634/**
James Smart3621a712009-04-06 18:47:14 -04001635 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001636 *
1637 * Description:
1638 * Macro that given an attr e.g. hba_queue_depth expands
1639 * into a function with the name lpfc_hba_queue_depth_show.
1640 *
1641 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1642 * @dev: class device that is converted into a Scsi_host.
1643 * @attr: device attribute, not used.
1644 * @buf: on return contains the attribute value in decimal.
1645 *
1646 * Returns: size of formatted string.
1647 **/
dea31012005-04-17 16:05:31 -05001648#define lpfc_param_show(attr) \
1649static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001650lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1651 char *buf) \
dea31012005-04-17 16:05:31 -05001652{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001653 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001654 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1655 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001656 return snprintf(buf, PAGE_SIZE, "%d\n",\
1657 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001658}
1659
James Smarte59058c2008-08-24 21:49:00 -04001660/**
James Smart3621a712009-04-06 18:47:14 -04001661 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001662 *
1663 * Description:
1664 * Macro that given an attr e.g. hba_queue_depth expands
1665 * into a function with the name lpfc_hba_queue_depth_show
1666 *
1667 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1668 * @dev: class device that is converted into a Scsi_host.
1669 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001670 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001671 *
1672 * Returns: size of formatted string.
1673 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001674#define lpfc_param_hex_show(attr) \
1675static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001676lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1677 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001678{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001679 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1681 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001682 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001683 val = phba->cfg_##attr;\
1684 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1685 phba->cfg_##attr);\
1686}
1687
James Smarte59058c2008-08-24 21:49:00 -04001688/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001689 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001690 *
1691 * Description:
1692 * Macro that given an attr e.g. hba_queue_depth expands
1693 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1694 * takes a default argument, a minimum and maximum argument.
1695 *
1696 * lpfc_##attr##_init: Initializes an attribute.
1697 * @phba: pointer the the adapter structure.
1698 * @val: integer attribute value.
1699 *
1700 * Validates the min and max values then sets the adapter config field
1701 * accordingly, or uses the default if out of range and prints an error message.
1702 *
1703 * Returns:
1704 * zero on success
1705 * -EINVAL if default used
1706 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001707#define lpfc_param_init(attr, default, minval, maxval) \
1708static int \
James Smart84d1b002010-02-12 14:42:33 -05001709lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001710{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001711 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001712 phba->cfg_##attr = val;\
1713 return 0;\
1714 }\
1715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001716 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1717 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001718 phba->cfg_##attr = default;\
1719 return -EINVAL;\
1720}
1721
James Smarte59058c2008-08-24 21:49:00 -04001722/**
James Smart3621a712009-04-06 18:47:14 -04001723 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001724 *
1725 * Description:
1726 * Macro that given an attr e.g. hba_queue_depth expands
1727 * into a function with the name lpfc_hba_queue_depth_set
1728 *
1729 * lpfc_##attr##_set: Sets an attribute value.
1730 * @phba: pointer the the adapter structure.
1731 * @val: integer attribute value.
1732 *
1733 * Description:
1734 * Validates the min and max values then sets the
1735 * adapter config field if in the valid range. prints error message
1736 * and does not set the parameter if invalid.
1737 *
1738 * Returns:
1739 * zero on success
1740 * -EINVAL if val is invalid
1741 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001742#define lpfc_param_set(attr, default, minval, maxval) \
1743static int \
James Smart84d1b002010-02-12 14:42:33 -05001744lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001745{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001746 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1748 "3052 lpfc_" #attr " changed from %d to %d\n", \
1749 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001750 phba->cfg_##attr = val;\
1751 return 0;\
1752 }\
1753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001754 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1755 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001756 return -EINVAL;\
1757}
1758
James Smarte59058c2008-08-24 21:49:00 -04001759/**
James Smart3621a712009-04-06 18:47:14 -04001760 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001761 *
1762 * Description:
1763 * Macro that given an attr e.g. hba_queue_depth expands
1764 * into a function with the name lpfc_hba_queue_depth_store.
1765 *
1766 * lpfc_##attr##_store: Set an sttribute value.
1767 * @dev: class device that is converted into a Scsi_host.
1768 * @attr: device attribute, not used.
1769 * @buf: contains the attribute value in ascii.
1770 * @count: not used.
1771 *
1772 * Description:
1773 * Convert the ascii text number to an integer, then
1774 * use the lpfc_##attr##_set function to set the value.
1775 *
1776 * Returns:
1777 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1778 * length of buffer upon success.
1779 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001780#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001781static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001782lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1783 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001784{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001785 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001786 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1787 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001788 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001789 if (!isdigit(buf[0]))\
1790 return -EINVAL;\
1791 if (sscanf(buf, "%i", &val) != 1)\
1792 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001793 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001794 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001795 else \
1796 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001797}
1798
James Smarte59058c2008-08-24 21:49:00 -04001799/**
James Smart3621a712009-04-06 18:47:14 -04001800 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001801 *
1802 * Description:
1803 * Macro that given an attr e.g. hba_queue_depth expands
1804 * into a function with the name lpfc_hba_queue_depth_show
1805 *
1806 * lpfc_##attr##_show: prints the attribute value in decimal.
1807 * @dev: class device that is converted into a Scsi_host.
1808 * @attr: device attribute, not used.
1809 * @buf: on return contains the attribute value in decimal.
1810 *
1811 * Returns: length of formatted string.
1812 **/
James Smart3de2a652007-08-02 11:09:59 -04001813#define lpfc_vport_param_show(attr) \
1814static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001815lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1816 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001817{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001818 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001819 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001820 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1821}
1822
James Smarte59058c2008-08-24 21:49:00 -04001823/**
James Smart3621a712009-04-06 18:47:14 -04001824 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001825 *
1826 * Description:
1827 * Macro that given an attr e.g.
1828 * hba_queue_depth expands into a function with the name
1829 * lpfc_hba_queue_depth_show
1830 *
James Smart3621a712009-04-06 18:47:14 -04001831 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001832 * @dev: class device that is converted into a Scsi_host.
1833 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001834 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001835 *
1836 * Returns: length of formatted string.
1837 **/
James Smart3de2a652007-08-02 11:09:59 -04001838#define lpfc_vport_param_hex_show(attr) \
1839static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001840lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1841 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001842{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001843 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001844 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001845 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1846}
1847
James Smarte59058c2008-08-24 21:49:00 -04001848/**
James Smart3621a712009-04-06 18:47:14 -04001849 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001850 *
1851 * Description:
1852 * Macro that given an attr e.g. hba_queue_depth expands
1853 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1854 * takes a default argument, a minimum and maximum argument.
1855 *
1856 * lpfc_##attr##_init: validates the min and max values then sets the
1857 * adapter config field accordingly, or uses the default if out of range
1858 * and prints an error message.
1859 * @phba: pointer the the adapter structure.
1860 * @val: integer attribute value.
1861 *
1862 * Returns:
1863 * zero on success
1864 * -EINVAL if default used
1865 **/
James Smart3de2a652007-08-02 11:09:59 -04001866#define lpfc_vport_param_init(attr, default, minval, maxval) \
1867static int \
James Smart84d1b002010-02-12 14:42:33 -05001868lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001869{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001870 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04001871 vport->cfg_##attr = val;\
1872 return 0;\
1873 }\
James Smarte8b62012007-08-02 11:10:09 -04001874 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001875 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001876 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001877 vport->cfg_##attr = default;\
1878 return -EINVAL;\
1879}
1880
James Smarte59058c2008-08-24 21:49:00 -04001881/**
James Smart3621a712009-04-06 18:47:14 -04001882 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001883 *
1884 * Description:
1885 * Macro that given an attr e.g. hba_queue_depth expands
1886 * into a function with the name lpfc_hba_queue_depth_set
1887 *
1888 * lpfc_##attr##_set: validates the min and max values then sets the
1889 * adapter config field if in the valid range. prints error message
1890 * and does not set the parameter if invalid.
1891 * @phba: pointer the the adapter structure.
1892 * @val: integer attribute value.
1893 *
1894 * Returns:
1895 * zero on success
1896 * -EINVAL if val is invalid
1897 **/
James Smart3de2a652007-08-02 11:09:59 -04001898#define lpfc_vport_param_set(attr, default, minval, maxval) \
1899static int \
James Smart84d1b002010-02-12 14:42:33 -05001900lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001901{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001902 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001903 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04001904 "3053 lpfc_" #attr \
1905 " changed from %d (x%x) to %d (x%x)\n", \
1906 vport->cfg_##attr, vport->cfg_##attr, \
1907 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04001908 vport->cfg_##attr = val;\
1909 return 0;\
1910 }\
James Smarte8b62012007-08-02 11:10:09 -04001911 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001912 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001913 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001914 return -EINVAL;\
1915}
1916
James Smarte59058c2008-08-24 21:49:00 -04001917/**
James Smart3621a712009-04-06 18:47:14 -04001918 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001919 *
1920 * Description:
1921 * Macro that given an attr e.g. hba_queue_depth
1922 * expands into a function with the name lpfc_hba_queue_depth_store
1923 *
1924 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1925 * use the lpfc_##attr##_set function to set the value.
1926 * @cdev: class device that is converted into a Scsi_host.
1927 * @buf: contains the attribute value in decimal.
1928 * @count: not used.
1929 *
1930 * Returns:
1931 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1932 * length of buffer upon success.
1933 **/
James Smart3de2a652007-08-02 11:09:59 -04001934#define lpfc_vport_param_store(attr) \
1935static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001936lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1937 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001938{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001939 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001940 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001941 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001942 if (!isdigit(buf[0]))\
1943 return -EINVAL;\
1944 if (sscanf(buf, "%i", &val) != 1)\
1945 return -EINVAL;\
1946 if (lpfc_##attr##_set(vport, val) == 0) \
1947 return strlen(buf);\
1948 else \
1949 return -EINVAL;\
1950}
1951
1952
James Smart81301a92008-12-04 22:39:46 -05001953static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1954static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1955static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1956static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001957static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1958static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1959static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1960static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1961static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1962static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1963static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1964static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001965static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1966 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001967static DEVICE_ATTR(option_rom_version, S_IRUGO,
1968 lpfc_option_rom_version_show, NULL);
1969static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1970 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001971static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001972static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1973static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001974static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001975static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1976 lpfc_board_mode_show, lpfc_board_mode_store);
1977static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1978static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1979static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1980static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1981static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1982static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1983static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1984static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1985static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001986static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1987static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001988static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001989static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1990 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05001991static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05001992static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
1993 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001994
James Smarta12e07b2006-12-02 13:35:30 -05001995static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05001996#define WWN_SZ 8
1997/**
1998 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
1999 * @buf: WWN string.
2000 * @cnt: Length of string.
2001 * @wwn: Array to receive converted wwn value.
2002 *
2003 * Returns:
2004 * -EINVAL if the buffer does not contain a valid wwn
2005 * 0 success
2006 **/
2007static size_t
2008lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2009{
2010 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002011
James Smart1ba981f2014-02-20 09:56:45 -05002012 /* Count may include a LF at end of string */
2013 if (buf[cnt-1] == '\n')
2014 cnt--;
2015
2016 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2017 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2018 return -EINVAL;
2019
2020 memset(wwn, 0, WWN_SZ);
2021
2022 /* Validate and store the new name */
2023 for (i = 0, j = 0; i < 16; i++) {
2024 if ((*buf >= 'a') && (*buf <= 'f'))
2025 j = ((j << 4) | ((*buf++ - 'a') + 10));
2026 else if ((*buf >= 'A') && (*buf <= 'F'))
2027 j = ((j << 4) | ((*buf++ - 'A') + 10));
2028 else if ((*buf >= '0') && (*buf <= '9'))
2029 j = ((j << 4) | (*buf++ - '0'));
2030 else
2031 return -EINVAL;
2032 if (i % 2) {
2033 wwn[i/2] = j & 0xff;
2034 j = 0;
2035 }
2036 }
2037 return 0;
2038}
James Smarte59058c2008-08-24 21:49:00 -04002039/**
James Smart3621a712009-04-06 18:47:14 -04002040 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002041 * @dev: class device that is converted into a Scsi_host.
2042 * @attr: device attribute, not used.
2043 * @buf: containing the string lpfc_soft_wwn_key.
2044 * @count: must be size of lpfc_soft_wwn_key.
2045 *
2046 * Returns:
2047 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2048 * length of buf indicates success
2049 **/
James Smartc3f28af2006-08-18 17:47:18 -04002050static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002051lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2052 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002053{
Tony Jonesee959b02008-02-22 00:13:36 +01002054 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002055 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2056 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002057 unsigned int cnt = count;
2058
2059 /*
2060 * We're doing a simple sanity check for soft_wwpn setting.
2061 * We require that the user write a specific key to enable
2062 * the soft_wwpn attribute to be settable. Once the attribute
2063 * is written, the enable key resets. If further updates are
2064 * desired, the key must be written again to re-enable the
2065 * attribute.
2066 *
2067 * The "key" is not secret - it is a hardcoded string shown
2068 * here. The intent is to protect against the random user or
2069 * application that is just writing attributes.
2070 */
2071
2072 /* count may include a LF at end of string */
2073 if (buf[cnt-1] == '\n')
2074 cnt--;
2075
James Smarta12e07b2006-12-02 13:35:30 -05002076 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2077 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002078 return -EINVAL;
2079
James Smarta12e07b2006-12-02 13:35:30 -05002080 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002081 return count;
2082}
Tony Jonesee959b02008-02-22 00:13:36 +01002083static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2084 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002085
James Smarte59058c2008-08-24 21:49:00 -04002086/**
James Smart3621a712009-04-06 18:47:14 -04002087 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002088 * @dev: class device that is converted into a Scsi_host.
2089 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002090 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002091 *
2092 * Returns: size of formatted string.
2093 **/
James Smartc3f28af2006-08-18 17:47:18 -04002094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002095lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2096 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002097{
Tony Jonesee959b02008-02-22 00:13:36 +01002098 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002099 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2100 struct lpfc_hba *phba = vport->phba;
2101
Randy Dunlapafc071e2006-10-23 21:47:13 -07002102 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2103 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002104}
2105
James Smarte59058c2008-08-24 21:49:00 -04002106/**
James Smart3621a712009-04-06 18:47:14 -04002107 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002108 * @dev class device that is converted into a Scsi_host.
2109 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002110 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002111 * @count: number of wwpn bytes in buf
2112 *
2113 * Returns:
2114 * -EACCES hba reset not enabled, adapter over temp
2115 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2116 * -EIO error taking adapter offline or online
2117 * value of count on success
2118 **/
James Smartc3f28af2006-08-18 17:47:18 -04002119static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002120lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2121 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002122{
Tony Jonesee959b02008-02-22 00:13:36 +01002123 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002124 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2125 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002126 struct completion online_compl;
James Smart1ba981f2014-02-20 09:56:45 -05002127 int stat1 = 0, stat2 = 0;
2128 unsigned int cnt = count;
2129 u8 wwpn[WWN_SZ];
James Smartfedd3b72011-02-16 12:39:24 -05002130 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002131
James Smart13815c82008-01-11 01:52:48 -05002132 if (!phba->cfg_enable_hba_reset)
2133 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002134 spin_lock_irq(&phba->hbalock);
2135 if (phba->over_temp_state == HBA_OVER_TEMP) {
2136 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002137 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002138 }
2139 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002140 /* count may include a LF at end of string */
2141 if (buf[cnt-1] == '\n')
2142 cnt--;
2143
James Smart1ba981f2014-02-20 09:56:45 -05002144 if (!phba->soft_wwn_enable)
James Smartc3f28af2006-08-18 17:47:18 -04002145 return -EINVAL;
2146
James Smart1ba981f2014-02-20 09:56:45 -05002147 /* lock setting wwpn, wwnn down */
James Smarta12e07b2006-12-02 13:35:30 -05002148 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002149
James Smart1ba981f2014-02-20 09:56:45 -05002150 rc = lpfc_wwn_set(buf, cnt, wwpn);
2151 if (!rc) {
2152 /* not able to set wwpn, unlock it */
2153 phba->soft_wwn_enable = 1;
2154 return rc;
James Smartc3f28af2006-08-18 17:47:18 -04002155 }
James Smart1ba981f2014-02-20 09:56:45 -05002156
James Smartc3f28af2006-08-18 17:47:18 -04002157 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002158 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002159 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002160 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002161
2162 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2163 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2164
James Smart46fa3112007-04-25 09:51:45 -04002165 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002166 if (stat1)
2167 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002168 "0463 lpfc_soft_wwpn attribute set failed to "
2169 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002170 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002171 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2172 LPFC_EVT_ONLINE);
2173 if (rc == 0)
2174 return -ENOMEM;
2175
James Smartc3f28af2006-08-18 17:47:18 -04002176 wait_for_completion(&online_compl);
2177 if (stat2)
2178 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002179 "0464 lpfc_soft_wwpn attribute set failed to "
2180 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002181 return (stat1 || stat2) ? -EIO : count;
2182}
James Smart1ba981f2014-02-20 09:56:45 -05002183static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002184 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002185
James Smarte59058c2008-08-24 21:49:00 -04002186/**
James Smart3621a712009-04-06 18:47:14 -04002187 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002188 * @dev: class device that is converted into a Scsi_host.
2189 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002190 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002191 *
2192 * Returns: size of formatted string.
2193 **/
James Smarta12e07b2006-12-02 13:35:30 -05002194static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002195lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2196 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002197{
Tony Jonesee959b02008-02-22 00:13:36 +01002198 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002199 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002200 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2201 (unsigned long long)phba->cfg_soft_wwnn);
2202}
2203
James Smarte59058c2008-08-24 21:49:00 -04002204/**
James Smart3621a712009-04-06 18:47:14 -04002205 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002206 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002207 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002208 * @count: number of wwnn bytes in buf.
2209 *
2210 * Returns:
2211 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2212 * value of count on success
2213 **/
James Smarta12e07b2006-12-02 13:35:30 -05002214static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002215lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2216 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002217{
Tony Jonesee959b02008-02-22 00:13:36 +01002218 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002219 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart1ba981f2014-02-20 09:56:45 -05002220 unsigned int cnt = count;
2221 u8 wwnn[WWN_SZ];
2222 int rc;
James Smarta12e07b2006-12-02 13:35:30 -05002223
2224 /* count may include a LF at end of string */
2225 if (buf[cnt-1] == '\n')
2226 cnt--;
2227
James Smart1ba981f2014-02-20 09:56:45 -05002228 if (!phba->soft_wwn_enable)
James Smarta12e07b2006-12-02 13:35:30 -05002229 return -EINVAL;
2230
James Smart1ba981f2014-02-20 09:56:45 -05002231 rc = lpfc_wwn_set(buf, cnt, wwnn);
2232 if (!rc) {
2233 /* Allow wwnn to be set many times, as long as the enable
2234 * is set. However, once the wwpn is set, everything locks.
2235 */
2236 return rc;
James Smarta12e07b2006-12-02 13:35:30 -05002237 }
James Smart1ba981f2014-02-20 09:56:45 -05002238
James Smarta12e07b2006-12-02 13:35:30 -05002239 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2240
2241 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2242 "lpfc%d: soft_wwnn set. Value will take effect upon "
2243 "setting of the soft_wwpn\n", phba->brd_no);
2244
2245 return count;
2246}
James Smart1ba981f2014-02-20 09:56:45 -05002247static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002248 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002249
James Smart1ba981f2014-02-20 09:56:45 -05002250/**
2251 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2252 * Optimized Access Storage (OAS) operations.
2253 * @dev: class device that is converted into a Scsi_host.
2254 * @attr: device attribute, not used.
2255 * @buf: buffer for passing information.
2256 *
2257 * Returns:
2258 * value of count
2259 **/
2260static ssize_t
2261lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2262 char *buf)
2263{
2264 struct Scsi_Host *shost = class_to_shost(dev);
2265 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2266
2267 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2268 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2269}
2270
2271/**
2272 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2273 * Optimized Access Storage (OAS) operations.
2274 * @dev: class device that is converted into a Scsi_host.
2275 * @attr: device attribute, not used.
2276 * @buf: buffer for passing information.
2277 * @count: Size of the data buffer.
2278 *
2279 * Returns:
2280 * -EINVAL count is invalid, invalid wwpn byte invalid
2281 * -EPERM oas is not supported by hba
2282 * value of count on success
2283 **/
2284static ssize_t
2285lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2286 const char *buf, size_t count)
2287{
2288 struct Scsi_Host *shost = class_to_shost(dev);
2289 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2290 unsigned int cnt = count;
2291 uint8_t wwpn[WWN_SZ];
2292 int rc;
2293
James Smartf38fa0b2014-04-04 13:52:21 -04002294 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002295 return -EPERM;
2296
2297 /* count may include a LF at end of string */
2298 if (buf[cnt-1] == '\n')
2299 cnt--;
2300
2301 rc = lpfc_wwn_set(buf, cnt, wwpn);
2302 if (rc)
2303 return rc;
2304
2305 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2306 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2307 if (wwn_to_u64(wwpn) == 0)
2308 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2309 else
2310 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2311 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2312 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2313 return count;
2314}
2315static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2316 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2317
2318/**
James Smartc92c8412016-07-06 12:36:05 -07002319 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2320 * Optimized Access Storage (OAS) operations.
2321 * @dev: class device that is converted into a Scsi_host.
2322 * @attr: device attribute, not used.
2323 * @buf: buffer for passing information.
2324 *
2325 * Returns:
2326 * value of count
2327 **/
2328static ssize_t
2329lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2330 char *buf)
2331{
2332 struct Scsi_Host *shost = class_to_shost(dev);
2333 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2334
2335 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2336}
2337
2338/**
2339 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2340 * Optimized Access Storage (OAS) operations.
2341 * @dev: class device that is converted into a Scsi_host.
2342 * @attr: device attribute, not used.
2343 * @buf: buffer for passing information.
2344 * @count: Size of the data buffer.
2345 *
2346 * Returns:
2347 * -EINVAL count is invalid, invalid wwpn byte invalid
2348 * -EPERM oas is not supported by hba
2349 * value of count on success
2350 **/
2351static ssize_t
2352lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2353 const char *buf, size_t count)
2354{
2355 struct Scsi_Host *shost = class_to_shost(dev);
2356 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2357 unsigned int cnt = count;
2358 unsigned long val;
2359 int ret;
2360
2361 if (!phba->cfg_fof)
2362 return -EPERM;
2363
2364 /* count may include a LF at end of string */
2365 if (buf[cnt-1] == '\n')
2366 cnt--;
2367
2368 ret = kstrtoul(buf, 0, &val);
2369 if (ret || (val > 0x7f))
2370 return -EINVAL;
2371
2372 if (val)
2373 phba->cfg_oas_priority = (uint8_t)val;
2374 else
2375 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2376 return count;
2377}
2378static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2379 lpfc_oas_priority_show, lpfc_oas_priority_store);
2380
2381/**
James Smart1ba981f2014-02-20 09:56:45 -05002382 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2383 * for Optimized Access Storage (OAS) operations.
2384 * @dev: class device that is converted into a Scsi_host.
2385 * @attr: device attribute, not used.
2386 * @buf: buffer for passing information.
2387 *
2388 * Returns:
2389 * value of count on success
2390 **/
2391static ssize_t
2392lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2393 char *buf)
2394{
2395 struct Scsi_Host *shost = class_to_shost(dev);
2396 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2397
2398 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2399 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2400}
2401
2402/**
2403 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2404 * for Optimized Access Storage (OAS) operations.
2405 * @dev: class device that is converted into a Scsi_host.
2406 * @attr: device attribute, not used.
2407 * @buf: buffer for passing information.
2408 * @count: Size of the data buffer.
2409 *
2410 * Returns:
2411 * -EINVAL count is invalid, invalid wwpn byte invalid
2412 * -EPERM oas is not supported by hba
2413 * value of count on success
2414 **/
2415static ssize_t
2416lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2417 const char *buf, size_t count)
2418{
2419 struct Scsi_Host *shost = class_to_shost(dev);
2420 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2421 unsigned int cnt = count;
2422 uint8_t wwpn[WWN_SZ];
2423 int rc;
2424
James Smartf38fa0b2014-04-04 13:52:21 -04002425 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002426 return -EPERM;
2427
2428 /* count may include a LF at end of string */
2429 if (buf[cnt-1] == '\n')
2430 cnt--;
2431
2432 rc = lpfc_wwn_set(buf, cnt, wwpn);
2433 if (rc)
2434 return rc;
2435
2436 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2437 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2438 if (wwn_to_u64(wwpn) == 0)
2439 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2440 else
2441 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2442 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartc92c8412016-07-06 12:36:05 -07002443 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002444 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2445 return count;
2446}
2447static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2448 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2449
2450/**
2451 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2452 * of whether luns will be enabled or disabled
2453 * for Optimized Access Storage (OAS) operations.
2454 * @dev: class device that is converted into a Scsi_host.
2455 * @attr: device attribute, not used.
2456 * @buf: buffer for passing information.
2457 *
2458 * Returns:
2459 * size of formatted string.
2460 **/
2461static ssize_t
2462lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2463 char *buf)
2464{
2465 struct Scsi_Host *shost = class_to_shost(dev);
2466 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2467
2468 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2469}
2470
2471/**
2472 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2473 * of whether luns will be enabled or disabled
2474 * for Optimized Access Storage (OAS) operations.
2475 * @dev: class device that is converted into a Scsi_host.
2476 * @attr: device attribute, not used.
2477 * @buf: buffer for passing information.
2478 * @count: Size of the data buffer.
2479 *
2480 * Returns:
2481 * -EINVAL count is invalid, invalid wwpn byte invalid
2482 * -EPERM oas is not supported by hba
2483 * value of count on success
2484 **/
2485static ssize_t
2486lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2487 const char *buf, size_t count)
2488{
2489 struct Scsi_Host *shost = class_to_shost(dev);
2490 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2491 int val = 0;
2492
James Smartf38fa0b2014-04-04 13:52:21 -04002493 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002494 return -EPERM;
2495
2496 if (!isdigit(buf[0]))
2497 return -EINVAL;
2498
2499 if (sscanf(buf, "%i", &val) != 1)
2500 return -EINVAL;
2501
2502 if ((val != 0) && (val != 1))
2503 return -EINVAL;
2504
2505 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002506 return strlen(buf);
2507}
2508static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2509 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2510
2511/**
2512 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2513 * Storage (OAS) lun returned by the
2514 * lpfc_oas_lun_show function.
2515 * @dev: class device that is converted into a Scsi_host.
2516 * @attr: device attribute, not used.
2517 * @buf: buffer for passing information.
2518 *
2519 * Returns:
2520 * size of formatted string.
2521 **/
2522static ssize_t
2523lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2524 char *buf)
2525{
2526 struct Scsi_Host *shost = class_to_shost(dev);
2527 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2528
2529 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2530 return -EFAULT;
2531
2532 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2533}
2534static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2535 lpfc_oas_lun_status_show, NULL);
2536
2537
2538/**
2539 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2540 * (OAS) operations.
2541 * @phba: lpfc_hba pointer.
2542 * @ndlp: pointer to fcp target node.
2543 * @lun: the fc lun for setting oas state.
2544 * @oas_state: the oas state to be set to the lun.
2545 *
2546 * Returns:
2547 * SUCCESS : 0
2548 * -EPERM OAS is not enabled or not supported by this port.
2549 *
2550 */
2551static size_t
2552lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002553 uint8_t tgt_wwpn[], uint64_t lun,
2554 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002555{
2556
2557 int rc = 0;
2558
James Smartf38fa0b2014-04-04 13:52:21 -04002559 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002560 return -EPERM;
2561
2562 if (oas_state) {
2563 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002564 (struct lpfc_name *)tgt_wwpn,
2565 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002566 rc = -ENOMEM;
2567 } else {
2568 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2569 (struct lpfc_name *)tgt_wwpn, lun);
2570 }
2571 return rc;
2572
2573}
2574
2575/**
2576 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2577 * Access Storage (OAS) operations.
2578 * @phba: lpfc_hba pointer.
2579 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2580 * @tgt_wwpn: wwpn of the target associated with the returned lun
2581 * @lun_status: status of the lun returned lun
2582 *
2583 * Returns the first or next lun enabled for OAS operations for the vport/target
2584 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2585 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2586 *
2587 * Return:
2588 * lun that is OAS enabled for the vport/target
2589 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2590 */
2591static uint64_t
2592lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2593 uint8_t tgt_wwpn[], uint32_t *lun_status)
2594{
2595 uint64_t found_lun;
2596
2597 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2598 return NOT_OAS_ENABLED_LUN;
2599 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2600 phba->sli4_hba.oas_next_vpt_wwpn,
2601 (struct lpfc_name *)
2602 phba->sli4_hba.oas_next_tgt_wwpn,
2603 &phba->sli4_hba.oas_next_lun,
2604 (struct lpfc_name *)vpt_wwpn,
2605 (struct lpfc_name *)tgt_wwpn,
2606 &found_lun, lun_status))
2607 return found_lun;
2608 else
2609 return NOT_OAS_ENABLED_LUN;
2610}
2611
2612/**
2613 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2614 * @phba: lpfc_hba pointer.
2615 * @vpt_wwpn: vport wwpn by reference.
2616 * @tgt_wwpn: target wwpn by reference.
2617 * @lun: the fc lun for setting oas state.
2618 * @oas_state: the oas state to be set to the oas_lun.
2619 *
2620 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2621 * a lun for OAS operations.
2622 *
2623 * Return:
2624 * SUCCESS: 0
2625 * -ENOMEM: failed to enable an lun for OAS operations
2626 * -EPERM: OAS is not enabled
2627 */
2628static ssize_t
2629lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2630 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002631 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002632{
2633
2634 int rc;
2635
2636 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002637 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002638 return rc;
2639}
2640
2641/**
2642 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2643 * @dev: class device that is converted into a Scsi_host.
2644 * @attr: device attribute, not used.
2645 * @buf: buffer for passing information.
2646 *
2647 * This routine returns a lun enabled for OAS each time the function
2648 * is called.
2649 *
2650 * Returns:
2651 * SUCCESS: size of formatted string.
2652 * -EFAULT: target or vport wwpn was not set properly.
2653 * -EPERM: oas is not enabled.
2654 **/
2655static ssize_t
2656lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2657 char *buf)
2658{
2659 struct Scsi_Host *shost = class_to_shost(dev);
2660 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2661
2662 uint64_t oas_lun;
2663 int len = 0;
2664
James Smartf38fa0b2014-04-04 13:52:21 -04002665 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002666 return -EPERM;
2667
2668 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2669 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2670 return -EFAULT;
2671
2672 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2673 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2674 return -EFAULT;
2675
2676 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2677 phba->cfg_oas_tgt_wwpn,
2678 &phba->cfg_oas_lun_status);
2679 if (oas_lun != NOT_OAS_ENABLED_LUN)
2680 phba->cfg_oas_flags |= OAS_LUN_VALID;
2681
2682 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2683
2684 return len;
2685}
2686
2687/**
2688 * lpfc_oas_lun_store - Sets the OAS state for lun
2689 * @dev: class device that is converted into a Scsi_host.
2690 * @attr: device attribute, not used.
2691 * @buf: buffer for passing information.
2692 *
2693 * This function sets the OAS state for lun. Before this function is called,
2694 * the vport wwpn, target wwpn, and oas state need to be set.
2695 *
2696 * Returns:
2697 * SUCCESS: size of formatted string.
2698 * -EFAULT: target or vport wwpn was not set properly.
2699 * -EPERM: oas is not enabled.
2700 * size of formatted string.
2701 **/
2702static ssize_t
2703lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2704 const char *buf, size_t count)
2705{
2706 struct Scsi_Host *shost = class_to_shost(dev);
2707 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2708 uint64_t scsi_lun;
2709 ssize_t rc;
2710
James Smartf38fa0b2014-04-04 13:52:21 -04002711 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002712 return -EPERM;
2713
2714 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2715 return -EFAULT;
2716
2717 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2718 return -EFAULT;
2719
2720 if (!isdigit(buf[0]))
2721 return -EINVAL;
2722
2723 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2724 return -EINVAL;
2725
2726 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002727 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2728 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002729 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2730 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartc92c8412016-07-06 12:36:05 -07002731 phba->cfg_oas_priority, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002732
2733 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002734 phba->cfg_oas_tgt_wwpn, scsi_lun,
2735 phba->cfg_oas_lun_state,
2736 phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002737 if (rc)
2738 return rc;
2739
2740 return count;
2741}
2742static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2743 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002744
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002745static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002746module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002747MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2748 " 0 - none,"
2749 " 1 - poll with interrupts enabled"
2750 " 3 - poll and disable FCP ring interrupts");
2751
Tony Jonesee959b02008-02-22 00:13:36 +01002752static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2753 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002754
James Smart12247e82016-07-06 12:36:09 -07002755LPFC_ATTR(sli_mode, 0, 0, 3,
2756 "SLI mode selector:"
2757 " 0 - auto (SLI-3 if supported),"
2758 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2759 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05002760
James Smart458c0832016-07-06 12:36:07 -07002761LPFC_ATTR_R(enable_npiv, 1, 0, 1,
2762 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05002763
James Smart7d791df2011-07-22 18:37:52 -04002764LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2765 "FCF Fast failover=1 Priority failover=2");
2766
James Smartc14e9952013-03-01 16:38:01 -05002767int lpfc_enable_rrq = 2;
James Smartab56dc22011-02-16 12:39:57 -05002768module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002769MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2770lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002771/*
2772# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2773# 0x0 = disabled, XRI/OXID use not tracked.
2774# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2775# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2776*/
2777lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002778static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2779
dea31012005-04-17 16:05:31 -05002780/*
James Smart84d1b002010-02-12 14:42:33 -05002781# lpfc_suppress_link_up: Bring link up at initialization
2782# 0x0 = bring link up (issue MBX_INIT_LINK)
2783# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2784# 0x2 = never bring up link
2785# Default value is 0.
2786*/
James Smarte40a02c2010-02-26 14:13:54 -05002787LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2788 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2789 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002790/*
2791# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2792# 1 - (1024)
2793# 2 - (2048)
2794# 3 - (3072)
2795# 4 - (4096)
2796# 5 - (5120)
2797*/
2798static ssize_t
2799lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2800{
2801 struct Scsi_Host *shost = class_to_shost(dev);
2802 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2803
2804 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2805}
2806
2807static DEVICE_ATTR(iocb_hw, S_IRUGO,
2808 lpfc_iocb_hw_show, NULL);
2809static ssize_t
2810lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2811{
2812 struct Scsi_Host *shost = class_to_shost(dev);
2813 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2814
2815 return snprintf(buf, PAGE_SIZE, "%d\n",
2816 phba->sli.ring[LPFC_ELS_RING].txq_max);
2817}
2818
2819static DEVICE_ATTR(txq_hw, S_IRUGO,
2820 lpfc_txq_hw_show, NULL);
2821static ssize_t
2822lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2823 char *buf)
2824{
2825 struct Scsi_Host *shost = class_to_shost(dev);
2826 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2827
2828 return snprintf(buf, PAGE_SIZE, "%d\n",
2829 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2830}
2831
2832static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2833 lpfc_txcmplq_hw_show, NULL);
2834
2835int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002836module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002837MODULE_PARM_DESC(lpfc_iocb_cnt,
2838 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2839lpfc_param_show(iocb_cnt);
2840lpfc_param_init(iocb_cnt, 2, 1, 5);
2841static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2842 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002843
2844/*
James Smartc01f3202006-08-18 17:47:08 -04002845# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2846# until the timer expires. Value range is [0,255]. Default value is 30.
2847*/
2848static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2849static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2850module_param(lpfc_nodev_tmo, int, 0);
2851MODULE_PARM_DESC(lpfc_nodev_tmo,
2852 "Seconds driver will hold I/O waiting "
2853 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002854
2855/**
James Smart3621a712009-04-06 18:47:14 -04002856 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002857 * @dev: class converted to a Scsi_host structure.
2858 * @attr: device attribute, not used.
2859 * @buf: on return contains the dev loss timeout in decimal.
2860 *
2861 * Returns: size of formatted string.
2862 **/
James Smartc01f3202006-08-18 17:47:08 -04002863static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002864lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2865 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002866{
Tony Jonesee959b02008-02-22 00:13:36 +01002867 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002868 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002869
James Smart3de2a652007-08-02 11:09:59 -04002870 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002871}
2872
James Smarte59058c2008-08-24 21:49:00 -04002873/**
James Smart3621a712009-04-06 18:47:14 -04002874 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002875 * @vport: lpfc vport structure pointer.
2876 * @val: contains the nodev timeout value.
2877 *
2878 * Description:
2879 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2880 * a kernel error message is printed and zero is returned.
2881 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2882 * Otherwise nodev tmo is set to the default value.
2883 *
2884 * Returns:
2885 * zero if already set or if val is in range
2886 * -EINVAL val out of range
2887 **/
James Smartc01f3202006-08-18 17:47:08 -04002888static int
James Smart3de2a652007-08-02 11:09:59 -04002889lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002890{
James Smart3de2a652007-08-02 11:09:59 -04002891 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2892 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2893 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002894 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002895 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002896 "parameter because devloss_tmo is "
2897 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002898 return 0;
2899 }
2900
2901 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002902 vport->cfg_nodev_tmo = val;
2903 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002904 return 0;
2905 }
James Smarte8b62012007-08-02 11:10:09 -04002906 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2907 "0400 lpfc_nodev_tmo attribute cannot be set to"
2908 " %d, allowed range is [%d, %d]\n",
2909 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002910 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002911 return -EINVAL;
2912}
2913
James Smarte59058c2008-08-24 21:49:00 -04002914/**
James Smart3621a712009-04-06 18:47:14 -04002915 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002916 * @vport: lpfc vport structure pointer.
2917 *
2918 * Description:
2919 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2920 **/
James Smart7054a602007-04-25 09:52:34 -04002921static void
James Smart3de2a652007-08-02 11:09:59 -04002922lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002923{
James Smart858c9f62007-06-17 19:56:39 -05002924 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002925 struct lpfc_nodelist *ndlp;
2926
James Smart51ef4c22007-08-02 11:10:31 -04002927 shost = lpfc_shost_from_vport(vport);
2928 spin_lock_irq(shost->host_lock);
2929 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002930 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002931 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2932 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002933}
2934
James Smarte59058c2008-08-24 21:49:00 -04002935/**
James Smart3621a712009-04-06 18:47:14 -04002936 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002937 * @vport: lpfc vport structure pointer.
2938 * @val: contains the tmo value.
2939 *
2940 * Description:
2941 * If the devloss tmo is already set or the vport dev loss tmo has changed
2942 * then a kernel error message is printed and zero is returned.
2943 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2944 * Otherwise nodev tmo is set to the default value.
2945 *
2946 * Returns:
2947 * zero if already set or if val is in range
2948 * -EINVAL val out of range
2949 **/
James Smartc01f3202006-08-18 17:47:08 -04002950static int
James Smart3de2a652007-08-02 11:09:59 -04002951lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002952{
James Smart3de2a652007-08-02 11:09:59 -04002953 if (vport->dev_loss_tmo_changed ||
2954 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002955 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2956 "0401 Ignoring change to nodev_tmo "
2957 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002958 return 0;
2959 }
James Smartc01f3202006-08-18 17:47:08 -04002960 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002961 vport->cfg_nodev_tmo = val;
2962 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002963 /*
2964 * For compat: set the fc_host dev loss so new rports
2965 * will get the value.
2966 */
2967 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002968 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002969 return 0;
2970 }
James Smarte8b62012007-08-02 11:10:09 -04002971 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2972 "0403 lpfc_nodev_tmo attribute cannot be set to"
2973 "%d, allowed range is [%d, %d]\n",
2974 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002975 return -EINVAL;
2976}
2977
James Smart3de2a652007-08-02 11:09:59 -04002978lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002979
Tony Jonesee959b02008-02-22 00:13:36 +01002980static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2981 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002982
2983/*
2984# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2985# disappear until the timer expires. Value range is [0,255]. Default
2986# value is 30.
2987*/
James Smartab56dc22011-02-16 12:39:57 -05002988module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002989MODULE_PARM_DESC(lpfc_devloss_tmo,
2990 "Seconds driver will hold I/O waiting "
2991 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002992lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2993 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2994lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002995
2996/**
James Smart3621a712009-04-06 18:47:14 -04002997 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002998 * @vport: lpfc vport structure pointer.
2999 * @val: contains the tmo value.
3000 *
3001 * Description:
3002 * If val is in a valid range then set the vport nodev tmo,
3003 * devloss tmo, also set the vport dev loss tmo changed flag.
3004 * Else a kernel error message is printed.
3005 *
3006 * Returns:
3007 * zero if val is in range
3008 * -EINVAL val out of range
3009 **/
James Smartc01f3202006-08-18 17:47:08 -04003010static int
James Smart3de2a652007-08-02 11:09:59 -04003011lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003012{
3013 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003014 vport->cfg_nodev_tmo = val;
3015 vport->cfg_devloss_tmo = val;
3016 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003017 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003018 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003019 return 0;
3020 }
3021
James Smarte8b62012007-08-02 11:10:09 -04003022 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3023 "0404 lpfc_devloss_tmo attribute cannot be set to"
3024 " %d, allowed range is [%d, %d]\n",
3025 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003026 return -EINVAL;
3027}
3028
James Smart3de2a652007-08-02 11:09:59 -04003029lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003030static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3031 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003032
3033/*
dea31012005-04-17 16:05:31 -05003034# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3035# deluged with LOTS of information.
3036# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003037# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003038*/
James Smartf4b4c682009-05-22 14:53:12 -04003039LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003040 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003041
3042/*
James Smart7ee5d432007-10-27 13:37:17 -04003043# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3044# objects that have been registered with the nameserver after login.
3045*/
James Smartcf971242012-03-01 22:37:32 -05003046LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003047 "Deregister nameserver objects before LOGO");
3048
3049/*
dea31012005-04-17 16:05:31 -05003050# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003051# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3052# If this parameter value is greater than 1/8th the maximum number of exchanges
3053# supported by the HBA port, then the lun queue depth will be reduced to
3054# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003055*/
James Smart572709e2013-07-15 18:32:43 -04003056LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003057 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003058
3059/*
James Smart7dc517d2010-07-14 15:32:10 -04003060# tgt_queue_depth: This parameter is used to limit the number of outstanding
3061# commands per target port. Value range is [10,65535]. Default value is 65535.
3062*/
3063LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003064 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003065
3066/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003067# hba_queue_depth: This parameter is used to limit the number of outstanding
3068# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3069# value is greater than the maximum number of exchanges supported by the HBA,
3070# then maximum number of exchanges supported by the HBA is used to determine
3071# the hba_queue_depth.
3072*/
3073LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3074 "Max number of FCP commands we can queue to a lpfc HBA");
3075
3076/*
James Smart92d7f7b2007-06-17 19:56:38 -05003077# peer_port_login: This parameter allows/prevents logins
3078# between peer ports hosted on the same physical port.
3079# When this parameter is set 0 peer ports of same physical port
3080# are not allowed to login to each other.
3081# When this parameter is set 1 peer ports of same physical port
3082# are allowed to login to each other.
3083# Default value of this parameter is 0.
3084*/
James Smart3de2a652007-08-02 11:09:59 -04003085LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3086 "Allow peer ports on the same physical port to login to each "
3087 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003088
3089/*
James Smart3de2a652007-08-02 11:09:59 -04003090# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003091# between Virtual Ports and remote initiators.
3092# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3093# other initiators and will attempt to PLOGI all remote ports.
3094# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3095# remote ports and will not attempt to PLOGI to other initiators.
3096# This parameter does not restrict to the physical port.
3097# This parameter does not restrict logins to Fabric resident remote ports.
3098# Default value of this parameter is 1.
3099*/
James Smart3de2a652007-08-02 11:09:59 -04003100static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003101module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003102MODULE_PARM_DESC(lpfc_restrict_login,
3103 "Restrict virtual ports login to remote initiators.");
3104lpfc_vport_param_show(restrict_login);
3105
James Smarte59058c2008-08-24 21:49:00 -04003106/**
James Smart3621a712009-04-06 18:47:14 -04003107 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003108 * @vport: lpfc vport structure pointer.
3109 * @val: contains the restrict login value.
3110 *
3111 * Description:
3112 * If val is not in a valid range then log a kernel error message and set
3113 * the vport restrict login to one.
3114 * If the port type is physical clear the restrict login flag and return.
3115 * Else set the restrict login flag to val.
3116 *
3117 * Returns:
3118 * zero if val is in range
3119 * -EINVAL val out of range
3120 **/
James Smart3de2a652007-08-02 11:09:59 -04003121static int
3122lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3123{
3124 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003125 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003126 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003127 "be set to %d, allowed range is [0, 1]\n",
3128 val);
James Smart3de2a652007-08-02 11:09:59 -04003129 vport->cfg_restrict_login = 1;
3130 return -EINVAL;
3131 }
3132 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3133 vport->cfg_restrict_login = 0;
3134 return 0;
3135 }
3136 vport->cfg_restrict_login = val;
3137 return 0;
3138}
3139
James Smarte59058c2008-08-24 21:49:00 -04003140/**
James Smart3621a712009-04-06 18:47:14 -04003141 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003142 * @vport: lpfc vport structure pointer.
3143 * @val: contains the restrict login value.
3144 *
3145 * Description:
3146 * If val is not in a valid range then log a kernel error message and set
3147 * the vport restrict login to one.
3148 * If the port type is physical and the val is not zero log a kernel
3149 * error message, clear the restrict login flag and return zero.
3150 * Else set the restrict login flag to val.
3151 *
3152 * Returns:
3153 * zero if val is in range
3154 * -EINVAL val out of range
3155 **/
James Smart3de2a652007-08-02 11:09:59 -04003156static int
3157lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3158{
3159 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003160 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003161 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003162 "be set to %d, allowed range is [0, 1]\n",
3163 val);
James Smart3de2a652007-08-02 11:09:59 -04003164 vport->cfg_restrict_login = 1;
3165 return -EINVAL;
3166 }
3167 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003168 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3169 "0468 lpfc_restrict_login must be 0 for "
3170 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003171 vport->cfg_restrict_login = 0;
3172 return 0;
3173 }
3174 vport->cfg_restrict_login = val;
3175 return 0;
3176}
3177lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003178static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3179 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003180
3181/*
dea31012005-04-17 16:05:31 -05003182# Some disk devices have a "select ID" or "select Target" capability.
3183# From a protocol standpoint "select ID" usually means select the
3184# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3185# annex" which contains a table that maps a "select ID" (a number
3186# between 0 and 7F) to an ALPA. By default, for compatibility with
3187# older drivers, the lpfc driver scans this table from low ALPA to high
3188# ALPA.
3189#
3190# Turning on the scan-down variable (on = 1, off = 0) will
3191# cause the lpfc driver to use an inverted table, effectively
3192# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3193#
3194# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3195# and will not work across a fabric. Also this parameter will take
3196# effect only in the case when ALPA map is not available.)
3197*/
James Smart3de2a652007-08-02 11:09:59 -04003198LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3199 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003200
3201/*
dea31012005-04-17 16:05:31 -05003202# lpfc_topology: link topology for init link
3203# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003204# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003205# 0x02 = attempt point-to-point mode only
3206# 0x04 = attempt loop mode only
3207# 0x06 = attempt point-to-point mode then loop
3208# Set point-to-point mode if you want to run as an N_Port.
3209# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3210# Default value is 0.
3211*/
James Smarte59058c2008-08-24 21:49:00 -04003212
3213/**
James Smart3621a712009-04-06 18:47:14 -04003214 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003215 * @phba: lpfc_hba pointer.
3216 * @val: topology value.
3217 *
3218 * Description:
3219 * If val is in a valid range then set the adapter's topology field and
3220 * issue a lip; if the lip fails reset the topology to the old value.
3221 *
3222 * If the value is not in range log a kernel error message and return an error.
3223 *
3224 * Returns:
3225 * zero if val is in range and lip okay
3226 * non-zero return value from lpfc_issue_lip()
3227 * -EINVAL val out of range
3228 **/
James Smarta257bf92009-04-06 18:48:10 -04003229static ssize_t
3230lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3231 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003232{
James Smarta257bf92009-04-06 18:48:10 -04003233 struct Scsi_Host *shost = class_to_shost(dev);
3234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3235 struct lpfc_hba *phba = vport->phba;
3236 int val = 0;
3237 int nolip = 0;
3238 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003239 int err;
3240 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003241
3242 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3243 nolip = 1;
3244 val_buf = &buf[strlen("nolip ")];
3245 }
3246
3247 if (!isdigit(val_buf[0]))
3248 return -EINVAL;
3249 if (sscanf(val_buf, "%i", &val) != 1)
3250 return -EINVAL;
3251
James Smart83108bd2008-01-11 01:53:09 -05003252 if (val >= 0 && val <= 6) {
3253 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003254 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3255 val == 4) {
3256 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3257 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003258 val);
James Smartff78d8f2011-12-13 13:21:35 -05003259 return -EINVAL;
3260 }
James Smartd38dd522015-08-31 16:48:17 -04003261 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3262 val == 4) {
3263 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3264 "3114 Loop mode not supported\n");
3265 return -EINVAL;
3266 }
3267 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003268 if (nolip)
3269 return strlen(buf);
3270
James Smart88a2cfb2011-07-22 18:36:33 -04003271 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3272 "3054 lpfc_topology changed from %d to %d\n",
3273 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003274 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3275 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003276 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003277 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003278 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003279 return -EINVAL;
3280 } else
3281 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003282 }
3283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3284 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3285 "allowed range is [0, 6]\n",
3286 phba->brd_no, val);
3287 return -EINVAL;
3288}
3289static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05003290module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003291MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
3292lpfc_param_show(topology)
3293lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01003294static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003295 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003296
James Smart21e9a0a2009-05-22 14:53:21 -04003297/**
3298 * lpfc_static_vport_show: Read callback function for
3299 * lpfc_static_vport sysfs file.
3300 * @dev: Pointer to class device object.
3301 * @attr: device attribute structure.
3302 * @buf: Data buffer.
3303 *
3304 * This function is the read call back function for
3305 * lpfc_static_vport sysfs file. The lpfc_static_vport
3306 * sysfs file report the mageability of the vport.
3307 **/
3308static ssize_t
3309lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3310 char *buf)
3311{
3312 struct Scsi_Host *shost = class_to_shost(dev);
3313 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3314 if (vport->vport_flag & STATIC_VPORT)
3315 sprintf(buf, "1\n");
3316 else
3317 sprintf(buf, "0\n");
3318
3319 return strlen(buf);
3320}
3321
3322/*
3323 * Sysfs attribute to control the statistical data collection.
3324 */
3325static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3326 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003327
3328/**
James Smart3621a712009-04-06 18:47:14 -04003329 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003330 * @dev: Pointer to class device.
3331 * @buf: Data buffer.
3332 * @count: Size of the data buffer.
3333 *
3334 * This function get called when an user write to the lpfc_stat_data_ctrl
3335 * sysfs file. This function parse the command written to the sysfs file
3336 * and take appropriate action. These commands are used for controlling
3337 * driver statistical data collection.
3338 * Following are the command this function handles.
3339 *
3340 * setbucket <bucket_type> <base> <step>
3341 * = Set the latency buckets.
3342 * destroybucket = destroy all the buckets.
3343 * start = start data collection
3344 * stop = stop data collection
3345 * reset = reset the collected data
3346 **/
3347static ssize_t
3348lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3349 const char *buf, size_t count)
3350{
3351 struct Scsi_Host *shost = class_to_shost(dev);
3352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3353 struct lpfc_hba *phba = vport->phba;
3354#define LPFC_MAX_DATA_CTRL_LEN 1024
3355 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3356 unsigned long i;
3357 char *str_ptr, *token;
3358 struct lpfc_vport **vports;
3359 struct Scsi_Host *v_shost;
3360 char *bucket_type_str, *base_str, *step_str;
3361 unsigned long base, step, bucket_type;
3362
3363 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003364 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003365 return -EINVAL;
3366
James Smarteb016562014-09-03 12:58:06 -04003367 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003368 str_ptr = &bucket_data[0];
3369 /* Ignore this token - this is command token */
3370 token = strsep(&str_ptr, "\t ");
3371 if (!token)
3372 return -EINVAL;
3373
3374 bucket_type_str = strsep(&str_ptr, "\t ");
3375 if (!bucket_type_str)
3376 return -EINVAL;
3377
3378 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3379 bucket_type = LPFC_LINEAR_BUCKET;
3380 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3381 bucket_type = LPFC_POWER2_BUCKET;
3382 else
3383 return -EINVAL;
3384
3385 base_str = strsep(&str_ptr, "\t ");
3386 if (!base_str)
3387 return -EINVAL;
3388 base = simple_strtoul(base_str, NULL, 0);
3389
3390 step_str = strsep(&str_ptr, "\t ");
3391 if (!step_str)
3392 return -EINVAL;
3393 step = simple_strtoul(step_str, NULL, 0);
3394 if (!step)
3395 return -EINVAL;
3396
3397 /* Block the data collection for every vport */
3398 vports = lpfc_create_vport_work_array(phba);
3399 if (vports == NULL)
3400 return -ENOMEM;
3401
James Smartf4b4c682009-05-22 14:53:12 -04003402 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003403 v_shost = lpfc_shost_from_vport(vports[i]);
3404 spin_lock_irq(v_shost->host_lock);
3405 /* Block and reset data collection */
3406 vports[i]->stat_data_blocked = 1;
3407 if (vports[i]->stat_data_enabled)
3408 lpfc_vport_reset_stat_data(vports[i]);
3409 spin_unlock_irq(v_shost->host_lock);
3410 }
3411
3412 /* Set the bucket attributes */
3413 phba->bucket_type = bucket_type;
3414 phba->bucket_base = base;
3415 phba->bucket_step = step;
3416
James Smartf4b4c682009-05-22 14:53:12 -04003417 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003418 v_shost = lpfc_shost_from_vport(vports[i]);
3419
3420 /* Unblock data collection */
3421 spin_lock_irq(v_shost->host_lock);
3422 vports[i]->stat_data_blocked = 0;
3423 spin_unlock_irq(v_shost->host_lock);
3424 }
3425 lpfc_destroy_vport_work_array(phba, vports);
3426 return strlen(buf);
3427 }
3428
3429 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3430 vports = lpfc_create_vport_work_array(phba);
3431 if (vports == NULL)
3432 return -ENOMEM;
3433
James Smartf4b4c682009-05-22 14:53:12 -04003434 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003435 v_shost = lpfc_shost_from_vport(vports[i]);
3436 spin_lock_irq(shost->host_lock);
3437 vports[i]->stat_data_blocked = 1;
3438 lpfc_free_bucket(vport);
3439 vport->stat_data_enabled = 0;
3440 vports[i]->stat_data_blocked = 0;
3441 spin_unlock_irq(shost->host_lock);
3442 }
3443 lpfc_destroy_vport_work_array(phba, vports);
3444 phba->bucket_type = LPFC_NO_BUCKET;
3445 phba->bucket_base = 0;
3446 phba->bucket_step = 0;
3447 return strlen(buf);
3448 }
3449
3450 if (!strncmp(buf, "start", strlen("start"))) {
3451 /* If no buckets configured return error */
3452 if (phba->bucket_type == LPFC_NO_BUCKET)
3453 return -EINVAL;
3454 spin_lock_irq(shost->host_lock);
3455 if (vport->stat_data_enabled) {
3456 spin_unlock_irq(shost->host_lock);
3457 return strlen(buf);
3458 }
3459 lpfc_alloc_bucket(vport);
3460 vport->stat_data_enabled = 1;
3461 spin_unlock_irq(shost->host_lock);
3462 return strlen(buf);
3463 }
3464
3465 if (!strncmp(buf, "stop", strlen("stop"))) {
3466 spin_lock_irq(shost->host_lock);
3467 if (vport->stat_data_enabled == 0) {
3468 spin_unlock_irq(shost->host_lock);
3469 return strlen(buf);
3470 }
3471 lpfc_free_bucket(vport);
3472 vport->stat_data_enabled = 0;
3473 spin_unlock_irq(shost->host_lock);
3474 return strlen(buf);
3475 }
3476
3477 if (!strncmp(buf, "reset", strlen("reset"))) {
3478 if ((phba->bucket_type == LPFC_NO_BUCKET)
3479 || !vport->stat_data_enabled)
3480 return strlen(buf);
3481 spin_lock_irq(shost->host_lock);
3482 vport->stat_data_blocked = 1;
3483 lpfc_vport_reset_stat_data(vport);
3484 vport->stat_data_blocked = 0;
3485 spin_unlock_irq(shost->host_lock);
3486 return strlen(buf);
3487 }
3488 return -EINVAL;
3489}
3490
3491
3492/**
James Smart3621a712009-04-06 18:47:14 -04003493 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003494 * @dev: Pointer to class device object.
3495 * @buf: Data buffer.
3496 *
3497 * This function is the read call back function for
3498 * lpfc_stat_data_ctrl sysfs file. This function report the
3499 * current statistical data collection state.
3500 **/
3501static ssize_t
3502lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3503 char *buf)
3504{
3505 struct Scsi_Host *shost = class_to_shost(dev);
3506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3507 struct lpfc_hba *phba = vport->phba;
3508 int index = 0;
3509 int i;
3510 char *bucket_type;
3511 unsigned long bucket_value;
3512
3513 switch (phba->bucket_type) {
3514 case LPFC_LINEAR_BUCKET:
3515 bucket_type = "linear";
3516 break;
3517 case LPFC_POWER2_BUCKET:
3518 bucket_type = "power2";
3519 break;
3520 default:
3521 bucket_type = "No Bucket";
3522 break;
3523 }
3524
3525 sprintf(&buf[index], "Statistical Data enabled :%d, "
3526 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3527 " Bucket step :%d\nLatency Ranges :",
3528 vport->stat_data_enabled, vport->stat_data_blocked,
3529 bucket_type, phba->bucket_base, phba->bucket_step);
3530 index = strlen(buf);
3531 if (phba->bucket_type != LPFC_NO_BUCKET) {
3532 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3533 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3534 bucket_value = phba->bucket_base +
3535 phba->bucket_step * i;
3536 else
3537 bucket_value = phba->bucket_base +
3538 (1 << i) * phba->bucket_step;
3539
3540 if (index + 10 > PAGE_SIZE)
3541 break;
3542 sprintf(&buf[index], "%08ld ", bucket_value);
3543 index = strlen(buf);
3544 }
3545 }
3546 sprintf(&buf[index], "\n");
3547 return strlen(buf);
3548}
3549
3550/*
3551 * Sysfs attribute to control the statistical data collection.
3552 */
3553static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3554 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3555
3556/*
3557 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3558 */
3559
3560/*
3561 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3562 * for each target.
3563 */
3564#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3565#define MAX_STAT_DATA_SIZE_PER_TARGET \
3566 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3567
3568
3569/**
James Smart3621a712009-04-06 18:47:14 -04003570 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003571 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003572 * @kobj: Pointer to the kernel object
3573 * @bin_attr: Attribute object
3574 * @buff: Buffer pointer
3575 * @off: File offset
3576 * @count: Buffer size
3577 *
3578 * This function is the read call back function for lpfc_drvr_stat_data
3579 * sysfs file. This function export the statistical data to user
3580 * applications.
3581 **/
3582static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003583sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3584 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003585 char *buf, loff_t off, size_t count)
3586{
3587 struct device *dev = container_of(kobj, struct device,
3588 kobj);
3589 struct Scsi_Host *shost = class_to_shost(dev);
3590 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3591 struct lpfc_hba *phba = vport->phba;
3592 int i = 0, index = 0;
3593 unsigned long nport_index;
3594 struct lpfc_nodelist *ndlp = NULL;
3595 nport_index = (unsigned long)off /
3596 MAX_STAT_DATA_SIZE_PER_TARGET;
3597
3598 if (!vport->stat_data_enabled || vport->stat_data_blocked
3599 || (phba->bucket_type == LPFC_NO_BUCKET))
3600 return 0;
3601
3602 spin_lock_irq(shost->host_lock);
3603 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3604 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3605 continue;
3606
3607 if (nport_index > 0) {
3608 nport_index--;
3609 continue;
3610 }
3611
3612 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3613 > count)
3614 break;
3615
3616 if (!ndlp->lat_data)
3617 continue;
3618
3619 /* Print the WWN */
3620 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3621 ndlp->nlp_portname.u.wwn[0],
3622 ndlp->nlp_portname.u.wwn[1],
3623 ndlp->nlp_portname.u.wwn[2],
3624 ndlp->nlp_portname.u.wwn[3],
3625 ndlp->nlp_portname.u.wwn[4],
3626 ndlp->nlp_portname.u.wwn[5],
3627 ndlp->nlp_portname.u.wwn[6],
3628 ndlp->nlp_portname.u.wwn[7]);
3629
3630 index = strlen(buf);
3631
3632 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3633 sprintf(&buf[index], "%010u,",
3634 ndlp->lat_data[i].cmd_count);
3635 index = strlen(buf);
3636 }
3637 sprintf(&buf[index], "\n");
3638 index = strlen(buf);
3639 }
3640 spin_unlock_irq(shost->host_lock);
3641 return index;
3642}
3643
3644static struct bin_attribute sysfs_drvr_stat_data_attr = {
3645 .attr = {
3646 .name = "lpfc_drvr_stat_data",
3647 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003648 },
3649 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3650 .read = sysfs_drvr_stat_data_read,
3651 .write = NULL,
3652};
3653
dea31012005-04-17 16:05:31 -05003654/*
3655# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3656# connection.
James Smart76a95d72010-11-20 23:11:48 -05003657# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003658*/
James Smarte59058c2008-08-24 21:49:00 -04003659/**
James Smart3621a712009-04-06 18:47:14 -04003660 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003661 * @phba: lpfc_hba pointer.
3662 * @val: link speed value.
3663 *
3664 * Description:
3665 * If val is in a valid range then set the adapter's link speed field and
3666 * issue a lip; if the lip fails reset the link speed to the old value.
3667 *
3668 * Notes:
3669 * If the value is not in range log a kernel error message and return an error.
3670 *
3671 * Returns:
3672 * zero if val is in range and lip okay.
3673 * non-zero return value from lpfc_issue_lip()
3674 * -EINVAL val out of range
3675 **/
James Smarta257bf92009-04-06 18:48:10 -04003676static ssize_t
3677lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3678 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003679{
James Smarta257bf92009-04-06 18:48:10 -04003680 struct Scsi_Host *shost = class_to_shost(dev);
3681 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3682 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003683 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003684 int nolip = 0;
3685 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003686 int err;
3687 uint32_t prev_val;
3688
James Smarta257bf92009-04-06 18:48:10 -04003689 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3690 nolip = 1;
3691 val_buf = &buf[strlen("nolip ")];
3692 }
3693
3694 if (!isdigit(val_buf[0]))
3695 return -EINVAL;
3696 if (sscanf(val_buf, "%i", &val) != 1)
3697 return -EINVAL;
3698
James Smart88a2cfb2011-07-22 18:36:33 -04003699 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3700 "3055 lpfc_link_speed changed from %d to %d %s\n",
3701 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3702
James Smart76a95d72010-11-20 23:11:48 -05003703 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3704 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3705 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3706 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3707 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04003708 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3709 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05003710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3711 "2879 lpfc_link_speed attribute cannot be set "
3712 "to %d. Speed is not supported by this port.\n",
3713 val);
James Smart83108bd2008-01-11 01:53:09 -05003714 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003715 }
James Smartff78d8f2011-12-13 13:21:35 -05003716 if (val == LPFC_USER_LINK_SPEED_16G &&
3717 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3718 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3719 "3112 lpfc_link_speed attribute cannot be set "
3720 "to %d. Speed is not supported in loop mode.\n",
3721 val);
3722 return -EINVAL;
3723 }
James Smart76a95d72010-11-20 23:11:48 -05003724 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3725 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003726 prev_val = phba->cfg_link_speed;
3727 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003728 if (nolip)
3729 return strlen(buf);
3730
James Smart83108bd2008-01-11 01:53:09 -05003731 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003732 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003733 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003734 return -EINVAL;
3735 } else
3736 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003737 }
James Smart83108bd2008-01-11 01:53:09 -05003738 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003739 "0469 lpfc_link_speed attribute cannot be set to %d, "
3740 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003741 return -EINVAL;
3742}
3743
3744static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003745module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003746MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3747lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003748
3749/**
James Smart3621a712009-04-06 18:47:14 -04003750 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003751 * @phba: lpfc_hba pointer.
3752 * @val: link speed value.
3753 *
3754 * Description:
3755 * If val is in a valid range then set the adapter's link speed field.
3756 *
3757 * Notes:
3758 * If the value is not in range log a kernel error message, clear the link
3759 * speed and return an error.
3760 *
3761 * Returns:
3762 * zero if val saved.
3763 * -EINVAL val out of range
3764 **/
James Smart83108bd2008-01-11 01:53:09 -05003765static int
3766lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3767{
James Smartff78d8f2011-12-13 13:21:35 -05003768 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3770 "3111 lpfc_link_speed of %d cannot "
3771 "support loop mode, setting topology to default.\n",
3772 val);
3773 phba->cfg_topology = 0;
3774 }
James Smart76a95d72010-11-20 23:11:48 -05003775 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3776 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003777 phba->cfg_link_speed = val;
3778 return 0;
3779 }
3780 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003781 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003782 "be set to %d, allowed values are "
3783 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003784 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003785 return -EINVAL;
3786}
3787
Tony Jonesee959b02008-02-22 00:13:36 +01003788static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003789 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003790
3791/*
James Smart0d878412009-10-02 15:16:56 -04003792# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3793# 0 = aer disabled or not supported
3794# 1 = aer supported and enabled (default)
3795# Value range is [0,1]. Default value is 1.
3796*/
3797
3798/**
3799 * lpfc_aer_support_store - Set the adapter for aer support
3800 *
3801 * @dev: class device that is converted into a Scsi_host.
3802 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003803 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003804 * @count: unused variable.
3805 *
3806 * Description:
3807 * If the val is 1 and currently the device's AER capability was not
3808 * enabled, invoke the kernel's enable AER helper routine, trying to
3809 * enable the device's AER capability. If the helper routine enabling
3810 * AER returns success, update the device's cfg_aer_support flag to
3811 * indicate AER is supported by the device; otherwise, if the device
3812 * AER capability is already enabled to support AER, then do nothing.
3813 *
3814 * If the val is 0 and currently the device's AER support was enabled,
3815 * invoke the kernel's disable AER helper routine. After that, update
3816 * the device's cfg_aer_support flag to indicate AER is not supported
3817 * by the device; otherwise, if the device AER capability is already
3818 * disabled from supporting AER, then do nothing.
3819 *
3820 * Returns:
3821 * length of the buf on success if val is in range the intended mode
3822 * is supported.
3823 * -EINVAL if val out of range or intended mode is not supported.
3824 **/
3825static ssize_t
3826lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3827 const char *buf, size_t count)
3828{
3829 struct Scsi_Host *shost = class_to_shost(dev);
3830 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3831 struct lpfc_hba *phba = vport->phba;
3832 int val = 0, rc = -EINVAL;
3833
3834 if (!isdigit(buf[0]))
3835 return -EINVAL;
3836 if (sscanf(buf, "%i", &val) != 1)
3837 return -EINVAL;
3838
3839 switch (val) {
3840 case 0:
3841 if (phba->hba_flag & HBA_AER_ENABLED) {
3842 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3843 if (!rc) {
3844 spin_lock_irq(&phba->hbalock);
3845 phba->hba_flag &= ~HBA_AER_ENABLED;
3846 spin_unlock_irq(&phba->hbalock);
3847 phba->cfg_aer_support = 0;
3848 rc = strlen(buf);
3849 } else
James Smart891478a2009-11-18 15:40:23 -05003850 rc = -EPERM;
3851 } else {
James Smart0d878412009-10-02 15:16:56 -04003852 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003853 rc = strlen(buf);
3854 }
James Smart0d878412009-10-02 15:16:56 -04003855 break;
3856 case 1:
3857 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3858 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3859 if (!rc) {
3860 spin_lock_irq(&phba->hbalock);
3861 phba->hba_flag |= HBA_AER_ENABLED;
3862 spin_unlock_irq(&phba->hbalock);
3863 phba->cfg_aer_support = 1;
3864 rc = strlen(buf);
3865 } else
James Smart891478a2009-11-18 15:40:23 -05003866 rc = -EPERM;
3867 } else {
James Smart0d878412009-10-02 15:16:56 -04003868 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003869 rc = strlen(buf);
3870 }
James Smart0d878412009-10-02 15:16:56 -04003871 break;
3872 default:
3873 rc = -EINVAL;
3874 break;
3875 }
3876 return rc;
3877}
3878
3879static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003880module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003881MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3882lpfc_param_show(aer_support)
3883
3884/**
3885 * lpfc_aer_support_init - Set the initial adapters aer support flag
3886 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003887 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003888 *
3889 * Description:
3890 * If val is in a valid range [0,1], then set the adapter's initial
3891 * cfg_aer_support field. It will be up to the driver's probe_one
3892 * routine to determine whether the device's AER support can be set
3893 * or not.
3894 *
3895 * Notes:
3896 * If the value is not in range log a kernel error message, and
3897 * choose the default value of setting AER support and return.
3898 *
3899 * Returns:
3900 * zero if val saved.
3901 * -EINVAL val out of range
3902 **/
3903static int
3904lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3905{
3906 if (val == 0 || val == 1) {
3907 phba->cfg_aer_support = val;
3908 return 0;
3909 }
3910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3911 "2712 lpfc_aer_support attribute value %d out "
3912 "of range, allowed values are 0|1, setting it "
3913 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003914 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003915 phba->cfg_aer_support = 1;
3916 return -EINVAL;
3917}
3918
3919static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3920 lpfc_aer_support_show, lpfc_aer_support_store);
3921
3922/**
3923 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3924 * @dev: class device that is converted into a Scsi_host.
3925 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003926 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003927 * @count: unused variable.
3928 *
3929 * Description:
3930 * If the @buf contains 1 and the device currently has the AER support
3931 * enabled, then invokes the kernel AER helper routine
3932 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3933 * error status register.
3934 *
3935 * Notes:
3936 *
3937 * Returns:
3938 * -EINVAL if the buf does not contain the 1 or the device is not currently
3939 * enabled with the AER support.
3940 **/
3941static ssize_t
3942lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3943 const char *buf, size_t count)
3944{
3945 struct Scsi_Host *shost = class_to_shost(dev);
3946 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3947 struct lpfc_hba *phba = vport->phba;
3948 int val, rc = -1;
3949
3950 if (!isdigit(buf[0]))
3951 return -EINVAL;
3952 if (sscanf(buf, "%i", &val) != 1)
3953 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003954 if (val != 1)
3955 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003956
James Smart891478a2009-11-18 15:40:23 -05003957 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003958 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3959
3960 if (rc == 0)
3961 return strlen(buf);
3962 else
James Smart891478a2009-11-18 15:40:23 -05003963 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003964}
3965
3966static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3967 lpfc_aer_cleanup_state);
3968
James Smart912e3ac2011-05-24 11:42:11 -04003969/**
3970 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3971 *
3972 * @dev: class device that is converted into a Scsi_host.
3973 * @attr: device attribute, not used.
3974 * @buf: containing the string the number of vfs to be enabled.
3975 * @count: unused variable.
3976 *
3977 * Description:
3978 * When this api is called either through user sysfs, the driver shall
3979 * try to enable or disable SR-IOV virtual functions according to the
3980 * following:
3981 *
3982 * If zero virtual function has been enabled to the physical function,
3983 * the driver shall invoke the pci enable virtual function api trying
3984 * to enable the virtual functions. If the nr_vfn provided is greater
3985 * than the maximum supported, the maximum virtual function number will
3986 * be used for invoking the api; otherwise, the nr_vfn provided shall
3987 * be used for invoking the api. If the api call returned success, the
3988 * actual number of virtual functions enabled will be set to the driver
3989 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3990 * cfg_sriov_nr_virtfn remains zero.
3991 *
3992 * If none-zero virtual functions have already been enabled to the
3993 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3994 * -EINVAL will be returned and the driver does nothing;
3995 *
3996 * If the nr_vfn provided is zero and none-zero virtual functions have
3997 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3998 * disabling virtual function api shall be invoded to disable all the
3999 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4000 * zero. Otherwise, if zero virtual function has been enabled, do
4001 * nothing.
4002 *
4003 * Returns:
4004 * length of the buf on success if val is in range the intended mode
4005 * is supported.
4006 * -EINVAL if val out of range or intended mode is not supported.
4007 **/
4008static ssize_t
4009lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4010 const char *buf, size_t count)
4011{
4012 struct Scsi_Host *shost = class_to_shost(dev);
4013 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4014 struct lpfc_hba *phba = vport->phba;
4015 struct pci_dev *pdev = phba->pcidev;
4016 int val = 0, rc = -EINVAL;
4017
4018 /* Sanity check on user data */
4019 if (!isdigit(buf[0]))
4020 return -EINVAL;
4021 if (sscanf(buf, "%i", &val) != 1)
4022 return -EINVAL;
4023 if (val < 0)
4024 return -EINVAL;
4025
4026 /* Request disabling virtual functions */
4027 if (val == 0) {
4028 if (phba->cfg_sriov_nr_virtfn > 0) {
4029 pci_disable_sriov(pdev);
4030 phba->cfg_sriov_nr_virtfn = 0;
4031 }
4032 return strlen(buf);
4033 }
4034
4035 /* Request enabling virtual functions */
4036 if (phba->cfg_sriov_nr_virtfn > 0) {
4037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4038 "3018 There are %d virtual functions "
4039 "enabled on physical function.\n",
4040 phba->cfg_sriov_nr_virtfn);
4041 return -EEXIST;
4042 }
4043
4044 if (val <= LPFC_MAX_VFN_PER_PFN)
4045 phba->cfg_sriov_nr_virtfn = val;
4046 else {
4047 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4048 "3019 Enabling %d virtual functions is not "
4049 "allowed.\n", val);
4050 return -EINVAL;
4051 }
4052
4053 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4054 if (rc) {
4055 phba->cfg_sriov_nr_virtfn = 0;
4056 rc = -EPERM;
4057 } else
4058 rc = strlen(buf);
4059
4060 return rc;
4061}
4062
4063static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
4064module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
4065MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
4066lpfc_param_show(sriov_nr_virtfn)
4067
4068/**
4069 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
4070 * @phba: lpfc_hba pointer.
4071 * @val: link speed value.
4072 *
4073 * Description:
4074 * If val is in a valid range [0,255], then set the adapter's initial
4075 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
4076 * number shall be used instead. It will be up to the driver's probe_one
4077 * routine to determine whether the device's SR-IOV is supported or not.
4078 *
4079 * Returns:
4080 * zero if val saved.
4081 * -EINVAL val out of range
4082 **/
4083static int
4084lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
4085{
4086 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
4087 phba->cfg_sriov_nr_virtfn = val;
4088 return 0;
4089 }
4090
4091 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4092 "3017 Enabling %d virtual functions is not "
4093 "allowed.\n", val);
4094 return -EINVAL;
4095}
4096static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4097 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4098
James Smart173edbb2012-06-12 13:54:50 -04004099/**
James Smartc71ab862012-10-31 14:44:33 -04004100 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4101 *
4102 * @dev: class device that is converted into a Scsi_host.
4103 * @attr: device attribute, not used.
4104 * @buf: containing the string the number of vfs to be enabled.
4105 * @count: unused variable.
4106 *
4107 * Description:
4108 *
4109 * Returns:
4110 * length of the buf on success if val is in range the intended mode
4111 * is supported.
4112 * -EINVAL if val out of range or intended mode is not supported.
4113 **/
4114static ssize_t
4115lpfc_request_firmware_upgrade_store(struct device *dev,
4116 struct device_attribute *attr,
4117 const char *buf, size_t count)
4118{
4119 struct Scsi_Host *shost = class_to_shost(dev);
4120 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4121 struct lpfc_hba *phba = vport->phba;
4122 int val = 0, rc = -EINVAL;
4123
4124 /* Sanity check on user data */
4125 if (!isdigit(buf[0]))
4126 return -EINVAL;
4127 if (sscanf(buf, "%i", &val) != 1)
4128 return -EINVAL;
4129 if (val != 1)
4130 return -EINVAL;
4131
4132 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4133 if (rc)
4134 rc = -EPERM;
4135 else
4136 rc = strlen(buf);
4137 return rc;
4138}
4139
4140static int lpfc_req_fw_upgrade;
4141module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4142MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4143lpfc_param_show(request_firmware_upgrade)
4144
4145/**
4146 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4147 * @phba: lpfc_hba pointer.
4148 * @val: 0 or 1.
4149 *
4150 * Description:
4151 * Set the initial Linux generic firmware upgrade enable or disable flag.
4152 *
4153 * Returns:
4154 * zero if val saved.
4155 * -EINVAL val out of range
4156 **/
4157static int
4158lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4159{
4160 if (val >= 0 && val <= 1) {
4161 phba->cfg_request_firmware_upgrade = val;
4162 return 0;
4163 }
4164 return -EINVAL;
4165}
4166static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4167 lpfc_request_firmware_upgrade_show,
4168 lpfc_request_firmware_upgrade_store);
4169
4170/**
James Smart173edbb2012-06-12 13:54:50 -04004171 * lpfc_fcp_imax_store
4172 *
4173 * @dev: class device that is converted into a Scsi_host.
4174 * @attr: device attribute, not used.
4175 * @buf: string with the number of fast-path FCP interrupts per second.
4176 * @count: unused variable.
4177 *
4178 * Description:
4179 * If val is in a valid range [636,651042], then set the adapter's
4180 * maximum number of fast-path FCP interrupts per second.
4181 *
4182 * Returns:
4183 * length of the buf on success if val is in range the intended mode
4184 * is supported.
4185 * -EINVAL if val out of range or intended mode is not supported.
4186 **/
4187static ssize_t
4188lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4189 const char *buf, size_t count)
4190{
4191 struct Scsi_Host *shost = class_to_shost(dev);
4192 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4193 struct lpfc_hba *phba = vport->phba;
4194 int val = 0, i;
4195
James Smartbf8dae82012-08-03 12:36:24 -04004196 /* fcp_imax is only valid for SLI4 */
4197 if (phba->sli_rev != LPFC_SLI_REV4)
4198 return -EINVAL;
4199
James Smart173edbb2012-06-12 13:54:50 -04004200 /* Sanity check on user data */
4201 if (!isdigit(buf[0]))
4202 return -EINVAL;
4203 if (sscanf(buf, "%i", &val) != 1)
4204 return -EINVAL;
4205
James Smartbf8dae82012-08-03 12:36:24 -04004206 /*
4207 * Value range for the HBA is [5000,5000000]
4208 * The value for each EQ depends on how many EQs are configured.
4209 */
4210 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04004211 return -EINVAL;
4212
4213 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04004214 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04004215 lpfc_modify_fcp_eq_delay(phba, i);
4216
4217 return strlen(buf);
4218}
4219
4220/*
4221# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004222# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004223#
James Smartbf8dae82012-08-03 12:36:24 -04004224# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004225*/
James Smartbf8dae82012-08-03 12:36:24 -04004226static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004227module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4228MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004229 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004230lpfc_param_show(fcp_imax)
4231
4232/**
4233 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4234 * @phba: lpfc_hba pointer.
4235 * @val: link speed value.
4236 *
4237 * Description:
4238 * If val is in a valid range [636,651042], then initialize the adapter's
4239 * maximum number of fast-path FCP interrupts per second.
4240 *
4241 * Returns:
4242 * zero if val saved.
4243 * -EINVAL val out of range
4244 **/
4245static int
4246lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4247{
James Smartbf8dae82012-08-03 12:36:24 -04004248 if (phba->sli_rev != LPFC_SLI_REV4) {
4249 phba->cfg_fcp_imax = 0;
4250 return 0;
4251 }
4252
4253 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04004254 phba->cfg_fcp_imax = val;
4255 return 0;
4256 }
4257
4258 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4259 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04004260 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004261
4262 return 0;
4263}
4264
4265static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4266 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4267
James Smart7bb03bb2013-04-17 20:19:16 -04004268/**
4269 * lpfc_state_show - Display current driver CPU affinity
4270 * @dev: class converted to a Scsi_host structure.
4271 * @attr: device attribute, not used.
4272 * @buf: on return contains text describing the state of the link.
4273 *
4274 * Returns: size of formatted string.
4275 **/
4276static ssize_t
4277lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4278 char *buf)
4279{
4280 struct Scsi_Host *shost = class_to_shost(dev);
4281 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4282 struct lpfc_hba *phba = vport->phba;
4283 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004284 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004285
4286 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4287 (phba->intr_type != MSIX))
4288 return len;
4289
4290 switch (phba->cfg_fcp_cpu_map) {
4291 case 0:
4292 len += snprintf(buf + len, PAGE_SIZE-len,
4293 "fcp_cpu_map: No mapping (%d)\n",
4294 phba->cfg_fcp_cpu_map);
4295 return len;
4296 case 1:
4297 len += snprintf(buf + len, PAGE_SIZE-len,
4298 "fcp_cpu_map: HBA centric mapping (%d): "
4299 "%d online CPUs\n",
4300 phba->cfg_fcp_cpu_map,
4301 phba->sli4_hba.num_online_cpu);
4302 break;
4303 case 2:
4304 len += snprintf(buf + len, PAGE_SIZE-len,
4305 "fcp_cpu_map: Driver centric mapping (%d): "
4306 "%d online CPUs\n",
4307 phba->cfg_fcp_cpu_map,
4308 phba->sli4_hba.num_online_cpu);
4309 break;
4310 }
4311
James Smart76fd07a2014-02-20 09:57:18 -05004312 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4313 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4314
4315 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004316 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4317 len += snprintf(buf + len, PAGE_SIZE-len,
4318 "CPU %02d io_chan %02d "
4319 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004320 phba->sli4_hba.curr_disp_cpu,
4321 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004322 cpup->core_id);
4323 else
4324 len += snprintf(buf + len, PAGE_SIZE-len,
4325 "CPU %02d io_chan %02d "
4326 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004327 phba->sli4_hba.curr_disp_cpu,
4328 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004329 cpup->core_id, cpup->irq);
4330
James Smart76fd07a2014-02-20 09:57:18 -05004331 phba->sli4_hba.curr_disp_cpu++;
4332
4333 /* display max number of CPUs keeping some margin */
4334 if (phba->sli4_hba.curr_disp_cpu <
4335 phba->sli4_hba.num_present_cpu &&
4336 (len >= (PAGE_SIZE - 64))) {
4337 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4338 break;
4339 }
James Smart7bb03bb2013-04-17 20:19:16 -04004340 }
James Smart76fd07a2014-02-20 09:57:18 -05004341
4342 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4343 phba->sli4_hba.curr_disp_cpu = 0;
4344
James Smart7bb03bb2013-04-17 20:19:16 -04004345 return len;
4346}
4347
4348/**
4349 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4350 * @dev: class device that is converted into a Scsi_host.
4351 * @attr: device attribute, not used.
4352 * @buf: one or more lpfc_polling_flags values.
4353 * @count: not used.
4354 *
4355 * Returns:
4356 * -EINVAL - Not implemented yet.
4357 **/
4358static ssize_t
4359lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4360 const char *buf, size_t count)
4361{
4362 int status = -EINVAL;
4363 return status;
4364}
4365
4366/*
4367# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4368# for the HBA.
4369#
4370# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4371# 0 - Do not affinitze IRQ vectors
4372# 1 - Affintize HBA vectors with respect to each HBA
4373# (start with CPU0 for each HBA)
4374# 2 - Affintize HBA vectors with respect to the entire driver
4375# (round robin thru all CPUs across all HBAs)
4376*/
4377static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4378module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4379MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4380 "Defines how to map CPUs to IRQ vectors per HBA");
4381
4382/**
4383 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4384 * @phba: lpfc_hba pointer.
4385 * @val: link speed value.
4386 *
4387 * Description:
4388 * If val is in a valid range [0-2], then affinitze the adapter's
4389 * MSIX vectors.
4390 *
4391 * Returns:
4392 * zero if val saved.
4393 * -EINVAL val out of range
4394 **/
4395static int
4396lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4397{
4398 if (phba->sli_rev != LPFC_SLI_REV4) {
4399 phba->cfg_fcp_cpu_map = 0;
4400 return 0;
4401 }
4402
4403 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4404 phba->cfg_fcp_cpu_map = val;
4405 return 0;
4406 }
4407
4408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4409 "3326 fcp_cpu_map: %d out of range, using default\n",
4410 val);
4411 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4412
4413 return 0;
4414}
4415
4416static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4417 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4418
James Smart0d878412009-10-02 15:16:56 -04004419/*
dea31012005-04-17 16:05:31 -05004420# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4421# Value range is [2,3]. Default value is 3.
4422*/
James Smart3de2a652007-08-02 11:09:59 -04004423LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4424 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004425
4426/*
4427# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4428# is [0,1]. Default value is 0.
4429*/
James Smart3de2a652007-08-02 11:09:59 -04004430LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4431 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004432
4433/*
James Smart3cb01c52013-07-15 18:35:04 -04004434# lpfc_first_burst_size: First burst size to use on the NPorts
4435# that support first burst.
4436# Value range is [0,65536]. Default value is 0.
4437*/
4438LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4439 "First burst size for Targets that support first burst");
4440
4441/*
James Smart977b5a02008-09-07 11:52:04 -04004442# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4443# depth. Default value is 0. When the value of this parameter is zero the
4444# SCSI command completion time is not used for controlling I/O queue depth. When
4445# the parameter is set to a non-zero value, the I/O queue depth is controlled
4446# to limit the I/O completion time to the parameter value.
4447# The value is set in milliseconds.
4448*/
4449static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05004450module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04004451MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
4452 "Use command completion time to control queue depth");
4453lpfc_vport_param_show(max_scsicmpl_time);
4454lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
4455static int
4456lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4457{
4458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4459 struct lpfc_nodelist *ndlp, *next_ndlp;
4460
4461 if (val == vport->cfg_max_scsicmpl_time)
4462 return 0;
4463 if ((val < 0) || (val > 60000))
4464 return -EINVAL;
4465 vport->cfg_max_scsicmpl_time = val;
4466
4467 spin_lock_irq(shost->host_lock);
4468 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4469 if (!NLP_CHK_NODE_ACT(ndlp))
4470 continue;
4471 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4472 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004473 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004474 }
4475 spin_unlock_irq(shost->host_lock);
4476 return 0;
4477}
4478lpfc_vport_param_store(max_scsicmpl_time);
4479static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4480 lpfc_max_scsicmpl_time_show,
4481 lpfc_max_scsicmpl_time_store);
4482
4483/*
dea31012005-04-17 16:05:31 -05004484# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4485# range is [0,1]. Default value is 0.
4486*/
4487LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4488
4489/*
James Smart49aa1432012-08-03 12:36:42 -04004490# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4491# range is [0,1]. Default value is 0.
4492# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4493# For [1], FCP commands are issued to a Work Queue associated with the
4494# current CPU.
James Smartec2087a2013-09-06 12:20:36 -04004495# It would be set to 1 by the driver if it's able to set up cpu affinity
4496# for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4497# roundrobin scheduling of FCP I/Os through WQs will be used.
James Smart49aa1432012-08-03 12:36:42 -04004498*/
James Smartec2087a2013-09-06 12:20:36 -04004499LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
James Smart49aa1432012-08-03 12:36:42 -04004500 "issuing commands [0] - Round Robin, [1] - Current CPU");
4501
4502/*
James Smarta6571c62012-10-31 14:44:42 -04004503# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4504# range is [0,1]. Default value is 0.
4505# For [0], bus reset issues target reset to ALL devices
4506# For [1], bus reset issues target reset to non-FCP2 devices
4507*/
4508LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4509 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4510
4511
4512/*
dea31012005-04-17 16:05:31 -05004513# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4514# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004515# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004516# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4517# cr_delay is set to 0.
4518*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004519LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004520 "interrupt response is generated");
4521
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004522LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004523 "interrupt response is generated");
4524
4525/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004526# lpfc_multi_ring_support: Determines how many rings to spread available
4527# cmd/rsp IOCB entries across.
4528# Value range is [1,2]. Default value is 1.
4529*/
4530LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4531 "SLI rings to spread IOCB entries across");
4532
4533/*
James Smarta4bc3372006-12-02 13:34:16 -05004534# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4535# identifies what rctl value to configure the additional ring for.
4536# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4537*/
James Smart6a9c52c2009-10-02 15:16:51 -04004538LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004539 255, "Identifies RCTL for additional ring configuration");
4540
4541/*
4542# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4543# identifies what type value to configure the additional ring for.
4544# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4545*/
James Smart6a9c52c2009-10-02 15:16:51 -04004546LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004547 255, "Identifies TYPE for additional ring configuration");
4548
4549/*
James Smart4258e982015-12-16 18:11:58 -05004550# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4551# 0 = SmartSAN functionality disabled (default)
4552# 1 = SmartSAN functionality enabled
4553# This parameter will override the value of lpfc_fdmi_on module parameter.
4554# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004555*/
James Smart4258e982015-12-16 18:11:58 -05004556LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4557
4558/*
4559# lpfc_fdmi_on: Controls FDMI support.
4560# 0 No FDMI support (default)
4561# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004562# Traditional FDMI support means the driver will assume FDMI-2 support;
4563# however, if that fails, it will fallback to FDMI-1.
4564# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4565# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4566# lpfc_fdmi_on.
4567# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004568*/
James Smart8663cbb2016-03-31 14:12:33 -07004569LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004570
4571/*
4572# Specifies the maximum number of ELS cmds we can have outstanding (for
4573# discovery). Value range is [1,64]. Default value = 32.
4574*/
James Smart3de2a652007-08-02 11:09:59 -04004575LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004576 "during discovery");
4577
4578/*
James Smartc4a7c922013-05-31 17:04:59 -04004579# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4580# will be scanned by the SCSI midlayer when sequential scanning is
4581# used; and is also the highest LUN ID allowed when the SCSI midlayer
4582# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4583# LUN ID limit, but the SCSI midlayer requires this field for the uses
4584# above. The lpfc driver limits the default value to 255 for two reasons.
4585# As it bounds the sequential scan loop, scanning for thousands of luns
4586# on a target can take minutes of wall clock time. Additionally,
4587# there are FC targets, such as JBODs, that only recognize 8-bits of
4588# LUN ID. When they receive a value greater than 8 bits, they chop off
4589# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4590# and so on all as LUN ID 0. This causes the linux kernel, which sees
4591# valid responses at each of the LUN IDs, to believe there are multiple
4592# devices present, when in fact, there is only 1.
4593# A customer that is aware of their target behaviors, and the results as
4594# indicated above, is welcome to increase the lpfc_max_luns value.
4595# As mentioned, this value is not used by the lpfc driver, only the
4596# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004597# Value range is [0,65535]. Default value is 255.
4598# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004599*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004600LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004601
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004602/*
4603# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4604# Value range is [1,255], default value is 10.
4605*/
4606LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4607 "Milliseconds driver will wait between polling FCP ring");
4608
James Smart4ff43242006-12-02 13:34:56 -05004609/*
James Smart0c411222013-09-06 12:22:46 -04004610# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4611# to complete in seconds. Value range is [5,180], default value is 60.
4612*/
4613LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4614 "Maximum time to wait for task management commands to complete");
4615/*
James Smart4ff43242006-12-02 13:34:56 -05004616# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4617# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004618# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004619# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004620# 2 = MSI-X enabled (default)
4621# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004622*/
George Kadianakis8605c462010-01-17 21:19:31 +02004623LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004624 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004625
James Smart13815c82008-01-11 01:52:48 -05004626/*
James Smart67d12732012-08-03 12:36:13 -04004627# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4628#
4629# Value range is [1,7]. Default value is 4.
4630*/
4631LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4632 LPFC_FCP_IO_CHAN_MAX,
4633 "Set the number of FCP I/O channels");
4634
4635/*
James Smart13815c82008-01-11 01:52:48 -05004636# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4637# 0 = HBA resets disabled
4638# 1 = HBA resets enabled (default)
4639# Value range is [0,1]. Default value is 1.
4640*/
4641LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004642
James Smart13815c82008-01-11 01:52:48 -05004643/*
James Smarteb7a3392010-11-20 23:12:02 -05004644# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004645# 0 = HBA Heartbeat disabled
4646# 1 = HBA Heartbeat enabled (default)
4647# Value range is [0,1]. Default value is 1.
4648*/
James Smarteb7a3392010-11-20 23:12:02 -05004649LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004650
James Smart83108bd2008-01-11 01:53:09 -05004651/*
James Smart1ba981f2014-02-20 09:56:45 -05004652# lpfc_EnableXLane: Enable Express Lane Feature
4653# 0x0 Express Lane Feature disabled
4654# 0x1 Express Lane Feature enabled
4655# Value range is [0,1]. Default value is 0.
4656*/
4657LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4658
4659/*
4660# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4661# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4662# Value range is [0x0,0x7f]. Default value is 0
4663*/
James Smart28d7f3d2014-05-21 08:05:28 -04004664LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004665
4666/*
James Smart81301a92008-12-04 22:39:46 -05004667# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4668# 0 = BlockGuard disabled (default)
4669# 1 = BlockGuard enabled
4670# Value range is [0,1]. Default value is 0.
4671*/
4672LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4673
James Smart6fb120a2009-05-22 14:52:59 -04004674/*
James Smartba20c852012-08-03 12:36:52 -04004675# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4676# 0 = disabled (default)
4677# 1 = enabled
4678# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004679#
4680# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004681*/
4682unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4683
James Smartba20c852012-08-03 12:36:52 -04004684/*
James Smart81301a92008-12-04 22:39:46 -05004685# lpfc_prot_mask: i
4686# - Bit mask of host protection capabilities used to register with the
4687# SCSI mid-layer
4688# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4689# - Allows you to ultimately specify which profiles to use
4690# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004691# - SHOST_DIF_TYPE1_PROTECTION 1
4692# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4693# - SHOST_DIX_TYPE0_PROTECTION 8
4694# HBA supports DIX Type 0: Host to HBA protection only
4695# - SHOST_DIX_TYPE1_PROTECTION 16
4696# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004697#
4698*/
James Smart7c56b9f2011-07-22 18:36:25 -04004699unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4700 SHOST_DIX_TYPE0_PROTECTION |
4701 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004702
James Smartab56dc22011-02-16 12:39:57 -05004703module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004704MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4705
4706/*
4707# lpfc_prot_guard: i
4708# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004709# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004710# - Allows you to ultimately specify which profiles to use
4711# - Default will result in registering capabilities for all guard types
4712#
4713*/
4714unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004715module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004716MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4717
James Smart92494142011-02-16 12:39:44 -05004718/*
4719 * Delay initial NPort discovery when Clean Address bit is cleared in
4720 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4721 * This parameter can have value 0 or 1.
4722 * When this parameter is set to 0, no delay is added to the initial
4723 * discovery.
4724 * When this parameter is set to non-zero value, initial Nport discovery is
4725 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4726 * accept and FCID/Fabric name/Fabric portname is changed.
4727 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4728 * when Clean Address bit is cleared in FLOGI/FDISC
4729 * accept and FCID/Fabric name/Fabric portname is changed.
4730 * Default value is 0.
4731 */
James Smart8eb8b962016-07-06 12:36:08 -07004732LPFC_ATTR(delay_discovery, 0, 0, 1,
4733 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05004734
4735/*
James Smart3621a712009-04-06 18:47:14 -04004736 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004737 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004738 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4739 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004740 * Because of the additional overhead involved in setting up T10-DIF,
4741 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4742 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004743 */
4744LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4745 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4746
James Smart96f70772013-04-17 20:16:15 -04004747/*
4748 * This parameter will be depricated, the driver cannot limit the
4749 * protection data s/g list.
4750 */
4751LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4752 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4753 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004754
James Smart7bdedb32016-07-06 12:36:00 -07004755/*
4756 * lpfc_enable_mds_diags: Enable MDS Diagnostics
4757 * 0 = MDS Diagnostics disabled (default)
4758 * 1 = MDS Diagnostics enabled
4759 * Value range is [0,1]. Default value is 0.
4760 */
4761LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
4762
Tony Jonesee959b02008-02-22 00:13:36 +01004763struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004764 &dev_attr_bg_info,
4765 &dev_attr_bg_guard_err,
4766 &dev_attr_bg_apptag_err,
4767 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004768 &dev_attr_info,
4769 &dev_attr_serialnum,
4770 &dev_attr_modeldesc,
4771 &dev_attr_modelname,
4772 &dev_attr_programtype,
4773 &dev_attr_portnum,
4774 &dev_attr_fwrev,
4775 &dev_attr_hdw,
4776 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004777 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004778 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004779 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004780 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004781 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004782 &dev_attr_lpfc_temp_sensor,
4783 &dev_attr_lpfc_log_verbose,
4784 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004785 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004786 &dev_attr_lpfc_hba_queue_depth,
4787 &dev_attr_lpfc_peer_port_login,
4788 &dev_attr_lpfc_nodev_tmo,
4789 &dev_attr_lpfc_devloss_tmo,
4790 &dev_attr_lpfc_fcp_class,
4791 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004792 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004793 &dev_attr_lpfc_ack0,
4794 &dev_attr_lpfc_topology,
4795 &dev_attr_lpfc_scan_down,
4796 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004797 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004798 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004799 &dev_attr_lpfc_cr_delay,
4800 &dev_attr_lpfc_cr_count,
4801 &dev_attr_lpfc_multi_ring_support,
4802 &dev_attr_lpfc_multi_ring_rctl,
4803 &dev_attr_lpfc_multi_ring_type,
4804 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05004805 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01004806 &dev_attr_lpfc_max_luns,
4807 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004808 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004809 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004810 &dev_attr_nport_evt_cnt,
4811 &dev_attr_board_mode,
4812 &dev_attr_max_vpi,
4813 &dev_attr_used_vpi,
4814 &dev_attr_max_rpi,
4815 &dev_attr_used_rpi,
4816 &dev_attr_max_xri,
4817 &dev_attr_used_xri,
4818 &dev_attr_npiv_info,
4819 &dev_attr_issue_reset,
4820 &dev_attr_lpfc_poll,
4821 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04004822 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01004823 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004824 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004825 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04004826 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004827 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004828 &dev_attr_lpfc_soft_wwnn,
4829 &dev_attr_lpfc_soft_wwpn,
4830 &dev_attr_lpfc_soft_wwn_enable,
4831 &dev_attr_lpfc_enable_hba_reset,
4832 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05004833 &dev_attr_lpfc_EnableXLane,
4834 &dev_attr_lpfc_XLanePriority,
4835 &dev_attr_lpfc_xlane_lun,
4836 &dev_attr_lpfc_xlane_tgt,
4837 &dev_attr_lpfc_xlane_vpt,
4838 &dev_attr_lpfc_xlane_lun_state,
4839 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07004840 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01004841 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004842 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004843 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004844 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004845 &dev_attr_lpfc_aer_support,
4846 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004847 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004848 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004849 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004850 &dev_attr_lpfc_iocb_cnt,
4851 &dev_attr_iocb_hw,
4852 &dev_attr_txq_hw,
4853 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004854 &dev_attr_lpfc_fips_level,
4855 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004856 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004857 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004858 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05004859 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07004860 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05004861 NULL,
4862};
4863
Tony Jonesee959b02008-02-22 00:13:36 +01004864struct device_attribute *lpfc_vport_attrs[] = {
4865 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004866 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004867 &dev_attr_num_discovered_ports,
4868 &dev_attr_lpfc_drvr_version,
4869 &dev_attr_lpfc_log_verbose,
4870 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004871 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004872 &dev_attr_lpfc_nodev_tmo,
4873 &dev_attr_lpfc_devloss_tmo,
4874 &dev_attr_lpfc_hba_queue_depth,
4875 &dev_attr_lpfc_peer_port_login,
4876 &dev_attr_lpfc_restrict_login,
4877 &dev_attr_lpfc_fcp_class,
4878 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004879 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004880 &dev_attr_lpfc_max_luns,
4881 &dev_attr_nport_evt_cnt,
4882 &dev_attr_npiv_info,
4883 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004884 &dev_attr_lpfc_max_scsicmpl_time,
4885 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004886 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004887 &dev_attr_lpfc_fips_level,
4888 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004889 NULL,
4890};
4891
James Smarte59058c2008-08-24 21:49:00 -04004892/**
James Smart3621a712009-04-06 18:47:14 -04004893 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004894 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004895 * @kobj: kernel kobject that contains the kernel class device.
4896 * @bin_attr: kernel attributes passed to us.
4897 * @buf: contains the data to be written to the adapter IOREG space.
4898 * @off: offset into buffer to beginning of data.
4899 * @count: bytes to transfer.
4900 *
4901 * Description:
4902 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4903 * Uses the adapter io control registers to send buf contents to the adapter.
4904 *
4905 * Returns:
4906 * -ERANGE off and count combo out of range
4907 * -EINVAL off, count or buff address invalid
4908 * -EPERM adapter is offline
4909 * value of count, buf contents written
4910 **/
dea31012005-04-17 16:05:31 -05004911static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004912sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4913 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004914 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004915{
4916 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004917 struct device *dev = container_of(kobj, struct device, kobj);
4918 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004919 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4920 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004921
James Smartf1126682009-06-10 17:22:44 -04004922 if (phba->sli_rev >= LPFC_SLI_REV4)
4923 return -EPERM;
4924
dea31012005-04-17 16:05:31 -05004925 if ((off + count) > FF_REG_AREA_SIZE)
4926 return -ERANGE;
4927
James Smartf7a919b2011-08-21 21:49:16 -04004928 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4929 return 0;
dea31012005-04-17 16:05:31 -05004930
4931 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4932 return -EINVAL;
4933
James Smartf7a919b2011-08-21 21:49:16 -04004934 /* This is to protect HBA registers from accidental writes. */
4935 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4936 return -EINVAL;
4937
4938 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004939 return -EPERM;
dea31012005-04-17 16:05:31 -05004940
James Smart2e0fef82007-06-17 19:56:36 -05004941 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004942 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4943 buf_off += sizeof(uint32_t))
4944 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004945 phba->ctrl_regs_memmap_p + off + buf_off);
4946
James Smart2e0fef82007-06-17 19:56:36 -05004947 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004948
4949 return count;
4950}
4951
James Smarte59058c2008-08-24 21:49:00 -04004952/**
James Smart3621a712009-04-06 18:47:14 -04004953 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004954 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004955 * @kobj: kernel kobject that contains the kernel class device.
4956 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004957 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004958 * @off: offset into buffer to beginning of data.
4959 * @count: bytes to transfer.
4960 *
4961 * Description:
4962 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4963 * Uses the adapter io control registers to read data into buf.
4964 *
4965 * Returns:
4966 * -ERANGE off and count combo out of range
4967 * -EINVAL off, count or buff address invalid
4968 * value of count, buf contents read
4969 **/
dea31012005-04-17 16:05:31 -05004970static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004971sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4972 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004973 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004974{
4975 size_t buf_off;
4976 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004977 struct device *dev = container_of(kobj, struct device, kobj);
4978 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004979 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4980 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004981
James Smartf1126682009-06-10 17:22:44 -04004982 if (phba->sli_rev >= LPFC_SLI_REV4)
4983 return -EPERM;
4984
dea31012005-04-17 16:05:31 -05004985 if (off > FF_REG_AREA_SIZE)
4986 return -ERANGE;
4987
4988 if ((off + count) > FF_REG_AREA_SIZE)
4989 count = FF_REG_AREA_SIZE - off;
4990
4991 if (count == 0) return 0;
4992
4993 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4994 return -EINVAL;
4995
James Smart2e0fef82007-06-17 19:56:36 -05004996 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004997
4998 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4999 tmp_ptr = (uint32_t *)(buf + buf_off);
5000 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5001 }
5002
James Smart2e0fef82007-06-17 19:56:36 -05005003 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005004
5005 return count;
5006}
5007
5008static struct bin_attribute sysfs_ctlreg_attr = {
5009 .attr = {
5010 .name = "ctlreg",
5011 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005012 },
5013 .size = 256,
5014 .read = sysfs_ctlreg_read,
5015 .write = sysfs_ctlreg_write,
5016};
5017
James Smarte59058c2008-08-24 21:49:00 -04005018/**
James Smart3621a712009-04-06 18:47:14 -04005019 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005020 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005021 * @kobj: kernel kobject that contains the kernel class device.
5022 * @bin_attr: kernel attributes passed to us.
5023 * @buf: contains the data to be written to sysfs mbox.
5024 * @off: offset into buffer to beginning of data.
5025 * @count: bytes to transfer.
5026 *
5027 * Description:
James Smart026abb82011-12-13 13:20:45 -05005028 * Deprecated function. All mailbox access from user space is performed via the
5029 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005030 *
5031 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005032 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005033 **/
dea31012005-04-17 16:05:31 -05005034static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005035sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5036 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005037 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005038{
James Smart026abb82011-12-13 13:20:45 -05005039 return -EPERM;
dea31012005-04-17 16:05:31 -05005040}
5041
James Smarte59058c2008-08-24 21:49:00 -04005042/**
James Smart3621a712009-04-06 18:47:14 -04005043 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005044 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005045 * @kobj: kernel kobject that contains the kernel class device.
5046 * @bin_attr: kernel attributes passed to us.
5047 * @buf: contains the data to be read from sysfs mbox.
5048 * @off: offset into buffer to beginning of data.
5049 * @count: bytes to transfer.
5050 *
5051 * Description:
James Smart026abb82011-12-13 13:20:45 -05005052 * Deprecated function. All mailbox access from user space is performed via the
5053 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005054 *
5055 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005056 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005057 **/
dea31012005-04-17 16:05:31 -05005058static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005059sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5060 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005061 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005062{
James Smart026abb82011-12-13 13:20:45 -05005063 return -EPERM;
dea31012005-04-17 16:05:31 -05005064}
5065
5066static struct bin_attribute sysfs_mbox_attr = {
5067 .attr = {
5068 .name = "mbox",
5069 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005070 },
James Smartc0c11512011-05-24 11:41:34 -04005071 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005072 .read = sysfs_mbox_read,
5073 .write = sysfs_mbox_write,
5074};
5075
James Smarte59058c2008-08-24 21:49:00 -04005076/**
James Smart3621a712009-04-06 18:47:14 -04005077 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005078 * @vport: address of lpfc vport structure.
5079 *
5080 * Return codes:
5081 * zero on success
5082 * error return code from sysfs_create_bin_file()
5083 **/
dea31012005-04-17 16:05:31 -05005084int
James Smart2e0fef82007-06-17 19:56:36 -05005085lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005086{
James Smart2e0fef82007-06-17 19:56:36 -05005087 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005088 int error;
5089
Tony Jonesee959b02008-02-22 00:13:36 +01005090 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005091 &sysfs_drvr_stat_data_attr);
5092
5093 /* Virtual ports do not need ctrl_reg and mbox */
5094 if (error || vport->port_type == LPFC_NPIV_PORT)
5095 goto out;
5096
5097 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005098 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005099 if (error)
James Smarteada2722008-12-04 22:39:13 -05005100 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005101
Tony Jonesee959b02008-02-22 00:13:36 +01005102 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005103 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005104 if (error)
5105 goto out_remove_ctlreg_attr;
5106
5107 return 0;
5108out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005109 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005110out_remove_stat_attr:
5111 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5112 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005113out:
5114 return error;
5115}
5116
James Smarte59058c2008-08-24 21:49:00 -04005117/**
James Smart3621a712009-04-06 18:47:14 -04005118 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005119 * @vport: address of lpfc vport structure.
5120 **/
dea31012005-04-17 16:05:31 -05005121void
James Smart2e0fef82007-06-17 19:56:36 -05005122lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005123{
James Smart2e0fef82007-06-17 19:56:36 -05005124 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005125 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5126 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005127 /* Virtual ports do not need ctrl_reg and mbox */
5128 if (vport->port_type == LPFC_NPIV_PORT)
5129 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005130 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5131 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005132}
5133
dea31012005-04-17 16:05:31 -05005134/*
5135 * Dynamic FC Host Attributes Support
5136 */
5137
James Smarte59058c2008-08-24 21:49:00 -04005138/**
James Smartf89885d2016-12-19 15:07:24 -08005139 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5140 * @shost: kernel scsi host pointer.
5141 **/
5142static void
5143lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5144{
5145 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5146
5147 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5148 sizeof fc_host_symbolic_name(shost));
5149}
5150
5151/**
James Smart3621a712009-04-06 18:47:14 -04005152 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005153 * @shost: kernel scsi host pointer.
5154 **/
dea31012005-04-17 16:05:31 -05005155static void
5156lpfc_get_host_port_id(struct Scsi_Host *shost)
5157{
James Smart2e0fef82007-06-17 19:56:36 -05005158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5159
dea31012005-04-17 16:05:31 -05005160 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005161 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005162}
5163
James Smarte59058c2008-08-24 21:49:00 -04005164/**
James Smart3621a712009-04-06 18:47:14 -04005165 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005166 * @shost: kernel scsi host pointer.
5167 **/
dea31012005-04-17 16:05:31 -05005168static void
5169lpfc_get_host_port_type(struct Scsi_Host *shost)
5170{
James Smart2e0fef82007-06-17 19:56:36 -05005171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5172 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005173
5174 spin_lock_irq(shost->host_lock);
5175
James Smart92d7f7b2007-06-17 19:56:38 -05005176 if (vport->port_type == LPFC_NPIV_PORT) {
5177 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5178 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005179 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005180 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005181 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5182 else
5183 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5184 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005185 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005186 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5187 else
5188 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5189 }
5190 } else
5191 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5192
5193 spin_unlock_irq(shost->host_lock);
5194}
5195
James Smarte59058c2008-08-24 21:49:00 -04005196/**
James Smart3621a712009-04-06 18:47:14 -04005197 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005198 * @shost: kernel scsi host pointer.
5199 **/
dea31012005-04-17 16:05:31 -05005200static void
5201lpfc_get_host_port_state(struct Scsi_Host *shost)
5202{
James Smart2e0fef82007-06-17 19:56:36 -05005203 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5204 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005205
5206 spin_lock_irq(shost->host_lock);
5207
James Smart2e0fef82007-06-17 19:56:36 -05005208 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005209 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5210 else {
James Smart2e0fef82007-06-17 19:56:36 -05005211 switch (phba->link_state) {
5212 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005213 case LPFC_LINK_DOWN:
5214 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5215 break;
5216 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005217 case LPFC_CLEAR_LA:
5218 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005219 /* Links up, reports port state accordingly */
5220 if (vport->port_state < LPFC_VPORT_READY)
5221 fc_host_port_state(shost) =
5222 FC_PORTSTATE_BYPASSED;
5223 else
5224 fc_host_port_state(shost) =
5225 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005226 break;
5227 case LPFC_HBA_ERROR:
5228 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5229 break;
5230 default:
5231 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5232 break;
5233 }
5234 }
5235
5236 spin_unlock_irq(shost->host_lock);
5237}
5238
James Smarte59058c2008-08-24 21:49:00 -04005239/**
James Smart3621a712009-04-06 18:47:14 -04005240 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005241 * @shost: kernel scsi host pointer.
5242 **/
dea31012005-04-17 16:05:31 -05005243static void
5244lpfc_get_host_speed(struct Scsi_Host *shost)
5245{
James Smart2e0fef82007-06-17 19:56:36 -05005246 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5247 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005248
5249 spin_lock_irq(shost->host_lock);
5250
James Smarta085e872015-12-16 18:12:02 -05005251 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005252 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005253 case LPFC_LINK_SPEED_1GHZ:
5254 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005255 break;
James Smart76a95d72010-11-20 23:11:48 -05005256 case LPFC_LINK_SPEED_2GHZ:
5257 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005258 break;
James Smart76a95d72010-11-20 23:11:48 -05005259 case LPFC_LINK_SPEED_4GHZ:
5260 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005261 break;
James Smart76a95d72010-11-20 23:11:48 -05005262 case LPFC_LINK_SPEED_8GHZ:
5263 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005264 break;
James Smart76a95d72010-11-20 23:11:48 -05005265 case LPFC_LINK_SPEED_10GHZ:
5266 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005267 break;
James Smart76a95d72010-11-20 23:11:48 -05005268 case LPFC_LINK_SPEED_16GHZ:
5269 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5270 break;
James Smartd38dd522015-08-31 16:48:17 -04005271 case LPFC_LINK_SPEED_32GHZ:
5272 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5273 break;
James Smart76a95d72010-11-20 23:11:48 -05005274 default:
5275 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005276 break;
5277 }
James Smart09372822008-01-11 01:52:54 -05005278 } else
5279 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005280
5281 spin_unlock_irq(shost->host_lock);
5282}
5283
James Smarte59058c2008-08-24 21:49:00 -04005284/**
James Smart3621a712009-04-06 18:47:14 -04005285 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005286 * @shost: kernel scsi host pointer.
5287 **/
dea31012005-04-17 16:05:31 -05005288static void
5289lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5290{
James Smart2e0fef82007-06-17 19:56:36 -05005291 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5292 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005293 u64 node_name;
dea31012005-04-17 16:05:31 -05005294
5295 spin_lock_irq(shost->host_lock);
5296
James Smart73d91e52011-10-10 21:32:10 -04005297 if ((vport->port_state > LPFC_FLOGI) &&
5298 ((vport->fc_flag & FC_FABRIC) ||
5299 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5300 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005301 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005302 else
5303 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005304 node_name = 0;
dea31012005-04-17 16:05:31 -05005305
5306 spin_unlock_irq(shost->host_lock);
5307
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005308 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005309}
5310
James Smarte59058c2008-08-24 21:49:00 -04005311/**
James Smart3621a712009-04-06 18:47:14 -04005312 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005313 * @shost: kernel scsi host pointer.
5314 *
5315 * Notes:
5316 * NULL on error for link down, no mbox pool, sli2 active,
5317 * management not allowed, memory allocation error, or mbox error.
5318 *
5319 * Returns:
5320 * NULL for error
5321 * address of the adapter host statistics
5322 **/
dea31012005-04-17 16:05:31 -05005323static struct fc_host_statistics *
5324lpfc_get_stats(struct Scsi_Host *shost)
5325{
James Smart2e0fef82007-06-17 19:56:36 -05005326 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5327 struct lpfc_hba *phba = vport->phba;
5328 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005329 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005330 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005331 LPFC_MBOXQ_t *pmboxq;
5332 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005333 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005334 int rc = 0;
dea31012005-04-17 16:05:31 -05005335
James Smart92d7f7b2007-06-17 19:56:38 -05005336 /*
5337 * prevent udev from issuing mailbox commands until the port is
5338 * configured.
5339 */
James Smart2e0fef82007-06-17 19:56:36 -05005340 if (phba->link_state < LPFC_LINK_DOWN ||
5341 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005342 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005343 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005344
5345 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005346 return NULL;
5347
dea31012005-04-17 16:05:31 -05005348 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5349 if (!pmboxq)
5350 return NULL;
5351 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5352
James Smart04c68492009-05-22 14:52:52 -04005353 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005354 pmb->mbxCommand = MBX_READ_STATUS;
5355 pmb->mbxOwner = OWN_HOST;
5356 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005357 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005358
James Smart75baf692010-06-08 18:31:21 -04005359 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005360 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005361 else
dea31012005-04-17 16:05:31 -05005362 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5363
5364 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005365 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005366 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005367 return NULL;
5368 }
5369
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005370 memset(hs, 0, sizeof (struct fc_host_statistics));
5371
dea31012005-04-17 16:05:31 -05005372 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005373 /*
5374 * The MBX_READ_STATUS returns tx_k_bytes which has to
5375 * converted to words
5376 */
5377 hs->tx_words = (uint64_t)
5378 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5379 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005380 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005381 hs->rx_words = (uint64_t)
5382 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5383 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005384
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005385 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005386 pmb->mbxCommand = MBX_READ_LNK_STAT;
5387 pmb->mbxOwner = OWN_HOST;
5388 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005389 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005390
James Smart75baf692010-06-08 18:31:21 -04005391 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005392 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005393 else
dea31012005-04-17 16:05:31 -05005394 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5395
5396 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005397 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005398 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005399 return NULL;
5400 }
5401
5402 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5403 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5404 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5405 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5406 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5407 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5408 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5409
James Smart64ba8812006-08-02 15:24:34 -04005410 hs->link_failure_count -= lso->link_failure_count;
5411 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5412 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5413 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5414 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5415 hs->invalid_crc_count -= lso->invalid_crc_count;
5416 hs->error_frames -= lso->error_frames;
5417
James Smart76a95d72010-11-20 23:11:48 -05005418 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005419 hs->lip_count = -1;
5420 hs->nos_count = (phba->link_events >> 1);
5421 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005422 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005423 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005424 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005425 hs->nos_count = -1;
5426 } else {
5427 hs->lip_count = -1;
5428 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005429 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005430 }
5431
5432 hs->dumped_frames = -1;
5433
James Smart64ba8812006-08-02 15:24:34 -04005434 seconds = get_seconds();
5435 if (seconds < psli->stats_start)
5436 hs->seconds_since_last_reset = seconds +
5437 ((unsigned long)-1 - psli->stats_start);
5438 else
5439 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005440
James Smart1dcb58e2007-04-25 09:51:30 -04005441 mempool_free(pmboxq, phba->mbox_mem_pool);
5442
dea31012005-04-17 16:05:31 -05005443 return hs;
5444}
5445
James Smarte59058c2008-08-24 21:49:00 -04005446/**
James Smart3621a712009-04-06 18:47:14 -04005447 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005448 * @shost: kernel scsi host pointer.
5449 **/
James Smart64ba8812006-08-02 15:24:34 -04005450static void
5451lpfc_reset_stats(struct Scsi_Host *shost)
5452{
James Smart2e0fef82007-06-17 19:56:36 -05005453 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5454 struct lpfc_hba *phba = vport->phba;
5455 struct lpfc_sli *psli = &phba->sli;
5456 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005457 LPFC_MBOXQ_t *pmboxq;
5458 MAILBOX_t *pmb;
5459 int rc = 0;
5460
James Smart2e0fef82007-06-17 19:56:36 -05005461 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005462 return;
5463
James Smart64ba8812006-08-02 15:24:34 -04005464 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5465 if (!pmboxq)
5466 return;
5467 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5468
James Smart04c68492009-05-22 14:52:52 -04005469 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005470 pmb->mbxCommand = MBX_READ_STATUS;
5471 pmb->mbxOwner = OWN_HOST;
5472 pmb->un.varWords[0] = 0x1; /* reset request */
5473 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005474 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005475
James Smart2e0fef82007-06-17 19:56:36 -05005476 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005477 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005478 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5479 else
5480 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5481
5482 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005483 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005484 mempool_free(pmboxq, phba->mbox_mem_pool);
5485 return;
5486 }
5487
5488 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5489 pmb->mbxCommand = MBX_READ_LNK_STAT;
5490 pmb->mbxOwner = OWN_HOST;
5491 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005492 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005493
James Smart2e0fef82007-06-17 19:56:36 -05005494 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005495 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005496 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5497 else
5498 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5499
5500 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005501 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005502 mempool_free( pmboxq, phba->mbox_mem_pool);
5503 return;
5504 }
5505
5506 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5507 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5508 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5509 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5510 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5511 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5512 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005513 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005514 lso->link_events = (phba->link_events >> 1);
5515 else
5516 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005517
5518 psli->stats_start = get_seconds();
5519
James Smart1dcb58e2007-04-25 09:51:30 -04005520 mempool_free(pmboxq, phba->mbox_mem_pool);
5521
James Smart64ba8812006-08-02 15:24:34 -04005522 return;
5523}
dea31012005-04-17 16:05:31 -05005524
5525/*
5526 * The LPFC driver treats linkdown handling as target loss events so there
5527 * are no sysfs handlers for link_down_tmo.
5528 */
James Smart685f0bf2007-04-25 09:53:08 -04005529
James Smarte59058c2008-08-24 21:49:00 -04005530/**
James Smart3621a712009-04-06 18:47:14 -04005531 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005532 * @starget: kernel scsi target pointer.
5533 *
5534 * Returns:
5535 * address of the node list if found
5536 * NULL target not found
5537 **/
James Smart685f0bf2007-04-25 09:53:08 -04005538static struct lpfc_nodelist *
5539lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005540{
James Smart2e0fef82007-06-17 19:56:36 -05005541 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005543 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005544
5545 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005546 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005547 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005548 if (NLP_CHK_NODE_ACT(ndlp) &&
5549 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005550 starget->id == ndlp->nlp_sid) {
5551 spin_unlock_irq(shost->host_lock);
5552 return ndlp;
dea31012005-04-17 16:05:31 -05005553 }
5554 }
5555 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005556 return NULL;
5557}
dea31012005-04-17 16:05:31 -05005558
James Smarte59058c2008-08-24 21:49:00 -04005559/**
James Smart3621a712009-04-06 18:47:14 -04005560 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005561 * @starget: kernel scsi target pointer.
5562 **/
James Smart685f0bf2007-04-25 09:53:08 -04005563static void
5564lpfc_get_starget_port_id(struct scsi_target *starget)
5565{
5566 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5567
5568 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005569}
5570
James Smarte59058c2008-08-24 21:49:00 -04005571/**
James Smart3621a712009-04-06 18:47:14 -04005572 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005573 * @starget: kernel scsi target pointer.
5574 *
5575 * Description: Set the target node name to the ndlp node name wwn or zero.
5576 **/
dea31012005-04-17 16:05:31 -05005577static void
5578lpfc_get_starget_node_name(struct scsi_target *starget)
5579{
James Smart685f0bf2007-04-25 09:53:08 -04005580 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005581
James Smart685f0bf2007-04-25 09:53:08 -04005582 fc_starget_node_name(starget) =
5583 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005584}
5585
James Smarte59058c2008-08-24 21:49:00 -04005586/**
James Smart3621a712009-04-06 18:47:14 -04005587 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005588 * @starget: kernel scsi target pointer.
5589 *
5590 * Description: set the target port name to the ndlp port name wwn or zero.
5591 **/
dea31012005-04-17 16:05:31 -05005592static void
5593lpfc_get_starget_port_name(struct scsi_target *starget)
5594{
James Smart685f0bf2007-04-25 09:53:08 -04005595 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005596
James Smart685f0bf2007-04-25 09:53:08 -04005597 fc_starget_port_name(starget) =
5598 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005599}
5600
James Smarte59058c2008-08-24 21:49:00 -04005601/**
James Smart3621a712009-04-06 18:47:14 -04005602 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005603 * @rport: fc rport address.
5604 * @timeout: new value for dev loss tmo.
5605 *
5606 * Description:
5607 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5608 * dev_loss_tmo to one.
5609 **/
dea31012005-04-17 16:05:31 -05005610static void
dea31012005-04-17 16:05:31 -05005611lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5612{
dea31012005-04-17 16:05:31 -05005613 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005614 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005615 else
James Smartc01f3202006-08-18 17:47:08 -04005616 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005617}
5618
James Smarte59058c2008-08-24 21:49:00 -04005619/**
James Smart3621a712009-04-06 18:47:14 -04005620 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005621 *
5622 * Description:
5623 * Macro that uses field to generate a function with the name lpfc_show_rport_
5624 *
5625 * lpfc_show_rport_##field: returns the bytes formatted in buf
5626 * @cdev: class converted to an fc_rport.
5627 * @buf: on return contains the target_field or zero.
5628 *
5629 * Returns: size of formatted string.
5630 **/
dea31012005-04-17 16:05:31 -05005631#define lpfc_rport_show_function(field, format_string, sz, cast) \
5632static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005633lpfc_show_rport_##field (struct device *dev, \
5634 struct device_attribute *attr, \
5635 char *buf) \
dea31012005-04-17 16:05:31 -05005636{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005637 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005638 struct lpfc_rport_data *rdata = rport->hostdata; \
5639 return snprintf(buf, sz, format_string, \
5640 (rdata->target) ? cast rdata->target->field : 0); \
5641}
5642
5643#define lpfc_rport_rd_attr(field, format_string, sz) \
5644 lpfc_rport_show_function(field, format_string, sz, ) \
5645static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5646
James Smarteada2722008-12-04 22:39:13 -05005647/**
James Smart3621a712009-04-06 18:47:14 -04005648 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005649 * @fc_vport: The fc_vport who's symbolic name has been changed.
5650 *
5651 * Description:
5652 * This function is called by the transport after the @fc_vport's symbolic name
5653 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005654 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005655 **/
5656static void
5657lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5658{
5659 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5660
5661 if (vport->port_state == LPFC_VPORT_READY)
5662 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5663}
dea31012005-04-17 16:05:31 -05005664
James Smartf4b4c682009-05-22 14:53:12 -04005665/**
5666 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5667 * @phba: Pointer to lpfc_hba struct.
5668 *
5669 * This function is called by the lpfc_get_cfgparam() routine to set the
5670 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005671 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005672 * before hba port or vport created.
5673 **/
5674static void
5675lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5676{
5677 phba->cfg_log_verbose = verbose;
5678}
5679
dea31012005-04-17 16:05:31 -05005680struct fc_function_template lpfc_transport_functions = {
5681 /* fixed attributes the driver supports */
5682 .show_host_node_name = 1,
5683 .show_host_port_name = 1,
5684 .show_host_supported_classes = 1,
5685 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005686 .show_host_supported_speeds = 1,
5687 .show_host_maxframe_size = 1,
James Smartf89885d2016-12-19 15:07:24 -08005688
5689 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05005690 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005691
5692 /* dynamic attributes the driver supports */
5693 .get_host_port_id = lpfc_get_host_port_id,
5694 .show_host_port_id = 1,
5695
5696 .get_host_port_type = lpfc_get_host_port_type,
5697 .show_host_port_type = 1,
5698
5699 .get_host_port_state = lpfc_get_host_port_state,
5700 .show_host_port_state = 1,
5701
5702 /* active_fc4s is shown but doesn't change (thus no get function) */
5703 .show_host_active_fc4s = 1,
5704
5705 .get_host_speed = lpfc_get_host_speed,
5706 .show_host_speed = 1,
5707
5708 .get_host_fabric_name = lpfc_get_host_fabric_name,
5709 .show_host_fabric_name = 1,
5710
5711 /*
5712 * The LPFC driver treats linkdown handling as target loss events
5713 * so there are no sysfs handlers for link_down_tmo.
5714 */
5715
5716 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005717 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005718
5719 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5720 .show_rport_maxframe_size = 1,
5721 .show_rport_supported_classes = 1,
5722
dea31012005-04-17 16:05:31 -05005723 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5724 .show_rport_dev_loss_tmo = 1,
5725
5726 .get_starget_port_id = lpfc_get_starget_port_id,
5727 .show_starget_port_id = 1,
5728
5729 .get_starget_node_name = lpfc_get_starget_node_name,
5730 .show_starget_node_name = 1,
5731
5732 .get_starget_port_name = lpfc_get_starget_port_name,
5733 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005734
5735 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005736 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5737 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005738
James Smart92d7f7b2007-06-17 19:56:38 -05005739 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005740
5741 .vport_disable = lpfc_vport_disable,
5742
5743 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005744
5745 .bsg_request = lpfc_bsg_request,
5746 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005747};
5748
James Smart98c9ea52007-10-27 13:37:33 -04005749struct fc_function_template lpfc_vport_transport_functions = {
5750 /* fixed attributes the driver supports */
5751 .show_host_node_name = 1,
5752 .show_host_port_name = 1,
5753 .show_host_supported_classes = 1,
5754 .show_host_supported_fc4s = 1,
5755 .show_host_supported_speeds = 1,
5756 .show_host_maxframe_size = 1,
James Smartf89885d2016-12-19 15:07:24 -08005757
5758 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05005759 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005760
5761 /* dynamic attributes the driver supports */
5762 .get_host_port_id = lpfc_get_host_port_id,
5763 .show_host_port_id = 1,
5764
5765 .get_host_port_type = lpfc_get_host_port_type,
5766 .show_host_port_type = 1,
5767
5768 .get_host_port_state = lpfc_get_host_port_state,
5769 .show_host_port_state = 1,
5770
5771 /* active_fc4s is shown but doesn't change (thus no get function) */
5772 .show_host_active_fc4s = 1,
5773
5774 .get_host_speed = lpfc_get_host_speed,
5775 .show_host_speed = 1,
5776
5777 .get_host_fabric_name = lpfc_get_host_fabric_name,
5778 .show_host_fabric_name = 1,
5779
5780 /*
5781 * The LPFC driver treats linkdown handling as target loss events
5782 * so there are no sysfs handlers for link_down_tmo.
5783 */
5784
5785 .get_fc_host_stats = lpfc_get_stats,
5786 .reset_fc_host_stats = lpfc_reset_stats,
5787
5788 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5789 .show_rport_maxframe_size = 1,
5790 .show_rport_supported_classes = 1,
5791
5792 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5793 .show_rport_dev_loss_tmo = 1,
5794
5795 .get_starget_port_id = lpfc_get_starget_port_id,
5796 .show_starget_port_id = 1,
5797
5798 .get_starget_node_name = lpfc_get_starget_node_name,
5799 .show_starget_node_name = 1,
5800
5801 .get_starget_port_name = lpfc_get_starget_port_name,
5802 .show_starget_port_name = 1,
5803
5804 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5805 .terminate_rport_io = lpfc_terminate_rport_io,
5806
5807 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005808
5809 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005810};
5811
James Smarte59058c2008-08-24 21:49:00 -04005812/**
James Smart3621a712009-04-06 18:47:14 -04005813 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005814 * @phba: lpfc_hba pointer.
5815 **/
dea31012005-04-17 16:05:31 -05005816void
5817lpfc_get_cfgparam(struct lpfc_hba *phba)
5818{
James Smart49aa1432012-08-03 12:36:42 -04005819 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005820 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005821 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5822 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005823 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005824 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5825 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005826 lpfc_ack0_init(phba, lpfc_ack0);
5827 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005828 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005829 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04005830 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005831 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005832 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005833 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05005834 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
5835 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05005836 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005837 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005838 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart67d12732012-08-03 12:36:13 -04005839 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005840 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5841 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart1ba981f2014-02-20 09:56:45 -05005842 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5843 if (phba->sli_rev != LPFC_SLI_REV4)
5844 phba->cfg_EnableXLane = 0;
5845 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5846 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5847 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5848 phba->cfg_oas_lun_state = 0;
5849 phba->cfg_oas_lun_status = 0;
5850 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07005851 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05005852 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005853 if (phba->sli_rev == LPFC_SLI_REV4)
5854 phba->cfg_poll = 0;
5855 else
James Smart1ba981f2014-02-20 09:56:45 -05005856 phba->cfg_poll = lpfc_poll;
James Smart4258e982015-12-16 18:11:58 -05005857
James Smarta12e07b2006-12-02 13:35:30 -05005858 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005859 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005860 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005861 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005862 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005863 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005864 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005865 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005866 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005867 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005868 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07005869 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07005870 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05005871 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07005872 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04005873 return;
5874}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005875
James Smarte59058c2008-08-24 21:49:00 -04005876/**
James Smart3621a712009-04-06 18:47:14 -04005877 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005878 * @vport: lpfc_vport pointer.
5879 **/
James Smart3de2a652007-08-02 11:09:59 -04005880void
5881lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5882{
James Smarte8b62012007-08-02 11:10:09 -04005883 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005884 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005885 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005886 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5887 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5888 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5889 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5890 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5891 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04005892 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04005893 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005894 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5895 lpfc_max_luns_init(vport, lpfc_max_luns);
5896 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005897 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005898 return;
5899}