blob: 6793df86a425f407a3943af35551388fad4cabfd [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 Smart2e0fef82007-06-17 19:56:36 -0500638 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500639 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500640 return -EPERM;
641
642 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
643
644 if (!pmboxq)
645 return -ENOMEM;
646
647 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400648 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
649 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400650
James Smart33ccf8d2006-08-17 11:57:58 -0400651 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500652
James Smart04c68492009-05-22 14:52:52 -0400653 if ((mbxstatus == MBX_SUCCESS) &&
654 (pmboxq->u.mb.mbxStatus == 0 ||
655 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400656 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
657 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
658 phba->cfg_link_speed);
659 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
660 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400661 if ((mbxstatus == MBX_SUCCESS) &&
662 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
663 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
664 "2859 SLI authentication is required "
665 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400666 }
667
James Smart5b8bd0c2007-04-25 09:52:49 -0400668 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500669 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400670 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500671
672 if (mbxstatus == MBXERR_ERROR)
673 return -EIO;
674
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700675 return 0;
dea31012005-04-17 16:05:31 -0500676}
677
James Smarte59058c2008-08-24 21:49:00 -0400678/**
James Smart3621a712009-04-06 18:47:14 -0400679 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400680 * @phba: lpfc_hba pointer.
681 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
682 *
683 * Notes:
684 * Assumes any error from lpfc_do_offline() will be negative.
685 * Can wait up to 5 seconds for the port ring buffers count
686 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400687 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400688 *
689 * Returns:
690 * -EIO error posting the event
691 * zero for success
692 **/
James Smart40496f02006-07-06 15:50:22 -0400693static int
James Smart46fa3112007-04-25 09:51:45 -0400694lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
695{
696 struct completion online_compl;
697 struct lpfc_sli_ring *pring;
698 struct lpfc_sli *psli;
699 int status = 0;
700 int cnt = 0;
701 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500702 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400703
704 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500705 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400706 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500707 if (rc == 0)
708 return -ENOMEM;
709
James Smart46fa3112007-04-25 09:51:45 -0400710 wait_for_completion(&online_compl);
711
712 if (status != 0)
713 return -EIO;
714
715 psli = &phba->sli;
716
James Smart09372822008-01-11 01:52:54 -0500717 /* Wait a little for things to settle down, but not
718 * long enough for dev loss timeout to expire.
719 */
James Smart46fa3112007-04-25 09:51:45 -0400720 for (i = 0; i < psli->num_rings; i++) {
721 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500722 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400723 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500724 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400725 lpfc_printf_log(phba,
726 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400727 "0466 Outstanding IO when "
728 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400729 break;
730 }
731 }
732 }
733
734 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500735 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
736 if (rc == 0)
737 return -ENOMEM;
738
James Smart46fa3112007-04-25 09:51:45 -0400739 wait_for_completion(&online_compl);
740
741 if (status != 0)
742 return -EIO;
743
744 return 0;
745}
746
James Smarte59058c2008-08-24 21:49:00 -0400747/**
James Smart3621a712009-04-06 18:47:14 -0400748 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400749 * @phba: lpfc_hba pointer.
750 *
751 * Description:
752 * If the port is configured to allow a reset then the hba is brought
753 * offline then online.
754 *
755 * Notes:
756 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500757 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400758 *
759 * Returns:
760 * lpfc_do_offline() return code if not zero
761 * -EIO reset not configured or error posting the event
762 * zero for success
763 **/
James Smart7f860592011-03-11 16:05:52 -0500764int
James Smart40496f02006-07-06 15:50:22 -0400765lpfc_selective_reset(struct lpfc_hba *phba)
766{
767 struct completion online_compl;
768 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500769 int rc;
James Smart40496f02006-07-06 15:50:22 -0400770
James Smart71157c92013-07-15 18:34:36 -0400771 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400772 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500773
James Smart71157c92013-07-15 18:34:36 -0400774 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
775 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400776
James Smart71157c92013-07-15 18:34:36 -0400777 if (status != 0)
778 return status;
779 }
James Smart40496f02006-07-06 15:50:22 -0400780
781 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500782 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400783 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500784 if (rc == 0)
785 return -ENOMEM;
786
James Smart40496f02006-07-06 15:50:22 -0400787 wait_for_completion(&online_compl);
788
789 if (status != 0)
790 return -EIO;
791
792 return 0;
793}
794
James Smarte59058c2008-08-24 21:49:00 -0400795/**
James Smart3621a712009-04-06 18:47:14 -0400796 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400797 * @dev: class device that is converted into a Scsi_host.
798 * @attr: device attribute, not used.
799 * @buf: containing the string "selective".
800 * @count: unused variable.
801 *
802 * Description:
803 * If the buf contains the string "selective" then lpfc_selective_reset()
804 * is called to perform the reset.
805 *
806 * Notes:
807 * Assumes any error from lpfc_selective_reset() will be negative.
808 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200809 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400810 *
811 * Returns:
812 * -EINVAL if the buffer does not contain the string "selective"
813 * length of buf if lpfc-selective_reset() if the call succeeds
814 * return value of lpfc_selective_reset() if the call fails
815**/
James Smart40496f02006-07-06 15:50:22 -0400816static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100817lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
818 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400819{
Tony Jonesee959b02008-02-22 00:13:36 +0100820 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500821 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
822 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400823 int status = -EINVAL;
824
James Smart73d91e52011-10-10 21:32:10 -0400825 if (!phba->cfg_enable_hba_reset)
826 return -EACCES;
827
James Smart40496f02006-07-06 15:50:22 -0400828 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500829 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400830
831 if (status == 0)
832 return strlen(buf);
833 else
834 return status;
835}
836
James Smarte59058c2008-08-24 21:49:00 -0400837/**
James Smart88a2cfb2011-07-22 18:36:33 -0400838 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
839 * @phba: lpfc_hba pointer.
840 *
841 * Description:
842 * SLI4 interface type-2 device to wait on the sliport status register for
843 * the readyness after performing a firmware reset.
844 *
845 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +0900846 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -0500847 * reset, -EIO when port timeout from recovering from the reset.
848 *
849 * Note:
850 * As the caller will interpret the return code by value, be careful in making
851 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400852 **/
James Smart73d91e52011-10-10 21:32:10 -0400853int
James Smart88a2cfb2011-07-22 18:36:33 -0400854lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
855{
James Smartf7a919b2011-08-21 21:49:16 -0400856 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400857 int i;
858
James Smartf7a919b2011-08-21 21:49:16 -0400859 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400860 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
861 &portstat_reg.word0);
862
Masanari Iida0b1587b2013-07-17 04:37:44 +0900863 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -0400864 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
865 !bf_get(lpfc_sliport_status_err, &portstat_reg))
866 return -EPERM;
867
James Smart88a2cfb2011-07-22 18:36:33 -0400868 /* wait for the SLI port firmware ready after firmware reset */
869 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
870 msleep(10);
871 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
872 &portstat_reg.word0);
873 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
874 continue;
875 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
876 continue;
877 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
878 continue;
879 break;
880 }
881
882 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
883 return 0;
884 else
885 return -EIO;
886}
887
888/**
James Smart52d52442011-05-24 11:42:45 -0400889 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400890 * @phba: lpfc_hba pointer.
891 *
892 * Description:
James Smart52d52442011-05-24 11:42:45 -0400893 * Request SLI4 interface type-2 device to perform a physical register set
894 * access.
James Smartc0c11512011-05-24 11:41:34 -0400895 *
896 * Returns:
897 * zero for success
898 **/
899static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400900lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400901{
902 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400903 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500904 uint32_t before_fc_flag;
905 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400906 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500907 int status = 0, rc = 0;
908 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400909
910 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400911 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400912
James Smart52d52442011-05-24 11:42:45 -0400913 if ((phba->sli_rev < LPFC_SLI_REV4) ||
914 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
915 LPFC_SLI_INTF_IF_TYPE_2))
916 return -EPERM;
917
James Smart026abb82011-12-13 13:20:45 -0500918 /* Keep state if we need to restore back */
919 before_fc_flag = phba->pport->fc_flag;
920 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
921
James Smartb76f2dc2011-07-22 18:37:42 -0400922 /* Disable SR-IOV virtual functions if enabled */
923 if (phba->cfg_sriov_nr_virtfn) {
924 pci_disable_sriov(pdev);
925 phba->cfg_sriov_nr_virtfn = 0;
926 }
James Smart229adb02013-04-17 20:16:51 -0400927
James Smart02936352014-04-04 13:52:12 -0400928 if (opcode == LPFC_FW_DUMP)
929 phba->hba_flag |= HBA_FW_DUMP_OP;
930
James Smartc0c11512011-05-24 11:41:34 -0400931 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
932
James Smart02936352014-04-04 13:52:12 -0400933 if (status != 0) {
934 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -0400935 return status;
James Smart02936352014-04-04 13:52:12 -0400936 }
James Smartc0c11512011-05-24 11:41:34 -0400937
938 /* wait for the device to be quiesced before firmware reset */
939 msleep(100);
940
941 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
942 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400943
944 if (opcode == LPFC_FW_DUMP)
945 reg_val |= LPFC_FW_DUMP_REQUEST;
946 else if (opcode == LPFC_FW_RESET)
947 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
948 else if (opcode == LPFC_DV_RESET)
949 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
950
James Smartc0c11512011-05-24 11:41:34 -0400951 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
952 LPFC_CTL_PDEV_CTL_OFFSET);
953 /* flush */
954 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
955
956 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400957 rc = lpfc_sli4_pdev_status_reg_wait(phba);
958
James Smart026abb82011-12-13 13:20:45 -0500959 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +0900960 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -0500961 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +0900962 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -0500963 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500964 } else if (rc == -EIO) {
965 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500966 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
967 "3153 Fail to perform the requested "
968 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400969 return rc;
James Smart026abb82011-12-13 13:20:45 -0500970 }
971
972 /* keep the original port state */
973 if (before_fc_flag & FC_OFFLINE_MODE)
974 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400975
976 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500977 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
978 LPFC_EVT_ONLINE);
979 if (!job_posted)
980 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400981
982 wait_for_completion(&online_compl);
983
James Smart026abb82011-12-13 13:20:45 -0500984out:
985 /* in any case, restore the virtual functions enabled as before */
986 if (sriov_nr_virtfn) {
987 sriov_err =
988 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
989 if (!sriov_err)
990 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
991 }
James Smartc0c11512011-05-24 11:41:34 -0400992
James Smart026abb82011-12-13 13:20:45 -0500993 /* return proper error code */
994 if (!rc) {
995 if (!job_posted)
996 rc = -ENOMEM;
997 else if (status)
998 rc = -EIO;
999 }
1000 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001001}
1002
1003/**
James Smart3621a712009-04-06 18:47:14 -04001004 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001005 * @dev: class device that is converted into a Scsi_host.
1006 * @attr: device attribute, not used.
1007 * @buf: on return contains the ascii number of nport events.
1008 *
1009 * Returns: size of formatted string.
1010 **/
dea31012005-04-17 16:05:31 -05001011static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001012lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1013 char *buf)
dea31012005-04-17 16:05:31 -05001014{
Tony Jonesee959b02008-02-22 00:13:36 +01001015 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1017 struct lpfc_hba *phba = vport->phba;
1018
dea31012005-04-17 16:05:31 -05001019 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1020}
1021
James Smarte59058c2008-08-24 21:49:00 -04001022/**
James Smart3621a712009-04-06 18:47:14 -04001023 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001024 * @dev: class device that is converted into a Scsi_host.
1025 * @attr: device attribute, not used.
1026 * @buf: on return contains the state of the adapter.
1027 *
1028 * Returns: size of formatted string.
1029 **/
dea31012005-04-17 16:05:31 -05001030static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001031lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1032 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001033{
Tony Jonesee959b02008-02-22 00:13:36 +01001034 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001035 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1036 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001037 char * state;
1038
James Smart2e0fef82007-06-17 19:56:36 -05001039 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001040 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001041 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001042 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001043 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001044 state = "offline";
1045 else
1046 state = "online";
1047
1048 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1049}
1050
James Smarte59058c2008-08-24 21:49:00 -04001051/**
James Smart3621a712009-04-06 18:47:14 -04001052 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001053 * @dev: class device that is converted into a Scsi_host.
1054 * @attr: device attribute, not used.
1055 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1056 * @count: unused variable.
1057 *
1058 * Returns:
1059 * -EACCES if enable hba reset not enabled
1060 * -EINVAL if the buffer does not contain a valid string (see above)
1061 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1062 * buf length greater than zero indicates success
1063 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001064static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001065lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1066 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001067{
Tony Jonesee959b02008-02-22 00:13:36 +01001068 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001069 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1070 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001071 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001072 char *board_mode_str = NULL;
1073 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001074 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001075
James Smart026abb82011-12-13 13:20:45 -05001076 if (!phba->cfg_enable_hba_reset) {
1077 status = -EACCES;
1078 goto board_mode_out;
1079 }
James Smart88a2cfb2011-07-22 18:36:33 -04001080
1081 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001082 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001083
Jamie Wellnitz41415862006-02-28 19:25:27 -05001084 init_completion(&online_compl);
1085
James Smart46fa3112007-04-25 09:51:45 -04001086 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001087 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001088 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001089 if (rc == 0) {
1090 status = -ENOMEM;
1091 goto board_mode_out;
1092 }
James Smart46fa3112007-04-25 09:51:45 -04001093 wait_for_completion(&online_compl);
1094 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1095 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001096 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001097 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001098 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001099 else
1100 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001101 else if (strncmp(buf, "error", sizeof("error") - 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_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001106 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001107 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1108 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1109 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1110 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1111 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001112 else
James Smart026abb82011-12-13 13:20:45 -05001113 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001114
James Smart026abb82011-12-13 13:20:45 -05001115board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001116 if (!status)
1117 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001118 else {
1119 board_mode_str = strchr(buf, '\n');
1120 if (board_mode_str)
1121 *board_mode_str = '\0';
1122 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1123 "3097 Failed \"%s\", status(%d), "
1124 "fc_flag(x%x)\n",
1125 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001126 return status;
James Smart026abb82011-12-13 13:20:45 -05001127 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001128}
1129
James Smarte59058c2008-08-24 21:49:00 -04001130/**
James Smart3621a712009-04-06 18:47:14 -04001131 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001132 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001133 * @mxri: max xri count.
1134 * @axri: available xri count.
1135 * @mrpi: max rpi count.
1136 * @arpi: available rpi count.
1137 * @mvpi: max vpi count.
1138 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001139 *
1140 * Description:
1141 * If an integer pointer for an count is not null then the value for the
1142 * count is returned.
1143 *
1144 * Returns:
1145 * zero on error
1146 * one for success
1147 **/
James Smart311464e2007-08-02 11:10:37 -04001148static int
James Smart858c9f62007-06-17 19:56:39 -05001149lpfc_get_hba_info(struct lpfc_hba *phba,
1150 uint32_t *mxri, uint32_t *axri,
1151 uint32_t *mrpi, uint32_t *arpi,
1152 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001153{
James Smart04c68492009-05-22 14:52:52 -04001154 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001155 LPFC_MBOXQ_t *pmboxq;
1156 MAILBOX_t *pmb;
1157 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001158 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001159
1160 /*
1161 * prevent udev from issuing mailbox commands until the port is
1162 * configured.
1163 */
1164 if (phba->link_state < LPFC_LINK_DOWN ||
1165 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001166 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001167 return 0;
1168
1169 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1170 return 0;
1171
1172 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1173 if (!pmboxq)
1174 return 0;
1175 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1176
James Smart04c68492009-05-22 14:52:52 -04001177 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001178 pmb->mbxCommand = MBX_READ_CONFIG;
1179 pmb->mbxOwner = OWN_HOST;
1180 pmboxq->context1 = NULL;
1181
James Smart75baf692010-06-08 18:31:21 -04001182 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001183 rc = MBX_NOT_FINISHED;
1184 else
1185 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1186
1187 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001188 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001189 mempool_free(pmboxq, phba->mbox_mem_pool);
1190 return 0;
1191 }
1192
James Smartda0436e2009-05-22 14:51:39 -04001193 if (phba->sli_rev == LPFC_SLI_REV4) {
1194 rd_config = &pmboxq->u.mqe.un.rd_config;
1195 if (mrpi)
1196 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1197 if (arpi)
1198 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1199 phba->sli4_hba.max_cfg_param.rpi_used;
1200 if (mxri)
1201 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1202 if (axri)
1203 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1204 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001205
1206 /* Account for differences with SLI-3. Get vpi count from
1207 * mailbox data and subtract one for max vpi value.
1208 */
1209 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1210 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1211
James Smartda0436e2009-05-22 14:51:39 -04001212 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001213 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001214 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001215 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001216 } else {
1217 if (mrpi)
1218 *mrpi = pmb->un.varRdConfig.max_rpi;
1219 if (arpi)
1220 *arpi = pmb->un.varRdConfig.avail_rpi;
1221 if (mxri)
1222 *mxri = pmb->un.varRdConfig.max_xri;
1223 if (axri)
1224 *axri = pmb->un.varRdConfig.avail_xri;
1225 if (mvpi)
1226 *mvpi = pmb->un.varRdConfig.max_vpi;
1227 if (avpi)
1228 *avpi = pmb->un.varRdConfig.avail_vpi;
1229 }
James Smart92d7f7b2007-06-17 19:56:38 -05001230
1231 mempool_free(pmboxq, phba->mbox_mem_pool);
1232 return 1;
1233}
1234
James Smarte59058c2008-08-24 21:49:00 -04001235/**
James Smart3621a712009-04-06 18:47:14 -04001236 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001237 * @dev: class device that is converted into a Scsi_host.
1238 * @attr: device attribute, not used.
1239 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1240 *
1241 * Description:
1242 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1243 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1244 * to "Unknown" and the buffer length is returned, therefore the caller
1245 * must check for "Unknown" in the buffer to detect a failure.
1246 *
1247 * Returns: size of formatted string.
1248 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001249static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001250lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1251 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001252{
Tony Jonesee959b02008-02-22 00:13:36 +01001253 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1255 struct lpfc_hba *phba = vport->phba;
1256 uint32_t cnt;
1257
James Smart858c9f62007-06-17 19:56:39 -05001258 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001259 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1260 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1261}
1262
James Smarte59058c2008-08-24 21:49:00 -04001263/**
James Smart3621a712009-04-06 18:47:14 -04001264 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001265 * @dev: class device that is converted into a Scsi_host.
1266 * @attr: device attribute, not used.
1267 * @buf: containing the used rpi count in decimal or "Unknown".
1268 *
1269 * Description:
1270 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1271 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1272 * to "Unknown" and the buffer length is returned, therefore the caller
1273 * must check for "Unknown" in the buffer to detect a failure.
1274 *
1275 * Returns: size of formatted string.
1276 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001277static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001278lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1279 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001280{
Tony Jonesee959b02008-02-22 00:13:36 +01001281 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001282 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1283 struct lpfc_hba *phba = vport->phba;
1284 uint32_t cnt, acnt;
1285
James Smart858c9f62007-06-17 19:56:39 -05001286 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001287 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1288 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1289}
1290
James Smarte59058c2008-08-24 21:49:00 -04001291/**
James Smart3621a712009-04-06 18:47:14 -04001292 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001293 * @dev: class device that is converted into a Scsi_host.
1294 * @attr: device attribute, not used.
1295 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1296 *
1297 * Description:
1298 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1299 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1300 * to "Unknown" and the buffer length is returned, therefore the caller
1301 * must check for "Unknown" in the buffer to detect a failure.
1302 *
1303 * Returns: size of formatted string.
1304 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001305static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001306lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1307 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001308{
Tony Jonesee959b02008-02-22 00:13:36 +01001309 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001310 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1311 struct lpfc_hba *phba = vport->phba;
1312 uint32_t cnt;
1313
James Smart858c9f62007-06-17 19:56:39 -05001314 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001315 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1316 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1317}
1318
James Smarte59058c2008-08-24 21:49:00 -04001319/**
James Smart3621a712009-04-06 18:47:14 -04001320 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001321 * @dev: class device that is converted into a Scsi_host.
1322 * @attr: device attribute, not used.
1323 * @buf: on return contains the used xri count in decimal or "Unknown".
1324 *
1325 * Description:
1326 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1327 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1328 * to "Unknown" and the buffer length is returned, therefore the caller
1329 * must check for "Unknown" in the buffer to detect a failure.
1330 *
1331 * Returns: size of formatted string.
1332 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001333static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001334lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1335 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001336{
Tony Jonesee959b02008-02-22 00:13:36 +01001337 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1339 struct lpfc_hba *phba = vport->phba;
1340 uint32_t cnt, acnt;
1341
James Smart858c9f62007-06-17 19:56:39 -05001342 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1343 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1344 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1345}
1346
James Smarte59058c2008-08-24 21:49:00 -04001347/**
James Smart3621a712009-04-06 18:47:14 -04001348 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001349 * @dev: class device that is converted into a Scsi_host.
1350 * @attr: device attribute, not used.
1351 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1352 *
1353 * Description:
1354 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1355 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1356 * to "Unknown" and the buffer length is returned, therefore the caller
1357 * must check for "Unknown" in the buffer to detect a failure.
1358 *
1359 * Returns: size of formatted string.
1360 **/
James Smart858c9f62007-06-17 19:56:39 -05001361static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001362lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1363 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001364{
Tony Jonesee959b02008-02-22 00:13:36 +01001365 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1367 struct lpfc_hba *phba = vport->phba;
1368 uint32_t cnt;
1369
1370 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1371 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1372 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1373}
1374
James Smarte59058c2008-08-24 21:49:00 -04001375/**
James Smart3621a712009-04-06 18:47:14 -04001376 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001377 * @dev: class device that is converted into a Scsi_host.
1378 * @attr: device attribute, not used.
1379 * @buf: on return contains the used vpi count in decimal or "Unknown".
1380 *
1381 * Description:
1382 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1383 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1384 * to "Unknown" and the buffer length is returned, therefore the caller
1385 * must check for "Unknown" in the buffer to detect a failure.
1386 *
1387 * Returns: size of formatted string.
1388 **/
James Smart858c9f62007-06-17 19:56:39 -05001389static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001390lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1391 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001392{
Tony Jonesee959b02008-02-22 00:13:36 +01001393 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001394 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1395 struct lpfc_hba *phba = vport->phba;
1396 uint32_t cnt, acnt;
1397
1398 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001399 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1400 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1401}
1402
James Smarte59058c2008-08-24 21:49:00 -04001403/**
James Smart3621a712009-04-06 18:47:14 -04001404 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001405 * @dev: class device that is converted into a Scsi_host.
1406 * @attr: device attribute, not used.
1407 * @buf: text that must be interpreted to determine if npiv is supported.
1408 *
1409 * Description:
1410 * Buffer will contain text indicating npiv is not suppoerted on the port,
1411 * the port is an NPIV physical port, or it is an npiv virtual port with
1412 * the id of the vport.
1413 *
1414 * Returns: size of formatted string.
1415 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001416static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001417lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1418 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001419{
Tony Jonesee959b02008-02-22 00:13:36 +01001420 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001421 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1422 struct lpfc_hba *phba = vport->phba;
1423
1424 if (!(phba->max_vpi))
1425 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1426 if (vport->port_type == LPFC_PHYSICAL_PORT)
1427 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1428 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1429}
1430
James Smarte59058c2008-08-24 21:49:00 -04001431/**
James Smart3621a712009-04-06 18:47:14 -04001432 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001433 * @dev: class device that is converted into a Scsi_host.
1434 * @attr: device attribute, not used.
1435 * @buf: on return contains the cfg_poll in hex.
1436 *
1437 * Notes:
1438 * cfg_poll should be a lpfc_polling_flags type.
1439 *
1440 * Returns: size of formatted string.
1441 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001442static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001443lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1444 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001445{
Tony Jonesee959b02008-02-22 00:13:36 +01001446 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001447 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1448 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001449
1450 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1451}
1452
James Smarte59058c2008-08-24 21:49:00 -04001453/**
James Smart3621a712009-04-06 18:47:14 -04001454 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001455 * @dev: class device that is converted into a Scsi_host.
1456 * @attr: device attribute, not used.
1457 * @buf: one or more lpfc_polling_flags values.
1458 * @count: not used.
1459 *
1460 * Notes:
1461 * buf contents converted to integer and checked for a valid value.
1462 *
1463 * Returns:
1464 * -EINVAL if the buffer connot be converted or is out of range
1465 * length of the buf on success
1466 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001467static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001468lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1469 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001470{
Tony Jonesee959b02008-02-22 00:13:36 +01001471 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001472 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1473 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001474 uint32_t creg_val;
1475 uint32_t old_val;
1476 int val=0;
1477
1478 if (!isdigit(buf[0]))
1479 return -EINVAL;
1480
1481 if (sscanf(buf, "%i", &val) != 1)
1482 return -EINVAL;
1483
1484 if ((val & 0x3) != val)
1485 return -EINVAL;
1486
James Smart45ed1192009-10-02 15:17:02 -04001487 if (phba->sli_rev == LPFC_SLI_REV4)
1488 val = 0;
1489
James Smart88a2cfb2011-07-22 18:36:33 -04001490 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1491 "3051 lpfc_poll changed from %d to %d\n",
1492 phba->cfg_poll, val);
1493
James Smart2e0fef82007-06-17 19:56:36 -05001494 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001495
1496 old_val = phba->cfg_poll;
1497
1498 if (val & ENABLE_FCP_RING_POLLING) {
1499 if ((val & DISABLE_FCP_RING_INT) &&
1500 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001501 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1502 spin_unlock_irq(&phba->hbalock);
1503 return -EINVAL;
1504 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001505 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1506 writel(creg_val, phba->HCregaddr);
1507 readl(phba->HCregaddr); /* flush */
1508
1509 lpfc_poll_start_timer(phba);
1510 }
1511 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001512 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001513 return -EINVAL;
1514 }
1515
1516 if (!(val & DISABLE_FCP_RING_INT) &&
1517 (old_val & DISABLE_FCP_RING_INT))
1518 {
James Smart2e0fef82007-06-17 19:56:36 -05001519 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001520 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001521 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001522 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1523 spin_unlock_irq(&phba->hbalock);
1524 return -EINVAL;
1525 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001526 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1527 writel(creg_val, phba->HCregaddr);
1528 readl(phba->HCregaddr); /* flush */
1529 }
1530
1531 phba->cfg_poll = val;
1532
James Smart2e0fef82007-06-17 19:56:36 -05001533 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001534
1535 return strlen(buf);
1536}
dea31012005-04-17 16:05:31 -05001537
James Smarte59058c2008-08-24 21:49:00 -04001538/**
James Smartbc739052010-08-04 16:11:18 -04001539 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1540 * @dev: class unused variable.
1541 * @attr: device attribute, not used.
1542 * @buf: on return contains the module description text.
1543 *
1544 * Returns: size of formatted string.
1545 **/
1546static ssize_t
1547lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1548 char *buf)
1549{
1550 struct Scsi_Host *shost = class_to_shost(dev);
1551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1552 struct lpfc_hba *phba = vport->phba;
1553
1554 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1555}
1556
1557/**
1558 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1559 * @dev: class unused variable.
1560 * @attr: device attribute, not used.
1561 * @buf: on return contains the module description text.
1562 *
1563 * Returns: size of formatted string.
1564 **/
1565static ssize_t
1566lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1567 char *buf)
1568{
1569 struct Scsi_Host *shost = class_to_shost(dev);
1570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1571 struct lpfc_hba *phba = vport->phba;
1572
1573 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1574}
1575
1576/**
James Smartab56dc22011-02-16 12:39:57 -05001577 * lpfc_dss_show - Return the current state of dss and the configured state
1578 * @dev: class converted to a Scsi_host structure.
1579 * @attr: device attribute, not used.
1580 * @buf: on return contains the formatted text.
1581 *
1582 * Returns: size of formatted string.
1583 **/
1584static ssize_t
1585lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1586 char *buf)
1587{
1588 struct Scsi_Host *shost = class_to_shost(dev);
1589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1590 struct lpfc_hba *phba = vport->phba;
1591
1592 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1593 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1594 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1595 "" : "Not ");
1596}
1597
1598/**
James Smart912e3ac2011-05-24 11:42:11 -04001599 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1600 * @dev: class converted to a Scsi_host structure.
1601 * @attr: device attribute, not used.
1602 * @buf: on return contains the formatted support level.
1603 *
1604 * Description:
1605 * Returns the maximum number of virtual functions a physical function can
1606 * support, 0 will be returned if called on virtual function.
1607 *
1608 * Returns: size of formatted string.
1609 **/
1610static ssize_t
1611lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1612 struct device_attribute *attr,
1613 char *buf)
1614{
1615 struct Scsi_Host *shost = class_to_shost(dev);
1616 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1617 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001618 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001619
James Smart0a96e972011-07-22 18:37:28 -04001620 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1621 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001622}
1623
1624/**
James Smart3621a712009-04-06 18:47:14 -04001625 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001626 *
1627 * Description:
1628 * Macro that given an attr e.g. hba_queue_depth expands
1629 * into a function with the name lpfc_hba_queue_depth_show.
1630 *
1631 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1632 * @dev: class device that is converted into a Scsi_host.
1633 * @attr: device attribute, not used.
1634 * @buf: on return contains the attribute value in decimal.
1635 *
1636 * Returns: size of formatted string.
1637 **/
dea31012005-04-17 16:05:31 -05001638#define lpfc_param_show(attr) \
1639static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001640lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1641 char *buf) \
dea31012005-04-17 16:05:31 -05001642{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001643 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1645 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001646 return snprintf(buf, PAGE_SIZE, "%d\n",\
1647 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001648}
1649
James Smarte59058c2008-08-24 21:49:00 -04001650/**
James Smart3621a712009-04-06 18:47:14 -04001651 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001652 *
1653 * Description:
1654 * Macro that given an attr e.g. hba_queue_depth expands
1655 * into a function with the name lpfc_hba_queue_depth_show
1656 *
1657 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1658 * @dev: class device that is converted into a Scsi_host.
1659 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001660 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001661 *
1662 * Returns: size of formatted string.
1663 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001664#define lpfc_param_hex_show(attr) \
1665static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001666lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1667 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001668{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001669 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1671 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001672 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001673 val = phba->cfg_##attr;\
1674 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1675 phba->cfg_##attr);\
1676}
1677
James Smarte59058c2008-08-24 21:49:00 -04001678/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001679 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001680 *
1681 * Description:
1682 * Macro that given an attr e.g. hba_queue_depth expands
1683 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1684 * takes a default argument, a minimum and maximum argument.
1685 *
1686 * lpfc_##attr##_init: Initializes an attribute.
1687 * @phba: pointer the the adapter structure.
1688 * @val: integer attribute value.
1689 *
1690 * Validates the min and max values then sets the adapter config field
1691 * accordingly, or uses the default if out of range and prints an error message.
1692 *
1693 * Returns:
1694 * zero on success
1695 * -EINVAL if default used
1696 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001697#define lpfc_param_init(attr, default, minval, maxval) \
1698static int \
James Smart84d1b002010-02-12 14:42:33 -05001699lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001700{ \
1701 if (val >= minval && val <= maxval) {\
1702 phba->cfg_##attr = val;\
1703 return 0;\
1704 }\
1705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001706 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1707 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001708 phba->cfg_##attr = default;\
1709 return -EINVAL;\
1710}
1711
James Smarte59058c2008-08-24 21:49:00 -04001712/**
James Smart3621a712009-04-06 18:47:14 -04001713 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001714 *
1715 * Description:
1716 * Macro that given an attr e.g. hba_queue_depth expands
1717 * into a function with the name lpfc_hba_queue_depth_set
1718 *
1719 * lpfc_##attr##_set: Sets an attribute value.
1720 * @phba: pointer the the adapter structure.
1721 * @val: integer attribute value.
1722 *
1723 * Description:
1724 * Validates the min and max values then sets the
1725 * adapter config field if in the valid range. prints error message
1726 * and does not set the parameter if invalid.
1727 *
1728 * Returns:
1729 * zero on success
1730 * -EINVAL if val is invalid
1731 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001732#define lpfc_param_set(attr, default, minval, maxval) \
1733static int \
James Smart84d1b002010-02-12 14:42:33 -05001734lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001735{ \
1736 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001737 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1738 "3052 lpfc_" #attr " changed from %d to %d\n", \
1739 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001740 phba->cfg_##attr = val;\
1741 return 0;\
1742 }\
1743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001744 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1745 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001746 return -EINVAL;\
1747}
1748
James Smarte59058c2008-08-24 21:49:00 -04001749/**
James Smart3621a712009-04-06 18:47:14 -04001750 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001751 *
1752 * Description:
1753 * Macro that given an attr e.g. hba_queue_depth expands
1754 * into a function with the name lpfc_hba_queue_depth_store.
1755 *
1756 * lpfc_##attr##_store: Set an sttribute value.
1757 * @dev: class device that is converted into a Scsi_host.
1758 * @attr: device attribute, not used.
1759 * @buf: contains the attribute value in ascii.
1760 * @count: not used.
1761 *
1762 * Description:
1763 * Convert the ascii text number to an integer, then
1764 * use the lpfc_##attr##_set function to set the value.
1765 *
1766 * Returns:
1767 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1768 * length of buffer upon success.
1769 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001770#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001771static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001772lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1773 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001774{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001775 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1777 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001778 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001779 if (!isdigit(buf[0]))\
1780 return -EINVAL;\
1781 if (sscanf(buf, "%i", &val) != 1)\
1782 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001783 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001784 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001785 else \
1786 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001787}
1788
James Smarte59058c2008-08-24 21:49:00 -04001789/**
James Smart3621a712009-04-06 18:47:14 -04001790 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001791 *
1792 * Description:
1793 * Macro that given an attr e.g. hba_queue_depth expands
1794 * into a function with the name lpfc_hba_queue_depth_show
1795 *
1796 * lpfc_##attr##_show: prints the attribute value in decimal.
1797 * @dev: class device that is converted into a Scsi_host.
1798 * @attr: device attribute, not used.
1799 * @buf: on return contains the attribute value in decimal.
1800 *
1801 * Returns: length of formatted string.
1802 **/
James Smart3de2a652007-08-02 11:09:59 -04001803#define lpfc_vport_param_show(attr) \
1804static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001805lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1806 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001807{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001808 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001810 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1811}
1812
James Smarte59058c2008-08-24 21:49:00 -04001813/**
James Smart3621a712009-04-06 18:47:14 -04001814 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001815 *
1816 * Description:
1817 * Macro that given an attr e.g.
1818 * hba_queue_depth expands into a function with the name
1819 * lpfc_hba_queue_depth_show
1820 *
James Smart3621a712009-04-06 18:47:14 -04001821 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001822 * @dev: class device that is converted into a Scsi_host.
1823 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001824 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001825 *
1826 * Returns: length of formatted string.
1827 **/
James Smart3de2a652007-08-02 11:09:59 -04001828#define lpfc_vport_param_hex_show(attr) \
1829static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001830lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1831 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001832{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001833 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001834 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001835 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1836}
1837
James Smarte59058c2008-08-24 21:49:00 -04001838/**
James Smart3621a712009-04-06 18:47:14 -04001839 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001840 *
1841 * Description:
1842 * Macro that given an attr e.g. hba_queue_depth expands
1843 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1844 * takes a default argument, a minimum and maximum argument.
1845 *
1846 * lpfc_##attr##_init: validates the min and max values then sets the
1847 * adapter config field accordingly, or uses the default if out of range
1848 * and prints an error message.
1849 * @phba: pointer the the adapter structure.
1850 * @val: integer attribute value.
1851 *
1852 * Returns:
1853 * zero on success
1854 * -EINVAL if default used
1855 **/
James Smart3de2a652007-08-02 11:09:59 -04001856#define lpfc_vport_param_init(attr, default, minval, maxval) \
1857static int \
James Smart84d1b002010-02-12 14:42:33 -05001858lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001859{ \
1860 if (val >= minval && val <= maxval) {\
1861 vport->cfg_##attr = val;\
1862 return 0;\
1863 }\
James Smarte8b62012007-08-02 11:10:09 -04001864 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001865 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001866 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001867 vport->cfg_##attr = default;\
1868 return -EINVAL;\
1869}
1870
James Smarte59058c2008-08-24 21:49:00 -04001871/**
James Smart3621a712009-04-06 18:47:14 -04001872 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001873 *
1874 * Description:
1875 * Macro that given an attr e.g. hba_queue_depth expands
1876 * into a function with the name lpfc_hba_queue_depth_set
1877 *
1878 * lpfc_##attr##_set: validates the min and max values then sets the
1879 * adapter config field if in the valid range. prints error message
1880 * and does not set the parameter if invalid.
1881 * @phba: pointer the the adapter structure.
1882 * @val: integer attribute value.
1883 *
1884 * Returns:
1885 * zero on success
1886 * -EINVAL if val is invalid
1887 **/
James Smart3de2a652007-08-02 11:09:59 -04001888#define lpfc_vport_param_set(attr, default, minval, maxval) \
1889static int \
James Smart84d1b002010-02-12 14:42:33 -05001890lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001891{ \
1892 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001893 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04001894 "3053 lpfc_" #attr \
1895 " changed from %d (x%x) to %d (x%x)\n", \
1896 vport->cfg_##attr, vport->cfg_##attr, \
1897 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04001898 vport->cfg_##attr = val;\
1899 return 0;\
1900 }\
James Smarte8b62012007-08-02 11:10:09 -04001901 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001902 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001903 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001904 return -EINVAL;\
1905}
1906
James Smarte59058c2008-08-24 21:49:00 -04001907/**
James Smart3621a712009-04-06 18:47:14 -04001908 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001909 *
1910 * Description:
1911 * Macro that given an attr e.g. hba_queue_depth
1912 * expands into a function with the name lpfc_hba_queue_depth_store
1913 *
1914 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1915 * use the lpfc_##attr##_set function to set the value.
1916 * @cdev: class device that is converted into a Scsi_host.
1917 * @buf: contains the attribute value in decimal.
1918 * @count: not used.
1919 *
1920 * Returns:
1921 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1922 * length of buffer upon success.
1923 **/
James Smart3de2a652007-08-02 11:09:59 -04001924#define lpfc_vport_param_store(attr) \
1925static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001926lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1927 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001928{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001929 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001930 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001931 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001932 if (!isdigit(buf[0]))\
1933 return -EINVAL;\
1934 if (sscanf(buf, "%i", &val) != 1)\
1935 return -EINVAL;\
1936 if (lpfc_##attr##_set(vport, val) == 0) \
1937 return strlen(buf);\
1938 else \
1939 return -EINVAL;\
1940}
1941
1942
James Smart81301a92008-12-04 22:39:46 -05001943static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1944static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1945static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1946static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001947static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1948static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1949static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1950static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1951static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1952static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1953static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1954static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001955static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1956 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001957static DEVICE_ATTR(option_rom_version, S_IRUGO,
1958 lpfc_option_rom_version_show, NULL);
1959static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1960 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001961static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001962static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1963static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001964static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001965static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1966 lpfc_board_mode_show, lpfc_board_mode_store);
1967static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1968static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1969static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1970static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1971static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1972static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1973static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1974static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1975static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001976static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1977static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001978static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001979static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1980 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05001981static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05001982static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
1983 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001984
James Smarta12e07b2006-12-02 13:35:30 -05001985static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05001986#define WWN_SZ 8
1987/**
1988 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
1989 * @buf: WWN string.
1990 * @cnt: Length of string.
1991 * @wwn: Array to receive converted wwn value.
1992 *
1993 * Returns:
1994 * -EINVAL if the buffer does not contain a valid wwn
1995 * 0 success
1996 **/
1997static size_t
1998lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
1999{
2000 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002001
James Smart1ba981f2014-02-20 09:56:45 -05002002 /* Count may include a LF at end of string */
2003 if (buf[cnt-1] == '\n')
2004 cnt--;
2005
2006 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2007 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2008 return -EINVAL;
2009
2010 memset(wwn, 0, WWN_SZ);
2011
2012 /* Validate and store the new name */
2013 for (i = 0, j = 0; i < 16; i++) {
2014 if ((*buf >= 'a') && (*buf <= 'f'))
2015 j = ((j << 4) | ((*buf++ - 'a') + 10));
2016 else if ((*buf >= 'A') && (*buf <= 'F'))
2017 j = ((j << 4) | ((*buf++ - 'A') + 10));
2018 else if ((*buf >= '0') && (*buf <= '9'))
2019 j = ((j << 4) | (*buf++ - '0'));
2020 else
2021 return -EINVAL;
2022 if (i % 2) {
2023 wwn[i/2] = j & 0xff;
2024 j = 0;
2025 }
2026 }
2027 return 0;
2028}
James Smarte59058c2008-08-24 21:49:00 -04002029/**
James Smart3621a712009-04-06 18:47:14 -04002030 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002031 * @dev: class device that is converted into a Scsi_host.
2032 * @attr: device attribute, not used.
2033 * @buf: containing the string lpfc_soft_wwn_key.
2034 * @count: must be size of lpfc_soft_wwn_key.
2035 *
2036 * Returns:
2037 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2038 * length of buf indicates success
2039 **/
James Smartc3f28af2006-08-18 17:47:18 -04002040static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002041lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2042 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002043{
Tony Jonesee959b02008-02-22 00:13:36 +01002044 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002045 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2046 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002047 unsigned int cnt = count;
2048
2049 /*
2050 * We're doing a simple sanity check for soft_wwpn setting.
2051 * We require that the user write a specific key to enable
2052 * the soft_wwpn attribute to be settable. Once the attribute
2053 * is written, the enable key resets. If further updates are
2054 * desired, the key must be written again to re-enable the
2055 * attribute.
2056 *
2057 * The "key" is not secret - it is a hardcoded string shown
2058 * here. The intent is to protect against the random user or
2059 * application that is just writing attributes.
2060 */
2061
2062 /* count may include a LF at end of string */
2063 if (buf[cnt-1] == '\n')
2064 cnt--;
2065
James Smarta12e07b2006-12-02 13:35:30 -05002066 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2067 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002068 return -EINVAL;
2069
James Smarta12e07b2006-12-02 13:35:30 -05002070 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002071 return count;
2072}
Tony Jonesee959b02008-02-22 00:13:36 +01002073static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2074 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002075
James Smarte59058c2008-08-24 21:49:00 -04002076/**
James Smart3621a712009-04-06 18:47:14 -04002077 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002078 * @dev: class device that is converted into a Scsi_host.
2079 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002080 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002081 *
2082 * Returns: size of formatted string.
2083 **/
James Smartc3f28af2006-08-18 17:47:18 -04002084static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002085lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2086 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002087{
Tony Jonesee959b02008-02-22 00:13:36 +01002088 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2090 struct lpfc_hba *phba = vport->phba;
2091
Randy Dunlapafc071e2006-10-23 21:47:13 -07002092 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2093 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002094}
2095
James Smarte59058c2008-08-24 21:49:00 -04002096/**
James Smart3621a712009-04-06 18:47:14 -04002097 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002098 * @dev class device that is converted into a Scsi_host.
2099 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002100 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002101 * @count: number of wwpn bytes in buf
2102 *
2103 * Returns:
2104 * -EACCES hba reset not enabled, adapter over temp
2105 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2106 * -EIO error taking adapter offline or online
2107 * value of count on success
2108 **/
James Smartc3f28af2006-08-18 17:47:18 -04002109static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002110lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2111 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002112{
Tony Jonesee959b02008-02-22 00:13:36 +01002113 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2115 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002116 struct completion online_compl;
James Smart1ba981f2014-02-20 09:56:45 -05002117 int stat1 = 0, stat2 = 0;
2118 unsigned int cnt = count;
2119 u8 wwpn[WWN_SZ];
James Smartfedd3b72011-02-16 12:39:24 -05002120 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002121
James Smart13815c82008-01-11 01:52:48 -05002122 if (!phba->cfg_enable_hba_reset)
2123 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002124 spin_lock_irq(&phba->hbalock);
2125 if (phba->over_temp_state == HBA_OVER_TEMP) {
2126 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002127 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002128 }
2129 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002130 /* count may include a LF at end of string */
2131 if (buf[cnt-1] == '\n')
2132 cnt--;
2133
James Smart1ba981f2014-02-20 09:56:45 -05002134 if (!phba->soft_wwn_enable)
James Smartc3f28af2006-08-18 17:47:18 -04002135 return -EINVAL;
2136
James Smart1ba981f2014-02-20 09:56:45 -05002137 /* lock setting wwpn, wwnn down */
James Smarta12e07b2006-12-02 13:35:30 -05002138 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002139
James Smart1ba981f2014-02-20 09:56:45 -05002140 rc = lpfc_wwn_set(buf, cnt, wwpn);
2141 if (!rc) {
2142 /* not able to set wwpn, unlock it */
2143 phba->soft_wwn_enable = 1;
2144 return rc;
James Smartc3f28af2006-08-18 17:47:18 -04002145 }
James Smart1ba981f2014-02-20 09:56:45 -05002146
James Smartc3f28af2006-08-18 17:47:18 -04002147 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002148 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002149 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002150 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002151
2152 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2153 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2154
James Smart46fa3112007-04-25 09:51:45 -04002155 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002156 if (stat1)
2157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002158 "0463 lpfc_soft_wwpn attribute set failed to "
2159 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002160 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002161 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2162 LPFC_EVT_ONLINE);
2163 if (rc == 0)
2164 return -ENOMEM;
2165
James Smartc3f28af2006-08-18 17:47:18 -04002166 wait_for_completion(&online_compl);
2167 if (stat2)
2168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002169 "0464 lpfc_soft_wwpn attribute set failed to "
2170 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002171 return (stat1 || stat2) ? -EIO : count;
2172}
James Smart1ba981f2014-02-20 09:56:45 -05002173static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002174 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002175
James Smarte59058c2008-08-24 21:49:00 -04002176/**
James Smart3621a712009-04-06 18:47:14 -04002177 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002178 * @dev: class device that is converted into a Scsi_host.
2179 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002180 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002181 *
2182 * Returns: size of formatted string.
2183 **/
James Smarta12e07b2006-12-02 13:35:30 -05002184static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002185lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2186 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002187{
Tony Jonesee959b02008-02-22 00:13:36 +01002188 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002189 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002190 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2191 (unsigned long long)phba->cfg_soft_wwnn);
2192}
2193
James Smarte59058c2008-08-24 21:49:00 -04002194/**
James Smart3621a712009-04-06 18:47:14 -04002195 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002196 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002197 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002198 * @count: number of wwnn bytes in buf.
2199 *
2200 * Returns:
2201 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2202 * value of count on success
2203 **/
James Smarta12e07b2006-12-02 13:35:30 -05002204static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002205lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2206 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002207{
Tony Jonesee959b02008-02-22 00:13:36 +01002208 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002209 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart1ba981f2014-02-20 09:56:45 -05002210 unsigned int cnt = count;
2211 u8 wwnn[WWN_SZ];
2212 int rc;
James Smarta12e07b2006-12-02 13:35:30 -05002213
2214 /* count may include a LF at end of string */
2215 if (buf[cnt-1] == '\n')
2216 cnt--;
2217
James Smart1ba981f2014-02-20 09:56:45 -05002218 if (!phba->soft_wwn_enable)
James Smarta12e07b2006-12-02 13:35:30 -05002219 return -EINVAL;
2220
James Smart1ba981f2014-02-20 09:56:45 -05002221 rc = lpfc_wwn_set(buf, cnt, wwnn);
2222 if (!rc) {
2223 /* Allow wwnn to be set many times, as long as the enable
2224 * is set. However, once the wwpn is set, everything locks.
2225 */
2226 return rc;
James Smarta12e07b2006-12-02 13:35:30 -05002227 }
James Smart1ba981f2014-02-20 09:56:45 -05002228
James Smarta12e07b2006-12-02 13:35:30 -05002229 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2230
2231 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2232 "lpfc%d: soft_wwnn set. Value will take effect upon "
2233 "setting of the soft_wwpn\n", phba->brd_no);
2234
2235 return count;
2236}
James Smart1ba981f2014-02-20 09:56:45 -05002237static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002238 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002239
James Smart1ba981f2014-02-20 09:56:45 -05002240/**
2241 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2242 * Optimized Access Storage (OAS) operations.
2243 * @dev: class device that is converted into a Scsi_host.
2244 * @attr: device attribute, not used.
2245 * @buf: buffer for passing information.
2246 *
2247 * Returns:
2248 * value of count
2249 **/
2250static ssize_t
2251lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2252 char *buf)
2253{
2254 struct Scsi_Host *shost = class_to_shost(dev);
2255 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2256
2257 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2258 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2259}
2260
2261/**
2262 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2263 * Optimized Access Storage (OAS) operations.
2264 * @dev: class device that is converted into a Scsi_host.
2265 * @attr: device attribute, not used.
2266 * @buf: buffer for passing information.
2267 * @count: Size of the data buffer.
2268 *
2269 * Returns:
2270 * -EINVAL count is invalid, invalid wwpn byte invalid
2271 * -EPERM oas is not supported by hba
2272 * value of count on success
2273 **/
2274static ssize_t
2275lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2276 const char *buf, size_t count)
2277{
2278 struct Scsi_Host *shost = class_to_shost(dev);
2279 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2280 unsigned int cnt = count;
2281 uint8_t wwpn[WWN_SZ];
2282 int rc;
2283
James Smartf38fa0b2014-04-04 13:52:21 -04002284 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002285 return -EPERM;
2286
2287 /* count may include a LF at end of string */
2288 if (buf[cnt-1] == '\n')
2289 cnt--;
2290
2291 rc = lpfc_wwn_set(buf, cnt, wwpn);
2292 if (rc)
2293 return rc;
2294
2295 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2296 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2297 if (wwn_to_u64(wwpn) == 0)
2298 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2299 else
2300 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2301 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2302 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2303 return count;
2304}
2305static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2306 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2307
2308/**
James Smartc92c8412016-07-06 12:36:05 -07002309 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2310 * Optimized Access Storage (OAS) operations.
2311 * @dev: class device that is converted into a Scsi_host.
2312 * @attr: device attribute, not used.
2313 * @buf: buffer for passing information.
2314 *
2315 * Returns:
2316 * value of count
2317 **/
2318static ssize_t
2319lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2320 char *buf)
2321{
2322 struct Scsi_Host *shost = class_to_shost(dev);
2323 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2324
2325 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2326}
2327
2328/**
2329 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2330 * Optimized Access Storage (OAS) operations.
2331 * @dev: class device that is converted into a Scsi_host.
2332 * @attr: device attribute, not used.
2333 * @buf: buffer for passing information.
2334 * @count: Size of the data buffer.
2335 *
2336 * Returns:
2337 * -EINVAL count is invalid, invalid wwpn byte invalid
2338 * -EPERM oas is not supported by hba
2339 * value of count on success
2340 **/
2341static ssize_t
2342lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2343 const char *buf, size_t count)
2344{
2345 struct Scsi_Host *shost = class_to_shost(dev);
2346 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2347 unsigned int cnt = count;
2348 unsigned long val;
2349 int ret;
2350
2351 if (!phba->cfg_fof)
2352 return -EPERM;
2353
2354 /* count may include a LF at end of string */
2355 if (buf[cnt-1] == '\n')
2356 cnt--;
2357
2358 ret = kstrtoul(buf, 0, &val);
2359 if (ret || (val > 0x7f))
2360 return -EINVAL;
2361
2362 if (val)
2363 phba->cfg_oas_priority = (uint8_t)val;
2364 else
2365 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2366 return count;
2367}
2368static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2369 lpfc_oas_priority_show, lpfc_oas_priority_store);
2370
2371/**
James Smart1ba981f2014-02-20 09:56:45 -05002372 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2373 * for Optimized Access Storage (OAS) operations.
2374 * @dev: class device that is converted into a Scsi_host.
2375 * @attr: device attribute, not used.
2376 * @buf: buffer for passing information.
2377 *
2378 * Returns:
2379 * value of count on success
2380 **/
2381static ssize_t
2382lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2383 char *buf)
2384{
2385 struct Scsi_Host *shost = class_to_shost(dev);
2386 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2387
2388 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2389 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2390}
2391
2392/**
2393 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2394 * for Optimized Access Storage (OAS) operations.
2395 * @dev: class device that is converted into a Scsi_host.
2396 * @attr: device attribute, not used.
2397 * @buf: buffer for passing information.
2398 * @count: Size of the data buffer.
2399 *
2400 * Returns:
2401 * -EINVAL count is invalid, invalid wwpn byte invalid
2402 * -EPERM oas is not supported by hba
2403 * value of count on success
2404 **/
2405static ssize_t
2406lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2407 const char *buf, size_t count)
2408{
2409 struct Scsi_Host *shost = class_to_shost(dev);
2410 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2411 unsigned int cnt = count;
2412 uint8_t wwpn[WWN_SZ];
2413 int rc;
2414
James Smartf38fa0b2014-04-04 13:52:21 -04002415 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002416 return -EPERM;
2417
2418 /* count may include a LF at end of string */
2419 if (buf[cnt-1] == '\n')
2420 cnt--;
2421
2422 rc = lpfc_wwn_set(buf, cnt, wwpn);
2423 if (rc)
2424 return rc;
2425
2426 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2427 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2428 if (wwn_to_u64(wwpn) == 0)
2429 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2430 else
2431 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2432 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartc92c8412016-07-06 12:36:05 -07002433 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002434 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2435 return count;
2436}
2437static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2438 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2439
2440/**
2441 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2442 * of whether luns will be enabled or disabled
2443 * for Optimized Access Storage (OAS) operations.
2444 * @dev: class device that is converted into a Scsi_host.
2445 * @attr: device attribute, not used.
2446 * @buf: buffer for passing information.
2447 *
2448 * Returns:
2449 * size of formatted string.
2450 **/
2451static ssize_t
2452lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2453 char *buf)
2454{
2455 struct Scsi_Host *shost = class_to_shost(dev);
2456 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2457
2458 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2459}
2460
2461/**
2462 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2463 * of whether luns will be enabled or disabled
2464 * for Optimized Access Storage (OAS) operations.
2465 * @dev: class device that is converted into a Scsi_host.
2466 * @attr: device attribute, not used.
2467 * @buf: buffer for passing information.
2468 * @count: Size of the data buffer.
2469 *
2470 * Returns:
2471 * -EINVAL count is invalid, invalid wwpn byte invalid
2472 * -EPERM oas is not supported by hba
2473 * value of count on success
2474 **/
2475static ssize_t
2476lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2477 const char *buf, size_t count)
2478{
2479 struct Scsi_Host *shost = class_to_shost(dev);
2480 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2481 int val = 0;
2482
James Smartf38fa0b2014-04-04 13:52:21 -04002483 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002484 return -EPERM;
2485
2486 if (!isdigit(buf[0]))
2487 return -EINVAL;
2488
2489 if (sscanf(buf, "%i", &val) != 1)
2490 return -EINVAL;
2491
2492 if ((val != 0) && (val != 1))
2493 return -EINVAL;
2494
2495 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002496 return strlen(buf);
2497}
2498static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2499 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2500
2501/**
2502 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2503 * Storage (OAS) lun returned by the
2504 * lpfc_oas_lun_show function.
2505 * @dev: class device that is converted into a Scsi_host.
2506 * @attr: device attribute, not used.
2507 * @buf: buffer for passing information.
2508 *
2509 * Returns:
2510 * size of formatted string.
2511 **/
2512static ssize_t
2513lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2514 char *buf)
2515{
2516 struct Scsi_Host *shost = class_to_shost(dev);
2517 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2518
2519 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2520 return -EFAULT;
2521
2522 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2523}
2524static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2525 lpfc_oas_lun_status_show, NULL);
2526
2527
2528/**
2529 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2530 * (OAS) operations.
2531 * @phba: lpfc_hba pointer.
2532 * @ndlp: pointer to fcp target node.
2533 * @lun: the fc lun for setting oas state.
2534 * @oas_state: the oas state to be set to the lun.
2535 *
2536 * Returns:
2537 * SUCCESS : 0
2538 * -EPERM OAS is not enabled or not supported by this port.
2539 *
2540 */
2541static size_t
2542lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002543 uint8_t tgt_wwpn[], uint64_t lun,
2544 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002545{
2546
2547 int rc = 0;
2548
James Smartf38fa0b2014-04-04 13:52:21 -04002549 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002550 return -EPERM;
2551
2552 if (oas_state) {
2553 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002554 (struct lpfc_name *)tgt_wwpn,
2555 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002556 rc = -ENOMEM;
2557 } else {
2558 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2559 (struct lpfc_name *)tgt_wwpn, lun);
2560 }
2561 return rc;
2562
2563}
2564
2565/**
2566 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2567 * Access Storage (OAS) operations.
2568 * @phba: lpfc_hba pointer.
2569 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2570 * @tgt_wwpn: wwpn of the target associated with the returned lun
2571 * @lun_status: status of the lun returned lun
2572 *
2573 * Returns the first or next lun enabled for OAS operations for the vport/target
2574 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2575 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2576 *
2577 * Return:
2578 * lun that is OAS enabled for the vport/target
2579 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2580 */
2581static uint64_t
2582lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2583 uint8_t tgt_wwpn[], uint32_t *lun_status)
2584{
2585 uint64_t found_lun;
2586
2587 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2588 return NOT_OAS_ENABLED_LUN;
2589 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2590 phba->sli4_hba.oas_next_vpt_wwpn,
2591 (struct lpfc_name *)
2592 phba->sli4_hba.oas_next_tgt_wwpn,
2593 &phba->sli4_hba.oas_next_lun,
2594 (struct lpfc_name *)vpt_wwpn,
2595 (struct lpfc_name *)tgt_wwpn,
2596 &found_lun, lun_status))
2597 return found_lun;
2598 else
2599 return NOT_OAS_ENABLED_LUN;
2600}
2601
2602/**
2603 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2604 * @phba: lpfc_hba pointer.
2605 * @vpt_wwpn: vport wwpn by reference.
2606 * @tgt_wwpn: target wwpn by reference.
2607 * @lun: the fc lun for setting oas state.
2608 * @oas_state: the oas state to be set to the oas_lun.
2609 *
2610 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2611 * a lun for OAS operations.
2612 *
2613 * Return:
2614 * SUCCESS: 0
2615 * -ENOMEM: failed to enable an lun for OAS operations
2616 * -EPERM: OAS is not enabled
2617 */
2618static ssize_t
2619lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2620 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002621 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002622{
2623
2624 int rc;
2625
2626 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002627 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002628 return rc;
2629}
2630
2631/**
2632 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2633 * @dev: class device that is converted into a Scsi_host.
2634 * @attr: device attribute, not used.
2635 * @buf: buffer for passing information.
2636 *
2637 * This routine returns a lun enabled for OAS each time the function
2638 * is called.
2639 *
2640 * Returns:
2641 * SUCCESS: size of formatted string.
2642 * -EFAULT: target or vport wwpn was not set properly.
2643 * -EPERM: oas is not enabled.
2644 **/
2645static ssize_t
2646lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2647 char *buf)
2648{
2649 struct Scsi_Host *shost = class_to_shost(dev);
2650 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2651
2652 uint64_t oas_lun;
2653 int len = 0;
2654
James Smartf38fa0b2014-04-04 13:52:21 -04002655 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002656 return -EPERM;
2657
2658 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2659 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2660 return -EFAULT;
2661
2662 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2663 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2664 return -EFAULT;
2665
2666 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2667 phba->cfg_oas_tgt_wwpn,
2668 &phba->cfg_oas_lun_status);
2669 if (oas_lun != NOT_OAS_ENABLED_LUN)
2670 phba->cfg_oas_flags |= OAS_LUN_VALID;
2671
2672 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2673
2674 return len;
2675}
2676
2677/**
2678 * lpfc_oas_lun_store - Sets the OAS state for lun
2679 * @dev: class device that is converted into a Scsi_host.
2680 * @attr: device attribute, not used.
2681 * @buf: buffer for passing information.
2682 *
2683 * This function sets the OAS state for lun. Before this function is called,
2684 * the vport wwpn, target wwpn, and oas state need to be set.
2685 *
2686 * Returns:
2687 * SUCCESS: size of formatted string.
2688 * -EFAULT: target or vport wwpn was not set properly.
2689 * -EPERM: oas is not enabled.
2690 * size of formatted string.
2691 **/
2692static ssize_t
2693lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2694 const char *buf, size_t count)
2695{
2696 struct Scsi_Host *shost = class_to_shost(dev);
2697 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2698 uint64_t scsi_lun;
2699 ssize_t rc;
2700
James Smartf38fa0b2014-04-04 13:52:21 -04002701 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002702 return -EPERM;
2703
2704 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2705 return -EFAULT;
2706
2707 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2708 return -EFAULT;
2709
2710 if (!isdigit(buf[0]))
2711 return -EINVAL;
2712
2713 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2714 return -EINVAL;
2715
2716 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002717 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2718 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002719 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2720 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartc92c8412016-07-06 12:36:05 -07002721 phba->cfg_oas_priority, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002722
2723 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002724 phba->cfg_oas_tgt_wwpn, scsi_lun,
2725 phba->cfg_oas_lun_state,
2726 phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002727 if (rc)
2728 return rc;
2729
2730 return count;
2731}
2732static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2733 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002734
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002735static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002736module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002737MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2738 " 0 - none,"
2739 " 1 - poll with interrupts enabled"
2740 " 3 - poll and disable FCP ring interrupts");
2741
Tony Jonesee959b02008-02-22 00:13:36 +01002742static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2743 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002744
James Smart12247e82016-07-06 12:36:09 -07002745LPFC_ATTR(sli_mode, 0, 0, 3,
2746 "SLI mode selector:"
2747 " 0 - auto (SLI-3 if supported),"
2748 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2749 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05002750
James Smart458c0832016-07-06 12:36:07 -07002751LPFC_ATTR_R(enable_npiv, 1, 0, 1,
2752 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05002753
James Smart7d791df2011-07-22 18:37:52 -04002754LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2755 "FCF Fast failover=1 Priority failover=2");
2756
James Smartc14e9952013-03-01 16:38:01 -05002757int lpfc_enable_rrq = 2;
James Smartab56dc22011-02-16 12:39:57 -05002758module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002759MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2760lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002761/*
2762# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2763# 0x0 = disabled, XRI/OXID use not tracked.
2764# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2765# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2766*/
2767lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002768static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2769
dea31012005-04-17 16:05:31 -05002770/*
James Smart84d1b002010-02-12 14:42:33 -05002771# lpfc_suppress_link_up: Bring link up at initialization
2772# 0x0 = bring link up (issue MBX_INIT_LINK)
2773# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2774# 0x2 = never bring up link
2775# Default value is 0.
2776*/
James Smarte40a02c2010-02-26 14:13:54 -05002777LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2778 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2779 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002780/*
2781# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2782# 1 - (1024)
2783# 2 - (2048)
2784# 3 - (3072)
2785# 4 - (4096)
2786# 5 - (5120)
2787*/
2788static ssize_t
2789lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2790{
2791 struct Scsi_Host *shost = class_to_shost(dev);
2792 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2793
2794 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2795}
2796
2797static DEVICE_ATTR(iocb_hw, S_IRUGO,
2798 lpfc_iocb_hw_show, NULL);
2799static ssize_t
2800lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2801{
2802 struct Scsi_Host *shost = class_to_shost(dev);
2803 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2804
2805 return snprintf(buf, PAGE_SIZE, "%d\n",
2806 phba->sli.ring[LPFC_ELS_RING].txq_max);
2807}
2808
2809static DEVICE_ATTR(txq_hw, S_IRUGO,
2810 lpfc_txq_hw_show, NULL);
2811static ssize_t
2812lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2813 char *buf)
2814{
2815 struct Scsi_Host *shost = class_to_shost(dev);
2816 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2817
2818 return snprintf(buf, PAGE_SIZE, "%d\n",
2819 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2820}
2821
2822static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2823 lpfc_txcmplq_hw_show, NULL);
2824
2825int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002826module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002827MODULE_PARM_DESC(lpfc_iocb_cnt,
2828 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2829lpfc_param_show(iocb_cnt);
2830lpfc_param_init(iocb_cnt, 2, 1, 5);
2831static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2832 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002833
2834/*
James Smartc01f3202006-08-18 17:47:08 -04002835# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2836# until the timer expires. Value range is [0,255]. Default value is 30.
2837*/
2838static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2839static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2840module_param(lpfc_nodev_tmo, int, 0);
2841MODULE_PARM_DESC(lpfc_nodev_tmo,
2842 "Seconds driver will hold I/O waiting "
2843 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002844
2845/**
James Smart3621a712009-04-06 18:47:14 -04002846 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002847 * @dev: class converted to a Scsi_host structure.
2848 * @attr: device attribute, not used.
2849 * @buf: on return contains the dev loss timeout in decimal.
2850 *
2851 * Returns: size of formatted string.
2852 **/
James Smartc01f3202006-08-18 17:47:08 -04002853static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002854lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2855 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002856{
Tony Jonesee959b02008-02-22 00:13:36 +01002857 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002858 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002859
James Smart3de2a652007-08-02 11:09:59 -04002860 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002861}
2862
James Smarte59058c2008-08-24 21:49:00 -04002863/**
James Smart3621a712009-04-06 18:47:14 -04002864 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002865 * @vport: lpfc vport structure pointer.
2866 * @val: contains the nodev timeout value.
2867 *
2868 * Description:
2869 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2870 * a kernel error message is printed and zero is returned.
2871 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2872 * Otherwise nodev tmo is set to the default value.
2873 *
2874 * Returns:
2875 * zero if already set or if val is in range
2876 * -EINVAL val out of range
2877 **/
James Smartc01f3202006-08-18 17:47:08 -04002878static int
James Smart3de2a652007-08-02 11:09:59 -04002879lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002880{
James Smart3de2a652007-08-02 11:09:59 -04002881 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2882 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2883 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002884 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002885 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002886 "parameter because devloss_tmo is "
2887 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002888 return 0;
2889 }
2890
2891 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002892 vport->cfg_nodev_tmo = val;
2893 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002894 return 0;
2895 }
James Smarte8b62012007-08-02 11:10:09 -04002896 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2897 "0400 lpfc_nodev_tmo attribute cannot be set to"
2898 " %d, allowed range is [%d, %d]\n",
2899 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002900 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002901 return -EINVAL;
2902}
2903
James Smarte59058c2008-08-24 21:49:00 -04002904/**
James Smart3621a712009-04-06 18:47:14 -04002905 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002906 * @vport: lpfc vport structure pointer.
2907 *
2908 * Description:
2909 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2910 **/
James Smart7054a602007-04-25 09:52:34 -04002911static void
James Smart3de2a652007-08-02 11:09:59 -04002912lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002913{
James Smart858c9f62007-06-17 19:56:39 -05002914 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002915 struct lpfc_nodelist *ndlp;
2916
James Smart51ef4c22007-08-02 11:10:31 -04002917 shost = lpfc_shost_from_vport(vport);
2918 spin_lock_irq(shost->host_lock);
2919 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002920 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002921 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2922 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002923}
2924
James Smarte59058c2008-08-24 21:49:00 -04002925/**
James Smart3621a712009-04-06 18:47:14 -04002926 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002927 * @vport: lpfc vport structure pointer.
2928 * @val: contains the tmo value.
2929 *
2930 * Description:
2931 * If the devloss tmo is already set or the vport dev loss tmo has changed
2932 * then a kernel error message is printed and zero is returned.
2933 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2934 * Otherwise nodev tmo is set to the default value.
2935 *
2936 * Returns:
2937 * zero if already set or if val is in range
2938 * -EINVAL val out of range
2939 **/
James Smartc01f3202006-08-18 17:47:08 -04002940static int
James Smart3de2a652007-08-02 11:09:59 -04002941lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002942{
James Smart3de2a652007-08-02 11:09:59 -04002943 if (vport->dev_loss_tmo_changed ||
2944 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002945 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2946 "0401 Ignoring change to nodev_tmo "
2947 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002948 return 0;
2949 }
James Smartc01f3202006-08-18 17:47:08 -04002950 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002951 vport->cfg_nodev_tmo = val;
2952 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002953 /*
2954 * For compat: set the fc_host dev loss so new rports
2955 * will get the value.
2956 */
2957 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002958 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002959 return 0;
2960 }
James Smarte8b62012007-08-02 11:10:09 -04002961 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2962 "0403 lpfc_nodev_tmo attribute cannot be set to"
2963 "%d, allowed range is [%d, %d]\n",
2964 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002965 return -EINVAL;
2966}
2967
James Smart3de2a652007-08-02 11:09:59 -04002968lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002969
Tony Jonesee959b02008-02-22 00:13:36 +01002970static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2971 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002972
2973/*
2974# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2975# disappear until the timer expires. Value range is [0,255]. Default
2976# value is 30.
2977*/
James Smartab56dc22011-02-16 12:39:57 -05002978module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002979MODULE_PARM_DESC(lpfc_devloss_tmo,
2980 "Seconds driver will hold I/O waiting "
2981 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002982lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2983 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2984lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002985
2986/**
James Smart3621a712009-04-06 18:47:14 -04002987 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002988 * @vport: lpfc vport structure pointer.
2989 * @val: contains the tmo value.
2990 *
2991 * Description:
2992 * If val is in a valid range then set the vport nodev tmo,
2993 * devloss tmo, also set the vport dev loss tmo changed flag.
2994 * Else a kernel error message is printed.
2995 *
2996 * Returns:
2997 * zero if val is in range
2998 * -EINVAL val out of range
2999 **/
James Smartc01f3202006-08-18 17:47:08 -04003000static int
James Smart3de2a652007-08-02 11:09:59 -04003001lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003002{
3003 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003004 vport->cfg_nodev_tmo = val;
3005 vport->cfg_devloss_tmo = val;
3006 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003007 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003008 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003009 return 0;
3010 }
3011
James Smarte8b62012007-08-02 11:10:09 -04003012 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3013 "0404 lpfc_devloss_tmo attribute cannot be set to"
3014 " %d, allowed range is [%d, %d]\n",
3015 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003016 return -EINVAL;
3017}
3018
James Smart3de2a652007-08-02 11:09:59 -04003019lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003020static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3021 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003022
3023/*
dea31012005-04-17 16:05:31 -05003024# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3025# deluged with LOTS of information.
3026# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003027# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003028*/
James Smartf4b4c682009-05-22 14:53:12 -04003029LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003030 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003031
3032/*
James Smart7ee5d432007-10-27 13:37:17 -04003033# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3034# objects that have been registered with the nameserver after login.
3035*/
James Smartcf971242012-03-01 22:37:32 -05003036LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003037 "Deregister nameserver objects before LOGO");
3038
3039/*
dea31012005-04-17 16:05:31 -05003040# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003041# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3042# If this parameter value is greater than 1/8th the maximum number of exchanges
3043# supported by the HBA port, then the lun queue depth will be reduced to
3044# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003045*/
James Smart572709e2013-07-15 18:32:43 -04003046LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003047 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003048
3049/*
James Smart7dc517d2010-07-14 15:32:10 -04003050# tgt_queue_depth: This parameter is used to limit the number of outstanding
3051# commands per target port. Value range is [10,65535]. Default value is 65535.
3052*/
3053LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003054 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003055
3056/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003057# hba_queue_depth: This parameter is used to limit the number of outstanding
3058# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3059# value is greater than the maximum number of exchanges supported by the HBA,
3060# then maximum number of exchanges supported by the HBA is used to determine
3061# the hba_queue_depth.
3062*/
3063LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3064 "Max number of FCP commands we can queue to a lpfc HBA");
3065
3066/*
James Smart92d7f7b2007-06-17 19:56:38 -05003067# peer_port_login: This parameter allows/prevents logins
3068# between peer ports hosted on the same physical port.
3069# When this parameter is set 0 peer ports of same physical port
3070# are not allowed to login to each other.
3071# When this parameter is set 1 peer ports of same physical port
3072# are allowed to login to each other.
3073# Default value of this parameter is 0.
3074*/
James Smart3de2a652007-08-02 11:09:59 -04003075LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3076 "Allow peer ports on the same physical port to login to each "
3077 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003078
3079/*
James Smart3de2a652007-08-02 11:09:59 -04003080# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003081# between Virtual Ports and remote initiators.
3082# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3083# other initiators and will attempt to PLOGI all remote ports.
3084# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3085# remote ports and will not attempt to PLOGI to other initiators.
3086# This parameter does not restrict to the physical port.
3087# This parameter does not restrict logins to Fabric resident remote ports.
3088# Default value of this parameter is 1.
3089*/
James Smart3de2a652007-08-02 11:09:59 -04003090static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003091module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003092MODULE_PARM_DESC(lpfc_restrict_login,
3093 "Restrict virtual ports login to remote initiators.");
3094lpfc_vport_param_show(restrict_login);
3095
James Smarte59058c2008-08-24 21:49:00 -04003096/**
James Smart3621a712009-04-06 18:47:14 -04003097 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003098 * @vport: lpfc vport structure pointer.
3099 * @val: contains the restrict login value.
3100 *
3101 * Description:
3102 * If val is not in a valid range then log a kernel error message and set
3103 * the vport restrict login to one.
3104 * If the port type is physical clear the restrict login flag and return.
3105 * Else set the restrict login flag to val.
3106 *
3107 * Returns:
3108 * zero if val is in range
3109 * -EINVAL val out of range
3110 **/
James Smart3de2a652007-08-02 11:09:59 -04003111static int
3112lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3113{
3114 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003115 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003116 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003117 "be set to %d, allowed range is [0, 1]\n",
3118 val);
James Smart3de2a652007-08-02 11:09:59 -04003119 vport->cfg_restrict_login = 1;
3120 return -EINVAL;
3121 }
3122 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3123 vport->cfg_restrict_login = 0;
3124 return 0;
3125 }
3126 vport->cfg_restrict_login = val;
3127 return 0;
3128}
3129
James Smarte59058c2008-08-24 21:49:00 -04003130/**
James Smart3621a712009-04-06 18:47:14 -04003131 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003132 * @vport: lpfc vport structure pointer.
3133 * @val: contains the restrict login value.
3134 *
3135 * Description:
3136 * If val is not in a valid range then log a kernel error message and set
3137 * the vport restrict login to one.
3138 * If the port type is physical and the val is not zero log a kernel
3139 * error message, clear the restrict login flag and return zero.
3140 * Else set the restrict login flag to val.
3141 *
3142 * Returns:
3143 * zero if val is in range
3144 * -EINVAL val out of range
3145 **/
James Smart3de2a652007-08-02 11:09:59 -04003146static int
3147lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3148{
3149 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003150 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003151 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003152 "be set to %d, allowed range is [0, 1]\n",
3153 val);
James Smart3de2a652007-08-02 11:09:59 -04003154 vport->cfg_restrict_login = 1;
3155 return -EINVAL;
3156 }
3157 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003158 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3159 "0468 lpfc_restrict_login must be 0 for "
3160 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003161 vport->cfg_restrict_login = 0;
3162 return 0;
3163 }
3164 vport->cfg_restrict_login = val;
3165 return 0;
3166}
3167lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003168static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3169 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003170
3171/*
dea31012005-04-17 16:05:31 -05003172# Some disk devices have a "select ID" or "select Target" capability.
3173# From a protocol standpoint "select ID" usually means select the
3174# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3175# annex" which contains a table that maps a "select ID" (a number
3176# between 0 and 7F) to an ALPA. By default, for compatibility with
3177# older drivers, the lpfc driver scans this table from low ALPA to high
3178# ALPA.
3179#
3180# Turning on the scan-down variable (on = 1, off = 0) will
3181# cause the lpfc driver to use an inverted table, effectively
3182# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3183#
3184# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3185# and will not work across a fabric. Also this parameter will take
3186# effect only in the case when ALPA map is not available.)
3187*/
James Smart3de2a652007-08-02 11:09:59 -04003188LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3189 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003190
3191/*
dea31012005-04-17 16:05:31 -05003192# lpfc_topology: link topology for init link
3193# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003194# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003195# 0x02 = attempt point-to-point mode only
3196# 0x04 = attempt loop mode only
3197# 0x06 = attempt point-to-point mode then loop
3198# Set point-to-point mode if you want to run as an N_Port.
3199# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3200# Default value is 0.
3201*/
James Smarte59058c2008-08-24 21:49:00 -04003202
3203/**
James Smart3621a712009-04-06 18:47:14 -04003204 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003205 * @phba: lpfc_hba pointer.
3206 * @val: topology value.
3207 *
3208 * Description:
3209 * If val is in a valid range then set the adapter's topology field and
3210 * issue a lip; if the lip fails reset the topology to the old value.
3211 *
3212 * If the value is not in range log a kernel error message and return an error.
3213 *
3214 * Returns:
3215 * zero if val is in range and lip okay
3216 * non-zero return value from lpfc_issue_lip()
3217 * -EINVAL val out of range
3218 **/
James Smarta257bf92009-04-06 18:48:10 -04003219static ssize_t
3220lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3221 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003222{
James Smarta257bf92009-04-06 18:48:10 -04003223 struct Scsi_Host *shost = class_to_shost(dev);
3224 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3225 struct lpfc_hba *phba = vport->phba;
3226 int val = 0;
3227 int nolip = 0;
3228 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003229 int err;
3230 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003231
3232 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3233 nolip = 1;
3234 val_buf = &buf[strlen("nolip ")];
3235 }
3236
3237 if (!isdigit(val_buf[0]))
3238 return -EINVAL;
3239 if (sscanf(val_buf, "%i", &val) != 1)
3240 return -EINVAL;
3241
James Smart83108bd2008-01-11 01:53:09 -05003242 if (val >= 0 && val <= 6) {
3243 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003244 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3245 val == 4) {
3246 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3247 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003248 val);
James Smartff78d8f2011-12-13 13:21:35 -05003249 return -EINVAL;
3250 }
James Smartd38dd522015-08-31 16:48:17 -04003251 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3252 val == 4) {
3253 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3254 "3114 Loop mode not supported\n");
3255 return -EINVAL;
3256 }
3257 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003258 if (nolip)
3259 return strlen(buf);
3260
James Smart88a2cfb2011-07-22 18:36:33 -04003261 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3262 "3054 lpfc_topology changed from %d to %d\n",
3263 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003264 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3265 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003266 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003267 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003268 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003269 return -EINVAL;
3270 } else
3271 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003272 }
3273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3274 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3275 "allowed range is [0, 6]\n",
3276 phba->brd_no, val);
3277 return -EINVAL;
3278}
3279static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05003280module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003281MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
3282lpfc_param_show(topology)
3283lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01003284static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003285 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003286
James Smart21e9a0a2009-05-22 14:53:21 -04003287/**
3288 * lpfc_static_vport_show: Read callback function for
3289 * lpfc_static_vport sysfs file.
3290 * @dev: Pointer to class device object.
3291 * @attr: device attribute structure.
3292 * @buf: Data buffer.
3293 *
3294 * This function is the read call back function for
3295 * lpfc_static_vport sysfs file. The lpfc_static_vport
3296 * sysfs file report the mageability of the vport.
3297 **/
3298static ssize_t
3299lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3300 char *buf)
3301{
3302 struct Scsi_Host *shost = class_to_shost(dev);
3303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3304 if (vport->vport_flag & STATIC_VPORT)
3305 sprintf(buf, "1\n");
3306 else
3307 sprintf(buf, "0\n");
3308
3309 return strlen(buf);
3310}
3311
3312/*
3313 * Sysfs attribute to control the statistical data collection.
3314 */
3315static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3316 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003317
3318/**
James Smart3621a712009-04-06 18:47:14 -04003319 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003320 * @dev: Pointer to class device.
3321 * @buf: Data buffer.
3322 * @count: Size of the data buffer.
3323 *
3324 * This function get called when an user write to the lpfc_stat_data_ctrl
3325 * sysfs file. This function parse the command written to the sysfs file
3326 * and take appropriate action. These commands are used for controlling
3327 * driver statistical data collection.
3328 * Following are the command this function handles.
3329 *
3330 * setbucket <bucket_type> <base> <step>
3331 * = Set the latency buckets.
3332 * destroybucket = destroy all the buckets.
3333 * start = start data collection
3334 * stop = stop data collection
3335 * reset = reset the collected data
3336 **/
3337static ssize_t
3338lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3339 const char *buf, size_t count)
3340{
3341 struct Scsi_Host *shost = class_to_shost(dev);
3342 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3343 struct lpfc_hba *phba = vport->phba;
3344#define LPFC_MAX_DATA_CTRL_LEN 1024
3345 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3346 unsigned long i;
3347 char *str_ptr, *token;
3348 struct lpfc_vport **vports;
3349 struct Scsi_Host *v_shost;
3350 char *bucket_type_str, *base_str, *step_str;
3351 unsigned long base, step, bucket_type;
3352
3353 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003354 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003355 return -EINVAL;
3356
James Smarteb016562014-09-03 12:58:06 -04003357 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003358 str_ptr = &bucket_data[0];
3359 /* Ignore this token - this is command token */
3360 token = strsep(&str_ptr, "\t ");
3361 if (!token)
3362 return -EINVAL;
3363
3364 bucket_type_str = strsep(&str_ptr, "\t ");
3365 if (!bucket_type_str)
3366 return -EINVAL;
3367
3368 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3369 bucket_type = LPFC_LINEAR_BUCKET;
3370 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3371 bucket_type = LPFC_POWER2_BUCKET;
3372 else
3373 return -EINVAL;
3374
3375 base_str = strsep(&str_ptr, "\t ");
3376 if (!base_str)
3377 return -EINVAL;
3378 base = simple_strtoul(base_str, NULL, 0);
3379
3380 step_str = strsep(&str_ptr, "\t ");
3381 if (!step_str)
3382 return -EINVAL;
3383 step = simple_strtoul(step_str, NULL, 0);
3384 if (!step)
3385 return -EINVAL;
3386
3387 /* Block the data collection for every vport */
3388 vports = lpfc_create_vport_work_array(phba);
3389 if (vports == NULL)
3390 return -ENOMEM;
3391
James Smartf4b4c682009-05-22 14:53:12 -04003392 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003393 v_shost = lpfc_shost_from_vport(vports[i]);
3394 spin_lock_irq(v_shost->host_lock);
3395 /* Block and reset data collection */
3396 vports[i]->stat_data_blocked = 1;
3397 if (vports[i]->stat_data_enabled)
3398 lpfc_vport_reset_stat_data(vports[i]);
3399 spin_unlock_irq(v_shost->host_lock);
3400 }
3401
3402 /* Set the bucket attributes */
3403 phba->bucket_type = bucket_type;
3404 phba->bucket_base = base;
3405 phba->bucket_step = step;
3406
James Smartf4b4c682009-05-22 14:53:12 -04003407 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003408 v_shost = lpfc_shost_from_vport(vports[i]);
3409
3410 /* Unblock data collection */
3411 spin_lock_irq(v_shost->host_lock);
3412 vports[i]->stat_data_blocked = 0;
3413 spin_unlock_irq(v_shost->host_lock);
3414 }
3415 lpfc_destroy_vport_work_array(phba, vports);
3416 return strlen(buf);
3417 }
3418
3419 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3420 vports = lpfc_create_vport_work_array(phba);
3421 if (vports == NULL)
3422 return -ENOMEM;
3423
James Smartf4b4c682009-05-22 14:53:12 -04003424 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003425 v_shost = lpfc_shost_from_vport(vports[i]);
3426 spin_lock_irq(shost->host_lock);
3427 vports[i]->stat_data_blocked = 1;
3428 lpfc_free_bucket(vport);
3429 vport->stat_data_enabled = 0;
3430 vports[i]->stat_data_blocked = 0;
3431 spin_unlock_irq(shost->host_lock);
3432 }
3433 lpfc_destroy_vport_work_array(phba, vports);
3434 phba->bucket_type = LPFC_NO_BUCKET;
3435 phba->bucket_base = 0;
3436 phba->bucket_step = 0;
3437 return strlen(buf);
3438 }
3439
3440 if (!strncmp(buf, "start", strlen("start"))) {
3441 /* If no buckets configured return error */
3442 if (phba->bucket_type == LPFC_NO_BUCKET)
3443 return -EINVAL;
3444 spin_lock_irq(shost->host_lock);
3445 if (vport->stat_data_enabled) {
3446 spin_unlock_irq(shost->host_lock);
3447 return strlen(buf);
3448 }
3449 lpfc_alloc_bucket(vport);
3450 vport->stat_data_enabled = 1;
3451 spin_unlock_irq(shost->host_lock);
3452 return strlen(buf);
3453 }
3454
3455 if (!strncmp(buf, "stop", strlen("stop"))) {
3456 spin_lock_irq(shost->host_lock);
3457 if (vport->stat_data_enabled == 0) {
3458 spin_unlock_irq(shost->host_lock);
3459 return strlen(buf);
3460 }
3461 lpfc_free_bucket(vport);
3462 vport->stat_data_enabled = 0;
3463 spin_unlock_irq(shost->host_lock);
3464 return strlen(buf);
3465 }
3466
3467 if (!strncmp(buf, "reset", strlen("reset"))) {
3468 if ((phba->bucket_type == LPFC_NO_BUCKET)
3469 || !vport->stat_data_enabled)
3470 return strlen(buf);
3471 spin_lock_irq(shost->host_lock);
3472 vport->stat_data_blocked = 1;
3473 lpfc_vport_reset_stat_data(vport);
3474 vport->stat_data_blocked = 0;
3475 spin_unlock_irq(shost->host_lock);
3476 return strlen(buf);
3477 }
3478 return -EINVAL;
3479}
3480
3481
3482/**
James Smart3621a712009-04-06 18:47:14 -04003483 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003484 * @dev: Pointer to class device object.
3485 * @buf: Data buffer.
3486 *
3487 * This function is the read call back function for
3488 * lpfc_stat_data_ctrl sysfs file. This function report the
3489 * current statistical data collection state.
3490 **/
3491static ssize_t
3492lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3493 char *buf)
3494{
3495 struct Scsi_Host *shost = class_to_shost(dev);
3496 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3497 struct lpfc_hba *phba = vport->phba;
3498 int index = 0;
3499 int i;
3500 char *bucket_type;
3501 unsigned long bucket_value;
3502
3503 switch (phba->bucket_type) {
3504 case LPFC_LINEAR_BUCKET:
3505 bucket_type = "linear";
3506 break;
3507 case LPFC_POWER2_BUCKET:
3508 bucket_type = "power2";
3509 break;
3510 default:
3511 bucket_type = "No Bucket";
3512 break;
3513 }
3514
3515 sprintf(&buf[index], "Statistical Data enabled :%d, "
3516 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3517 " Bucket step :%d\nLatency Ranges :",
3518 vport->stat_data_enabled, vport->stat_data_blocked,
3519 bucket_type, phba->bucket_base, phba->bucket_step);
3520 index = strlen(buf);
3521 if (phba->bucket_type != LPFC_NO_BUCKET) {
3522 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3523 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3524 bucket_value = phba->bucket_base +
3525 phba->bucket_step * i;
3526 else
3527 bucket_value = phba->bucket_base +
3528 (1 << i) * phba->bucket_step;
3529
3530 if (index + 10 > PAGE_SIZE)
3531 break;
3532 sprintf(&buf[index], "%08ld ", bucket_value);
3533 index = strlen(buf);
3534 }
3535 }
3536 sprintf(&buf[index], "\n");
3537 return strlen(buf);
3538}
3539
3540/*
3541 * Sysfs attribute to control the statistical data collection.
3542 */
3543static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3544 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3545
3546/*
3547 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3548 */
3549
3550/*
3551 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3552 * for each target.
3553 */
3554#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3555#define MAX_STAT_DATA_SIZE_PER_TARGET \
3556 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3557
3558
3559/**
James Smart3621a712009-04-06 18:47:14 -04003560 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003561 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003562 * @kobj: Pointer to the kernel object
3563 * @bin_attr: Attribute object
3564 * @buff: Buffer pointer
3565 * @off: File offset
3566 * @count: Buffer size
3567 *
3568 * This function is the read call back function for lpfc_drvr_stat_data
3569 * sysfs file. This function export the statistical data to user
3570 * applications.
3571 **/
3572static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003573sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3574 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003575 char *buf, loff_t off, size_t count)
3576{
3577 struct device *dev = container_of(kobj, struct device,
3578 kobj);
3579 struct Scsi_Host *shost = class_to_shost(dev);
3580 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3581 struct lpfc_hba *phba = vport->phba;
3582 int i = 0, index = 0;
3583 unsigned long nport_index;
3584 struct lpfc_nodelist *ndlp = NULL;
3585 nport_index = (unsigned long)off /
3586 MAX_STAT_DATA_SIZE_PER_TARGET;
3587
3588 if (!vport->stat_data_enabled || vport->stat_data_blocked
3589 || (phba->bucket_type == LPFC_NO_BUCKET))
3590 return 0;
3591
3592 spin_lock_irq(shost->host_lock);
3593 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3594 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3595 continue;
3596
3597 if (nport_index > 0) {
3598 nport_index--;
3599 continue;
3600 }
3601
3602 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3603 > count)
3604 break;
3605
3606 if (!ndlp->lat_data)
3607 continue;
3608
3609 /* Print the WWN */
3610 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3611 ndlp->nlp_portname.u.wwn[0],
3612 ndlp->nlp_portname.u.wwn[1],
3613 ndlp->nlp_portname.u.wwn[2],
3614 ndlp->nlp_portname.u.wwn[3],
3615 ndlp->nlp_portname.u.wwn[4],
3616 ndlp->nlp_portname.u.wwn[5],
3617 ndlp->nlp_portname.u.wwn[6],
3618 ndlp->nlp_portname.u.wwn[7]);
3619
3620 index = strlen(buf);
3621
3622 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3623 sprintf(&buf[index], "%010u,",
3624 ndlp->lat_data[i].cmd_count);
3625 index = strlen(buf);
3626 }
3627 sprintf(&buf[index], "\n");
3628 index = strlen(buf);
3629 }
3630 spin_unlock_irq(shost->host_lock);
3631 return index;
3632}
3633
3634static struct bin_attribute sysfs_drvr_stat_data_attr = {
3635 .attr = {
3636 .name = "lpfc_drvr_stat_data",
3637 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003638 },
3639 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3640 .read = sysfs_drvr_stat_data_read,
3641 .write = NULL,
3642};
3643
dea31012005-04-17 16:05:31 -05003644/*
3645# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3646# connection.
James Smart76a95d72010-11-20 23:11:48 -05003647# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003648*/
James Smarte59058c2008-08-24 21:49:00 -04003649/**
James Smart3621a712009-04-06 18:47:14 -04003650 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003651 * @phba: lpfc_hba pointer.
3652 * @val: link speed value.
3653 *
3654 * Description:
3655 * If val is in a valid range then set the adapter's link speed field and
3656 * issue a lip; if the lip fails reset the link speed to the old value.
3657 *
3658 * Notes:
3659 * If the value is not in range log a kernel error message and return an error.
3660 *
3661 * Returns:
3662 * zero if val is in range and lip okay.
3663 * non-zero return value from lpfc_issue_lip()
3664 * -EINVAL val out of range
3665 **/
James Smarta257bf92009-04-06 18:48:10 -04003666static ssize_t
3667lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3668 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003669{
James Smarta257bf92009-04-06 18:48:10 -04003670 struct Scsi_Host *shost = class_to_shost(dev);
3671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3672 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003673 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003674 int nolip = 0;
3675 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003676 int err;
3677 uint32_t prev_val;
3678
James Smarta257bf92009-04-06 18:48:10 -04003679 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3680 nolip = 1;
3681 val_buf = &buf[strlen("nolip ")];
3682 }
3683
3684 if (!isdigit(val_buf[0]))
3685 return -EINVAL;
3686 if (sscanf(val_buf, "%i", &val) != 1)
3687 return -EINVAL;
3688
James Smart88a2cfb2011-07-22 18:36:33 -04003689 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3690 "3055 lpfc_link_speed changed from %d to %d %s\n",
3691 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3692
James Smart76a95d72010-11-20 23:11:48 -05003693 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3694 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3695 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3696 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3697 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04003698 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3699 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05003700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3701 "2879 lpfc_link_speed attribute cannot be set "
3702 "to %d. Speed is not supported by this port.\n",
3703 val);
James Smart83108bd2008-01-11 01:53:09 -05003704 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003705 }
James Smartff78d8f2011-12-13 13:21:35 -05003706 if (val == LPFC_USER_LINK_SPEED_16G &&
3707 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3709 "3112 lpfc_link_speed attribute cannot be set "
3710 "to %d. Speed is not supported in loop mode.\n",
3711 val);
3712 return -EINVAL;
3713 }
James Smart76a95d72010-11-20 23:11:48 -05003714 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3715 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003716 prev_val = phba->cfg_link_speed;
3717 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003718 if (nolip)
3719 return strlen(buf);
3720
James Smart83108bd2008-01-11 01:53:09 -05003721 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003722 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003723 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003724 return -EINVAL;
3725 } else
3726 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003727 }
James Smart83108bd2008-01-11 01:53:09 -05003728 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003729 "0469 lpfc_link_speed attribute cannot be set to %d, "
3730 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003731 return -EINVAL;
3732}
3733
3734static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003735module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003736MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3737lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003738
3739/**
James Smart3621a712009-04-06 18:47:14 -04003740 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003741 * @phba: lpfc_hba pointer.
3742 * @val: link speed value.
3743 *
3744 * Description:
3745 * If val is in a valid range then set the adapter's link speed field.
3746 *
3747 * Notes:
3748 * If the value is not in range log a kernel error message, clear the link
3749 * speed and return an error.
3750 *
3751 * Returns:
3752 * zero if val saved.
3753 * -EINVAL val out of range
3754 **/
James Smart83108bd2008-01-11 01:53:09 -05003755static int
3756lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3757{
James Smartff78d8f2011-12-13 13:21:35 -05003758 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3760 "3111 lpfc_link_speed of %d cannot "
3761 "support loop mode, setting topology to default.\n",
3762 val);
3763 phba->cfg_topology = 0;
3764 }
James Smart76a95d72010-11-20 23:11:48 -05003765 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3766 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003767 phba->cfg_link_speed = val;
3768 return 0;
3769 }
3770 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003771 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003772 "be set to %d, allowed values are "
3773 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003774 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003775 return -EINVAL;
3776}
3777
Tony Jonesee959b02008-02-22 00:13:36 +01003778static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003779 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003780
3781/*
James Smart0d878412009-10-02 15:16:56 -04003782# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3783# 0 = aer disabled or not supported
3784# 1 = aer supported and enabled (default)
3785# Value range is [0,1]. Default value is 1.
3786*/
3787
3788/**
3789 * lpfc_aer_support_store - Set the adapter for aer support
3790 *
3791 * @dev: class device that is converted into a Scsi_host.
3792 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003793 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003794 * @count: unused variable.
3795 *
3796 * Description:
3797 * If the val is 1 and currently the device's AER capability was not
3798 * enabled, invoke the kernel's enable AER helper routine, trying to
3799 * enable the device's AER capability. If the helper routine enabling
3800 * AER returns success, update the device's cfg_aer_support flag to
3801 * indicate AER is supported by the device; otherwise, if the device
3802 * AER capability is already enabled to support AER, then do nothing.
3803 *
3804 * If the val is 0 and currently the device's AER support was enabled,
3805 * invoke the kernel's disable AER helper routine. After that, update
3806 * the device's cfg_aer_support flag to indicate AER is not supported
3807 * by the device; otherwise, if the device AER capability is already
3808 * disabled from supporting AER, then do nothing.
3809 *
3810 * Returns:
3811 * length of the buf on success if val is in range the intended mode
3812 * is supported.
3813 * -EINVAL if val out of range or intended mode is not supported.
3814 **/
3815static ssize_t
3816lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3817 const char *buf, size_t count)
3818{
3819 struct Scsi_Host *shost = class_to_shost(dev);
3820 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3821 struct lpfc_hba *phba = vport->phba;
3822 int val = 0, rc = -EINVAL;
3823
3824 if (!isdigit(buf[0]))
3825 return -EINVAL;
3826 if (sscanf(buf, "%i", &val) != 1)
3827 return -EINVAL;
3828
3829 switch (val) {
3830 case 0:
3831 if (phba->hba_flag & HBA_AER_ENABLED) {
3832 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3833 if (!rc) {
3834 spin_lock_irq(&phba->hbalock);
3835 phba->hba_flag &= ~HBA_AER_ENABLED;
3836 spin_unlock_irq(&phba->hbalock);
3837 phba->cfg_aer_support = 0;
3838 rc = strlen(buf);
3839 } else
James Smart891478a2009-11-18 15:40:23 -05003840 rc = -EPERM;
3841 } else {
James Smart0d878412009-10-02 15:16:56 -04003842 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003843 rc = strlen(buf);
3844 }
James Smart0d878412009-10-02 15:16:56 -04003845 break;
3846 case 1:
3847 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3848 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3849 if (!rc) {
3850 spin_lock_irq(&phba->hbalock);
3851 phba->hba_flag |= HBA_AER_ENABLED;
3852 spin_unlock_irq(&phba->hbalock);
3853 phba->cfg_aer_support = 1;
3854 rc = strlen(buf);
3855 } else
James Smart891478a2009-11-18 15:40:23 -05003856 rc = -EPERM;
3857 } else {
James Smart0d878412009-10-02 15:16:56 -04003858 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003859 rc = strlen(buf);
3860 }
James Smart0d878412009-10-02 15:16:56 -04003861 break;
3862 default:
3863 rc = -EINVAL;
3864 break;
3865 }
3866 return rc;
3867}
3868
3869static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003870module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003871MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3872lpfc_param_show(aer_support)
3873
3874/**
3875 * lpfc_aer_support_init - Set the initial adapters aer support flag
3876 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003877 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003878 *
3879 * Description:
3880 * If val is in a valid range [0,1], then set the adapter's initial
3881 * cfg_aer_support field. It will be up to the driver's probe_one
3882 * routine to determine whether the device's AER support can be set
3883 * or not.
3884 *
3885 * Notes:
3886 * If the value is not in range log a kernel error message, and
3887 * choose the default value of setting AER support and return.
3888 *
3889 * Returns:
3890 * zero if val saved.
3891 * -EINVAL val out of range
3892 **/
3893static int
3894lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3895{
3896 if (val == 0 || val == 1) {
3897 phba->cfg_aer_support = val;
3898 return 0;
3899 }
3900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3901 "2712 lpfc_aer_support attribute value %d out "
3902 "of range, allowed values are 0|1, setting it "
3903 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003904 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003905 phba->cfg_aer_support = 1;
3906 return -EINVAL;
3907}
3908
3909static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3910 lpfc_aer_support_show, lpfc_aer_support_store);
3911
3912/**
3913 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3914 * @dev: class device that is converted into a Scsi_host.
3915 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003916 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003917 * @count: unused variable.
3918 *
3919 * Description:
3920 * If the @buf contains 1 and the device currently has the AER support
3921 * enabled, then invokes the kernel AER helper routine
3922 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3923 * error status register.
3924 *
3925 * Notes:
3926 *
3927 * Returns:
3928 * -EINVAL if the buf does not contain the 1 or the device is not currently
3929 * enabled with the AER support.
3930 **/
3931static ssize_t
3932lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3933 const char *buf, size_t count)
3934{
3935 struct Scsi_Host *shost = class_to_shost(dev);
3936 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3937 struct lpfc_hba *phba = vport->phba;
3938 int val, rc = -1;
3939
3940 if (!isdigit(buf[0]))
3941 return -EINVAL;
3942 if (sscanf(buf, "%i", &val) != 1)
3943 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003944 if (val != 1)
3945 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003946
James Smart891478a2009-11-18 15:40:23 -05003947 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003948 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3949
3950 if (rc == 0)
3951 return strlen(buf);
3952 else
James Smart891478a2009-11-18 15:40:23 -05003953 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003954}
3955
3956static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3957 lpfc_aer_cleanup_state);
3958
James Smart912e3ac2011-05-24 11:42:11 -04003959/**
3960 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3961 *
3962 * @dev: class device that is converted into a Scsi_host.
3963 * @attr: device attribute, not used.
3964 * @buf: containing the string the number of vfs to be enabled.
3965 * @count: unused variable.
3966 *
3967 * Description:
3968 * When this api is called either through user sysfs, the driver shall
3969 * try to enable or disable SR-IOV virtual functions according to the
3970 * following:
3971 *
3972 * If zero virtual function has been enabled to the physical function,
3973 * the driver shall invoke the pci enable virtual function api trying
3974 * to enable the virtual functions. If the nr_vfn provided is greater
3975 * than the maximum supported, the maximum virtual function number will
3976 * be used for invoking the api; otherwise, the nr_vfn provided shall
3977 * be used for invoking the api. If the api call returned success, the
3978 * actual number of virtual functions enabled will be set to the driver
3979 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3980 * cfg_sriov_nr_virtfn remains zero.
3981 *
3982 * If none-zero virtual functions have already been enabled to the
3983 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3984 * -EINVAL will be returned and the driver does nothing;
3985 *
3986 * If the nr_vfn provided is zero and none-zero virtual functions have
3987 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3988 * disabling virtual function api shall be invoded to disable all the
3989 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3990 * zero. Otherwise, if zero virtual function has been enabled, do
3991 * nothing.
3992 *
3993 * Returns:
3994 * length of the buf on success if val is in range the intended mode
3995 * is supported.
3996 * -EINVAL if val out of range or intended mode is not supported.
3997 **/
3998static ssize_t
3999lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4000 const char *buf, size_t count)
4001{
4002 struct Scsi_Host *shost = class_to_shost(dev);
4003 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4004 struct lpfc_hba *phba = vport->phba;
4005 struct pci_dev *pdev = phba->pcidev;
4006 int val = 0, rc = -EINVAL;
4007
4008 /* Sanity check on user data */
4009 if (!isdigit(buf[0]))
4010 return -EINVAL;
4011 if (sscanf(buf, "%i", &val) != 1)
4012 return -EINVAL;
4013 if (val < 0)
4014 return -EINVAL;
4015
4016 /* Request disabling virtual functions */
4017 if (val == 0) {
4018 if (phba->cfg_sriov_nr_virtfn > 0) {
4019 pci_disable_sriov(pdev);
4020 phba->cfg_sriov_nr_virtfn = 0;
4021 }
4022 return strlen(buf);
4023 }
4024
4025 /* Request enabling virtual functions */
4026 if (phba->cfg_sriov_nr_virtfn > 0) {
4027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4028 "3018 There are %d virtual functions "
4029 "enabled on physical function.\n",
4030 phba->cfg_sriov_nr_virtfn);
4031 return -EEXIST;
4032 }
4033
4034 if (val <= LPFC_MAX_VFN_PER_PFN)
4035 phba->cfg_sriov_nr_virtfn = val;
4036 else {
4037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4038 "3019 Enabling %d virtual functions is not "
4039 "allowed.\n", val);
4040 return -EINVAL;
4041 }
4042
4043 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4044 if (rc) {
4045 phba->cfg_sriov_nr_virtfn = 0;
4046 rc = -EPERM;
4047 } else
4048 rc = strlen(buf);
4049
4050 return rc;
4051}
4052
4053static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
4054module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
4055MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
4056lpfc_param_show(sriov_nr_virtfn)
4057
4058/**
4059 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
4060 * @phba: lpfc_hba pointer.
4061 * @val: link speed value.
4062 *
4063 * Description:
4064 * If val is in a valid range [0,255], then set the adapter's initial
4065 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
4066 * number shall be used instead. It will be up to the driver's probe_one
4067 * routine to determine whether the device's SR-IOV is supported or not.
4068 *
4069 * Returns:
4070 * zero if val saved.
4071 * -EINVAL val out of range
4072 **/
4073static int
4074lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
4075{
4076 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
4077 phba->cfg_sriov_nr_virtfn = val;
4078 return 0;
4079 }
4080
4081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4082 "3017 Enabling %d virtual functions is not "
4083 "allowed.\n", val);
4084 return -EINVAL;
4085}
4086static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4087 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4088
James Smart173edbb2012-06-12 13:54:50 -04004089/**
James Smartc71ab862012-10-31 14:44:33 -04004090 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4091 *
4092 * @dev: class device that is converted into a Scsi_host.
4093 * @attr: device attribute, not used.
4094 * @buf: containing the string the number of vfs to be enabled.
4095 * @count: unused variable.
4096 *
4097 * Description:
4098 *
4099 * Returns:
4100 * length of the buf on success if val is in range the intended mode
4101 * is supported.
4102 * -EINVAL if val out of range or intended mode is not supported.
4103 **/
4104static ssize_t
4105lpfc_request_firmware_upgrade_store(struct device *dev,
4106 struct device_attribute *attr,
4107 const char *buf, size_t count)
4108{
4109 struct Scsi_Host *shost = class_to_shost(dev);
4110 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4111 struct lpfc_hba *phba = vport->phba;
4112 int val = 0, rc = -EINVAL;
4113
4114 /* Sanity check on user data */
4115 if (!isdigit(buf[0]))
4116 return -EINVAL;
4117 if (sscanf(buf, "%i", &val) != 1)
4118 return -EINVAL;
4119 if (val != 1)
4120 return -EINVAL;
4121
4122 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4123 if (rc)
4124 rc = -EPERM;
4125 else
4126 rc = strlen(buf);
4127 return rc;
4128}
4129
4130static int lpfc_req_fw_upgrade;
4131module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4132MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4133lpfc_param_show(request_firmware_upgrade)
4134
4135/**
4136 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4137 * @phba: lpfc_hba pointer.
4138 * @val: 0 or 1.
4139 *
4140 * Description:
4141 * Set the initial Linux generic firmware upgrade enable or disable flag.
4142 *
4143 * Returns:
4144 * zero if val saved.
4145 * -EINVAL val out of range
4146 **/
4147static int
4148lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4149{
4150 if (val >= 0 && val <= 1) {
4151 phba->cfg_request_firmware_upgrade = val;
4152 return 0;
4153 }
4154 return -EINVAL;
4155}
4156static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4157 lpfc_request_firmware_upgrade_show,
4158 lpfc_request_firmware_upgrade_store);
4159
4160/**
James Smart173edbb2012-06-12 13:54:50 -04004161 * lpfc_fcp_imax_store
4162 *
4163 * @dev: class device that is converted into a Scsi_host.
4164 * @attr: device attribute, not used.
4165 * @buf: string with the number of fast-path FCP interrupts per second.
4166 * @count: unused variable.
4167 *
4168 * Description:
4169 * If val is in a valid range [636,651042], then set the adapter's
4170 * maximum number of fast-path FCP interrupts per second.
4171 *
4172 * Returns:
4173 * length of the buf on success if val is in range the intended mode
4174 * is supported.
4175 * -EINVAL if val out of range or intended mode is not supported.
4176 **/
4177static ssize_t
4178lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4179 const char *buf, size_t count)
4180{
4181 struct Scsi_Host *shost = class_to_shost(dev);
4182 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4183 struct lpfc_hba *phba = vport->phba;
4184 int val = 0, i;
4185
James Smartbf8dae82012-08-03 12:36:24 -04004186 /* fcp_imax is only valid for SLI4 */
4187 if (phba->sli_rev != LPFC_SLI_REV4)
4188 return -EINVAL;
4189
James Smart173edbb2012-06-12 13:54:50 -04004190 /* Sanity check on user data */
4191 if (!isdigit(buf[0]))
4192 return -EINVAL;
4193 if (sscanf(buf, "%i", &val) != 1)
4194 return -EINVAL;
4195
James Smartbf8dae82012-08-03 12:36:24 -04004196 /*
4197 * Value range for the HBA is [5000,5000000]
4198 * The value for each EQ depends on how many EQs are configured.
4199 */
4200 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04004201 return -EINVAL;
4202
4203 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04004204 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04004205 lpfc_modify_fcp_eq_delay(phba, i);
4206
4207 return strlen(buf);
4208}
4209
4210/*
4211# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004212# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004213#
James Smartbf8dae82012-08-03 12:36:24 -04004214# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004215*/
James Smartbf8dae82012-08-03 12:36:24 -04004216static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004217module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4218MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004219 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004220lpfc_param_show(fcp_imax)
4221
4222/**
4223 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4224 * @phba: lpfc_hba pointer.
4225 * @val: link speed value.
4226 *
4227 * Description:
4228 * If val is in a valid range [636,651042], then initialize the adapter's
4229 * maximum number of fast-path FCP interrupts per second.
4230 *
4231 * Returns:
4232 * zero if val saved.
4233 * -EINVAL val out of range
4234 **/
4235static int
4236lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4237{
James Smartbf8dae82012-08-03 12:36:24 -04004238 if (phba->sli_rev != LPFC_SLI_REV4) {
4239 phba->cfg_fcp_imax = 0;
4240 return 0;
4241 }
4242
4243 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04004244 phba->cfg_fcp_imax = val;
4245 return 0;
4246 }
4247
4248 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4249 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04004250 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004251
4252 return 0;
4253}
4254
4255static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4256 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4257
James Smart7bb03bb2013-04-17 20:19:16 -04004258/**
4259 * lpfc_state_show - Display current driver CPU affinity
4260 * @dev: class converted to a Scsi_host structure.
4261 * @attr: device attribute, not used.
4262 * @buf: on return contains text describing the state of the link.
4263 *
4264 * Returns: size of formatted string.
4265 **/
4266static ssize_t
4267lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4268 char *buf)
4269{
4270 struct Scsi_Host *shost = class_to_shost(dev);
4271 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4272 struct lpfc_hba *phba = vport->phba;
4273 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004274 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004275
4276 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4277 (phba->intr_type != MSIX))
4278 return len;
4279
4280 switch (phba->cfg_fcp_cpu_map) {
4281 case 0:
4282 len += snprintf(buf + len, PAGE_SIZE-len,
4283 "fcp_cpu_map: No mapping (%d)\n",
4284 phba->cfg_fcp_cpu_map);
4285 return len;
4286 case 1:
4287 len += snprintf(buf + len, PAGE_SIZE-len,
4288 "fcp_cpu_map: HBA centric mapping (%d): "
4289 "%d online CPUs\n",
4290 phba->cfg_fcp_cpu_map,
4291 phba->sli4_hba.num_online_cpu);
4292 break;
4293 case 2:
4294 len += snprintf(buf + len, PAGE_SIZE-len,
4295 "fcp_cpu_map: Driver centric mapping (%d): "
4296 "%d online CPUs\n",
4297 phba->cfg_fcp_cpu_map,
4298 phba->sli4_hba.num_online_cpu);
4299 break;
4300 }
4301
James Smart76fd07a2014-02-20 09:57:18 -05004302 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4303 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4304
4305 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004306 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4307 len += snprintf(buf + len, PAGE_SIZE-len,
4308 "CPU %02d io_chan %02d "
4309 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004310 phba->sli4_hba.curr_disp_cpu,
4311 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004312 cpup->core_id);
4313 else
4314 len += snprintf(buf + len, PAGE_SIZE-len,
4315 "CPU %02d io_chan %02d "
4316 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004317 phba->sli4_hba.curr_disp_cpu,
4318 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004319 cpup->core_id, cpup->irq);
4320
James Smart76fd07a2014-02-20 09:57:18 -05004321 phba->sli4_hba.curr_disp_cpu++;
4322
4323 /* display max number of CPUs keeping some margin */
4324 if (phba->sli4_hba.curr_disp_cpu <
4325 phba->sli4_hba.num_present_cpu &&
4326 (len >= (PAGE_SIZE - 64))) {
4327 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4328 break;
4329 }
James Smart7bb03bb2013-04-17 20:19:16 -04004330 }
James Smart76fd07a2014-02-20 09:57:18 -05004331
4332 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4333 phba->sli4_hba.curr_disp_cpu = 0;
4334
James Smart7bb03bb2013-04-17 20:19:16 -04004335 return len;
4336}
4337
4338/**
4339 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4340 * @dev: class device that is converted into a Scsi_host.
4341 * @attr: device attribute, not used.
4342 * @buf: one or more lpfc_polling_flags values.
4343 * @count: not used.
4344 *
4345 * Returns:
4346 * -EINVAL - Not implemented yet.
4347 **/
4348static ssize_t
4349lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4350 const char *buf, size_t count)
4351{
4352 int status = -EINVAL;
4353 return status;
4354}
4355
4356/*
4357# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4358# for the HBA.
4359#
4360# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4361# 0 - Do not affinitze IRQ vectors
4362# 1 - Affintize HBA vectors with respect to each HBA
4363# (start with CPU0 for each HBA)
4364# 2 - Affintize HBA vectors with respect to the entire driver
4365# (round robin thru all CPUs across all HBAs)
4366*/
4367static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4368module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4369MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4370 "Defines how to map CPUs to IRQ vectors per HBA");
4371
4372/**
4373 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4374 * @phba: lpfc_hba pointer.
4375 * @val: link speed value.
4376 *
4377 * Description:
4378 * If val is in a valid range [0-2], then affinitze the adapter's
4379 * MSIX vectors.
4380 *
4381 * Returns:
4382 * zero if val saved.
4383 * -EINVAL val out of range
4384 **/
4385static int
4386lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4387{
4388 if (phba->sli_rev != LPFC_SLI_REV4) {
4389 phba->cfg_fcp_cpu_map = 0;
4390 return 0;
4391 }
4392
4393 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4394 phba->cfg_fcp_cpu_map = val;
4395 return 0;
4396 }
4397
4398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4399 "3326 fcp_cpu_map: %d out of range, using default\n",
4400 val);
4401 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4402
4403 return 0;
4404}
4405
4406static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4407 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4408
James Smart0d878412009-10-02 15:16:56 -04004409/*
dea31012005-04-17 16:05:31 -05004410# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4411# Value range is [2,3]. Default value is 3.
4412*/
James Smart3de2a652007-08-02 11:09:59 -04004413LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4414 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004415
4416/*
4417# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4418# is [0,1]. Default value is 0.
4419*/
James Smart3de2a652007-08-02 11:09:59 -04004420LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4421 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004422
4423/*
James Smart3cb01c52013-07-15 18:35:04 -04004424# lpfc_first_burst_size: First burst size to use on the NPorts
4425# that support first burst.
4426# Value range is [0,65536]. Default value is 0.
4427*/
4428LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4429 "First burst size for Targets that support first burst");
4430
4431/*
James Smart977b5a02008-09-07 11:52:04 -04004432# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4433# depth. Default value is 0. When the value of this parameter is zero the
4434# SCSI command completion time is not used for controlling I/O queue depth. When
4435# the parameter is set to a non-zero value, the I/O queue depth is controlled
4436# to limit the I/O completion time to the parameter value.
4437# The value is set in milliseconds.
4438*/
4439static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05004440module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04004441MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
4442 "Use command completion time to control queue depth");
4443lpfc_vport_param_show(max_scsicmpl_time);
4444lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
4445static int
4446lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4447{
4448 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4449 struct lpfc_nodelist *ndlp, *next_ndlp;
4450
4451 if (val == vport->cfg_max_scsicmpl_time)
4452 return 0;
4453 if ((val < 0) || (val > 60000))
4454 return -EINVAL;
4455 vport->cfg_max_scsicmpl_time = val;
4456
4457 spin_lock_irq(shost->host_lock);
4458 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4459 if (!NLP_CHK_NODE_ACT(ndlp))
4460 continue;
4461 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4462 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004463 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004464 }
4465 spin_unlock_irq(shost->host_lock);
4466 return 0;
4467}
4468lpfc_vport_param_store(max_scsicmpl_time);
4469static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4470 lpfc_max_scsicmpl_time_show,
4471 lpfc_max_scsicmpl_time_store);
4472
4473/*
dea31012005-04-17 16:05:31 -05004474# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4475# range is [0,1]. Default value is 0.
4476*/
4477LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4478
4479/*
James Smart49aa1432012-08-03 12:36:42 -04004480# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4481# range is [0,1]. Default value is 0.
4482# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4483# For [1], FCP commands are issued to a Work Queue associated with the
4484# current CPU.
James Smartec2087a2013-09-06 12:20:36 -04004485# It would be set to 1 by the driver if it's able to set up cpu affinity
4486# for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4487# roundrobin scheduling of FCP I/Os through WQs will be used.
James Smart49aa1432012-08-03 12:36:42 -04004488*/
James Smartec2087a2013-09-06 12:20:36 -04004489LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
James Smart49aa1432012-08-03 12:36:42 -04004490 "issuing commands [0] - Round Robin, [1] - Current CPU");
4491
4492/*
James Smarta6571c62012-10-31 14:44:42 -04004493# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4494# range is [0,1]. Default value is 0.
4495# For [0], bus reset issues target reset to ALL devices
4496# For [1], bus reset issues target reset to non-FCP2 devices
4497*/
4498LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4499 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4500
4501
4502/*
dea31012005-04-17 16:05:31 -05004503# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4504# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004505# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004506# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4507# cr_delay is set to 0.
4508*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004509LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004510 "interrupt response is generated");
4511
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004512LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004513 "interrupt response is generated");
4514
4515/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004516# lpfc_multi_ring_support: Determines how many rings to spread available
4517# cmd/rsp IOCB entries across.
4518# Value range is [1,2]. Default value is 1.
4519*/
4520LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4521 "SLI rings to spread IOCB entries across");
4522
4523/*
James Smarta4bc3372006-12-02 13:34:16 -05004524# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4525# identifies what rctl value to configure the additional ring for.
4526# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4527*/
James Smart6a9c52c2009-10-02 15:16:51 -04004528LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004529 255, "Identifies RCTL for additional ring configuration");
4530
4531/*
4532# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4533# identifies what type value to configure the additional ring for.
4534# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4535*/
James Smart6a9c52c2009-10-02 15:16:51 -04004536LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004537 255, "Identifies TYPE for additional ring configuration");
4538
4539/*
James Smart4258e982015-12-16 18:11:58 -05004540# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4541# 0 = SmartSAN functionality disabled (default)
4542# 1 = SmartSAN functionality enabled
4543# This parameter will override the value of lpfc_fdmi_on module parameter.
4544# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004545*/
James Smart4258e982015-12-16 18:11:58 -05004546LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4547
4548/*
4549# lpfc_fdmi_on: Controls FDMI support.
4550# 0 No FDMI support (default)
4551# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004552# Traditional FDMI support means the driver will assume FDMI-2 support;
4553# however, if that fails, it will fallback to FDMI-1.
4554# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4555# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4556# lpfc_fdmi_on.
4557# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004558*/
James Smart8663cbb2016-03-31 14:12:33 -07004559LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004560
4561/*
4562# Specifies the maximum number of ELS cmds we can have outstanding (for
4563# discovery). Value range is [1,64]. Default value = 32.
4564*/
James Smart3de2a652007-08-02 11:09:59 -04004565LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004566 "during discovery");
4567
4568/*
James Smartc4a7c922013-05-31 17:04:59 -04004569# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4570# will be scanned by the SCSI midlayer when sequential scanning is
4571# used; and is also the highest LUN ID allowed when the SCSI midlayer
4572# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4573# LUN ID limit, but the SCSI midlayer requires this field for the uses
4574# above. The lpfc driver limits the default value to 255 for two reasons.
4575# As it bounds the sequential scan loop, scanning for thousands of luns
4576# on a target can take minutes of wall clock time. Additionally,
4577# there are FC targets, such as JBODs, that only recognize 8-bits of
4578# LUN ID. When they receive a value greater than 8 bits, they chop off
4579# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4580# and so on all as LUN ID 0. This causes the linux kernel, which sees
4581# valid responses at each of the LUN IDs, to believe there are multiple
4582# devices present, when in fact, there is only 1.
4583# A customer that is aware of their target behaviors, and the results as
4584# indicated above, is welcome to increase the lpfc_max_luns value.
4585# As mentioned, this value is not used by the lpfc driver, only the
4586# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004587# Value range is [0,65535]. Default value is 255.
4588# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004589*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004590LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004591
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004592/*
4593# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4594# Value range is [1,255], default value is 10.
4595*/
4596LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4597 "Milliseconds driver will wait between polling FCP ring");
4598
James Smart4ff43242006-12-02 13:34:56 -05004599/*
James Smart0c411222013-09-06 12:22:46 -04004600# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4601# to complete in seconds. Value range is [5,180], default value is 60.
4602*/
4603LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4604 "Maximum time to wait for task management commands to complete");
4605/*
James Smart4ff43242006-12-02 13:34:56 -05004606# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4607# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004608# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004609# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004610# 2 = MSI-X enabled (default)
4611# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004612*/
George Kadianakis8605c462010-01-17 21:19:31 +02004613LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004614 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004615
James Smart13815c82008-01-11 01:52:48 -05004616/*
James Smart67d12732012-08-03 12:36:13 -04004617# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4618#
4619# Value range is [1,7]. Default value is 4.
4620*/
4621LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4622 LPFC_FCP_IO_CHAN_MAX,
4623 "Set the number of FCP I/O channels");
4624
4625/*
James Smart13815c82008-01-11 01:52:48 -05004626# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4627# 0 = HBA resets disabled
4628# 1 = HBA resets enabled (default)
4629# Value range is [0,1]. Default value is 1.
4630*/
4631LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004632
James Smart13815c82008-01-11 01:52:48 -05004633/*
James Smarteb7a3392010-11-20 23:12:02 -05004634# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004635# 0 = HBA Heartbeat disabled
4636# 1 = HBA Heartbeat enabled (default)
4637# Value range is [0,1]. Default value is 1.
4638*/
James Smarteb7a3392010-11-20 23:12:02 -05004639LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004640
James Smart83108bd2008-01-11 01:53:09 -05004641/*
James Smart1ba981f2014-02-20 09:56:45 -05004642# lpfc_EnableXLane: Enable Express Lane Feature
4643# 0x0 Express Lane Feature disabled
4644# 0x1 Express Lane Feature enabled
4645# Value range is [0,1]. Default value is 0.
4646*/
4647LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4648
4649/*
4650# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4651# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4652# Value range is [0x0,0x7f]. Default value is 0
4653*/
James Smart28d7f3d2014-05-21 08:05:28 -04004654LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004655
4656/*
James Smart81301a92008-12-04 22:39:46 -05004657# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4658# 0 = BlockGuard disabled (default)
4659# 1 = BlockGuard enabled
4660# Value range is [0,1]. Default value is 0.
4661*/
4662LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4663
James Smart6fb120a2009-05-22 14:52:59 -04004664/*
James Smartba20c852012-08-03 12:36:52 -04004665# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4666# 0 = disabled (default)
4667# 1 = enabled
4668# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004669#
4670# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004671*/
4672unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4673
James Smartba20c852012-08-03 12:36:52 -04004674/*
James Smart81301a92008-12-04 22:39:46 -05004675# lpfc_prot_mask: i
4676# - Bit mask of host protection capabilities used to register with the
4677# SCSI mid-layer
4678# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4679# - Allows you to ultimately specify which profiles to use
4680# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004681# - SHOST_DIF_TYPE1_PROTECTION 1
4682# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4683# - SHOST_DIX_TYPE0_PROTECTION 8
4684# HBA supports DIX Type 0: Host to HBA protection only
4685# - SHOST_DIX_TYPE1_PROTECTION 16
4686# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004687#
4688*/
James Smart7c56b9f2011-07-22 18:36:25 -04004689unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4690 SHOST_DIX_TYPE0_PROTECTION |
4691 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004692
James Smartab56dc22011-02-16 12:39:57 -05004693module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004694MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4695
4696/*
4697# lpfc_prot_guard: i
4698# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004699# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004700# - Allows you to ultimately specify which profiles to use
4701# - Default will result in registering capabilities for all guard types
4702#
4703*/
4704unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004705module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004706MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4707
James Smart92494142011-02-16 12:39:44 -05004708/*
4709 * Delay initial NPort discovery when Clean Address bit is cleared in
4710 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4711 * This parameter can have value 0 or 1.
4712 * When this parameter is set to 0, no delay is added to the initial
4713 * discovery.
4714 * When this parameter is set to non-zero value, initial Nport discovery is
4715 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4716 * accept and FCID/Fabric name/Fabric portname is changed.
4717 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4718 * when Clean Address bit is cleared in FLOGI/FDISC
4719 * accept and FCID/Fabric name/Fabric portname is changed.
4720 * Default value is 0.
4721 */
James Smart8eb8b962016-07-06 12:36:08 -07004722LPFC_ATTR(delay_discovery, 0, 0, 1,
4723 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05004724
4725/*
James Smart3621a712009-04-06 18:47:14 -04004726 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004727 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004728 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4729 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004730 * Because of the additional overhead involved in setting up T10-DIF,
4731 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4732 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004733 */
4734LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4735 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4736
James Smart96f70772013-04-17 20:16:15 -04004737/*
4738 * This parameter will be depricated, the driver cannot limit the
4739 * protection data s/g list.
4740 */
4741LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4742 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4743 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004744
James Smart7bdedb32016-07-06 12:36:00 -07004745/*
4746 * lpfc_enable_mds_diags: Enable MDS Diagnostics
4747 * 0 = MDS Diagnostics disabled (default)
4748 * 1 = MDS Diagnostics enabled
4749 * Value range is [0,1]. Default value is 0.
4750 */
4751LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
4752
Tony Jonesee959b02008-02-22 00:13:36 +01004753struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004754 &dev_attr_bg_info,
4755 &dev_attr_bg_guard_err,
4756 &dev_attr_bg_apptag_err,
4757 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004758 &dev_attr_info,
4759 &dev_attr_serialnum,
4760 &dev_attr_modeldesc,
4761 &dev_attr_modelname,
4762 &dev_attr_programtype,
4763 &dev_attr_portnum,
4764 &dev_attr_fwrev,
4765 &dev_attr_hdw,
4766 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004767 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004768 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004769 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004770 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004771 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004772 &dev_attr_lpfc_temp_sensor,
4773 &dev_attr_lpfc_log_verbose,
4774 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004775 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004776 &dev_attr_lpfc_hba_queue_depth,
4777 &dev_attr_lpfc_peer_port_login,
4778 &dev_attr_lpfc_nodev_tmo,
4779 &dev_attr_lpfc_devloss_tmo,
4780 &dev_attr_lpfc_fcp_class,
4781 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004782 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004783 &dev_attr_lpfc_ack0,
4784 &dev_attr_lpfc_topology,
4785 &dev_attr_lpfc_scan_down,
4786 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004787 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004788 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004789 &dev_attr_lpfc_cr_delay,
4790 &dev_attr_lpfc_cr_count,
4791 &dev_attr_lpfc_multi_ring_support,
4792 &dev_attr_lpfc_multi_ring_rctl,
4793 &dev_attr_lpfc_multi_ring_type,
4794 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05004795 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01004796 &dev_attr_lpfc_max_luns,
4797 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004798 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004799 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004800 &dev_attr_nport_evt_cnt,
4801 &dev_attr_board_mode,
4802 &dev_attr_max_vpi,
4803 &dev_attr_used_vpi,
4804 &dev_attr_max_rpi,
4805 &dev_attr_used_rpi,
4806 &dev_attr_max_xri,
4807 &dev_attr_used_xri,
4808 &dev_attr_npiv_info,
4809 &dev_attr_issue_reset,
4810 &dev_attr_lpfc_poll,
4811 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04004812 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01004813 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004814 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004815 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04004816 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004817 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004818 &dev_attr_lpfc_soft_wwnn,
4819 &dev_attr_lpfc_soft_wwpn,
4820 &dev_attr_lpfc_soft_wwn_enable,
4821 &dev_attr_lpfc_enable_hba_reset,
4822 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05004823 &dev_attr_lpfc_EnableXLane,
4824 &dev_attr_lpfc_XLanePriority,
4825 &dev_attr_lpfc_xlane_lun,
4826 &dev_attr_lpfc_xlane_tgt,
4827 &dev_attr_lpfc_xlane_vpt,
4828 &dev_attr_lpfc_xlane_lun_state,
4829 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07004830 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01004831 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004832 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004833 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004834 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004835 &dev_attr_lpfc_aer_support,
4836 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004837 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004838 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004839 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004840 &dev_attr_lpfc_iocb_cnt,
4841 &dev_attr_iocb_hw,
4842 &dev_attr_txq_hw,
4843 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004844 &dev_attr_lpfc_fips_level,
4845 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004846 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004847 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004848 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05004849 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07004850 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05004851 NULL,
4852};
4853
Tony Jonesee959b02008-02-22 00:13:36 +01004854struct device_attribute *lpfc_vport_attrs[] = {
4855 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004856 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004857 &dev_attr_num_discovered_ports,
4858 &dev_attr_lpfc_drvr_version,
4859 &dev_attr_lpfc_log_verbose,
4860 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004861 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004862 &dev_attr_lpfc_nodev_tmo,
4863 &dev_attr_lpfc_devloss_tmo,
4864 &dev_attr_lpfc_hba_queue_depth,
4865 &dev_attr_lpfc_peer_port_login,
4866 &dev_attr_lpfc_restrict_login,
4867 &dev_attr_lpfc_fcp_class,
4868 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004869 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004870 &dev_attr_lpfc_max_luns,
4871 &dev_attr_nport_evt_cnt,
4872 &dev_attr_npiv_info,
4873 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004874 &dev_attr_lpfc_max_scsicmpl_time,
4875 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004876 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004877 &dev_attr_lpfc_fips_level,
4878 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004879 NULL,
4880};
4881
James Smarte59058c2008-08-24 21:49:00 -04004882/**
James Smart3621a712009-04-06 18:47:14 -04004883 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004884 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004885 * @kobj: kernel kobject that contains the kernel class device.
4886 * @bin_attr: kernel attributes passed to us.
4887 * @buf: contains the data to be written to the adapter IOREG space.
4888 * @off: offset into buffer to beginning of data.
4889 * @count: bytes to transfer.
4890 *
4891 * Description:
4892 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4893 * Uses the adapter io control registers to send buf contents to the adapter.
4894 *
4895 * Returns:
4896 * -ERANGE off and count combo out of range
4897 * -EINVAL off, count or buff address invalid
4898 * -EPERM adapter is offline
4899 * value of count, buf contents written
4900 **/
dea31012005-04-17 16:05:31 -05004901static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004902sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4903 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004904 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004905{
4906 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004907 struct device *dev = container_of(kobj, struct device, kobj);
4908 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4910 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004911
James Smartf1126682009-06-10 17:22:44 -04004912 if (phba->sli_rev >= LPFC_SLI_REV4)
4913 return -EPERM;
4914
dea31012005-04-17 16:05:31 -05004915 if ((off + count) > FF_REG_AREA_SIZE)
4916 return -ERANGE;
4917
James Smartf7a919b2011-08-21 21:49:16 -04004918 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4919 return 0;
dea31012005-04-17 16:05:31 -05004920
4921 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4922 return -EINVAL;
4923
James Smartf7a919b2011-08-21 21:49:16 -04004924 /* This is to protect HBA registers from accidental writes. */
4925 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4926 return -EINVAL;
4927
4928 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004929 return -EPERM;
dea31012005-04-17 16:05:31 -05004930
James Smart2e0fef82007-06-17 19:56:36 -05004931 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004932 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4933 buf_off += sizeof(uint32_t))
4934 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004935 phba->ctrl_regs_memmap_p + off + buf_off);
4936
James Smart2e0fef82007-06-17 19:56:36 -05004937 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004938
4939 return count;
4940}
4941
James Smarte59058c2008-08-24 21:49:00 -04004942/**
James Smart3621a712009-04-06 18:47:14 -04004943 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004944 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004945 * @kobj: kernel kobject that contains the kernel class device.
4946 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004947 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004948 * @off: offset into buffer to beginning of data.
4949 * @count: bytes to transfer.
4950 *
4951 * Description:
4952 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4953 * Uses the adapter io control registers to read data into buf.
4954 *
4955 * Returns:
4956 * -ERANGE off and count combo out of range
4957 * -EINVAL off, count or buff address invalid
4958 * value of count, buf contents read
4959 **/
dea31012005-04-17 16:05:31 -05004960static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004961sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4962 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004963 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004964{
4965 size_t buf_off;
4966 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004967 struct device *dev = container_of(kobj, struct device, kobj);
4968 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4970 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004971
James Smartf1126682009-06-10 17:22:44 -04004972 if (phba->sli_rev >= LPFC_SLI_REV4)
4973 return -EPERM;
4974
dea31012005-04-17 16:05:31 -05004975 if (off > FF_REG_AREA_SIZE)
4976 return -ERANGE;
4977
4978 if ((off + count) > FF_REG_AREA_SIZE)
4979 count = FF_REG_AREA_SIZE - off;
4980
4981 if (count == 0) return 0;
4982
4983 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4984 return -EINVAL;
4985
James Smart2e0fef82007-06-17 19:56:36 -05004986 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004987
4988 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4989 tmp_ptr = (uint32_t *)(buf + buf_off);
4990 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4991 }
4992
James Smart2e0fef82007-06-17 19:56:36 -05004993 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004994
4995 return count;
4996}
4997
4998static struct bin_attribute sysfs_ctlreg_attr = {
4999 .attr = {
5000 .name = "ctlreg",
5001 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005002 },
5003 .size = 256,
5004 .read = sysfs_ctlreg_read,
5005 .write = sysfs_ctlreg_write,
5006};
5007
James Smarte59058c2008-08-24 21:49:00 -04005008/**
James Smart3621a712009-04-06 18:47:14 -04005009 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005010 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005011 * @kobj: kernel kobject that contains the kernel class device.
5012 * @bin_attr: kernel attributes passed to us.
5013 * @buf: contains the data to be written to sysfs mbox.
5014 * @off: offset into buffer to beginning of data.
5015 * @count: bytes to transfer.
5016 *
5017 * Description:
James Smart026abb82011-12-13 13:20:45 -05005018 * Deprecated function. All mailbox access from user space is performed via the
5019 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005020 *
5021 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005022 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005023 **/
dea31012005-04-17 16:05:31 -05005024static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005025sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5026 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005027 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005028{
James Smart026abb82011-12-13 13:20:45 -05005029 return -EPERM;
dea31012005-04-17 16:05:31 -05005030}
5031
James Smarte59058c2008-08-24 21:49:00 -04005032/**
James Smart3621a712009-04-06 18:47:14 -04005033 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005034 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005035 * @kobj: kernel kobject that contains the kernel class device.
5036 * @bin_attr: kernel attributes passed to us.
5037 * @buf: contains the data to be read from sysfs mbox.
5038 * @off: offset into buffer to beginning of data.
5039 * @count: bytes to transfer.
5040 *
5041 * Description:
James Smart026abb82011-12-13 13:20:45 -05005042 * Deprecated function. All mailbox access from user space is performed via the
5043 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005044 *
5045 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005046 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005047 **/
dea31012005-04-17 16:05:31 -05005048static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005049sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5050 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005051 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005052{
James Smart026abb82011-12-13 13:20:45 -05005053 return -EPERM;
dea31012005-04-17 16:05:31 -05005054}
5055
5056static struct bin_attribute sysfs_mbox_attr = {
5057 .attr = {
5058 .name = "mbox",
5059 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005060 },
James Smartc0c11512011-05-24 11:41:34 -04005061 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005062 .read = sysfs_mbox_read,
5063 .write = sysfs_mbox_write,
5064};
5065
James Smarte59058c2008-08-24 21:49:00 -04005066/**
James Smart3621a712009-04-06 18:47:14 -04005067 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005068 * @vport: address of lpfc vport structure.
5069 *
5070 * Return codes:
5071 * zero on success
5072 * error return code from sysfs_create_bin_file()
5073 **/
dea31012005-04-17 16:05:31 -05005074int
James Smart2e0fef82007-06-17 19:56:36 -05005075lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005076{
James Smart2e0fef82007-06-17 19:56:36 -05005077 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005078 int error;
5079
Tony Jonesee959b02008-02-22 00:13:36 +01005080 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005081 &sysfs_drvr_stat_data_attr);
5082
5083 /* Virtual ports do not need ctrl_reg and mbox */
5084 if (error || vport->port_type == LPFC_NPIV_PORT)
5085 goto out;
5086
5087 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005088 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005089 if (error)
James Smarteada2722008-12-04 22:39:13 -05005090 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005091
Tony Jonesee959b02008-02-22 00:13:36 +01005092 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005093 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005094 if (error)
5095 goto out_remove_ctlreg_attr;
5096
5097 return 0;
5098out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005099 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005100out_remove_stat_attr:
5101 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5102 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005103out:
5104 return error;
5105}
5106
James Smarte59058c2008-08-24 21:49:00 -04005107/**
James Smart3621a712009-04-06 18:47:14 -04005108 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005109 * @vport: address of lpfc vport structure.
5110 **/
dea31012005-04-17 16:05:31 -05005111void
James Smart2e0fef82007-06-17 19:56:36 -05005112lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005113{
James Smart2e0fef82007-06-17 19:56:36 -05005114 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005115 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5116 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005117 /* Virtual ports do not need ctrl_reg and mbox */
5118 if (vport->port_type == LPFC_NPIV_PORT)
5119 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005120 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5121 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005122}
5123
dea31012005-04-17 16:05:31 -05005124/*
5125 * Dynamic FC Host Attributes Support
5126 */
5127
James Smarte59058c2008-08-24 21:49:00 -04005128/**
James Smart3621a712009-04-06 18:47:14 -04005129 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005130 * @shost: kernel scsi host pointer.
5131 **/
dea31012005-04-17 16:05:31 -05005132static void
5133lpfc_get_host_port_id(struct Scsi_Host *shost)
5134{
James Smart2e0fef82007-06-17 19:56:36 -05005135 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5136
dea31012005-04-17 16:05:31 -05005137 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005138 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005139}
5140
James Smarte59058c2008-08-24 21:49:00 -04005141/**
James Smart3621a712009-04-06 18:47:14 -04005142 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005143 * @shost: kernel scsi host pointer.
5144 **/
dea31012005-04-17 16:05:31 -05005145static void
5146lpfc_get_host_port_type(struct Scsi_Host *shost)
5147{
James Smart2e0fef82007-06-17 19:56:36 -05005148 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5149 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005150
5151 spin_lock_irq(shost->host_lock);
5152
James Smart92d7f7b2007-06-17 19:56:38 -05005153 if (vport->port_type == LPFC_NPIV_PORT) {
5154 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5155 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005156 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005157 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005158 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5159 else
5160 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5161 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005162 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005163 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5164 else
5165 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5166 }
5167 } else
5168 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5169
5170 spin_unlock_irq(shost->host_lock);
5171}
5172
James Smarte59058c2008-08-24 21:49:00 -04005173/**
James Smart3621a712009-04-06 18:47:14 -04005174 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005175 * @shost: kernel scsi host pointer.
5176 **/
dea31012005-04-17 16:05:31 -05005177static void
5178lpfc_get_host_port_state(struct Scsi_Host *shost)
5179{
James Smart2e0fef82007-06-17 19:56:36 -05005180 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5181 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005182
5183 spin_lock_irq(shost->host_lock);
5184
James Smart2e0fef82007-06-17 19:56:36 -05005185 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005186 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5187 else {
James Smart2e0fef82007-06-17 19:56:36 -05005188 switch (phba->link_state) {
5189 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005190 case LPFC_LINK_DOWN:
5191 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5192 break;
5193 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005194 case LPFC_CLEAR_LA:
5195 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005196 /* Links up, reports port state accordingly */
5197 if (vport->port_state < LPFC_VPORT_READY)
5198 fc_host_port_state(shost) =
5199 FC_PORTSTATE_BYPASSED;
5200 else
5201 fc_host_port_state(shost) =
5202 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005203 break;
5204 case LPFC_HBA_ERROR:
5205 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5206 break;
5207 default:
5208 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5209 break;
5210 }
5211 }
5212
5213 spin_unlock_irq(shost->host_lock);
5214}
5215
James Smarte59058c2008-08-24 21:49:00 -04005216/**
James Smart3621a712009-04-06 18:47:14 -04005217 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005218 * @shost: kernel scsi host pointer.
5219 **/
dea31012005-04-17 16:05:31 -05005220static void
5221lpfc_get_host_speed(struct Scsi_Host *shost)
5222{
James Smart2e0fef82007-06-17 19:56:36 -05005223 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5224 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005225
5226 spin_lock_irq(shost->host_lock);
5227
James Smarta085e872015-12-16 18:12:02 -05005228 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005229 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005230 case LPFC_LINK_SPEED_1GHZ:
5231 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005232 break;
James Smart76a95d72010-11-20 23:11:48 -05005233 case LPFC_LINK_SPEED_2GHZ:
5234 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005235 break;
James Smart76a95d72010-11-20 23:11:48 -05005236 case LPFC_LINK_SPEED_4GHZ:
5237 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005238 break;
James Smart76a95d72010-11-20 23:11:48 -05005239 case LPFC_LINK_SPEED_8GHZ:
5240 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005241 break;
James Smart76a95d72010-11-20 23:11:48 -05005242 case LPFC_LINK_SPEED_10GHZ:
5243 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005244 break;
James Smart76a95d72010-11-20 23:11:48 -05005245 case LPFC_LINK_SPEED_16GHZ:
5246 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5247 break;
James Smartd38dd522015-08-31 16:48:17 -04005248 case LPFC_LINK_SPEED_32GHZ:
5249 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5250 break;
James Smart76a95d72010-11-20 23:11:48 -05005251 default:
5252 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005253 break;
5254 }
James Smart09372822008-01-11 01:52:54 -05005255 } else
5256 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005257
5258 spin_unlock_irq(shost->host_lock);
5259}
5260
James Smarte59058c2008-08-24 21:49:00 -04005261/**
James Smart3621a712009-04-06 18:47:14 -04005262 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005263 * @shost: kernel scsi host pointer.
5264 **/
dea31012005-04-17 16:05:31 -05005265static void
5266lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5267{
James Smart2e0fef82007-06-17 19:56:36 -05005268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5269 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005270 u64 node_name;
dea31012005-04-17 16:05:31 -05005271
5272 spin_lock_irq(shost->host_lock);
5273
James Smart73d91e52011-10-10 21:32:10 -04005274 if ((vport->port_state > LPFC_FLOGI) &&
5275 ((vport->fc_flag & FC_FABRIC) ||
5276 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5277 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005278 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005279 else
5280 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005281 node_name = 0;
dea31012005-04-17 16:05:31 -05005282
5283 spin_unlock_irq(shost->host_lock);
5284
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005285 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005286}
5287
James Smarte59058c2008-08-24 21:49:00 -04005288/**
James Smart3621a712009-04-06 18:47:14 -04005289 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005290 * @shost: kernel scsi host pointer.
5291 *
5292 * Notes:
5293 * NULL on error for link down, no mbox pool, sli2 active,
5294 * management not allowed, memory allocation error, or mbox error.
5295 *
5296 * Returns:
5297 * NULL for error
5298 * address of the adapter host statistics
5299 **/
dea31012005-04-17 16:05:31 -05005300static struct fc_host_statistics *
5301lpfc_get_stats(struct Scsi_Host *shost)
5302{
James Smart2e0fef82007-06-17 19:56:36 -05005303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5304 struct lpfc_hba *phba = vport->phba;
5305 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005306 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005307 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005308 LPFC_MBOXQ_t *pmboxq;
5309 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005310 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005311 int rc = 0;
dea31012005-04-17 16:05:31 -05005312
James Smart92d7f7b2007-06-17 19:56:38 -05005313 /*
5314 * prevent udev from issuing mailbox commands until the port is
5315 * configured.
5316 */
James Smart2e0fef82007-06-17 19:56:36 -05005317 if (phba->link_state < LPFC_LINK_DOWN ||
5318 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005319 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005320 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005321
5322 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005323 return NULL;
5324
dea31012005-04-17 16:05:31 -05005325 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5326 if (!pmboxq)
5327 return NULL;
5328 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5329
James Smart04c68492009-05-22 14:52:52 -04005330 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005331 pmb->mbxCommand = MBX_READ_STATUS;
5332 pmb->mbxOwner = OWN_HOST;
5333 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005334 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005335
James Smart75baf692010-06-08 18:31:21 -04005336 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005337 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005338 else
dea31012005-04-17 16:05:31 -05005339 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5340
5341 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005342 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005343 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005344 return NULL;
5345 }
5346
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005347 memset(hs, 0, sizeof (struct fc_host_statistics));
5348
dea31012005-04-17 16:05:31 -05005349 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005350 /*
5351 * The MBX_READ_STATUS returns tx_k_bytes which has to
5352 * converted to words
5353 */
5354 hs->tx_words = (uint64_t)
5355 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5356 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005357 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005358 hs->rx_words = (uint64_t)
5359 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5360 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005361
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005362 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005363 pmb->mbxCommand = MBX_READ_LNK_STAT;
5364 pmb->mbxOwner = OWN_HOST;
5365 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005366 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005367
James Smart75baf692010-06-08 18:31:21 -04005368 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005369 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005370 else
dea31012005-04-17 16:05:31 -05005371 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5372
5373 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005374 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005375 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005376 return NULL;
5377 }
5378
5379 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5380 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5381 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5382 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5383 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5384 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5385 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5386
James Smart64ba8812006-08-02 15:24:34 -04005387 hs->link_failure_count -= lso->link_failure_count;
5388 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5389 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5390 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5391 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5392 hs->invalid_crc_count -= lso->invalid_crc_count;
5393 hs->error_frames -= lso->error_frames;
5394
James Smart76a95d72010-11-20 23:11:48 -05005395 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005396 hs->lip_count = -1;
5397 hs->nos_count = (phba->link_events >> 1);
5398 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005399 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005400 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005401 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005402 hs->nos_count = -1;
5403 } else {
5404 hs->lip_count = -1;
5405 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005406 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005407 }
5408
5409 hs->dumped_frames = -1;
5410
James Smart64ba8812006-08-02 15:24:34 -04005411 seconds = get_seconds();
5412 if (seconds < psli->stats_start)
5413 hs->seconds_since_last_reset = seconds +
5414 ((unsigned long)-1 - psli->stats_start);
5415 else
5416 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005417
James Smart1dcb58e2007-04-25 09:51:30 -04005418 mempool_free(pmboxq, phba->mbox_mem_pool);
5419
dea31012005-04-17 16:05:31 -05005420 return hs;
5421}
5422
James Smarte59058c2008-08-24 21:49:00 -04005423/**
James Smart3621a712009-04-06 18:47:14 -04005424 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005425 * @shost: kernel scsi host pointer.
5426 **/
James Smart64ba8812006-08-02 15:24:34 -04005427static void
5428lpfc_reset_stats(struct Scsi_Host *shost)
5429{
James Smart2e0fef82007-06-17 19:56:36 -05005430 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5431 struct lpfc_hba *phba = vport->phba;
5432 struct lpfc_sli *psli = &phba->sli;
5433 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005434 LPFC_MBOXQ_t *pmboxq;
5435 MAILBOX_t *pmb;
5436 int rc = 0;
5437
James Smart2e0fef82007-06-17 19:56:36 -05005438 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005439 return;
5440
James Smart64ba8812006-08-02 15:24:34 -04005441 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5442 if (!pmboxq)
5443 return;
5444 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5445
James Smart04c68492009-05-22 14:52:52 -04005446 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005447 pmb->mbxCommand = MBX_READ_STATUS;
5448 pmb->mbxOwner = OWN_HOST;
5449 pmb->un.varWords[0] = 0x1; /* reset request */
5450 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005451 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005452
James Smart2e0fef82007-06-17 19:56:36 -05005453 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005454 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005455 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5456 else
5457 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5458
5459 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005460 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005461 mempool_free(pmboxq, phba->mbox_mem_pool);
5462 return;
5463 }
5464
5465 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5466 pmb->mbxCommand = MBX_READ_LNK_STAT;
5467 pmb->mbxOwner = OWN_HOST;
5468 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005469 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005470
James Smart2e0fef82007-06-17 19:56:36 -05005471 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005472 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005473 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5474 else
5475 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5476
5477 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005478 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005479 mempool_free( pmboxq, phba->mbox_mem_pool);
5480 return;
5481 }
5482
5483 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5484 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5485 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5486 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5487 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5488 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5489 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005490 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005491 lso->link_events = (phba->link_events >> 1);
5492 else
5493 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005494
5495 psli->stats_start = get_seconds();
5496
James Smart1dcb58e2007-04-25 09:51:30 -04005497 mempool_free(pmboxq, phba->mbox_mem_pool);
5498
James Smart64ba8812006-08-02 15:24:34 -04005499 return;
5500}
dea31012005-04-17 16:05:31 -05005501
5502/*
5503 * The LPFC driver treats linkdown handling as target loss events so there
5504 * are no sysfs handlers for link_down_tmo.
5505 */
James Smart685f0bf2007-04-25 09:53:08 -04005506
James Smarte59058c2008-08-24 21:49:00 -04005507/**
James Smart3621a712009-04-06 18:47:14 -04005508 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005509 * @starget: kernel scsi target pointer.
5510 *
5511 * Returns:
5512 * address of the node list if found
5513 * NULL target not found
5514 **/
James Smart685f0bf2007-04-25 09:53:08 -04005515static struct lpfc_nodelist *
5516lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005517{
James Smart2e0fef82007-06-17 19:56:36 -05005518 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5519 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005520 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005521
5522 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005523 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005524 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005525 if (NLP_CHK_NODE_ACT(ndlp) &&
5526 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005527 starget->id == ndlp->nlp_sid) {
5528 spin_unlock_irq(shost->host_lock);
5529 return ndlp;
dea31012005-04-17 16:05:31 -05005530 }
5531 }
5532 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005533 return NULL;
5534}
dea31012005-04-17 16:05:31 -05005535
James Smarte59058c2008-08-24 21:49:00 -04005536/**
James Smart3621a712009-04-06 18:47:14 -04005537 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005538 * @starget: kernel scsi target pointer.
5539 **/
James Smart685f0bf2007-04-25 09:53:08 -04005540static void
5541lpfc_get_starget_port_id(struct scsi_target *starget)
5542{
5543 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5544
5545 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005546}
5547
James Smarte59058c2008-08-24 21:49:00 -04005548/**
James Smart3621a712009-04-06 18:47:14 -04005549 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005550 * @starget: kernel scsi target pointer.
5551 *
5552 * Description: Set the target node name to the ndlp node name wwn or zero.
5553 **/
dea31012005-04-17 16:05:31 -05005554static void
5555lpfc_get_starget_node_name(struct scsi_target *starget)
5556{
James Smart685f0bf2007-04-25 09:53:08 -04005557 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005558
James Smart685f0bf2007-04-25 09:53:08 -04005559 fc_starget_node_name(starget) =
5560 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005561}
5562
James Smarte59058c2008-08-24 21:49:00 -04005563/**
James Smart3621a712009-04-06 18:47:14 -04005564 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005565 * @starget: kernel scsi target pointer.
5566 *
5567 * Description: set the target port name to the ndlp port name wwn or zero.
5568 **/
dea31012005-04-17 16:05:31 -05005569static void
5570lpfc_get_starget_port_name(struct scsi_target *starget)
5571{
James Smart685f0bf2007-04-25 09:53:08 -04005572 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005573
James Smart685f0bf2007-04-25 09:53:08 -04005574 fc_starget_port_name(starget) =
5575 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005576}
5577
James Smarte59058c2008-08-24 21:49:00 -04005578/**
James Smart3621a712009-04-06 18:47:14 -04005579 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005580 * @rport: fc rport address.
5581 * @timeout: new value for dev loss tmo.
5582 *
5583 * Description:
5584 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5585 * dev_loss_tmo to one.
5586 **/
dea31012005-04-17 16:05:31 -05005587static void
dea31012005-04-17 16:05:31 -05005588lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5589{
dea31012005-04-17 16:05:31 -05005590 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005591 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005592 else
James Smartc01f3202006-08-18 17:47:08 -04005593 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005594}
5595
James Smarte59058c2008-08-24 21:49:00 -04005596/**
James Smart3621a712009-04-06 18:47:14 -04005597 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005598 *
5599 * Description:
5600 * Macro that uses field to generate a function with the name lpfc_show_rport_
5601 *
5602 * lpfc_show_rport_##field: returns the bytes formatted in buf
5603 * @cdev: class converted to an fc_rport.
5604 * @buf: on return contains the target_field or zero.
5605 *
5606 * Returns: size of formatted string.
5607 **/
dea31012005-04-17 16:05:31 -05005608#define lpfc_rport_show_function(field, format_string, sz, cast) \
5609static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005610lpfc_show_rport_##field (struct device *dev, \
5611 struct device_attribute *attr, \
5612 char *buf) \
dea31012005-04-17 16:05:31 -05005613{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005614 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005615 struct lpfc_rport_data *rdata = rport->hostdata; \
5616 return snprintf(buf, sz, format_string, \
5617 (rdata->target) ? cast rdata->target->field : 0); \
5618}
5619
5620#define lpfc_rport_rd_attr(field, format_string, sz) \
5621 lpfc_rport_show_function(field, format_string, sz, ) \
5622static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5623
James Smarteada2722008-12-04 22:39:13 -05005624/**
James Smart3621a712009-04-06 18:47:14 -04005625 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005626 * @fc_vport: The fc_vport who's symbolic name has been changed.
5627 *
5628 * Description:
5629 * This function is called by the transport after the @fc_vport's symbolic name
5630 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005631 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005632 **/
5633static void
5634lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5635{
5636 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5637
5638 if (vport->port_state == LPFC_VPORT_READY)
5639 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5640}
dea31012005-04-17 16:05:31 -05005641
James Smartf4b4c682009-05-22 14:53:12 -04005642/**
5643 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5644 * @phba: Pointer to lpfc_hba struct.
5645 *
5646 * This function is called by the lpfc_get_cfgparam() routine to set the
5647 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005648 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005649 * before hba port or vport created.
5650 **/
5651static void
5652lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5653{
5654 phba->cfg_log_verbose = verbose;
5655}
5656
dea31012005-04-17 16:05:31 -05005657struct fc_function_template lpfc_transport_functions = {
5658 /* fixed attributes the driver supports */
5659 .show_host_node_name = 1,
5660 .show_host_port_name = 1,
5661 .show_host_supported_classes = 1,
5662 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005663 .show_host_supported_speeds = 1,
5664 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005665 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005666
5667 /* dynamic attributes the driver supports */
5668 .get_host_port_id = lpfc_get_host_port_id,
5669 .show_host_port_id = 1,
5670
5671 .get_host_port_type = lpfc_get_host_port_type,
5672 .show_host_port_type = 1,
5673
5674 .get_host_port_state = lpfc_get_host_port_state,
5675 .show_host_port_state = 1,
5676
5677 /* active_fc4s is shown but doesn't change (thus no get function) */
5678 .show_host_active_fc4s = 1,
5679
5680 .get_host_speed = lpfc_get_host_speed,
5681 .show_host_speed = 1,
5682
5683 .get_host_fabric_name = lpfc_get_host_fabric_name,
5684 .show_host_fabric_name = 1,
5685
5686 /*
5687 * The LPFC driver treats linkdown handling as target loss events
5688 * so there are no sysfs handlers for link_down_tmo.
5689 */
5690
5691 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005692 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005693
5694 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5695 .show_rport_maxframe_size = 1,
5696 .show_rport_supported_classes = 1,
5697
dea31012005-04-17 16:05:31 -05005698 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5699 .show_rport_dev_loss_tmo = 1,
5700
5701 .get_starget_port_id = lpfc_get_starget_port_id,
5702 .show_starget_port_id = 1,
5703
5704 .get_starget_node_name = lpfc_get_starget_node_name,
5705 .show_starget_node_name = 1,
5706
5707 .get_starget_port_name = lpfc_get_starget_port_name,
5708 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005709
5710 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005711 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5712 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005713
James Smart92d7f7b2007-06-17 19:56:38 -05005714 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005715
5716 .vport_disable = lpfc_vport_disable,
5717
5718 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005719
5720 .bsg_request = lpfc_bsg_request,
5721 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005722};
5723
James Smart98c9ea52007-10-27 13:37:33 -04005724struct fc_function_template lpfc_vport_transport_functions = {
5725 /* fixed attributes the driver supports */
5726 .show_host_node_name = 1,
5727 .show_host_port_name = 1,
5728 .show_host_supported_classes = 1,
5729 .show_host_supported_fc4s = 1,
5730 .show_host_supported_speeds = 1,
5731 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005732 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005733
5734 /* dynamic attributes the driver supports */
5735 .get_host_port_id = lpfc_get_host_port_id,
5736 .show_host_port_id = 1,
5737
5738 .get_host_port_type = lpfc_get_host_port_type,
5739 .show_host_port_type = 1,
5740
5741 .get_host_port_state = lpfc_get_host_port_state,
5742 .show_host_port_state = 1,
5743
5744 /* active_fc4s is shown but doesn't change (thus no get function) */
5745 .show_host_active_fc4s = 1,
5746
5747 .get_host_speed = lpfc_get_host_speed,
5748 .show_host_speed = 1,
5749
5750 .get_host_fabric_name = lpfc_get_host_fabric_name,
5751 .show_host_fabric_name = 1,
5752
5753 /*
5754 * The LPFC driver treats linkdown handling as target loss events
5755 * so there are no sysfs handlers for link_down_tmo.
5756 */
5757
5758 .get_fc_host_stats = lpfc_get_stats,
5759 .reset_fc_host_stats = lpfc_reset_stats,
5760
5761 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5762 .show_rport_maxframe_size = 1,
5763 .show_rport_supported_classes = 1,
5764
5765 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5766 .show_rport_dev_loss_tmo = 1,
5767
5768 .get_starget_port_id = lpfc_get_starget_port_id,
5769 .show_starget_port_id = 1,
5770
5771 .get_starget_node_name = lpfc_get_starget_node_name,
5772 .show_starget_node_name = 1,
5773
5774 .get_starget_port_name = lpfc_get_starget_port_name,
5775 .show_starget_port_name = 1,
5776
5777 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5778 .terminate_rport_io = lpfc_terminate_rport_io,
5779
5780 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005781
5782 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005783};
5784
James Smarte59058c2008-08-24 21:49:00 -04005785/**
James Smart3621a712009-04-06 18:47:14 -04005786 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005787 * @phba: lpfc_hba pointer.
5788 **/
dea31012005-04-17 16:05:31 -05005789void
5790lpfc_get_cfgparam(struct lpfc_hba *phba)
5791{
James Smart49aa1432012-08-03 12:36:42 -04005792 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005793 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005794 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5795 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005796 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005797 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5798 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005799 lpfc_ack0_init(phba, lpfc_ack0);
5800 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005801 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005802 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04005803 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005804 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005805 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005806 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05005807 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
5808 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05005809 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005810 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005811 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart67d12732012-08-03 12:36:13 -04005812 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005813 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5814 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart1ba981f2014-02-20 09:56:45 -05005815 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5816 if (phba->sli_rev != LPFC_SLI_REV4)
5817 phba->cfg_EnableXLane = 0;
5818 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5819 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5820 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5821 phba->cfg_oas_lun_state = 0;
5822 phba->cfg_oas_lun_status = 0;
5823 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07005824 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05005825 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005826 if (phba->sli_rev == LPFC_SLI_REV4)
5827 phba->cfg_poll = 0;
5828 else
James Smart1ba981f2014-02-20 09:56:45 -05005829 phba->cfg_poll = lpfc_poll;
James Smart4258e982015-12-16 18:11:58 -05005830
James Smarta12e07b2006-12-02 13:35:30 -05005831 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005832 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005833 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005834 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005835 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005836 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005837 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005838 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005839 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005840 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005841 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07005842 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07005843 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05005844 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07005845 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04005846 return;
5847}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005848
James Smarte59058c2008-08-24 21:49:00 -04005849/**
James Smart3621a712009-04-06 18:47:14 -04005850 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005851 * @vport: lpfc_vport pointer.
5852 **/
James Smart3de2a652007-08-02 11:09:59 -04005853void
5854lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5855{
James Smarte8b62012007-08-02 11:10:09 -04005856 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005857 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005858 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005859 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5860 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5861 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5862 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5863 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5864 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04005865 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04005866 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005867 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5868 lpfc_max_luns_init(vport, lpfc_max_luns);
5869 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005870 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005871 return;
5872}