blob: c30fafe3bb3160b4f74ab7ef18b102092942fa6a [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
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001624static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1625{
1626 return val >= min && val <= max;
1627}
1628
James Smart912e3ac2011-05-24 11:42:11 -04001629/**
James Smart3621a712009-04-06 18:47:14 -04001630 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001631 *
1632 * Description:
1633 * Macro that given an attr e.g. hba_queue_depth expands
1634 * into a function with the name lpfc_hba_queue_depth_show.
1635 *
1636 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1637 * @dev: class device that is converted into a Scsi_host.
1638 * @attr: device attribute, not used.
1639 * @buf: on return contains the attribute value in decimal.
1640 *
1641 * Returns: size of formatted string.
1642 **/
dea31012005-04-17 16:05:31 -05001643#define lpfc_param_show(attr) \
1644static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001645lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1646 char *buf) \
dea31012005-04-17 16:05:31 -05001647{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001648 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001649 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1650 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001651 return snprintf(buf, PAGE_SIZE, "%d\n",\
1652 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001653}
1654
James Smarte59058c2008-08-24 21:49:00 -04001655/**
James Smart3621a712009-04-06 18:47:14 -04001656 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001657 *
1658 * Description:
1659 * Macro that given an attr e.g. hba_queue_depth expands
1660 * into a function with the name lpfc_hba_queue_depth_show
1661 *
1662 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1663 * @dev: class device that is converted into a Scsi_host.
1664 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001665 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001666 *
1667 * Returns: size of formatted string.
1668 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001669#define lpfc_param_hex_show(attr) \
1670static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001671lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1672 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001673{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001674 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001675 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1676 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001677 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001678 val = phba->cfg_##attr;\
1679 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1680 phba->cfg_##attr);\
1681}
1682
James Smarte59058c2008-08-24 21:49:00 -04001683/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001684 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001685 *
1686 * Description:
1687 * Macro that given an attr e.g. hba_queue_depth expands
1688 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1689 * takes a default argument, a minimum and maximum argument.
1690 *
1691 * lpfc_##attr##_init: Initializes an attribute.
1692 * @phba: pointer the the adapter structure.
1693 * @val: integer attribute value.
1694 *
1695 * Validates the min and max values then sets the adapter config field
1696 * accordingly, or uses the default if out of range and prints an error message.
1697 *
1698 * Returns:
1699 * zero on success
1700 * -EINVAL if default used
1701 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001702#define lpfc_param_init(attr, default, minval, maxval) \
1703static int \
James Smart84d1b002010-02-12 14:42:33 -05001704lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001705{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001706 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001707 phba->cfg_##attr = val;\
1708 return 0;\
1709 }\
1710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001711 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1712 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001713 phba->cfg_##attr = default;\
1714 return -EINVAL;\
1715}
1716
James Smarte59058c2008-08-24 21:49:00 -04001717/**
James Smart3621a712009-04-06 18:47:14 -04001718 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001719 *
1720 * Description:
1721 * Macro that given an attr e.g. hba_queue_depth expands
1722 * into a function with the name lpfc_hba_queue_depth_set
1723 *
1724 * lpfc_##attr##_set: Sets an attribute value.
1725 * @phba: pointer the the adapter structure.
1726 * @val: integer attribute value.
1727 *
1728 * Description:
1729 * Validates the min and max values then sets the
1730 * adapter config field if in the valid range. prints error message
1731 * and does not set the parameter if invalid.
1732 *
1733 * Returns:
1734 * zero on success
1735 * -EINVAL if val is invalid
1736 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001737#define lpfc_param_set(attr, default, minval, maxval) \
1738static int \
James Smart84d1b002010-02-12 14:42:33 -05001739lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001740{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001741 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1743 "3052 lpfc_" #attr " changed from %d to %d\n", \
1744 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001745 phba->cfg_##attr = val;\
1746 return 0;\
1747 }\
1748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001749 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1750 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001751 return -EINVAL;\
1752}
1753
James Smarte59058c2008-08-24 21:49:00 -04001754/**
James Smart3621a712009-04-06 18:47:14 -04001755 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001756 *
1757 * Description:
1758 * Macro that given an attr e.g. hba_queue_depth expands
1759 * into a function with the name lpfc_hba_queue_depth_store.
1760 *
1761 * lpfc_##attr##_store: Set an sttribute value.
1762 * @dev: class device that is converted into a Scsi_host.
1763 * @attr: device attribute, not used.
1764 * @buf: contains the attribute value in ascii.
1765 * @count: not used.
1766 *
1767 * Description:
1768 * Convert the ascii text number to an integer, then
1769 * use the lpfc_##attr##_set function to set the value.
1770 *
1771 * Returns:
1772 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1773 * length of buffer upon success.
1774 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001775#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001776static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001777lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1778 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001779{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001780 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001781 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1782 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001783 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001784 if (!isdigit(buf[0]))\
1785 return -EINVAL;\
1786 if (sscanf(buf, "%i", &val) != 1)\
1787 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001788 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001789 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001790 else \
1791 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001792}
1793
James Smarte59058c2008-08-24 21:49:00 -04001794/**
James Smart3621a712009-04-06 18:47:14 -04001795 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001796 *
1797 * Description:
1798 * Macro that given an attr e.g. hba_queue_depth expands
1799 * into a function with the name lpfc_hba_queue_depth_show
1800 *
1801 * lpfc_##attr##_show: prints the attribute value in decimal.
1802 * @dev: class device that is converted into a Scsi_host.
1803 * @attr: device attribute, not used.
1804 * @buf: on return contains the attribute value in decimal.
1805 *
1806 * Returns: length of formatted string.
1807 **/
James Smart3de2a652007-08-02 11:09:59 -04001808#define lpfc_vport_param_show(attr) \
1809static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001810lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1811 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001812{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001813 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001814 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001815 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1816}
1817
James Smarte59058c2008-08-24 21:49:00 -04001818/**
James Smart3621a712009-04-06 18:47:14 -04001819 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001820 *
1821 * Description:
1822 * Macro that given an attr e.g.
1823 * hba_queue_depth expands into a function with the name
1824 * lpfc_hba_queue_depth_show
1825 *
James Smart3621a712009-04-06 18:47:14 -04001826 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001827 * @dev: class device that is converted into a Scsi_host.
1828 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001829 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001830 *
1831 * Returns: length of formatted string.
1832 **/
James Smart3de2a652007-08-02 11:09:59 -04001833#define lpfc_vport_param_hex_show(attr) \
1834static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001835lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1836 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001837{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001838 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001840 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1841}
1842
James Smarte59058c2008-08-24 21:49:00 -04001843/**
James Smart3621a712009-04-06 18:47:14 -04001844 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001845 *
1846 * Description:
1847 * Macro that given an attr e.g. hba_queue_depth expands
1848 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1849 * takes a default argument, a minimum and maximum argument.
1850 *
1851 * lpfc_##attr##_init: validates the min and max values then sets the
1852 * adapter config field accordingly, or uses the default if out of range
1853 * and prints an error message.
1854 * @phba: pointer the the adapter structure.
1855 * @val: integer attribute value.
1856 *
1857 * Returns:
1858 * zero on success
1859 * -EINVAL if default used
1860 **/
James Smart3de2a652007-08-02 11:09:59 -04001861#define lpfc_vport_param_init(attr, default, minval, maxval) \
1862static int \
James Smart84d1b002010-02-12 14:42:33 -05001863lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001864{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001865 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04001866 vport->cfg_##attr = val;\
1867 return 0;\
1868 }\
James Smarte8b62012007-08-02 11:10:09 -04001869 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001870 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001871 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001872 vport->cfg_##attr = default;\
1873 return -EINVAL;\
1874}
1875
James Smarte59058c2008-08-24 21:49:00 -04001876/**
James Smart3621a712009-04-06 18:47:14 -04001877 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001878 *
1879 * Description:
1880 * Macro that given an attr e.g. hba_queue_depth expands
1881 * into a function with the name lpfc_hba_queue_depth_set
1882 *
1883 * lpfc_##attr##_set: validates the min and max values then sets the
1884 * adapter config field if in the valid range. prints error message
1885 * and does not set the parameter if invalid.
1886 * @phba: pointer the the adapter structure.
1887 * @val: integer attribute value.
1888 *
1889 * Returns:
1890 * zero on success
1891 * -EINVAL if val is invalid
1892 **/
James Smart3de2a652007-08-02 11:09:59 -04001893#define lpfc_vport_param_set(attr, default, minval, maxval) \
1894static int \
James Smart84d1b002010-02-12 14:42:33 -05001895lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001896{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001897 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001898 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04001899 "3053 lpfc_" #attr \
1900 " changed from %d (x%x) to %d (x%x)\n", \
1901 vport->cfg_##attr, vport->cfg_##attr, \
1902 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04001903 vport->cfg_##attr = val;\
1904 return 0;\
1905 }\
James Smarte8b62012007-08-02 11:10:09 -04001906 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001907 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001908 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001909 return -EINVAL;\
1910}
1911
James Smarte59058c2008-08-24 21:49:00 -04001912/**
James Smart3621a712009-04-06 18:47:14 -04001913 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001914 *
1915 * Description:
1916 * Macro that given an attr e.g. hba_queue_depth
1917 * expands into a function with the name lpfc_hba_queue_depth_store
1918 *
1919 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1920 * use the lpfc_##attr##_set function to set the value.
1921 * @cdev: class device that is converted into a Scsi_host.
1922 * @buf: contains the attribute value in decimal.
1923 * @count: not used.
1924 *
1925 * Returns:
1926 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1927 * length of buffer upon success.
1928 **/
James Smart3de2a652007-08-02 11:09:59 -04001929#define lpfc_vport_param_store(attr) \
1930static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001931lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1932 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001933{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001934 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001935 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001936 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001937 if (!isdigit(buf[0]))\
1938 return -EINVAL;\
1939 if (sscanf(buf, "%i", &val) != 1)\
1940 return -EINVAL;\
1941 if (lpfc_##attr##_set(vport, val) == 0) \
1942 return strlen(buf);\
1943 else \
1944 return -EINVAL;\
1945}
1946
1947
James Smart81301a92008-12-04 22:39:46 -05001948static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1949static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1950static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1951static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001952static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1953static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1954static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1955static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1956static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1957static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1958static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1959static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001960static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1961 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001962static DEVICE_ATTR(option_rom_version, S_IRUGO,
1963 lpfc_option_rom_version_show, NULL);
1964static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1965 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001966static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001967static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1968static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001969static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001970static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1971 lpfc_board_mode_show, lpfc_board_mode_store);
1972static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1973static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1974static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1975static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1976static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1977static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1978static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1979static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1980static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001981static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1982static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001983static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001984static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1985 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05001986static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05001987static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
1988 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001989
James Smart1ba981f2014-02-20 09:56:45 -05001990#define WWN_SZ 8
1991/**
1992 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
1993 * @buf: WWN string.
1994 * @cnt: Length of string.
1995 * @wwn: Array to receive converted wwn value.
1996 *
1997 * Returns:
1998 * -EINVAL if the buffer does not contain a valid wwn
1999 * 0 success
2000 **/
2001static size_t
2002lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2003{
2004 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002005
James Smart1ba981f2014-02-20 09:56:45 -05002006 /* Count may include a LF at end of string */
2007 if (buf[cnt-1] == '\n')
2008 cnt--;
2009
2010 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2011 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2012 return -EINVAL;
2013
2014 memset(wwn, 0, WWN_SZ);
2015
2016 /* Validate and store the new name */
2017 for (i = 0, j = 0; i < 16; i++) {
2018 if ((*buf >= 'a') && (*buf <= 'f'))
2019 j = ((j << 4) | ((*buf++ - 'a') + 10));
2020 else if ((*buf >= 'A') && (*buf <= 'F'))
2021 j = ((j << 4) | ((*buf++ - 'A') + 10));
2022 else if ((*buf >= '0') && (*buf <= '9'))
2023 j = ((j << 4) | (*buf++ - '0'));
2024 else
2025 return -EINVAL;
2026 if (i % 2) {
2027 wwn[i/2] = j & 0xff;
2028 j = 0;
2029 }
2030 }
2031 return 0;
2032}
James Smarta12e07b2006-12-02 13:35:30 -05002033
James Smart1ba981f2014-02-20 09:56:45 -05002034/**
2035 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2036 * Optimized Access Storage (OAS) operations.
2037 * @dev: class device that is converted into a Scsi_host.
2038 * @attr: device attribute, not used.
2039 * @buf: buffer for passing information.
2040 *
2041 * Returns:
2042 * value of count
2043 **/
2044static ssize_t
2045lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2046 char *buf)
2047{
2048 struct Scsi_Host *shost = class_to_shost(dev);
2049 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2050
2051 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2052 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2053}
2054
2055/**
2056 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2057 * Optimized Access Storage (OAS) operations.
2058 * @dev: class device that is converted into a Scsi_host.
2059 * @attr: device attribute, not used.
2060 * @buf: buffer for passing information.
2061 * @count: Size of the data buffer.
2062 *
2063 * Returns:
2064 * -EINVAL count is invalid, invalid wwpn byte invalid
2065 * -EPERM oas is not supported by hba
2066 * value of count on success
2067 **/
2068static ssize_t
2069lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2070 const char *buf, size_t count)
2071{
2072 struct Scsi_Host *shost = class_to_shost(dev);
2073 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2074 unsigned int cnt = count;
2075 uint8_t wwpn[WWN_SZ];
2076 int rc;
2077
James Smartf38fa0b2014-04-04 13:52:21 -04002078 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002079 return -EPERM;
2080
2081 /* count may include a LF at end of string */
2082 if (buf[cnt-1] == '\n')
2083 cnt--;
2084
2085 rc = lpfc_wwn_set(buf, cnt, wwpn);
2086 if (rc)
2087 return rc;
2088
2089 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2090 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2091 if (wwn_to_u64(wwpn) == 0)
2092 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2093 else
2094 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2095 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2096 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2097 return count;
2098}
2099static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2100 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2101
2102/**
James Smartc92c8412016-07-06 12:36:05 -07002103 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2104 * Optimized Access Storage (OAS) operations.
2105 * @dev: class device that is converted into a Scsi_host.
2106 * @attr: device attribute, not used.
2107 * @buf: buffer for passing information.
2108 *
2109 * Returns:
2110 * value of count
2111 **/
2112static ssize_t
2113lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2114 char *buf)
2115{
2116 struct Scsi_Host *shost = class_to_shost(dev);
2117 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2118
2119 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2120}
2121
2122/**
2123 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2124 * Optimized Access Storage (OAS) operations.
2125 * @dev: class device that is converted into a Scsi_host.
2126 * @attr: device attribute, not used.
2127 * @buf: buffer for passing information.
2128 * @count: Size of the data buffer.
2129 *
2130 * Returns:
2131 * -EINVAL count is invalid, invalid wwpn byte invalid
2132 * -EPERM oas is not supported by hba
2133 * value of count on success
2134 **/
2135static ssize_t
2136lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2137 const char *buf, size_t count)
2138{
2139 struct Scsi_Host *shost = class_to_shost(dev);
2140 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2141 unsigned int cnt = count;
2142 unsigned long val;
2143 int ret;
2144
2145 if (!phba->cfg_fof)
2146 return -EPERM;
2147
2148 /* count may include a LF at end of string */
2149 if (buf[cnt-1] == '\n')
2150 cnt--;
2151
2152 ret = kstrtoul(buf, 0, &val);
2153 if (ret || (val > 0x7f))
2154 return -EINVAL;
2155
2156 if (val)
2157 phba->cfg_oas_priority = (uint8_t)val;
2158 else
2159 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2160 return count;
2161}
2162static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2163 lpfc_oas_priority_show, lpfc_oas_priority_store);
2164
2165/**
James Smart1ba981f2014-02-20 09:56:45 -05002166 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2167 * for Optimized Access Storage (OAS) operations.
2168 * @dev: class device that is converted into a Scsi_host.
2169 * @attr: device attribute, not used.
2170 * @buf: buffer for passing information.
2171 *
2172 * Returns:
2173 * value of count on success
2174 **/
2175static ssize_t
2176lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2177 char *buf)
2178{
2179 struct Scsi_Host *shost = class_to_shost(dev);
2180 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2181
2182 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2183 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2184}
2185
2186/**
2187 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2188 * for Optimized Access Storage (OAS) operations.
2189 * @dev: class device that is converted into a Scsi_host.
2190 * @attr: device attribute, not used.
2191 * @buf: buffer for passing information.
2192 * @count: Size of the data buffer.
2193 *
2194 * Returns:
2195 * -EINVAL count is invalid, invalid wwpn byte invalid
2196 * -EPERM oas is not supported by hba
2197 * value of count on success
2198 **/
2199static ssize_t
2200lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2201 const char *buf, size_t count)
2202{
2203 struct Scsi_Host *shost = class_to_shost(dev);
2204 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2205 unsigned int cnt = count;
2206 uint8_t wwpn[WWN_SZ];
2207 int rc;
2208
James Smartf38fa0b2014-04-04 13:52:21 -04002209 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002210 return -EPERM;
2211
2212 /* count may include a LF at end of string */
2213 if (buf[cnt-1] == '\n')
2214 cnt--;
2215
2216 rc = lpfc_wwn_set(buf, cnt, wwpn);
2217 if (rc)
2218 return rc;
2219
2220 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2221 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2222 if (wwn_to_u64(wwpn) == 0)
2223 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2224 else
2225 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2226 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002227 if (phba->cfg_oas_priority == 0)
2228 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002229 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2230 return count;
2231}
2232static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2233 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2234
2235/**
2236 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2237 * of whether luns will be enabled or disabled
2238 * for Optimized Access Storage (OAS) operations.
2239 * @dev: class device that is converted into a Scsi_host.
2240 * @attr: device attribute, not used.
2241 * @buf: buffer for passing information.
2242 *
2243 * Returns:
2244 * size of formatted string.
2245 **/
2246static ssize_t
2247lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2248 char *buf)
2249{
2250 struct Scsi_Host *shost = class_to_shost(dev);
2251 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2252
2253 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2254}
2255
2256/**
2257 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2258 * of whether luns will be enabled or disabled
2259 * for Optimized Access Storage (OAS) operations.
2260 * @dev: class device that is converted into a Scsi_host.
2261 * @attr: device attribute, not used.
2262 * @buf: buffer for passing information.
2263 * @count: Size of the data buffer.
2264 *
2265 * Returns:
2266 * -EINVAL count is invalid, invalid wwpn byte invalid
2267 * -EPERM oas is not supported by hba
2268 * value of count on success
2269 **/
2270static ssize_t
2271lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2272 const char *buf, size_t count)
2273{
2274 struct Scsi_Host *shost = class_to_shost(dev);
2275 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2276 int val = 0;
2277
James Smartf38fa0b2014-04-04 13:52:21 -04002278 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002279 return -EPERM;
2280
2281 if (!isdigit(buf[0]))
2282 return -EINVAL;
2283
2284 if (sscanf(buf, "%i", &val) != 1)
2285 return -EINVAL;
2286
2287 if ((val != 0) && (val != 1))
2288 return -EINVAL;
2289
2290 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002291 return strlen(buf);
2292}
2293static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2294 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2295
2296/**
2297 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2298 * Storage (OAS) lun returned by the
2299 * lpfc_oas_lun_show function.
2300 * @dev: class device that is converted into a Scsi_host.
2301 * @attr: device attribute, not used.
2302 * @buf: buffer for passing information.
2303 *
2304 * Returns:
2305 * size of formatted string.
2306 **/
2307static ssize_t
2308lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2309 char *buf)
2310{
2311 struct Scsi_Host *shost = class_to_shost(dev);
2312 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2313
2314 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2315 return -EFAULT;
2316
2317 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2318}
2319static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2320 lpfc_oas_lun_status_show, NULL);
2321
2322
2323/**
2324 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2325 * (OAS) operations.
2326 * @phba: lpfc_hba pointer.
2327 * @ndlp: pointer to fcp target node.
2328 * @lun: the fc lun for setting oas state.
2329 * @oas_state: the oas state to be set to the lun.
2330 *
2331 * Returns:
2332 * SUCCESS : 0
2333 * -EPERM OAS is not enabled or not supported by this port.
2334 *
2335 */
2336static size_t
2337lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002338 uint8_t tgt_wwpn[], uint64_t lun,
2339 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002340{
2341
2342 int rc = 0;
2343
James Smartf38fa0b2014-04-04 13:52:21 -04002344 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002345 return -EPERM;
2346
2347 if (oas_state) {
2348 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002349 (struct lpfc_name *)tgt_wwpn,
2350 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002351 rc = -ENOMEM;
2352 } else {
2353 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002354 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002355 }
2356 return rc;
2357
2358}
2359
2360/**
2361 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2362 * Access Storage (OAS) operations.
2363 * @phba: lpfc_hba pointer.
2364 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2365 * @tgt_wwpn: wwpn of the target associated with the returned lun
2366 * @lun_status: status of the lun returned lun
2367 *
2368 * Returns the first or next lun enabled for OAS operations for the vport/target
2369 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2370 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2371 *
2372 * Return:
2373 * lun that is OAS enabled for the vport/target
2374 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2375 */
2376static uint64_t
2377lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002378 uint8_t tgt_wwpn[], uint32_t *lun_status,
2379 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002380{
2381 uint64_t found_lun;
2382
2383 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2384 return NOT_OAS_ENABLED_LUN;
2385 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2386 phba->sli4_hba.oas_next_vpt_wwpn,
2387 (struct lpfc_name *)
2388 phba->sli4_hba.oas_next_tgt_wwpn,
2389 &phba->sli4_hba.oas_next_lun,
2390 (struct lpfc_name *)vpt_wwpn,
2391 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002392 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002393 return found_lun;
2394 else
2395 return NOT_OAS_ENABLED_LUN;
2396}
2397
2398/**
2399 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2400 * @phba: lpfc_hba pointer.
2401 * @vpt_wwpn: vport wwpn by reference.
2402 * @tgt_wwpn: target wwpn by reference.
2403 * @lun: the fc lun for setting oas state.
2404 * @oas_state: the oas state to be set to the oas_lun.
2405 *
2406 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2407 * a lun for OAS operations.
2408 *
2409 * Return:
2410 * SUCCESS: 0
2411 * -ENOMEM: failed to enable an lun for OAS operations
2412 * -EPERM: OAS is not enabled
2413 */
2414static ssize_t
2415lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2416 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002417 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002418{
2419
2420 int rc;
2421
2422 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002423 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002424 return rc;
2425}
2426
2427/**
2428 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2429 * @dev: class device that is converted into a Scsi_host.
2430 * @attr: device attribute, not used.
2431 * @buf: buffer for passing information.
2432 *
2433 * This routine returns a lun enabled for OAS each time the function
2434 * is called.
2435 *
2436 * Returns:
2437 * SUCCESS: size of formatted string.
2438 * -EFAULT: target or vport wwpn was not set properly.
2439 * -EPERM: oas is not enabled.
2440 **/
2441static ssize_t
2442lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2443 char *buf)
2444{
2445 struct Scsi_Host *shost = class_to_shost(dev);
2446 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2447
2448 uint64_t oas_lun;
2449 int len = 0;
2450
James Smartf38fa0b2014-04-04 13:52:21 -04002451 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002452 return -EPERM;
2453
2454 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2455 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2456 return -EFAULT;
2457
2458 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2459 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2460 return -EFAULT;
2461
2462 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2463 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002464 &phba->cfg_oas_lun_status,
2465 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002466 if (oas_lun != NOT_OAS_ENABLED_LUN)
2467 phba->cfg_oas_flags |= OAS_LUN_VALID;
2468
2469 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2470
2471 return len;
2472}
2473
2474/**
2475 * lpfc_oas_lun_store - Sets the OAS state for lun
2476 * @dev: class device that is converted into a Scsi_host.
2477 * @attr: device attribute, not used.
2478 * @buf: buffer for passing information.
2479 *
2480 * This function sets the OAS state for lun. Before this function is called,
2481 * the vport wwpn, target wwpn, and oas state need to be set.
2482 *
2483 * Returns:
2484 * SUCCESS: size of formatted string.
2485 * -EFAULT: target or vport wwpn was not set properly.
2486 * -EPERM: oas is not enabled.
2487 * size of formatted string.
2488 **/
2489static ssize_t
2490lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2491 const char *buf, size_t count)
2492{
2493 struct Scsi_Host *shost = class_to_shost(dev);
2494 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2495 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08002496 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05002497 ssize_t rc;
2498
James Smartf38fa0b2014-04-04 13:52:21 -04002499 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002500 return -EPERM;
2501
2502 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2503 return -EFAULT;
2504
2505 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2506 return -EFAULT;
2507
2508 if (!isdigit(buf[0]))
2509 return -EINVAL;
2510
2511 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2512 return -EINVAL;
2513
James Smartb5749fe2016-12-19 15:07:26 -08002514 pri = phba->cfg_oas_priority;
2515 if (pri == 0)
2516 pri = phba->cfg_XLanePriority;
2517
James Smart1ba981f2014-02-20 09:56:45 -05002518 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002519 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2520 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002521 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2522 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002523 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002524
2525 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002526 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002527 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002528 if (rc)
2529 return rc;
2530
2531 return count;
2532}
2533static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2534 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002535
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002536static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002537module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002538MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2539 " 0 - none,"
2540 " 1 - poll with interrupts enabled"
2541 " 3 - poll and disable FCP ring interrupts");
2542
Tony Jonesee959b02008-02-22 00:13:36 +01002543static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2544 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002545
James Smart12247e82016-07-06 12:36:09 -07002546LPFC_ATTR(sli_mode, 0, 0, 3,
2547 "SLI mode selector:"
2548 " 0 - auto (SLI-3 if supported),"
2549 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2550 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05002551
James Smart458c0832016-07-06 12:36:07 -07002552LPFC_ATTR_R(enable_npiv, 1, 0, 1,
2553 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05002554
James Smart7d791df2011-07-22 18:37:52 -04002555LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2556 "FCF Fast failover=1 Priority failover=2");
2557
James Smarte5771b42013-03-01 16:37:14 -05002558/*
2559# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2560# 0x0 = disabled, XRI/OXID use not tracked.
2561# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2562# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2563*/
James Smart31202b02016-10-13 15:06:08 -07002564LPFC_ATTR_R(enable_rrq, 2, 0, 2,
2565 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05002566
dea31012005-04-17 16:05:31 -05002567/*
James Smart84d1b002010-02-12 14:42:33 -05002568# lpfc_suppress_link_up: Bring link up at initialization
2569# 0x0 = bring link up (issue MBX_INIT_LINK)
2570# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2571# 0x2 = never bring up link
2572# Default value is 0.
2573*/
James Smarte40a02c2010-02-26 14:13:54 -05002574LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2575 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2576 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002577/*
2578# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2579# 1 - (1024)
2580# 2 - (2048)
2581# 3 - (3072)
2582# 4 - (4096)
2583# 5 - (5120)
2584*/
2585static ssize_t
2586lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2587{
2588 struct Scsi_Host *shost = class_to_shost(dev);
2589 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2590
2591 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2592}
2593
2594static DEVICE_ATTR(iocb_hw, S_IRUGO,
2595 lpfc_iocb_hw_show, NULL);
2596static ssize_t
2597lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2598{
2599 struct Scsi_Host *shost = class_to_shost(dev);
2600 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2601
2602 return snprintf(buf, PAGE_SIZE, "%d\n",
2603 phba->sli.ring[LPFC_ELS_RING].txq_max);
2604}
2605
2606static DEVICE_ATTR(txq_hw, S_IRUGO,
2607 lpfc_txq_hw_show, NULL);
2608static ssize_t
2609lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2610 char *buf)
2611{
2612 struct Scsi_Host *shost = class_to_shost(dev);
2613 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2614
2615 return snprintf(buf, PAGE_SIZE, "%d\n",
2616 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2617}
2618
2619static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2620 lpfc_txcmplq_hw_show, NULL);
2621
James Smart0d8c8ba2016-10-13 15:06:07 -07002622LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04002623 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05002624
2625/*
James Smartc01f3202006-08-18 17:47:08 -04002626# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2627# until the timer expires. Value range is [0,255]. Default value is 30.
2628*/
2629static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2630static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2631module_param(lpfc_nodev_tmo, int, 0);
2632MODULE_PARM_DESC(lpfc_nodev_tmo,
2633 "Seconds driver will hold I/O waiting "
2634 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002635
2636/**
James Smart3621a712009-04-06 18:47:14 -04002637 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002638 * @dev: class converted to a Scsi_host structure.
2639 * @attr: device attribute, not used.
2640 * @buf: on return contains the dev loss timeout in decimal.
2641 *
2642 * Returns: size of formatted string.
2643 **/
James Smartc01f3202006-08-18 17:47:08 -04002644static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002645lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2646 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002647{
Tony Jonesee959b02008-02-22 00:13:36 +01002648 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002649 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002650
James Smart3de2a652007-08-02 11:09:59 -04002651 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002652}
2653
James Smarte59058c2008-08-24 21:49:00 -04002654/**
James Smart3621a712009-04-06 18:47:14 -04002655 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002656 * @vport: lpfc vport structure pointer.
2657 * @val: contains the nodev timeout value.
2658 *
2659 * Description:
2660 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2661 * a kernel error message is printed and zero is returned.
2662 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2663 * Otherwise nodev tmo is set to the default value.
2664 *
2665 * Returns:
2666 * zero if already set or if val is in range
2667 * -EINVAL val out of range
2668 **/
James Smartc01f3202006-08-18 17:47:08 -04002669static int
James Smart3de2a652007-08-02 11:09:59 -04002670lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002671{
James Smart3de2a652007-08-02 11:09:59 -04002672 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2673 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2674 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002675 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07002676 "0407 Ignoring lpfc_nodev_tmo module "
2677 "parameter because lpfc_devloss_tmo "
2678 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002679 return 0;
2680 }
2681
2682 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002683 vport->cfg_nodev_tmo = val;
2684 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002685 return 0;
2686 }
James Smarte8b62012007-08-02 11:10:09 -04002687 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2688 "0400 lpfc_nodev_tmo attribute cannot be set to"
2689 " %d, allowed range is [%d, %d]\n",
2690 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002691 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002692 return -EINVAL;
2693}
2694
James Smarte59058c2008-08-24 21:49:00 -04002695/**
James Smart3621a712009-04-06 18:47:14 -04002696 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002697 * @vport: lpfc vport structure pointer.
2698 *
2699 * Description:
2700 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2701 **/
James Smart7054a602007-04-25 09:52:34 -04002702static void
James Smart3de2a652007-08-02 11:09:59 -04002703lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002704{
James Smart858c9f62007-06-17 19:56:39 -05002705 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002706 struct lpfc_nodelist *ndlp;
2707
James Smart51ef4c22007-08-02 11:10:31 -04002708 shost = lpfc_shost_from_vport(vport);
2709 spin_lock_irq(shost->host_lock);
2710 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002711 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002712 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2713 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002714}
2715
James Smarte59058c2008-08-24 21:49:00 -04002716/**
James Smart3621a712009-04-06 18:47:14 -04002717 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002718 * @vport: lpfc vport structure pointer.
2719 * @val: contains the tmo value.
2720 *
2721 * Description:
2722 * If the devloss tmo is already set or the vport dev loss tmo has changed
2723 * then a kernel error message is printed and zero is returned.
2724 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2725 * Otherwise nodev tmo is set to the default value.
2726 *
2727 * Returns:
2728 * zero if already set or if val is in range
2729 * -EINVAL val out of range
2730 **/
James Smartc01f3202006-08-18 17:47:08 -04002731static int
James Smart3de2a652007-08-02 11:09:59 -04002732lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002733{
James Smart3de2a652007-08-02 11:09:59 -04002734 if (vport->dev_loss_tmo_changed ||
2735 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002736 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07002737 "0401 Ignoring change to lpfc_nodev_tmo "
2738 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002739 return 0;
2740 }
James Smartc01f3202006-08-18 17:47:08 -04002741 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002742 vport->cfg_nodev_tmo = val;
2743 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002744 /*
2745 * For compat: set the fc_host dev loss so new rports
2746 * will get the value.
2747 */
2748 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002749 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002750 return 0;
2751 }
James Smarte8b62012007-08-02 11:10:09 -04002752 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07002753 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04002754 "%d, allowed range is [%d, %d]\n",
2755 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002756 return -EINVAL;
2757}
2758
James Smart3de2a652007-08-02 11:09:59 -04002759lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002760
Tony Jonesee959b02008-02-22 00:13:36 +01002761static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2762 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002763
2764/*
2765# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2766# disappear until the timer expires. Value range is [0,255]. Default
2767# value is 30.
2768*/
James Smartab56dc22011-02-16 12:39:57 -05002769module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002770MODULE_PARM_DESC(lpfc_devloss_tmo,
2771 "Seconds driver will hold I/O waiting "
2772 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002773lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2774 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2775lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002776
2777/**
James Smart3621a712009-04-06 18:47:14 -04002778 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002779 * @vport: lpfc vport structure pointer.
2780 * @val: contains the tmo value.
2781 *
2782 * Description:
2783 * If val is in a valid range then set the vport nodev tmo,
2784 * devloss tmo, also set the vport dev loss tmo changed flag.
2785 * Else a kernel error message is printed.
2786 *
2787 * Returns:
2788 * zero if val is in range
2789 * -EINVAL val out of range
2790 **/
James Smartc01f3202006-08-18 17:47:08 -04002791static int
James Smart3de2a652007-08-02 11:09:59 -04002792lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002793{
2794 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002795 vport->cfg_nodev_tmo = val;
2796 vport->cfg_devloss_tmo = val;
2797 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002798 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002799 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002800 return 0;
2801 }
2802
James Smarte8b62012007-08-02 11:10:09 -04002803 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07002804 "0404 lpfc_devloss_tmo attribute cannot be set to "
2805 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04002806 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002807 return -EINVAL;
2808}
2809
James Smart3de2a652007-08-02 11:09:59 -04002810lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002811static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2812 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002813
2814/*
dea31012005-04-17 16:05:31 -05002815# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2816# deluged with LOTS of information.
2817# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002818# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002819*/
James Smartf4b4c682009-05-22 14:53:12 -04002820LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002821 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002822
2823/*
James Smart7ee5d432007-10-27 13:37:17 -04002824# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2825# objects that have been registered with the nameserver after login.
2826*/
James Smartcf971242012-03-01 22:37:32 -05002827LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04002828 "Deregister nameserver objects before LOGO");
2829
2830/*
dea31012005-04-17 16:05:31 -05002831# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04002832# commands per FCP LUN. Value range is [1,512]. Default value is 30.
2833# If this parameter value is greater than 1/8th the maximum number of exchanges
2834# supported by the HBA port, then the lun queue depth will be reduced to
2835# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05002836*/
James Smart572709e2013-07-15 18:32:43 -04002837LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04002838 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002839
2840/*
James Smart7dc517d2010-07-14 15:32:10 -04002841# tgt_queue_depth: This parameter is used to limit the number of outstanding
2842# commands per target port. Value range is [10,65535]. Default value is 65535.
2843*/
2844LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04002845 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04002846
2847/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002848# hba_queue_depth: This parameter is used to limit the number of outstanding
2849# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2850# value is greater than the maximum number of exchanges supported by the HBA,
2851# then maximum number of exchanges supported by the HBA is used to determine
2852# the hba_queue_depth.
2853*/
2854LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2855 "Max number of FCP commands we can queue to a lpfc HBA");
2856
2857/*
James Smart92d7f7b2007-06-17 19:56:38 -05002858# peer_port_login: This parameter allows/prevents logins
2859# between peer ports hosted on the same physical port.
2860# When this parameter is set 0 peer ports of same physical port
2861# are not allowed to login to each other.
2862# When this parameter is set 1 peer ports of same physical port
2863# are allowed to login to each other.
2864# Default value of this parameter is 0.
2865*/
James Smart3de2a652007-08-02 11:09:59 -04002866LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2867 "Allow peer ports on the same physical port to login to each "
2868 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002869
2870/*
James Smart3de2a652007-08-02 11:09:59 -04002871# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002872# between Virtual Ports and remote initiators.
2873# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2874# other initiators and will attempt to PLOGI all remote ports.
2875# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2876# remote ports and will not attempt to PLOGI to other initiators.
2877# This parameter does not restrict to the physical port.
2878# This parameter does not restrict logins to Fabric resident remote ports.
2879# Default value of this parameter is 1.
2880*/
James Smart3de2a652007-08-02 11:09:59 -04002881static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002882module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002883MODULE_PARM_DESC(lpfc_restrict_login,
2884 "Restrict virtual ports login to remote initiators.");
2885lpfc_vport_param_show(restrict_login);
2886
James Smarte59058c2008-08-24 21:49:00 -04002887/**
James Smart3621a712009-04-06 18:47:14 -04002888 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002889 * @vport: lpfc vport structure pointer.
2890 * @val: contains the restrict login value.
2891 *
2892 * Description:
2893 * If val is not in a valid range then log a kernel error message and set
2894 * the vport restrict login to one.
2895 * If the port type is physical clear the restrict login flag and return.
2896 * Else set the restrict login flag to val.
2897 *
2898 * Returns:
2899 * zero if val is in range
2900 * -EINVAL val out of range
2901 **/
James Smart3de2a652007-08-02 11:09:59 -04002902static int
2903lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2904{
2905 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002906 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002907 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002908 "be set to %d, allowed range is [0, 1]\n",
2909 val);
James Smart3de2a652007-08-02 11:09:59 -04002910 vport->cfg_restrict_login = 1;
2911 return -EINVAL;
2912 }
2913 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2914 vport->cfg_restrict_login = 0;
2915 return 0;
2916 }
2917 vport->cfg_restrict_login = val;
2918 return 0;
2919}
2920
James Smarte59058c2008-08-24 21:49:00 -04002921/**
James Smart3621a712009-04-06 18:47:14 -04002922 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002923 * @vport: lpfc vport structure pointer.
2924 * @val: contains the restrict login value.
2925 *
2926 * Description:
2927 * If val is not in a valid range then log a kernel error message and set
2928 * the vport restrict login to one.
2929 * If the port type is physical and the val is not zero log a kernel
2930 * error message, clear the restrict login flag and return zero.
2931 * Else set the restrict login flag to val.
2932 *
2933 * Returns:
2934 * zero if val is in range
2935 * -EINVAL val out of range
2936 **/
James Smart3de2a652007-08-02 11:09:59 -04002937static int
2938lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2939{
2940 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002941 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002942 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002943 "be set to %d, allowed range is [0, 1]\n",
2944 val);
James Smart3de2a652007-08-02 11:09:59 -04002945 vport->cfg_restrict_login = 1;
2946 return -EINVAL;
2947 }
2948 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002949 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2950 "0468 lpfc_restrict_login must be 0 for "
2951 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002952 vport->cfg_restrict_login = 0;
2953 return 0;
2954 }
2955 vport->cfg_restrict_login = val;
2956 return 0;
2957}
2958lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002959static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2960 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002961
2962/*
dea31012005-04-17 16:05:31 -05002963# Some disk devices have a "select ID" or "select Target" capability.
2964# From a protocol standpoint "select ID" usually means select the
2965# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2966# annex" which contains a table that maps a "select ID" (a number
2967# between 0 and 7F) to an ALPA. By default, for compatibility with
2968# older drivers, the lpfc driver scans this table from low ALPA to high
2969# ALPA.
2970#
2971# Turning on the scan-down variable (on = 1, off = 0) will
2972# cause the lpfc driver to use an inverted table, effectively
2973# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2974#
2975# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2976# and will not work across a fabric. Also this parameter will take
2977# effect only in the case when ALPA map is not available.)
2978*/
James Smart3de2a652007-08-02 11:09:59 -04002979LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2980 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002981
2982/*
dea31012005-04-17 16:05:31 -05002983# lpfc_topology: link topology for init link
2984# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002985# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002986# 0x02 = attempt point-to-point mode only
2987# 0x04 = attempt loop mode only
2988# 0x06 = attempt point-to-point mode then loop
2989# Set point-to-point mode if you want to run as an N_Port.
2990# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2991# Default value is 0.
2992*/
James Smart0a035432016-10-13 15:06:10 -07002993LPFC_ATTR(topology, 0, 0, 6,
2994 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04002995
2996/**
James Smart3621a712009-04-06 18:47:14 -04002997 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002998 * @phba: lpfc_hba pointer.
2999 * @val: topology value.
3000 *
3001 * Description:
3002 * If val is in a valid range then set the adapter's topology field and
3003 * issue a lip; if the lip fails reset the topology to the old value.
3004 *
3005 * If the value is not in range log a kernel error message and return an error.
3006 *
3007 * Returns:
3008 * zero if val is in range and lip okay
3009 * non-zero return value from lpfc_issue_lip()
3010 * -EINVAL val out of range
3011 **/
James Smarta257bf92009-04-06 18:48:10 -04003012static ssize_t
3013lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3014 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003015{
James Smarta257bf92009-04-06 18:48:10 -04003016 struct Scsi_Host *shost = class_to_shost(dev);
3017 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3018 struct lpfc_hba *phba = vport->phba;
3019 int val = 0;
3020 int nolip = 0;
3021 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003022 int err;
3023 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003024
3025 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3026 nolip = 1;
3027 val_buf = &buf[strlen("nolip ")];
3028 }
3029
3030 if (!isdigit(val_buf[0]))
3031 return -EINVAL;
3032 if (sscanf(val_buf, "%i", &val) != 1)
3033 return -EINVAL;
3034
James Smart83108bd2008-01-11 01:53:09 -05003035 if (val >= 0 && val <= 6) {
3036 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003037 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3038 val == 4) {
3039 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3040 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003041 val);
James Smartff78d8f2011-12-13 13:21:35 -05003042 return -EINVAL;
3043 }
James Smartd38dd522015-08-31 16:48:17 -04003044 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3045 val == 4) {
3046 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3047 "3114 Loop mode not supported\n");
3048 return -EINVAL;
3049 }
3050 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003051 if (nolip)
3052 return strlen(buf);
3053
James Smart88a2cfb2011-07-22 18:36:33 -04003054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3055 "3054 lpfc_topology changed from %d to %d\n",
3056 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003057 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3058 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003059 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003060 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003061 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003062 return -EINVAL;
3063 } else
3064 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003065 }
3066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3067 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3068 "allowed range is [0, 6]\n",
3069 phba->brd_no, val);
3070 return -EINVAL;
3071}
James Smart0a035432016-10-13 15:06:10 -07003072
James Smart83108bd2008-01-11 01:53:09 -05003073lpfc_param_show(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01003074static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003075 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003076
James Smart21e9a0a2009-05-22 14:53:21 -04003077/**
3078 * lpfc_static_vport_show: Read callback function for
3079 * lpfc_static_vport sysfs file.
3080 * @dev: Pointer to class device object.
3081 * @attr: device attribute structure.
3082 * @buf: Data buffer.
3083 *
3084 * This function is the read call back function for
3085 * lpfc_static_vport sysfs file. The lpfc_static_vport
3086 * sysfs file report the mageability of the vport.
3087 **/
3088static ssize_t
3089lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3090 char *buf)
3091{
3092 struct Scsi_Host *shost = class_to_shost(dev);
3093 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3094 if (vport->vport_flag & STATIC_VPORT)
3095 sprintf(buf, "1\n");
3096 else
3097 sprintf(buf, "0\n");
3098
3099 return strlen(buf);
3100}
3101
3102/*
3103 * Sysfs attribute to control the statistical data collection.
3104 */
3105static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3106 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003107
3108/**
James Smart3621a712009-04-06 18:47:14 -04003109 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003110 * @dev: Pointer to class device.
3111 * @buf: Data buffer.
3112 * @count: Size of the data buffer.
3113 *
3114 * This function get called when an user write to the lpfc_stat_data_ctrl
3115 * sysfs file. This function parse the command written to the sysfs file
3116 * and take appropriate action. These commands are used for controlling
3117 * driver statistical data collection.
3118 * Following are the command this function handles.
3119 *
3120 * setbucket <bucket_type> <base> <step>
3121 * = Set the latency buckets.
3122 * destroybucket = destroy all the buckets.
3123 * start = start data collection
3124 * stop = stop data collection
3125 * reset = reset the collected data
3126 **/
3127static ssize_t
3128lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3129 const char *buf, size_t count)
3130{
3131 struct Scsi_Host *shost = class_to_shost(dev);
3132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3133 struct lpfc_hba *phba = vport->phba;
3134#define LPFC_MAX_DATA_CTRL_LEN 1024
3135 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3136 unsigned long i;
3137 char *str_ptr, *token;
3138 struct lpfc_vport **vports;
3139 struct Scsi_Host *v_shost;
3140 char *bucket_type_str, *base_str, *step_str;
3141 unsigned long base, step, bucket_type;
3142
3143 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003144 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003145 return -EINVAL;
3146
James Smarteb016562014-09-03 12:58:06 -04003147 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003148 str_ptr = &bucket_data[0];
3149 /* Ignore this token - this is command token */
3150 token = strsep(&str_ptr, "\t ");
3151 if (!token)
3152 return -EINVAL;
3153
3154 bucket_type_str = strsep(&str_ptr, "\t ");
3155 if (!bucket_type_str)
3156 return -EINVAL;
3157
3158 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3159 bucket_type = LPFC_LINEAR_BUCKET;
3160 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3161 bucket_type = LPFC_POWER2_BUCKET;
3162 else
3163 return -EINVAL;
3164
3165 base_str = strsep(&str_ptr, "\t ");
3166 if (!base_str)
3167 return -EINVAL;
3168 base = simple_strtoul(base_str, NULL, 0);
3169
3170 step_str = strsep(&str_ptr, "\t ");
3171 if (!step_str)
3172 return -EINVAL;
3173 step = simple_strtoul(step_str, NULL, 0);
3174 if (!step)
3175 return -EINVAL;
3176
3177 /* Block the data collection for every vport */
3178 vports = lpfc_create_vport_work_array(phba);
3179 if (vports == NULL)
3180 return -ENOMEM;
3181
James Smartf4b4c682009-05-22 14:53:12 -04003182 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003183 v_shost = lpfc_shost_from_vport(vports[i]);
3184 spin_lock_irq(v_shost->host_lock);
3185 /* Block and reset data collection */
3186 vports[i]->stat_data_blocked = 1;
3187 if (vports[i]->stat_data_enabled)
3188 lpfc_vport_reset_stat_data(vports[i]);
3189 spin_unlock_irq(v_shost->host_lock);
3190 }
3191
3192 /* Set the bucket attributes */
3193 phba->bucket_type = bucket_type;
3194 phba->bucket_base = base;
3195 phba->bucket_step = step;
3196
James Smartf4b4c682009-05-22 14:53:12 -04003197 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003198 v_shost = lpfc_shost_from_vport(vports[i]);
3199
3200 /* Unblock data collection */
3201 spin_lock_irq(v_shost->host_lock);
3202 vports[i]->stat_data_blocked = 0;
3203 spin_unlock_irq(v_shost->host_lock);
3204 }
3205 lpfc_destroy_vport_work_array(phba, vports);
3206 return strlen(buf);
3207 }
3208
3209 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3210 vports = lpfc_create_vport_work_array(phba);
3211 if (vports == NULL)
3212 return -ENOMEM;
3213
James Smartf4b4c682009-05-22 14:53:12 -04003214 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003215 v_shost = lpfc_shost_from_vport(vports[i]);
3216 spin_lock_irq(shost->host_lock);
3217 vports[i]->stat_data_blocked = 1;
3218 lpfc_free_bucket(vport);
3219 vport->stat_data_enabled = 0;
3220 vports[i]->stat_data_blocked = 0;
3221 spin_unlock_irq(shost->host_lock);
3222 }
3223 lpfc_destroy_vport_work_array(phba, vports);
3224 phba->bucket_type = LPFC_NO_BUCKET;
3225 phba->bucket_base = 0;
3226 phba->bucket_step = 0;
3227 return strlen(buf);
3228 }
3229
3230 if (!strncmp(buf, "start", strlen("start"))) {
3231 /* If no buckets configured return error */
3232 if (phba->bucket_type == LPFC_NO_BUCKET)
3233 return -EINVAL;
3234 spin_lock_irq(shost->host_lock);
3235 if (vport->stat_data_enabled) {
3236 spin_unlock_irq(shost->host_lock);
3237 return strlen(buf);
3238 }
3239 lpfc_alloc_bucket(vport);
3240 vport->stat_data_enabled = 1;
3241 spin_unlock_irq(shost->host_lock);
3242 return strlen(buf);
3243 }
3244
3245 if (!strncmp(buf, "stop", strlen("stop"))) {
3246 spin_lock_irq(shost->host_lock);
3247 if (vport->stat_data_enabled == 0) {
3248 spin_unlock_irq(shost->host_lock);
3249 return strlen(buf);
3250 }
3251 lpfc_free_bucket(vport);
3252 vport->stat_data_enabled = 0;
3253 spin_unlock_irq(shost->host_lock);
3254 return strlen(buf);
3255 }
3256
3257 if (!strncmp(buf, "reset", strlen("reset"))) {
3258 if ((phba->bucket_type == LPFC_NO_BUCKET)
3259 || !vport->stat_data_enabled)
3260 return strlen(buf);
3261 spin_lock_irq(shost->host_lock);
3262 vport->stat_data_blocked = 1;
3263 lpfc_vport_reset_stat_data(vport);
3264 vport->stat_data_blocked = 0;
3265 spin_unlock_irq(shost->host_lock);
3266 return strlen(buf);
3267 }
3268 return -EINVAL;
3269}
3270
3271
3272/**
James Smart3621a712009-04-06 18:47:14 -04003273 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003274 * @dev: Pointer to class device object.
3275 * @buf: Data buffer.
3276 *
3277 * This function is the read call back function for
3278 * lpfc_stat_data_ctrl sysfs file. This function report the
3279 * current statistical data collection state.
3280 **/
3281static ssize_t
3282lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3283 char *buf)
3284{
3285 struct Scsi_Host *shost = class_to_shost(dev);
3286 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3287 struct lpfc_hba *phba = vport->phba;
3288 int index = 0;
3289 int i;
3290 char *bucket_type;
3291 unsigned long bucket_value;
3292
3293 switch (phba->bucket_type) {
3294 case LPFC_LINEAR_BUCKET:
3295 bucket_type = "linear";
3296 break;
3297 case LPFC_POWER2_BUCKET:
3298 bucket_type = "power2";
3299 break;
3300 default:
3301 bucket_type = "No Bucket";
3302 break;
3303 }
3304
3305 sprintf(&buf[index], "Statistical Data enabled :%d, "
3306 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3307 " Bucket step :%d\nLatency Ranges :",
3308 vport->stat_data_enabled, vport->stat_data_blocked,
3309 bucket_type, phba->bucket_base, phba->bucket_step);
3310 index = strlen(buf);
3311 if (phba->bucket_type != LPFC_NO_BUCKET) {
3312 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3313 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3314 bucket_value = phba->bucket_base +
3315 phba->bucket_step * i;
3316 else
3317 bucket_value = phba->bucket_base +
3318 (1 << i) * phba->bucket_step;
3319
3320 if (index + 10 > PAGE_SIZE)
3321 break;
3322 sprintf(&buf[index], "%08ld ", bucket_value);
3323 index = strlen(buf);
3324 }
3325 }
3326 sprintf(&buf[index], "\n");
3327 return strlen(buf);
3328}
3329
3330/*
3331 * Sysfs attribute to control the statistical data collection.
3332 */
3333static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3334 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3335
3336/*
3337 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3338 */
3339
3340/*
3341 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3342 * for each target.
3343 */
3344#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3345#define MAX_STAT_DATA_SIZE_PER_TARGET \
3346 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3347
3348
3349/**
James Smart3621a712009-04-06 18:47:14 -04003350 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003351 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003352 * @kobj: Pointer to the kernel object
3353 * @bin_attr: Attribute object
3354 * @buff: Buffer pointer
3355 * @off: File offset
3356 * @count: Buffer size
3357 *
3358 * This function is the read call back function for lpfc_drvr_stat_data
3359 * sysfs file. This function export the statistical data to user
3360 * applications.
3361 **/
3362static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003363sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3364 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003365 char *buf, loff_t off, size_t count)
3366{
3367 struct device *dev = container_of(kobj, struct device,
3368 kobj);
3369 struct Scsi_Host *shost = class_to_shost(dev);
3370 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3371 struct lpfc_hba *phba = vport->phba;
3372 int i = 0, index = 0;
3373 unsigned long nport_index;
3374 struct lpfc_nodelist *ndlp = NULL;
3375 nport_index = (unsigned long)off /
3376 MAX_STAT_DATA_SIZE_PER_TARGET;
3377
3378 if (!vport->stat_data_enabled || vport->stat_data_blocked
3379 || (phba->bucket_type == LPFC_NO_BUCKET))
3380 return 0;
3381
3382 spin_lock_irq(shost->host_lock);
3383 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3384 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3385 continue;
3386
3387 if (nport_index > 0) {
3388 nport_index--;
3389 continue;
3390 }
3391
3392 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3393 > count)
3394 break;
3395
3396 if (!ndlp->lat_data)
3397 continue;
3398
3399 /* Print the WWN */
3400 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3401 ndlp->nlp_portname.u.wwn[0],
3402 ndlp->nlp_portname.u.wwn[1],
3403 ndlp->nlp_portname.u.wwn[2],
3404 ndlp->nlp_portname.u.wwn[3],
3405 ndlp->nlp_portname.u.wwn[4],
3406 ndlp->nlp_portname.u.wwn[5],
3407 ndlp->nlp_portname.u.wwn[6],
3408 ndlp->nlp_portname.u.wwn[7]);
3409
3410 index = strlen(buf);
3411
3412 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3413 sprintf(&buf[index], "%010u,",
3414 ndlp->lat_data[i].cmd_count);
3415 index = strlen(buf);
3416 }
3417 sprintf(&buf[index], "\n");
3418 index = strlen(buf);
3419 }
3420 spin_unlock_irq(shost->host_lock);
3421 return index;
3422}
3423
3424static struct bin_attribute sysfs_drvr_stat_data_attr = {
3425 .attr = {
3426 .name = "lpfc_drvr_stat_data",
3427 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003428 },
3429 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3430 .read = sysfs_drvr_stat_data_read,
3431 .write = NULL,
3432};
3433
dea31012005-04-17 16:05:31 -05003434/*
3435# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3436# connection.
James Smart76a95d72010-11-20 23:11:48 -05003437# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003438*/
James Smarte59058c2008-08-24 21:49:00 -04003439/**
James Smart3621a712009-04-06 18:47:14 -04003440 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003441 * @phba: lpfc_hba pointer.
3442 * @val: link speed value.
3443 *
3444 * Description:
3445 * If val is in a valid range then set the adapter's link speed field and
3446 * issue a lip; if the lip fails reset the link speed to the old value.
3447 *
3448 * Notes:
3449 * If the value is not in range log a kernel error message and return an error.
3450 *
3451 * Returns:
3452 * zero if val is in range and lip okay.
3453 * non-zero return value from lpfc_issue_lip()
3454 * -EINVAL val out of range
3455 **/
James Smarta257bf92009-04-06 18:48:10 -04003456static ssize_t
3457lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3458 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003459{
James Smarta257bf92009-04-06 18:48:10 -04003460 struct Scsi_Host *shost = class_to_shost(dev);
3461 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3462 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003463 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003464 int nolip = 0;
3465 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003466 int err;
James Smartc6918162016-10-13 15:06:16 -07003467 uint32_t prev_val, if_type;
3468
3469 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3470 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
3471 phba->hba_flag & HBA_FORCED_LINK_SPEED)
3472 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05003473
James Smarta257bf92009-04-06 18:48:10 -04003474 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3475 nolip = 1;
3476 val_buf = &buf[strlen("nolip ")];
3477 }
3478
3479 if (!isdigit(val_buf[0]))
3480 return -EINVAL;
3481 if (sscanf(val_buf, "%i", &val) != 1)
3482 return -EINVAL;
3483
James Smart88a2cfb2011-07-22 18:36:33 -04003484 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3485 "3055 lpfc_link_speed changed from %d to %d %s\n",
3486 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3487
James Smart76a95d72010-11-20 23:11:48 -05003488 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3489 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3490 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3491 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3492 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04003493 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3494 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05003495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3496 "2879 lpfc_link_speed attribute cannot be set "
3497 "to %d. Speed is not supported by this port.\n",
3498 val);
James Smart83108bd2008-01-11 01:53:09 -05003499 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003500 }
James Smartff78d8f2011-12-13 13:21:35 -05003501 if (val == LPFC_USER_LINK_SPEED_16G &&
3502 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3503 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3504 "3112 lpfc_link_speed attribute cannot be set "
3505 "to %d. Speed is not supported in loop mode.\n",
3506 val);
3507 return -EINVAL;
3508 }
James Smart76a95d72010-11-20 23:11:48 -05003509 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3510 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003511 prev_val = phba->cfg_link_speed;
3512 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003513 if (nolip)
3514 return strlen(buf);
3515
James Smart83108bd2008-01-11 01:53:09 -05003516 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003517 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003518 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003519 return -EINVAL;
3520 } else
3521 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003522 }
James Smart83108bd2008-01-11 01:53:09 -05003523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003524 "0469 lpfc_link_speed attribute cannot be set to %d, "
3525 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003526 return -EINVAL;
3527}
3528
3529static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003530module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003531MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3532lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003533
3534/**
James Smart3621a712009-04-06 18:47:14 -04003535 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003536 * @phba: lpfc_hba pointer.
3537 * @val: link speed value.
3538 *
3539 * Description:
3540 * If val is in a valid range then set the adapter's link speed field.
3541 *
3542 * Notes:
3543 * If the value is not in range log a kernel error message, clear the link
3544 * speed and return an error.
3545 *
3546 * Returns:
3547 * zero if val saved.
3548 * -EINVAL val out of range
3549 **/
James Smart83108bd2008-01-11 01:53:09 -05003550static int
3551lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3552{
James Smartff78d8f2011-12-13 13:21:35 -05003553 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3554 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3555 "3111 lpfc_link_speed of %d cannot "
3556 "support loop mode, setting topology to default.\n",
3557 val);
3558 phba->cfg_topology = 0;
3559 }
James Smart76a95d72010-11-20 23:11:48 -05003560 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3561 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003562 phba->cfg_link_speed = val;
3563 return 0;
3564 }
3565 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003566 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003567 "be set to %d, allowed values are "
3568 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003569 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003570 return -EINVAL;
3571}
3572
Tony Jonesee959b02008-02-22 00:13:36 +01003573static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003574 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003575
3576/*
James Smart0d878412009-10-02 15:16:56 -04003577# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3578# 0 = aer disabled or not supported
3579# 1 = aer supported and enabled (default)
3580# Value range is [0,1]. Default value is 1.
3581*/
James Smart506139a2016-10-13 15:06:09 -07003582LPFC_ATTR(aer_support, 1, 0, 1,
3583 "Enable PCIe device AER support");
3584lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04003585
3586/**
3587 * lpfc_aer_support_store - Set the adapter for aer support
3588 *
3589 * @dev: class device that is converted into a Scsi_host.
3590 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003591 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003592 * @count: unused variable.
3593 *
3594 * Description:
3595 * If the val is 1 and currently the device's AER capability was not
3596 * enabled, invoke the kernel's enable AER helper routine, trying to
3597 * enable the device's AER capability. If the helper routine enabling
3598 * AER returns success, update the device's cfg_aer_support flag to
3599 * indicate AER is supported by the device; otherwise, if the device
3600 * AER capability is already enabled to support AER, then do nothing.
3601 *
3602 * If the val is 0 and currently the device's AER support was enabled,
3603 * invoke the kernel's disable AER helper routine. After that, update
3604 * the device's cfg_aer_support flag to indicate AER is not supported
3605 * by the device; otherwise, if the device AER capability is already
3606 * disabled from supporting AER, then do nothing.
3607 *
3608 * Returns:
3609 * length of the buf on success if val is in range the intended mode
3610 * is supported.
3611 * -EINVAL if val out of range or intended mode is not supported.
3612 **/
3613static ssize_t
3614lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3615 const char *buf, size_t count)
3616{
3617 struct Scsi_Host *shost = class_to_shost(dev);
3618 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3619 struct lpfc_hba *phba = vport->phba;
3620 int val = 0, rc = -EINVAL;
3621
3622 if (!isdigit(buf[0]))
3623 return -EINVAL;
3624 if (sscanf(buf, "%i", &val) != 1)
3625 return -EINVAL;
3626
3627 switch (val) {
3628 case 0:
3629 if (phba->hba_flag & HBA_AER_ENABLED) {
3630 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3631 if (!rc) {
3632 spin_lock_irq(&phba->hbalock);
3633 phba->hba_flag &= ~HBA_AER_ENABLED;
3634 spin_unlock_irq(&phba->hbalock);
3635 phba->cfg_aer_support = 0;
3636 rc = strlen(buf);
3637 } else
James Smart891478a2009-11-18 15:40:23 -05003638 rc = -EPERM;
3639 } else {
James Smart0d878412009-10-02 15:16:56 -04003640 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003641 rc = strlen(buf);
3642 }
James Smart0d878412009-10-02 15:16:56 -04003643 break;
3644 case 1:
3645 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3646 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3647 if (!rc) {
3648 spin_lock_irq(&phba->hbalock);
3649 phba->hba_flag |= HBA_AER_ENABLED;
3650 spin_unlock_irq(&phba->hbalock);
3651 phba->cfg_aer_support = 1;
3652 rc = strlen(buf);
3653 } else
James Smart891478a2009-11-18 15:40:23 -05003654 rc = -EPERM;
3655 } else {
James Smart0d878412009-10-02 15:16:56 -04003656 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003657 rc = strlen(buf);
3658 }
James Smart0d878412009-10-02 15:16:56 -04003659 break;
3660 default:
3661 rc = -EINVAL;
3662 break;
3663 }
3664 return rc;
3665}
3666
James Smart0d878412009-10-02 15:16:56 -04003667static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3668 lpfc_aer_support_show, lpfc_aer_support_store);
3669
3670/**
3671 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3672 * @dev: class device that is converted into a Scsi_host.
3673 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003674 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003675 * @count: unused variable.
3676 *
3677 * Description:
3678 * If the @buf contains 1 and the device currently has the AER support
3679 * enabled, then invokes the kernel AER helper routine
3680 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3681 * error status register.
3682 *
3683 * Notes:
3684 *
3685 * Returns:
3686 * -EINVAL if the buf does not contain the 1 or the device is not currently
3687 * enabled with the AER support.
3688 **/
3689static ssize_t
3690lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3691 const char *buf, size_t count)
3692{
3693 struct Scsi_Host *shost = class_to_shost(dev);
3694 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3695 struct lpfc_hba *phba = vport->phba;
3696 int val, rc = -1;
3697
3698 if (!isdigit(buf[0]))
3699 return -EINVAL;
3700 if (sscanf(buf, "%i", &val) != 1)
3701 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003702 if (val != 1)
3703 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003704
James Smart891478a2009-11-18 15:40:23 -05003705 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003706 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3707
3708 if (rc == 0)
3709 return strlen(buf);
3710 else
James Smart891478a2009-11-18 15:40:23 -05003711 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003712}
3713
3714static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3715 lpfc_aer_cleanup_state);
3716
James Smart912e3ac2011-05-24 11:42:11 -04003717/**
3718 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3719 *
3720 * @dev: class device that is converted into a Scsi_host.
3721 * @attr: device attribute, not used.
3722 * @buf: containing the string the number of vfs to be enabled.
3723 * @count: unused variable.
3724 *
3725 * Description:
3726 * When this api is called either through user sysfs, the driver shall
3727 * try to enable or disable SR-IOV virtual functions according to the
3728 * following:
3729 *
3730 * If zero virtual function has been enabled to the physical function,
3731 * the driver shall invoke the pci enable virtual function api trying
3732 * to enable the virtual functions. If the nr_vfn provided is greater
3733 * than the maximum supported, the maximum virtual function number will
3734 * be used for invoking the api; otherwise, the nr_vfn provided shall
3735 * be used for invoking the api. If the api call returned success, the
3736 * actual number of virtual functions enabled will be set to the driver
3737 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3738 * cfg_sriov_nr_virtfn remains zero.
3739 *
3740 * If none-zero virtual functions have already been enabled to the
3741 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3742 * -EINVAL will be returned and the driver does nothing;
3743 *
3744 * If the nr_vfn provided is zero and none-zero virtual functions have
3745 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3746 * disabling virtual function api shall be invoded to disable all the
3747 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3748 * zero. Otherwise, if zero virtual function has been enabled, do
3749 * nothing.
3750 *
3751 * Returns:
3752 * length of the buf on success if val is in range the intended mode
3753 * is supported.
3754 * -EINVAL if val out of range or intended mode is not supported.
3755 **/
3756static ssize_t
3757lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3758 const char *buf, size_t count)
3759{
3760 struct Scsi_Host *shost = class_to_shost(dev);
3761 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3762 struct lpfc_hba *phba = vport->phba;
3763 struct pci_dev *pdev = phba->pcidev;
3764 int val = 0, rc = -EINVAL;
3765
3766 /* Sanity check on user data */
3767 if (!isdigit(buf[0]))
3768 return -EINVAL;
3769 if (sscanf(buf, "%i", &val) != 1)
3770 return -EINVAL;
3771 if (val < 0)
3772 return -EINVAL;
3773
3774 /* Request disabling virtual functions */
3775 if (val == 0) {
3776 if (phba->cfg_sriov_nr_virtfn > 0) {
3777 pci_disable_sriov(pdev);
3778 phba->cfg_sriov_nr_virtfn = 0;
3779 }
3780 return strlen(buf);
3781 }
3782
3783 /* Request enabling virtual functions */
3784 if (phba->cfg_sriov_nr_virtfn > 0) {
3785 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3786 "3018 There are %d virtual functions "
3787 "enabled on physical function.\n",
3788 phba->cfg_sriov_nr_virtfn);
3789 return -EEXIST;
3790 }
3791
3792 if (val <= LPFC_MAX_VFN_PER_PFN)
3793 phba->cfg_sriov_nr_virtfn = val;
3794 else {
3795 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3796 "3019 Enabling %d virtual functions is not "
3797 "allowed.\n", val);
3798 return -EINVAL;
3799 }
3800
3801 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3802 if (rc) {
3803 phba->cfg_sriov_nr_virtfn = 0;
3804 rc = -EPERM;
3805 } else
3806 rc = strlen(buf);
3807
3808 return rc;
3809}
3810
James Smart0cfbbf22016-10-13 15:06:12 -07003811LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
3812 "Enable PCIe device SR-IOV virtual fn");
3813
James Smart912e3ac2011-05-24 11:42:11 -04003814lpfc_param_show(sriov_nr_virtfn)
James Smart912e3ac2011-05-24 11:42:11 -04003815static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3816 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3817
James Smart173edbb2012-06-12 13:54:50 -04003818/**
James Smartc71ab862012-10-31 14:44:33 -04003819 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
3820 *
3821 * @dev: class device that is converted into a Scsi_host.
3822 * @attr: device attribute, not used.
3823 * @buf: containing the string the number of vfs to be enabled.
3824 * @count: unused variable.
3825 *
3826 * Description:
3827 *
3828 * Returns:
3829 * length of the buf on success if val is in range the intended mode
3830 * is supported.
3831 * -EINVAL if val out of range or intended mode is not supported.
3832 **/
3833static ssize_t
3834lpfc_request_firmware_upgrade_store(struct device *dev,
3835 struct device_attribute *attr,
3836 const char *buf, size_t count)
3837{
3838 struct Scsi_Host *shost = class_to_shost(dev);
3839 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3840 struct lpfc_hba *phba = vport->phba;
3841 int val = 0, rc = -EINVAL;
3842
3843 /* Sanity check on user data */
3844 if (!isdigit(buf[0]))
3845 return -EINVAL;
3846 if (sscanf(buf, "%i", &val) != 1)
3847 return -EINVAL;
3848 if (val != 1)
3849 return -EINVAL;
3850
3851 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
3852 if (rc)
3853 rc = -EPERM;
3854 else
3855 rc = strlen(buf);
3856 return rc;
3857}
3858
3859static int lpfc_req_fw_upgrade;
3860module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
3861MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
3862lpfc_param_show(request_firmware_upgrade)
3863
3864/**
3865 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
3866 * @phba: lpfc_hba pointer.
3867 * @val: 0 or 1.
3868 *
3869 * Description:
3870 * Set the initial Linux generic firmware upgrade enable or disable flag.
3871 *
3872 * Returns:
3873 * zero if val saved.
3874 * -EINVAL val out of range
3875 **/
3876static int
3877lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
3878{
3879 if (val >= 0 && val <= 1) {
3880 phba->cfg_request_firmware_upgrade = val;
3881 return 0;
3882 }
3883 return -EINVAL;
3884}
3885static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
3886 lpfc_request_firmware_upgrade_show,
3887 lpfc_request_firmware_upgrade_store);
3888
3889/**
James Smart173edbb2012-06-12 13:54:50 -04003890 * lpfc_fcp_imax_store
3891 *
3892 * @dev: class device that is converted into a Scsi_host.
3893 * @attr: device attribute, not used.
3894 * @buf: string with the number of fast-path FCP interrupts per second.
3895 * @count: unused variable.
3896 *
3897 * Description:
3898 * If val is in a valid range [636,651042], then set the adapter's
3899 * maximum number of fast-path FCP interrupts per second.
3900 *
3901 * Returns:
3902 * length of the buf on success if val is in range the intended mode
3903 * is supported.
3904 * -EINVAL if val out of range or intended mode is not supported.
3905 **/
3906static ssize_t
3907lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
3908 const char *buf, size_t count)
3909{
3910 struct Scsi_Host *shost = class_to_shost(dev);
3911 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3912 struct lpfc_hba *phba = vport->phba;
3913 int val = 0, i;
3914
James Smartbf8dae82012-08-03 12:36:24 -04003915 /* fcp_imax is only valid for SLI4 */
3916 if (phba->sli_rev != LPFC_SLI_REV4)
3917 return -EINVAL;
3918
James Smart173edbb2012-06-12 13:54:50 -04003919 /* Sanity check on user data */
3920 if (!isdigit(buf[0]))
3921 return -EINVAL;
3922 if (sscanf(buf, "%i", &val) != 1)
3923 return -EINVAL;
3924
James Smartbf8dae82012-08-03 12:36:24 -04003925 /*
3926 * Value range for the HBA is [5000,5000000]
3927 * The value for each EQ depends on how many EQs are configured.
3928 */
3929 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04003930 return -EINVAL;
3931
3932 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04003933 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04003934 lpfc_modify_fcp_eq_delay(phba, i);
3935
3936 return strlen(buf);
3937}
3938
3939/*
3940# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04003941# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04003942#
James Smartbf8dae82012-08-03 12:36:24 -04003943# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04003944*/
James Smartbf8dae82012-08-03 12:36:24 -04003945static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003946module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
3947MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04003948 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04003949lpfc_param_show(fcp_imax)
3950
3951/**
3952 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
3953 * @phba: lpfc_hba pointer.
3954 * @val: link speed value.
3955 *
3956 * Description:
3957 * If val is in a valid range [636,651042], then initialize the adapter's
3958 * maximum number of fast-path FCP interrupts per second.
3959 *
3960 * Returns:
3961 * zero if val saved.
3962 * -EINVAL val out of range
3963 **/
3964static int
3965lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
3966{
James Smartbf8dae82012-08-03 12:36:24 -04003967 if (phba->sli_rev != LPFC_SLI_REV4) {
3968 phba->cfg_fcp_imax = 0;
3969 return 0;
3970 }
3971
3972 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04003973 phba->cfg_fcp_imax = val;
3974 return 0;
3975 }
3976
3977 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003978 "3016 lpfc_fcp_imax: %d out of range, using default\n",
3979 val);
James Smartbf8dae82012-08-03 12:36:24 -04003980 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003981
3982 return 0;
3983}
3984
3985static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
3986 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
3987
James Smart7bb03bb2013-04-17 20:19:16 -04003988/**
3989 * lpfc_state_show - Display current driver CPU affinity
3990 * @dev: class converted to a Scsi_host structure.
3991 * @attr: device attribute, not used.
3992 * @buf: on return contains text describing the state of the link.
3993 *
3994 * Returns: size of formatted string.
3995 **/
3996static ssize_t
3997lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
3998 char *buf)
3999{
4000 struct Scsi_Host *shost = class_to_shost(dev);
4001 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4002 struct lpfc_hba *phba = vport->phba;
4003 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004004 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004005
4006 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4007 (phba->intr_type != MSIX))
4008 return len;
4009
4010 switch (phba->cfg_fcp_cpu_map) {
4011 case 0:
4012 len += snprintf(buf + len, PAGE_SIZE-len,
4013 "fcp_cpu_map: No mapping (%d)\n",
4014 phba->cfg_fcp_cpu_map);
4015 return len;
4016 case 1:
4017 len += snprintf(buf + len, PAGE_SIZE-len,
4018 "fcp_cpu_map: HBA centric mapping (%d): "
4019 "%d online CPUs\n",
4020 phba->cfg_fcp_cpu_map,
4021 phba->sli4_hba.num_online_cpu);
4022 break;
4023 case 2:
4024 len += snprintf(buf + len, PAGE_SIZE-len,
4025 "fcp_cpu_map: Driver centric mapping (%d): "
4026 "%d online CPUs\n",
4027 phba->cfg_fcp_cpu_map,
4028 phba->sli4_hba.num_online_cpu);
4029 break;
4030 }
4031
James Smart76fd07a2014-02-20 09:57:18 -05004032 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4033 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4034
4035 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004036 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4037 len += snprintf(buf + len, PAGE_SIZE-len,
4038 "CPU %02d io_chan %02d "
4039 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004040 phba->sli4_hba.curr_disp_cpu,
4041 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004042 cpup->core_id);
4043 else
4044 len += snprintf(buf + len, PAGE_SIZE-len,
4045 "CPU %02d io_chan %02d "
4046 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004047 phba->sli4_hba.curr_disp_cpu,
4048 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004049 cpup->core_id, cpup->irq);
4050
James Smart76fd07a2014-02-20 09:57:18 -05004051 phba->sli4_hba.curr_disp_cpu++;
4052
4053 /* display max number of CPUs keeping some margin */
4054 if (phba->sli4_hba.curr_disp_cpu <
4055 phba->sli4_hba.num_present_cpu &&
4056 (len >= (PAGE_SIZE - 64))) {
4057 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4058 break;
4059 }
James Smart7bb03bb2013-04-17 20:19:16 -04004060 }
James Smart76fd07a2014-02-20 09:57:18 -05004061
4062 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4063 phba->sli4_hba.curr_disp_cpu = 0;
4064
James Smart7bb03bb2013-04-17 20:19:16 -04004065 return len;
4066}
4067
4068/**
4069 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4070 * @dev: class device that is converted into a Scsi_host.
4071 * @attr: device attribute, not used.
4072 * @buf: one or more lpfc_polling_flags values.
4073 * @count: not used.
4074 *
4075 * Returns:
4076 * -EINVAL - Not implemented yet.
4077 **/
4078static ssize_t
4079lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4080 const char *buf, size_t count)
4081{
4082 int status = -EINVAL;
4083 return status;
4084}
4085
4086/*
4087# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4088# for the HBA.
4089#
4090# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4091# 0 - Do not affinitze IRQ vectors
4092# 1 - Affintize HBA vectors with respect to each HBA
4093# (start with CPU0 for each HBA)
4094# 2 - Affintize HBA vectors with respect to the entire driver
4095# (round robin thru all CPUs across all HBAs)
4096*/
4097static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4098module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4099MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4100 "Defines how to map CPUs to IRQ vectors per HBA");
4101
4102/**
4103 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4104 * @phba: lpfc_hba pointer.
4105 * @val: link speed value.
4106 *
4107 * Description:
4108 * If val is in a valid range [0-2], then affinitze the adapter's
4109 * MSIX vectors.
4110 *
4111 * Returns:
4112 * zero if val saved.
4113 * -EINVAL val out of range
4114 **/
4115static int
4116lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4117{
4118 if (phba->sli_rev != LPFC_SLI_REV4) {
4119 phba->cfg_fcp_cpu_map = 0;
4120 return 0;
4121 }
4122
4123 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4124 phba->cfg_fcp_cpu_map = val;
4125 return 0;
4126 }
4127
4128 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004129 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4130 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004131 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4132
4133 return 0;
4134}
4135
4136static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4137 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4138
James Smart0d878412009-10-02 15:16:56 -04004139/*
dea31012005-04-17 16:05:31 -05004140# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4141# Value range is [2,3]. Default value is 3.
4142*/
James Smart3de2a652007-08-02 11:09:59 -04004143LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4144 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004145
4146/*
4147# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4148# is [0,1]. Default value is 0.
4149*/
James Smart3de2a652007-08-02 11:09:59 -04004150LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4151 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004152
4153/*
James Smart3cb01c52013-07-15 18:35:04 -04004154# lpfc_first_burst_size: First burst size to use on the NPorts
4155# that support first burst.
4156# Value range is [0,65536]. Default value is 0.
4157*/
4158LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4159 "First burst size for Targets that support first burst");
4160
4161/*
James Smart977b5a02008-09-07 11:52:04 -04004162# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4163# depth. Default value is 0. When the value of this parameter is zero the
4164# SCSI command completion time is not used for controlling I/O queue depth. When
4165# the parameter is set to a non-zero value, the I/O queue depth is controlled
4166# to limit the I/O completion time to the parameter value.
4167# The value is set in milliseconds.
4168*/
James Smarted5b1522016-10-13 15:06:11 -07004169LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004170 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004171
James Smart977b5a02008-09-07 11:52:04 -04004172lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004173static int
4174lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4175{
4176 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4177 struct lpfc_nodelist *ndlp, *next_ndlp;
4178
4179 if (val == vport->cfg_max_scsicmpl_time)
4180 return 0;
4181 if ((val < 0) || (val > 60000))
4182 return -EINVAL;
4183 vport->cfg_max_scsicmpl_time = val;
4184
4185 spin_lock_irq(shost->host_lock);
4186 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4187 if (!NLP_CHK_NODE_ACT(ndlp))
4188 continue;
4189 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4190 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004191 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004192 }
4193 spin_unlock_irq(shost->host_lock);
4194 return 0;
4195}
4196lpfc_vport_param_store(max_scsicmpl_time);
4197static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4198 lpfc_max_scsicmpl_time_show,
4199 lpfc_max_scsicmpl_time_store);
4200
4201/*
dea31012005-04-17 16:05:31 -05004202# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4203# range is [0,1]. Default value is 0.
4204*/
4205LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4206
4207/*
James Smart49aa1432012-08-03 12:36:42 -04004208# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4209# range is [0,1]. Default value is 0.
4210# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4211# For [1], FCP commands are issued to a Work Queue associated with the
4212# current CPU.
James Smartec2087a2013-09-06 12:20:36 -04004213# It would be set to 1 by the driver if it's able to set up cpu affinity
4214# for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4215# roundrobin scheduling of FCP I/Os through WQs will be used.
James Smart49aa1432012-08-03 12:36:42 -04004216*/
James Smartec2087a2013-09-06 12:20:36 -04004217LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
James Smart49aa1432012-08-03 12:36:42 -04004218 "issuing commands [0] - Round Robin, [1] - Current CPU");
4219
4220/*
James Smarta6571c62012-10-31 14:44:42 -04004221# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4222# range is [0,1]. Default value is 0.
4223# For [0], bus reset issues target reset to ALL devices
4224# For [1], bus reset issues target reset to non-FCP2 devices
4225*/
4226LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4227 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4228
4229
4230/*
dea31012005-04-17 16:05:31 -05004231# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4232# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004233# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004234# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4235# cr_delay is set to 0.
4236*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004237LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004238 "interrupt response is generated");
4239
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004240LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004241 "interrupt response is generated");
4242
4243/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004244# lpfc_multi_ring_support: Determines how many rings to spread available
4245# cmd/rsp IOCB entries across.
4246# Value range is [1,2]. Default value is 1.
4247*/
4248LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4249 "SLI rings to spread IOCB entries across");
4250
4251/*
James Smarta4bc3372006-12-02 13:34:16 -05004252# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4253# identifies what rctl value to configure the additional ring for.
4254# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4255*/
James Smart6a9c52c2009-10-02 15:16:51 -04004256LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004257 255, "Identifies RCTL for additional ring configuration");
4258
4259/*
4260# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4261# identifies what type value to configure the additional ring for.
4262# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4263*/
James Smart6a9c52c2009-10-02 15:16:51 -04004264LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004265 255, "Identifies TYPE for additional ring configuration");
4266
4267/*
James Smart4258e982015-12-16 18:11:58 -05004268# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4269# 0 = SmartSAN functionality disabled (default)
4270# 1 = SmartSAN functionality enabled
4271# This parameter will override the value of lpfc_fdmi_on module parameter.
4272# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004273*/
James Smart4258e982015-12-16 18:11:58 -05004274LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4275
4276/*
4277# lpfc_fdmi_on: Controls FDMI support.
4278# 0 No FDMI support (default)
4279# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004280# Traditional FDMI support means the driver will assume FDMI-2 support;
4281# however, if that fails, it will fallback to FDMI-1.
4282# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4283# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4284# lpfc_fdmi_on.
4285# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004286*/
James Smart8663cbb2016-03-31 14:12:33 -07004287LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004288
4289/*
4290# Specifies the maximum number of ELS cmds we can have outstanding (for
4291# discovery). Value range is [1,64]. Default value = 32.
4292*/
James Smart3de2a652007-08-02 11:09:59 -04004293LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004294 "during discovery");
4295
4296/*
James Smartc4a7c922013-05-31 17:04:59 -04004297# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4298# will be scanned by the SCSI midlayer when sequential scanning is
4299# used; and is also the highest LUN ID allowed when the SCSI midlayer
4300# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4301# LUN ID limit, but the SCSI midlayer requires this field for the uses
4302# above. The lpfc driver limits the default value to 255 for two reasons.
4303# As it bounds the sequential scan loop, scanning for thousands of luns
4304# on a target can take minutes of wall clock time. Additionally,
4305# there are FC targets, such as JBODs, that only recognize 8-bits of
4306# LUN ID. When they receive a value greater than 8 bits, they chop off
4307# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4308# and so on all as LUN ID 0. This causes the linux kernel, which sees
4309# valid responses at each of the LUN IDs, to believe there are multiple
4310# devices present, when in fact, there is only 1.
4311# A customer that is aware of their target behaviors, and the results as
4312# indicated above, is welcome to increase the lpfc_max_luns value.
4313# As mentioned, this value is not used by the lpfc driver, only the
4314# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004315# Value range is [0,65535]. Default value is 255.
4316# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004317*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004318LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004319
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004320/*
4321# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4322# Value range is [1,255], default value is 10.
4323*/
4324LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4325 "Milliseconds driver will wait between polling FCP ring");
4326
James Smart4ff43242006-12-02 13:34:56 -05004327/*
James Smart0c411222013-09-06 12:22:46 -04004328# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4329# to complete in seconds. Value range is [5,180], default value is 60.
4330*/
4331LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4332 "Maximum time to wait for task management commands to complete");
4333/*
James Smart4ff43242006-12-02 13:34:56 -05004334# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4335# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004336# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004337# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004338# 2 = MSI-X enabled (default)
4339# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004340*/
George Kadianakis8605c462010-01-17 21:19:31 +02004341LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004342 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004343
James Smart13815c82008-01-11 01:52:48 -05004344/*
James Smart67d12732012-08-03 12:36:13 -04004345# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4346#
4347# Value range is [1,7]. Default value is 4.
4348*/
4349LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4350 LPFC_FCP_IO_CHAN_MAX,
4351 "Set the number of FCP I/O channels");
4352
4353/*
James Smart13815c82008-01-11 01:52:48 -05004354# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4355# 0 = HBA resets disabled
4356# 1 = HBA resets enabled (default)
4357# Value range is [0,1]. Default value is 1.
4358*/
4359LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004360
James Smart13815c82008-01-11 01:52:48 -05004361/*
James Smarteb7a3392010-11-20 23:12:02 -05004362# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004363# 0 = HBA Heartbeat disabled
4364# 1 = HBA Heartbeat enabled (default)
4365# Value range is [0,1]. Default value is 1.
4366*/
James Smarteb7a3392010-11-20 23:12:02 -05004367LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004368
James Smart83108bd2008-01-11 01:53:09 -05004369/*
James Smart1ba981f2014-02-20 09:56:45 -05004370# lpfc_EnableXLane: Enable Express Lane Feature
4371# 0x0 Express Lane Feature disabled
4372# 0x1 Express Lane Feature enabled
4373# Value range is [0,1]. Default value is 0.
4374*/
4375LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4376
4377/*
4378# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4379# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4380# Value range is [0x0,0x7f]. Default value is 0
4381*/
James Smart28d7f3d2014-05-21 08:05:28 -04004382LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004383
4384/*
James Smart81301a92008-12-04 22:39:46 -05004385# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4386# 0 = BlockGuard disabled (default)
4387# 1 = BlockGuard enabled
4388# Value range is [0,1]. Default value is 0.
4389*/
4390LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4391
James Smart6fb120a2009-05-22 14:52:59 -04004392/*
James Smartba20c852012-08-03 12:36:52 -04004393# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4394# 0 = disabled (default)
4395# 1 = enabled
4396# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004397#
4398# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004399*/
4400unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4401
James Smartba20c852012-08-03 12:36:52 -04004402/*
James Smart81301a92008-12-04 22:39:46 -05004403# lpfc_prot_mask: i
4404# - Bit mask of host protection capabilities used to register with the
4405# SCSI mid-layer
4406# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4407# - Allows you to ultimately specify which profiles to use
4408# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004409# - SHOST_DIF_TYPE1_PROTECTION 1
4410# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4411# - SHOST_DIX_TYPE0_PROTECTION 8
4412# HBA supports DIX Type 0: Host to HBA protection only
4413# - SHOST_DIX_TYPE1_PROTECTION 16
4414# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004415#
4416*/
James Smartb3b98b72016-10-13 15:06:06 -07004417LPFC_ATTR(prot_mask,
4418 (SHOST_DIF_TYPE1_PROTECTION |
4419 SHOST_DIX_TYPE0_PROTECTION |
4420 SHOST_DIX_TYPE1_PROTECTION),
4421 0,
4422 (SHOST_DIF_TYPE1_PROTECTION |
4423 SHOST_DIX_TYPE0_PROTECTION |
4424 SHOST_DIX_TYPE1_PROTECTION),
4425 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05004426
4427/*
4428# lpfc_prot_guard: i
4429# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004430# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004431# - Allows you to ultimately specify which profiles to use
4432# - Default will result in registering capabilities for all guard types
4433#
4434*/
James Smartb3b98b72016-10-13 15:06:06 -07004435LPFC_ATTR(prot_guard,
4436 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
4437 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05004438
James Smart92494142011-02-16 12:39:44 -05004439/*
4440 * Delay initial NPort discovery when Clean Address bit is cleared in
4441 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4442 * This parameter can have value 0 or 1.
4443 * When this parameter is set to 0, no delay is added to the initial
4444 * discovery.
4445 * When this parameter is set to non-zero value, initial Nport discovery is
4446 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4447 * accept and FCID/Fabric name/Fabric portname is changed.
4448 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4449 * when Clean Address bit is cleared in FLOGI/FDISC
4450 * accept and FCID/Fabric name/Fabric portname is changed.
4451 * Default value is 0.
4452 */
James Smart8eb8b962016-07-06 12:36:08 -07004453LPFC_ATTR(delay_discovery, 0, 0, 1,
4454 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05004455
4456/*
James Smart3621a712009-04-06 18:47:14 -04004457 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004458 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004459 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4460 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004461 * Because of the additional overhead involved in setting up T10-DIF,
4462 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4463 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004464 */
4465LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4466 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4467
James Smart96f70772013-04-17 20:16:15 -04004468/*
4469 * This parameter will be depricated, the driver cannot limit the
4470 * protection data s/g list.
4471 */
4472LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4473 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4474 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004475
James Smart7bdedb32016-07-06 12:36:00 -07004476/*
4477 * lpfc_enable_mds_diags: Enable MDS Diagnostics
4478 * 0 = MDS Diagnostics disabled (default)
4479 * 1 = MDS Diagnostics enabled
4480 * Value range is [0,1]. Default value is 0.
4481 */
4482LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
4483
Tony Jonesee959b02008-02-22 00:13:36 +01004484struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004485 &dev_attr_bg_info,
4486 &dev_attr_bg_guard_err,
4487 &dev_attr_bg_apptag_err,
4488 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004489 &dev_attr_info,
4490 &dev_attr_serialnum,
4491 &dev_attr_modeldesc,
4492 &dev_attr_modelname,
4493 &dev_attr_programtype,
4494 &dev_attr_portnum,
4495 &dev_attr_fwrev,
4496 &dev_attr_hdw,
4497 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004498 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004499 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004500 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004501 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004502 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004503 &dev_attr_lpfc_temp_sensor,
4504 &dev_attr_lpfc_log_verbose,
4505 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004506 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004507 &dev_attr_lpfc_hba_queue_depth,
4508 &dev_attr_lpfc_peer_port_login,
4509 &dev_attr_lpfc_nodev_tmo,
4510 &dev_attr_lpfc_devloss_tmo,
4511 &dev_attr_lpfc_fcp_class,
4512 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004513 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004514 &dev_attr_lpfc_ack0,
4515 &dev_attr_lpfc_topology,
4516 &dev_attr_lpfc_scan_down,
4517 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004518 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004519 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004520 &dev_attr_lpfc_cr_delay,
4521 &dev_attr_lpfc_cr_count,
4522 &dev_attr_lpfc_multi_ring_support,
4523 &dev_attr_lpfc_multi_ring_rctl,
4524 &dev_attr_lpfc_multi_ring_type,
4525 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05004526 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01004527 &dev_attr_lpfc_max_luns,
4528 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004529 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004530 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004531 &dev_attr_nport_evt_cnt,
4532 &dev_attr_board_mode,
4533 &dev_attr_max_vpi,
4534 &dev_attr_used_vpi,
4535 &dev_attr_max_rpi,
4536 &dev_attr_used_rpi,
4537 &dev_attr_max_xri,
4538 &dev_attr_used_xri,
4539 &dev_attr_npiv_info,
4540 &dev_attr_issue_reset,
4541 &dev_attr_lpfc_poll,
4542 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04004543 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01004544 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004545 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004546 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04004547 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004548 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004549 &dev_attr_lpfc_enable_hba_reset,
4550 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05004551 &dev_attr_lpfc_EnableXLane,
4552 &dev_attr_lpfc_XLanePriority,
4553 &dev_attr_lpfc_xlane_lun,
4554 &dev_attr_lpfc_xlane_tgt,
4555 &dev_attr_lpfc_xlane_vpt,
4556 &dev_attr_lpfc_xlane_lun_state,
4557 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07004558 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01004559 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004560 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004561 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004562 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004563 &dev_attr_lpfc_aer_support,
4564 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004565 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004566 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004567 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004568 &dev_attr_lpfc_iocb_cnt,
4569 &dev_attr_iocb_hw,
4570 &dev_attr_txq_hw,
4571 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004572 &dev_attr_lpfc_fips_level,
4573 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004574 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004575 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004576 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05004577 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07004578 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05004579 NULL,
4580};
4581
Tony Jonesee959b02008-02-22 00:13:36 +01004582struct device_attribute *lpfc_vport_attrs[] = {
4583 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004584 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004585 &dev_attr_num_discovered_ports,
4586 &dev_attr_lpfc_drvr_version,
4587 &dev_attr_lpfc_log_verbose,
4588 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004589 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004590 &dev_attr_lpfc_nodev_tmo,
4591 &dev_attr_lpfc_devloss_tmo,
4592 &dev_attr_lpfc_hba_queue_depth,
4593 &dev_attr_lpfc_peer_port_login,
4594 &dev_attr_lpfc_restrict_login,
4595 &dev_attr_lpfc_fcp_class,
4596 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004597 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004598 &dev_attr_lpfc_max_luns,
4599 &dev_attr_nport_evt_cnt,
4600 &dev_attr_npiv_info,
4601 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004602 &dev_attr_lpfc_max_scsicmpl_time,
4603 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004604 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004605 &dev_attr_lpfc_fips_level,
4606 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004607 NULL,
4608};
4609
James Smarte59058c2008-08-24 21:49:00 -04004610/**
James Smart3621a712009-04-06 18:47:14 -04004611 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004612 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004613 * @kobj: kernel kobject that contains the kernel class device.
4614 * @bin_attr: kernel attributes passed to us.
4615 * @buf: contains the data to be written to the adapter IOREG space.
4616 * @off: offset into buffer to beginning of data.
4617 * @count: bytes to transfer.
4618 *
4619 * Description:
4620 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4621 * Uses the adapter io control registers to send buf contents to the adapter.
4622 *
4623 * Returns:
4624 * -ERANGE off and count combo out of range
4625 * -EINVAL off, count or buff address invalid
4626 * -EPERM adapter is offline
4627 * value of count, buf contents written
4628 **/
dea31012005-04-17 16:05:31 -05004629static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004630sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4631 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004632 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004633{
4634 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004635 struct device *dev = container_of(kobj, struct device, kobj);
4636 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4638 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004639
James Smartf1126682009-06-10 17:22:44 -04004640 if (phba->sli_rev >= LPFC_SLI_REV4)
4641 return -EPERM;
4642
dea31012005-04-17 16:05:31 -05004643 if ((off + count) > FF_REG_AREA_SIZE)
4644 return -ERANGE;
4645
James Smartf7a919b2011-08-21 21:49:16 -04004646 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4647 return 0;
dea31012005-04-17 16:05:31 -05004648
4649 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4650 return -EINVAL;
4651
James Smartf7a919b2011-08-21 21:49:16 -04004652 /* This is to protect HBA registers from accidental writes. */
4653 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4654 return -EINVAL;
4655
4656 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004657 return -EPERM;
dea31012005-04-17 16:05:31 -05004658
James Smart2e0fef82007-06-17 19:56:36 -05004659 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004660 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4661 buf_off += sizeof(uint32_t))
4662 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004663 phba->ctrl_regs_memmap_p + off + buf_off);
4664
James Smart2e0fef82007-06-17 19:56:36 -05004665 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004666
4667 return count;
4668}
4669
James Smarte59058c2008-08-24 21:49:00 -04004670/**
James Smart3621a712009-04-06 18:47:14 -04004671 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004672 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004673 * @kobj: kernel kobject that contains the kernel class device.
4674 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004675 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004676 * @off: offset into buffer to beginning of data.
4677 * @count: bytes to transfer.
4678 *
4679 * Description:
4680 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4681 * Uses the adapter io control registers to read data into buf.
4682 *
4683 * Returns:
4684 * -ERANGE off and count combo out of range
4685 * -EINVAL off, count or buff address invalid
4686 * value of count, buf contents read
4687 **/
dea31012005-04-17 16:05:31 -05004688static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004689sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4690 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004691 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004692{
4693 size_t buf_off;
4694 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004695 struct device *dev = container_of(kobj, struct device, kobj);
4696 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004697 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4698 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004699
James Smartf1126682009-06-10 17:22:44 -04004700 if (phba->sli_rev >= LPFC_SLI_REV4)
4701 return -EPERM;
4702
dea31012005-04-17 16:05:31 -05004703 if (off > FF_REG_AREA_SIZE)
4704 return -ERANGE;
4705
4706 if ((off + count) > FF_REG_AREA_SIZE)
4707 count = FF_REG_AREA_SIZE - off;
4708
4709 if (count == 0) return 0;
4710
4711 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4712 return -EINVAL;
4713
James Smart2e0fef82007-06-17 19:56:36 -05004714 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004715
4716 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4717 tmp_ptr = (uint32_t *)(buf + buf_off);
4718 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4719 }
4720
James Smart2e0fef82007-06-17 19:56:36 -05004721 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004722
4723 return count;
4724}
4725
4726static struct bin_attribute sysfs_ctlreg_attr = {
4727 .attr = {
4728 .name = "ctlreg",
4729 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004730 },
4731 .size = 256,
4732 .read = sysfs_ctlreg_read,
4733 .write = sysfs_ctlreg_write,
4734};
4735
James Smarte59058c2008-08-24 21:49:00 -04004736/**
James Smart3621a712009-04-06 18:47:14 -04004737 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004738 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004739 * @kobj: kernel kobject that contains the kernel class device.
4740 * @bin_attr: kernel attributes passed to us.
4741 * @buf: contains the data to be written to sysfs mbox.
4742 * @off: offset into buffer to beginning of data.
4743 * @count: bytes to transfer.
4744 *
4745 * Description:
James Smart026abb82011-12-13 13:20:45 -05004746 * Deprecated function. All mailbox access from user space is performed via the
4747 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004748 *
4749 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004750 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004751 **/
dea31012005-04-17 16:05:31 -05004752static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004753sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4754 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004755 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004756{
James Smart026abb82011-12-13 13:20:45 -05004757 return -EPERM;
dea31012005-04-17 16:05:31 -05004758}
4759
James Smarte59058c2008-08-24 21:49:00 -04004760/**
James Smart3621a712009-04-06 18:47:14 -04004761 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004762 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004763 * @kobj: kernel kobject that contains the kernel class device.
4764 * @bin_attr: kernel attributes passed to us.
4765 * @buf: contains the data to be read from sysfs mbox.
4766 * @off: offset into buffer to beginning of data.
4767 * @count: bytes to transfer.
4768 *
4769 * Description:
James Smart026abb82011-12-13 13:20:45 -05004770 * Deprecated function. All mailbox access from user space is performed via the
4771 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004772 *
4773 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004774 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004775 **/
dea31012005-04-17 16:05:31 -05004776static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004777sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4778 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004779 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004780{
James Smart026abb82011-12-13 13:20:45 -05004781 return -EPERM;
dea31012005-04-17 16:05:31 -05004782}
4783
4784static struct bin_attribute sysfs_mbox_attr = {
4785 .attr = {
4786 .name = "mbox",
4787 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004788 },
James Smartc0c11512011-05-24 11:41:34 -04004789 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004790 .read = sysfs_mbox_read,
4791 .write = sysfs_mbox_write,
4792};
4793
James Smarte59058c2008-08-24 21:49:00 -04004794/**
James Smart3621a712009-04-06 18:47:14 -04004795 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004796 * @vport: address of lpfc vport structure.
4797 *
4798 * Return codes:
4799 * zero on success
4800 * error return code from sysfs_create_bin_file()
4801 **/
dea31012005-04-17 16:05:31 -05004802int
James Smart2e0fef82007-06-17 19:56:36 -05004803lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004804{
James Smart2e0fef82007-06-17 19:56:36 -05004805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004806 int error;
4807
Tony Jonesee959b02008-02-22 00:13:36 +01004808 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004809 &sysfs_drvr_stat_data_attr);
4810
4811 /* Virtual ports do not need ctrl_reg and mbox */
4812 if (error || vport->port_type == LPFC_NPIV_PORT)
4813 goto out;
4814
4815 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004816 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004817 if (error)
James Smarteada2722008-12-04 22:39:13 -05004818 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004819
Tony Jonesee959b02008-02-22 00:13:36 +01004820 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004821 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004822 if (error)
4823 goto out_remove_ctlreg_attr;
4824
4825 return 0;
4826out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004827 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004828out_remove_stat_attr:
4829 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4830 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004831out:
4832 return error;
4833}
4834
James Smarte59058c2008-08-24 21:49:00 -04004835/**
James Smart3621a712009-04-06 18:47:14 -04004836 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004837 * @vport: address of lpfc vport structure.
4838 **/
dea31012005-04-17 16:05:31 -05004839void
James Smart2e0fef82007-06-17 19:56:36 -05004840lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004841{
James Smart2e0fef82007-06-17 19:56:36 -05004842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004843 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4844 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004845 /* Virtual ports do not need ctrl_reg and mbox */
4846 if (vport->port_type == LPFC_NPIV_PORT)
4847 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004848 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4849 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004850}
4851
dea31012005-04-17 16:05:31 -05004852/*
4853 * Dynamic FC Host Attributes Support
4854 */
4855
James Smarte59058c2008-08-24 21:49:00 -04004856/**
James Smart6c9231f2016-12-19 15:07:24 -08004857 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
4858 * @shost: kernel scsi host pointer.
4859 **/
4860static void
4861lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
4862{
4863 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4864
4865 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4866 sizeof fc_host_symbolic_name(shost));
4867}
4868
4869/**
James Smart3621a712009-04-06 18:47:14 -04004870 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004871 * @shost: kernel scsi host pointer.
4872 **/
dea31012005-04-17 16:05:31 -05004873static void
4874lpfc_get_host_port_id(struct Scsi_Host *shost)
4875{
James Smart2e0fef82007-06-17 19:56:36 -05004876 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4877
dea31012005-04-17 16:05:31 -05004878 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004879 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004880}
4881
James Smarte59058c2008-08-24 21:49:00 -04004882/**
James Smart3621a712009-04-06 18:47:14 -04004883 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004884 * @shost: kernel scsi host pointer.
4885 **/
dea31012005-04-17 16:05:31 -05004886static void
4887lpfc_get_host_port_type(struct Scsi_Host *shost)
4888{
James Smart2e0fef82007-06-17 19:56:36 -05004889 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4890 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004891
4892 spin_lock_irq(shost->host_lock);
4893
James Smart92d7f7b2007-06-17 19:56:38 -05004894 if (vport->port_type == LPFC_NPIV_PORT) {
4895 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4896 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004897 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004898 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004899 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4900 else
4901 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4902 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004903 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004904 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4905 else
4906 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4907 }
4908 } else
4909 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4910
4911 spin_unlock_irq(shost->host_lock);
4912}
4913
James Smarte59058c2008-08-24 21:49:00 -04004914/**
James Smart3621a712009-04-06 18:47:14 -04004915 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004916 * @shost: kernel scsi host pointer.
4917 **/
dea31012005-04-17 16:05:31 -05004918static void
4919lpfc_get_host_port_state(struct Scsi_Host *shost)
4920{
James Smart2e0fef82007-06-17 19:56:36 -05004921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4922 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004923
4924 spin_lock_irq(shost->host_lock);
4925
James Smart2e0fef82007-06-17 19:56:36 -05004926 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004927 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4928 else {
James Smart2e0fef82007-06-17 19:56:36 -05004929 switch (phba->link_state) {
4930 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004931 case LPFC_LINK_DOWN:
4932 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4933 break;
4934 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004935 case LPFC_CLEAR_LA:
4936 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05004937 /* Links up, reports port state accordingly */
4938 if (vport->port_state < LPFC_VPORT_READY)
4939 fc_host_port_state(shost) =
4940 FC_PORTSTATE_BYPASSED;
4941 else
4942 fc_host_port_state(shost) =
4943 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05004944 break;
4945 case LPFC_HBA_ERROR:
4946 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4947 break;
4948 default:
4949 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4950 break;
4951 }
4952 }
4953
4954 spin_unlock_irq(shost->host_lock);
4955}
4956
James Smarte59058c2008-08-24 21:49:00 -04004957/**
James Smart3621a712009-04-06 18:47:14 -04004958 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004959 * @shost: kernel scsi host pointer.
4960 **/
dea31012005-04-17 16:05:31 -05004961static void
4962lpfc_get_host_speed(struct Scsi_Host *shost)
4963{
James Smart2e0fef82007-06-17 19:56:36 -05004964 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4965 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004966
4967 spin_lock_irq(shost->host_lock);
4968
James Smarta085e872015-12-16 18:12:02 -05004969 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05004970 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004971 case LPFC_LINK_SPEED_1GHZ:
4972 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004973 break;
James Smart76a95d72010-11-20 23:11:48 -05004974 case LPFC_LINK_SPEED_2GHZ:
4975 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004976 break;
James Smart76a95d72010-11-20 23:11:48 -05004977 case LPFC_LINK_SPEED_4GHZ:
4978 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004979 break;
James Smart76a95d72010-11-20 23:11:48 -05004980 case LPFC_LINK_SPEED_8GHZ:
4981 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004982 break;
James Smart76a95d72010-11-20 23:11:48 -05004983 case LPFC_LINK_SPEED_10GHZ:
4984 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004985 break;
James Smart76a95d72010-11-20 23:11:48 -05004986 case LPFC_LINK_SPEED_16GHZ:
4987 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4988 break;
James Smartd38dd522015-08-31 16:48:17 -04004989 case LPFC_LINK_SPEED_32GHZ:
4990 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
4991 break;
James Smart76a95d72010-11-20 23:11:48 -05004992 default:
4993 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004994 break;
4995 }
James Smart09372822008-01-11 01:52:54 -05004996 } else
4997 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004998
4999 spin_unlock_irq(shost->host_lock);
5000}
5001
James Smarte59058c2008-08-24 21:49:00 -04005002/**
James Smart3621a712009-04-06 18:47:14 -04005003 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005004 * @shost: kernel scsi host pointer.
5005 **/
dea31012005-04-17 16:05:31 -05005006static void
5007lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5008{
James Smart2e0fef82007-06-17 19:56:36 -05005009 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5010 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005011 u64 node_name;
dea31012005-04-17 16:05:31 -05005012
5013 spin_lock_irq(shost->host_lock);
5014
James Smart73d91e52011-10-10 21:32:10 -04005015 if ((vport->port_state > LPFC_FLOGI) &&
5016 ((vport->fc_flag & FC_FABRIC) ||
5017 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5018 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005019 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005020 else
5021 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005022 node_name = 0;
dea31012005-04-17 16:05:31 -05005023
5024 spin_unlock_irq(shost->host_lock);
5025
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005026 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005027}
5028
James Smarte59058c2008-08-24 21:49:00 -04005029/**
James Smart3621a712009-04-06 18:47:14 -04005030 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005031 * @shost: kernel scsi host pointer.
5032 *
5033 * Notes:
5034 * NULL on error for link down, no mbox pool, sli2 active,
5035 * management not allowed, memory allocation error, or mbox error.
5036 *
5037 * Returns:
5038 * NULL for error
5039 * address of the adapter host statistics
5040 **/
dea31012005-04-17 16:05:31 -05005041static struct fc_host_statistics *
5042lpfc_get_stats(struct Scsi_Host *shost)
5043{
James Smart2e0fef82007-06-17 19:56:36 -05005044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5045 struct lpfc_hba *phba = vport->phba;
5046 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005047 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005048 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005049 LPFC_MBOXQ_t *pmboxq;
5050 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005051 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005052 int rc = 0;
dea31012005-04-17 16:05:31 -05005053
James Smart92d7f7b2007-06-17 19:56:38 -05005054 /*
5055 * prevent udev from issuing mailbox commands until the port is
5056 * configured.
5057 */
James Smart2e0fef82007-06-17 19:56:36 -05005058 if (phba->link_state < LPFC_LINK_DOWN ||
5059 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005060 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005061 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005062
5063 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005064 return NULL;
5065
dea31012005-04-17 16:05:31 -05005066 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5067 if (!pmboxq)
5068 return NULL;
5069 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5070
James Smart04c68492009-05-22 14:52:52 -04005071 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005072 pmb->mbxCommand = MBX_READ_STATUS;
5073 pmb->mbxOwner = OWN_HOST;
5074 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005075 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005076
James Smart75baf692010-06-08 18:31:21 -04005077 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005078 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005079 else
dea31012005-04-17 16:05:31 -05005080 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5081
5082 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005083 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005084 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005085 return NULL;
5086 }
5087
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005088 memset(hs, 0, sizeof (struct fc_host_statistics));
5089
dea31012005-04-17 16:05:31 -05005090 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005091 /*
5092 * The MBX_READ_STATUS returns tx_k_bytes which has to
5093 * converted to words
5094 */
5095 hs->tx_words = (uint64_t)
5096 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5097 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005098 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005099 hs->rx_words = (uint64_t)
5100 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5101 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005102
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005103 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005104 pmb->mbxCommand = MBX_READ_LNK_STAT;
5105 pmb->mbxOwner = OWN_HOST;
5106 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005107 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005108
James Smart75baf692010-06-08 18:31:21 -04005109 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005110 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005111 else
dea31012005-04-17 16:05:31 -05005112 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5113
5114 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005115 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005116 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005117 return NULL;
5118 }
5119
5120 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5121 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5122 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5123 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5124 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5125 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5126 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5127
James Smart64ba8812006-08-02 15:24:34 -04005128 hs->link_failure_count -= lso->link_failure_count;
5129 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5130 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5131 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5132 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5133 hs->invalid_crc_count -= lso->invalid_crc_count;
5134 hs->error_frames -= lso->error_frames;
5135
James Smart76a95d72010-11-20 23:11:48 -05005136 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005137 hs->lip_count = -1;
5138 hs->nos_count = (phba->link_events >> 1);
5139 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005140 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005141 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005142 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005143 hs->nos_count = -1;
5144 } else {
5145 hs->lip_count = -1;
5146 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005147 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005148 }
5149
5150 hs->dumped_frames = -1;
5151
James Smart64ba8812006-08-02 15:24:34 -04005152 seconds = get_seconds();
5153 if (seconds < psli->stats_start)
5154 hs->seconds_since_last_reset = seconds +
5155 ((unsigned long)-1 - psli->stats_start);
5156 else
5157 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005158
James Smart1dcb58e2007-04-25 09:51:30 -04005159 mempool_free(pmboxq, phba->mbox_mem_pool);
5160
dea31012005-04-17 16:05:31 -05005161 return hs;
5162}
5163
James Smarte59058c2008-08-24 21:49:00 -04005164/**
James Smart3621a712009-04-06 18:47:14 -04005165 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005166 * @shost: kernel scsi host pointer.
5167 **/
James Smart64ba8812006-08-02 15:24:34 -04005168static void
5169lpfc_reset_stats(struct Scsi_Host *shost)
5170{
James Smart2e0fef82007-06-17 19:56:36 -05005171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5172 struct lpfc_hba *phba = vport->phba;
5173 struct lpfc_sli *psli = &phba->sli;
5174 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005175 LPFC_MBOXQ_t *pmboxq;
5176 MAILBOX_t *pmb;
5177 int rc = 0;
5178
James Smart2e0fef82007-06-17 19:56:36 -05005179 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005180 return;
5181
James Smart64ba8812006-08-02 15:24:34 -04005182 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5183 if (!pmboxq)
5184 return;
5185 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5186
James Smart04c68492009-05-22 14:52:52 -04005187 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005188 pmb->mbxCommand = MBX_READ_STATUS;
5189 pmb->mbxOwner = OWN_HOST;
5190 pmb->un.varWords[0] = 0x1; /* reset request */
5191 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005192 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005193
James Smart2e0fef82007-06-17 19:56:36 -05005194 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005195 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005196 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5197 else
5198 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5199
5200 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005201 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005202 mempool_free(pmboxq, phba->mbox_mem_pool);
5203 return;
5204 }
5205
5206 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5207 pmb->mbxCommand = MBX_READ_LNK_STAT;
5208 pmb->mbxOwner = OWN_HOST;
5209 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005210 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005211
James Smart2e0fef82007-06-17 19:56:36 -05005212 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005213 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005214 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5215 else
5216 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5217
5218 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005219 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005220 mempool_free( pmboxq, phba->mbox_mem_pool);
5221 return;
5222 }
5223
5224 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5225 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5226 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5227 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5228 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5229 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5230 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005231 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005232 lso->link_events = (phba->link_events >> 1);
5233 else
5234 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005235
5236 psli->stats_start = get_seconds();
5237
James Smart1dcb58e2007-04-25 09:51:30 -04005238 mempool_free(pmboxq, phba->mbox_mem_pool);
5239
James Smart64ba8812006-08-02 15:24:34 -04005240 return;
5241}
dea31012005-04-17 16:05:31 -05005242
5243/*
5244 * The LPFC driver treats linkdown handling as target loss events so there
5245 * are no sysfs handlers for link_down_tmo.
5246 */
James Smart685f0bf2007-04-25 09:53:08 -04005247
James Smarte59058c2008-08-24 21:49:00 -04005248/**
James Smart3621a712009-04-06 18:47:14 -04005249 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005250 * @starget: kernel scsi target pointer.
5251 *
5252 * Returns:
5253 * address of the node list if found
5254 * NULL target not found
5255 **/
James Smart685f0bf2007-04-25 09:53:08 -04005256static struct lpfc_nodelist *
5257lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005258{
James Smart2e0fef82007-06-17 19:56:36 -05005259 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5260 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005261 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005262
5263 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005264 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005265 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005266 if (NLP_CHK_NODE_ACT(ndlp) &&
5267 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005268 starget->id == ndlp->nlp_sid) {
5269 spin_unlock_irq(shost->host_lock);
5270 return ndlp;
dea31012005-04-17 16:05:31 -05005271 }
5272 }
5273 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005274 return NULL;
5275}
dea31012005-04-17 16:05:31 -05005276
James Smarte59058c2008-08-24 21:49:00 -04005277/**
James Smart3621a712009-04-06 18:47:14 -04005278 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005279 * @starget: kernel scsi target pointer.
5280 **/
James Smart685f0bf2007-04-25 09:53:08 -04005281static void
5282lpfc_get_starget_port_id(struct scsi_target *starget)
5283{
5284 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5285
5286 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005287}
5288
James Smarte59058c2008-08-24 21:49:00 -04005289/**
James Smart3621a712009-04-06 18:47:14 -04005290 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005291 * @starget: kernel scsi target pointer.
5292 *
5293 * Description: Set the target node name to the ndlp node name wwn or zero.
5294 **/
dea31012005-04-17 16:05:31 -05005295static void
5296lpfc_get_starget_node_name(struct scsi_target *starget)
5297{
James Smart685f0bf2007-04-25 09:53:08 -04005298 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005299
James Smart685f0bf2007-04-25 09:53:08 -04005300 fc_starget_node_name(starget) =
5301 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005302}
5303
James Smarte59058c2008-08-24 21:49:00 -04005304/**
James Smart3621a712009-04-06 18:47:14 -04005305 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005306 * @starget: kernel scsi target pointer.
5307 *
5308 * Description: set the target port name to the ndlp port name wwn or zero.
5309 **/
dea31012005-04-17 16:05:31 -05005310static void
5311lpfc_get_starget_port_name(struct scsi_target *starget)
5312{
James Smart685f0bf2007-04-25 09:53:08 -04005313 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005314
James Smart685f0bf2007-04-25 09:53:08 -04005315 fc_starget_port_name(starget) =
5316 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005317}
5318
James Smarte59058c2008-08-24 21:49:00 -04005319/**
James Smart3621a712009-04-06 18:47:14 -04005320 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005321 * @rport: fc rport address.
5322 * @timeout: new value for dev loss tmo.
5323 *
5324 * Description:
5325 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5326 * dev_loss_tmo to one.
5327 **/
dea31012005-04-17 16:05:31 -05005328static void
dea31012005-04-17 16:05:31 -05005329lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5330{
dea31012005-04-17 16:05:31 -05005331 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005332 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005333 else
James Smartc01f3202006-08-18 17:47:08 -04005334 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005335}
5336
James Smarte59058c2008-08-24 21:49:00 -04005337/**
James Smart3621a712009-04-06 18:47:14 -04005338 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005339 *
5340 * Description:
5341 * Macro that uses field to generate a function with the name lpfc_show_rport_
5342 *
5343 * lpfc_show_rport_##field: returns the bytes formatted in buf
5344 * @cdev: class converted to an fc_rport.
5345 * @buf: on return contains the target_field or zero.
5346 *
5347 * Returns: size of formatted string.
5348 **/
dea31012005-04-17 16:05:31 -05005349#define lpfc_rport_show_function(field, format_string, sz, cast) \
5350static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005351lpfc_show_rport_##field (struct device *dev, \
5352 struct device_attribute *attr, \
5353 char *buf) \
dea31012005-04-17 16:05:31 -05005354{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005355 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005356 struct lpfc_rport_data *rdata = rport->hostdata; \
5357 return snprintf(buf, sz, format_string, \
5358 (rdata->target) ? cast rdata->target->field : 0); \
5359}
5360
5361#define lpfc_rport_rd_attr(field, format_string, sz) \
5362 lpfc_rport_show_function(field, format_string, sz, ) \
5363static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5364
James Smarteada2722008-12-04 22:39:13 -05005365/**
James Smart3621a712009-04-06 18:47:14 -04005366 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005367 * @fc_vport: The fc_vport who's symbolic name has been changed.
5368 *
5369 * Description:
5370 * This function is called by the transport after the @fc_vport's symbolic name
5371 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005372 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005373 **/
5374static void
5375lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5376{
5377 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5378
5379 if (vport->port_state == LPFC_VPORT_READY)
5380 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5381}
dea31012005-04-17 16:05:31 -05005382
James Smartf4b4c682009-05-22 14:53:12 -04005383/**
5384 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5385 * @phba: Pointer to lpfc_hba struct.
5386 *
5387 * This function is called by the lpfc_get_cfgparam() routine to set the
5388 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005389 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005390 * before hba port or vport created.
5391 **/
5392static void
5393lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5394{
5395 phba->cfg_log_verbose = verbose;
5396}
5397
dea31012005-04-17 16:05:31 -05005398struct fc_function_template lpfc_transport_functions = {
5399 /* fixed attributes the driver supports */
5400 .show_host_node_name = 1,
5401 .show_host_port_name = 1,
5402 .show_host_supported_classes = 1,
5403 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005404 .show_host_supported_speeds = 1,
5405 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08005406
5407 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05005408 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005409
5410 /* dynamic attributes the driver supports */
5411 .get_host_port_id = lpfc_get_host_port_id,
5412 .show_host_port_id = 1,
5413
5414 .get_host_port_type = lpfc_get_host_port_type,
5415 .show_host_port_type = 1,
5416
5417 .get_host_port_state = lpfc_get_host_port_state,
5418 .show_host_port_state = 1,
5419
5420 /* active_fc4s is shown but doesn't change (thus no get function) */
5421 .show_host_active_fc4s = 1,
5422
5423 .get_host_speed = lpfc_get_host_speed,
5424 .show_host_speed = 1,
5425
5426 .get_host_fabric_name = lpfc_get_host_fabric_name,
5427 .show_host_fabric_name = 1,
5428
5429 /*
5430 * The LPFC driver treats linkdown handling as target loss events
5431 * so there are no sysfs handlers for link_down_tmo.
5432 */
5433
5434 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005435 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005436
5437 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5438 .show_rport_maxframe_size = 1,
5439 .show_rport_supported_classes = 1,
5440
dea31012005-04-17 16:05:31 -05005441 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5442 .show_rport_dev_loss_tmo = 1,
5443
5444 .get_starget_port_id = lpfc_get_starget_port_id,
5445 .show_starget_port_id = 1,
5446
5447 .get_starget_node_name = lpfc_get_starget_node_name,
5448 .show_starget_node_name = 1,
5449
5450 .get_starget_port_name = lpfc_get_starget_port_name,
5451 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005452
5453 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005454 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5455 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005456
James Smart92d7f7b2007-06-17 19:56:38 -05005457 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005458
5459 .vport_disable = lpfc_vport_disable,
5460
5461 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005462
5463 .bsg_request = lpfc_bsg_request,
5464 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005465};
5466
James Smart98c9ea52007-10-27 13:37:33 -04005467struct fc_function_template lpfc_vport_transport_functions = {
5468 /* fixed attributes the driver supports */
5469 .show_host_node_name = 1,
5470 .show_host_port_name = 1,
5471 .show_host_supported_classes = 1,
5472 .show_host_supported_fc4s = 1,
5473 .show_host_supported_speeds = 1,
5474 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08005475
5476 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05005477 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005478
5479 /* dynamic attributes the driver supports */
5480 .get_host_port_id = lpfc_get_host_port_id,
5481 .show_host_port_id = 1,
5482
5483 .get_host_port_type = lpfc_get_host_port_type,
5484 .show_host_port_type = 1,
5485
5486 .get_host_port_state = lpfc_get_host_port_state,
5487 .show_host_port_state = 1,
5488
5489 /* active_fc4s is shown but doesn't change (thus no get function) */
5490 .show_host_active_fc4s = 1,
5491
5492 .get_host_speed = lpfc_get_host_speed,
5493 .show_host_speed = 1,
5494
5495 .get_host_fabric_name = lpfc_get_host_fabric_name,
5496 .show_host_fabric_name = 1,
5497
5498 /*
5499 * The LPFC driver treats linkdown handling as target loss events
5500 * so there are no sysfs handlers for link_down_tmo.
5501 */
5502
5503 .get_fc_host_stats = lpfc_get_stats,
5504 .reset_fc_host_stats = lpfc_reset_stats,
5505
5506 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5507 .show_rport_maxframe_size = 1,
5508 .show_rport_supported_classes = 1,
5509
5510 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5511 .show_rport_dev_loss_tmo = 1,
5512
5513 .get_starget_port_id = lpfc_get_starget_port_id,
5514 .show_starget_port_id = 1,
5515
5516 .get_starget_node_name = lpfc_get_starget_node_name,
5517 .show_starget_node_name = 1,
5518
5519 .get_starget_port_name = lpfc_get_starget_port_name,
5520 .show_starget_port_name = 1,
5521
5522 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5523 .terminate_rport_io = lpfc_terminate_rport_io,
5524
5525 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005526
5527 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005528};
5529
James Smarte59058c2008-08-24 21:49:00 -04005530/**
James Smart3621a712009-04-06 18:47:14 -04005531 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005532 * @phba: lpfc_hba pointer.
5533 **/
dea31012005-04-17 16:05:31 -05005534void
5535lpfc_get_cfgparam(struct lpfc_hba *phba)
5536{
James Smart49aa1432012-08-03 12:36:42 -04005537 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005538 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005539 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5540 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005541 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005542 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5543 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005544 lpfc_ack0_init(phba, lpfc_ack0);
5545 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005546 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005547 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04005548 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005549 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005550 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005551 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05005552 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
5553 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05005554 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005555 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005556 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart67d12732012-08-03 12:36:13 -04005557 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005558 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5559 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart1ba981f2014-02-20 09:56:45 -05005560 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5561 if (phba->sli_rev != LPFC_SLI_REV4)
5562 phba->cfg_EnableXLane = 0;
5563 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5564 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5565 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5566 phba->cfg_oas_lun_state = 0;
5567 phba->cfg_oas_lun_status = 0;
5568 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07005569 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05005570 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07005571 lpfc_prot_mask_init(phba, lpfc_prot_mask);
5572 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04005573 if (phba->sli_rev == LPFC_SLI_REV4)
5574 phba->cfg_poll = 0;
5575 else
James Smart1ba981f2014-02-20 09:56:45 -05005576 phba->cfg_poll = lpfc_poll;
James Smart4258e982015-12-16 18:11:58 -05005577
James Smart83108bd2008-01-11 01:53:09 -05005578 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005579 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005580 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005581 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005582 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005583 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005584 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005585 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005586 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07005587 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07005588 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05005589 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07005590 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04005591 return;
5592}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005593
James Smarte59058c2008-08-24 21:49:00 -04005594/**
James Smart3621a712009-04-06 18:47:14 -04005595 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005596 * @vport: lpfc_vport pointer.
5597 **/
James Smart3de2a652007-08-02 11:09:59 -04005598void
5599lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5600{
James Smarte8b62012007-08-02 11:10:09 -04005601 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005602 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005603 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005604 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5605 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5606 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5607 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5608 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5609 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04005610 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04005611 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005612 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5613 lpfc_max_luns_init(vport, lpfc_max_luns);
5614 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005615 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005616 return;
5617}