blob: a75404ae4fc189e7ec2a253eb13bdbdd3a38836c [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"
dea31012005-04-17 16:05:31 -050051
James Smartc01f3202006-08-18 17:47:08 -040052#define LPFC_DEF_DEVLOSS_TMO 30
53#define LPFC_MIN_DEVLOSS_TMO 1
54#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050055
James Smartf7a919b2011-08-21 21:49:16 -040056/*
57 * Write key size should be multiple of 4. If write key is changed
58 * make sure that library write key is also changed.
59 */
60#define LPFC_REG_WRITE_KEY_SIZE 4
61#define LPFC_REG_WRITE_KEY "EMLX"
62
James Smarte59058c2008-08-24 21:49:00 -040063/**
James Smart3621a712009-04-06 18:47:14 -040064 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040065 * @incr: integer to convert.
66 * @hdw: ascii string holding converted integer plus a string terminator.
67 *
68 * Description:
69 * JEDEC Joint Electron Device Engineering Council.
70 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71 * character string. The string is then terminated with a NULL in byte 9.
72 * Hex 0-9 becomes ascii '0' to '9'.
73 * Hex a-f becomes ascii '=' to 'B' capital B.
74 *
75 * Notes:
76 * Coded for 32 bit integers only.
77 **/
dea31012005-04-17 16:05:31 -050078static void
79lpfc_jedec_to_ascii(int incr, char hdw[])
80{
81 int i, j;
82 for (i = 0; i < 8; i++) {
83 j = (incr & 0xf);
84 if (j <= 9)
85 hdw[7 - i] = 0x30 + j;
86 else
87 hdw[7 - i] = 0x61 + j - 10;
88 incr = (incr >> 4);
89 }
90 hdw[8] = 0;
91 return;
92}
93
James Smarte59058c2008-08-24 21:49:00 -040094/**
James Smart3621a712009-04-06 18:47:14 -040095 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040096 * @dev: class unused variable.
97 * @attr: device attribute, not used.
98 * @buf: on return contains the module description text.
99 *
100 * Returns: size of formatted string.
101 **/
dea31012005-04-17 16:05:31 -0500102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100103lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
dea31012005-04-17 16:05:31 -0500105{
106 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
107}
108
James Smart45ed1192009-10-02 15:17:02 -0400109/**
110 * lpfc_enable_fip_show - Return the fip mode of the HBA
111 * @dev: class unused variable.
112 * @attr: device attribute, not used.
113 * @buf: on return contains the module description text.
114 *
115 * Returns: size of formatted string.
116 **/
117static ssize_t
118lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119 char *buf)
120{
121 struct Scsi_Host *shost = class_to_shost(dev);
122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
124
125 if (phba->hba_flag & HBA_FIP_SUPPORT)
126 return snprintf(buf, PAGE_SIZE, "1\n");
127 else
128 return snprintf(buf, PAGE_SIZE, "0\n");
129}
130
James Smart81301a92008-12-04 22:39:46 -0500131static ssize_t
132lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133 char *buf)
134{
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
138
139 if (phba->cfg_enable_bg)
140 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142 else
143 return snprintf(buf, PAGE_SIZE,
144 "BlockGuard Not Supported\n");
145 else
146 return snprintf(buf, PAGE_SIZE,
147 "BlockGuard Disabled\n");
148}
149
150static ssize_t
151lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152 char *buf)
153{
154 struct Scsi_Host *shost = class_to_shost(dev);
155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156 struct lpfc_hba *phba = vport->phba;
157
James Smart87b5c322008-12-16 10:34:09 -0500158 return snprintf(buf, PAGE_SIZE, "%llu\n",
159 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500160}
161
162static ssize_t
163lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164 char *buf)
165{
166 struct Scsi_Host *shost = class_to_shost(dev);
167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 struct lpfc_hba *phba = vport->phba;
169
James Smart87b5c322008-12-16 10:34:09 -0500170 return snprintf(buf, PAGE_SIZE, "%llu\n",
171 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500172}
173
174static ssize_t
175lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176 char *buf)
177{
178 struct Scsi_Host *shost = class_to_shost(dev);
179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 struct lpfc_hba *phba = vport->phba;
181
James Smart87b5c322008-12-16 10:34:09 -0500182 return snprintf(buf, PAGE_SIZE, "%llu\n",
183 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500184}
185
James Smarte59058c2008-08-24 21:49:00 -0400186/**
James Smart3621a712009-04-06 18:47:14 -0400187 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400188 * @dev: class converted to a Scsi_host structure.
189 * @attr: device attribute, not used.
190 * @buf: on return contains the formatted text from lpfc_info().
191 *
192 * Returns: size of formatted string.
193 **/
dea31012005-04-17 16:05:31 -0500194static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100195lpfc_info_show(struct device *dev, struct device_attribute *attr,
196 char *buf)
dea31012005-04-17 16:05:31 -0500197{
Tony Jonesee959b02008-02-22 00:13:36 +0100198 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500199
dea31012005-04-17 16:05:31 -0500200 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
201}
202
James Smarte59058c2008-08-24 21:49:00 -0400203/**
James Smart3621a712009-04-06 18:47:14 -0400204 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400205 * @dev: class converted to a Scsi_host structure.
206 * @attr: device attribute, not used.
207 * @buf: on return contains the formatted text serial number.
208 *
209 * Returns: size of formatted string.
210 **/
dea31012005-04-17 16:05:31 -0500211static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100212lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213 char *buf)
dea31012005-04-17 16:05:31 -0500214{
Tony Jonesee959b02008-02-22 00:13:36 +0100215 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217 struct lpfc_hba *phba = vport->phba;
218
dea31012005-04-17 16:05:31 -0500219 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
220}
221
James Smarte59058c2008-08-24 21:49:00 -0400222/**
James Smart3621a712009-04-06 18:47:14 -0400223 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400224 * @dev: class converted to a Scsi_host structure.
225 * @attr: device attribute, not used.
226 * @buf: on return contains the formatted support level.
227 *
228 * Description:
229 * Returns a number indicating the temperature sensor level currently
230 * supported, zero or one in ascii.
231 *
232 * Returns: size of formatted string.
233 **/
dea31012005-04-17 16:05:31 -0500234static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100235lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400237{
Tony Jonesee959b02008-02-22 00:13:36 +0100238 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 struct lpfc_hba *phba = vport->phba;
241 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
242}
243
James Smarte59058c2008-08-24 21:49:00 -0400244/**
James Smart3621a712009-04-06 18:47:14 -0400245 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400246 * @dev: class converted to a Scsi_host structure.
247 * @attr: device attribute, not used.
248 * @buf: on return contains the scsi vpd model description.
249 *
250 * Returns: size of formatted string.
251 **/
James Smart57127f12007-10-27 13:37:05 -0400252static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100253lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254 char *buf)
dea31012005-04-17 16:05:31 -0500255{
Tony Jonesee959b02008-02-22 00:13:36 +0100256 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258 struct lpfc_hba *phba = vport->phba;
259
dea31012005-04-17 16:05:31 -0500260 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
261}
262
James Smarte59058c2008-08-24 21:49:00 -0400263/**
James Smart3621a712009-04-06 18:47:14 -0400264 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400265 * @dev: class converted to a Scsi_host structure.
266 * @attr: device attribute, not used.
267 * @buf: on return contains the scsi vpd model name.
268 *
269 * Returns: size of formatted string.
270 **/
dea31012005-04-17 16:05:31 -0500271static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100272lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273 char *buf)
dea31012005-04-17 16:05:31 -0500274{
Tony Jonesee959b02008-02-22 00:13:36 +0100275 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277 struct lpfc_hba *phba = vport->phba;
278
dea31012005-04-17 16:05:31 -0500279 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
280}
281
James Smarte59058c2008-08-24 21:49:00 -0400282/**
James Smart3621a712009-04-06 18:47:14 -0400283 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400284 * @dev: class converted to a Scsi_host structure.
285 * @attr: device attribute, not used.
286 * @buf: on return contains the scsi vpd program type.
287 *
288 * Returns: size of formatted string.
289 **/
dea31012005-04-17 16:05:31 -0500290static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100291lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292 char *buf)
dea31012005-04-17 16:05:31 -0500293{
Tony Jonesee959b02008-02-22 00:13:36 +0100294 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500295 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296 struct lpfc_hba *phba = vport->phba;
297
dea31012005-04-17 16:05:31 -0500298 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
299}
300
James Smarte59058c2008-08-24 21:49:00 -0400301/**
James Smart3621a712009-04-06 18:47:14 -0400302 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400303 * @dev: class converted to a Scsi_host structure.
304 * @attr: device attribute, not used.
305 * @buf: on return contains the Menlo Maintenance sli flag.
306 *
307 * Returns: size of formatted string.
308 **/
309static ssize_t
310lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311{
312 struct Scsi_Host *shost = class_to_shost(dev);
313 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314 struct lpfc_hba *phba = vport->phba;
315
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
318}
319
320/**
James Smart3621a712009-04-06 18:47:14 -0400321 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400322 * @dev: class converted to a Scsi_host structure.
323 * @attr: device attribute, not used.
324 * @buf: on return contains scsi vpd program type.
325 *
326 * Returns: size of formatted string.
327 **/
dea31012005-04-17 16:05:31 -0500328static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100329lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330 char *buf)
dea31012005-04-17 16:05:31 -0500331{
Tony Jonesee959b02008-02-22 00:13:36 +0100332 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500333 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334 struct lpfc_hba *phba = vport->phba;
335
dea31012005-04-17 16:05:31 -0500336 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
337}
338
James Smarte59058c2008-08-24 21:49:00 -0400339/**
James Smart3621a712009-04-06 18:47:14 -0400340 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400341 * @dev: class converted to a Scsi_host structure.
342 * @attr: device attribute, not used.
343 * @buf: on return contains the scsi vpd program type.
344 *
345 * Returns: size of formatted string.
346 **/
dea31012005-04-17 16:05:31 -0500347static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100348lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349 char *buf)
dea31012005-04-17 16:05:31 -0500350{
Tony Jonesee959b02008-02-22 00:13:36 +0100351 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500354 uint32_t if_type;
355 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500356 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500357 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500358
dea31012005-04-17 16:05:31 -0500359 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500360 if_type = phba->sli4_hba.pc_sli4_params.if_type;
361 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
362
363 if (phba->sli_rev < LPFC_SLI_REV4)
364 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
365 fwrev, phba->sli_rev);
366 else
367 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
368 fwrev, phba->sli_rev, if_type, sli_family);
369
370 return len;
dea31012005-04-17 16:05:31 -0500371}
372
James Smarte59058c2008-08-24 21:49:00 -0400373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the scsi vpd program type.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500383{
384 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500388 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500389
dea31012005-04-17 16:05:31 -0500390 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
391 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
392}
James Smarte59058c2008-08-24 21:49:00 -0400393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains the ROM and FCode ascii strings.
399 *
400 * Returns: size of formatted string.
401 **/
dea31012005-04-17 16:05:31 -0500402static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100403lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
404 char *buf)
dea31012005-04-17 16:05:31 -0500405{
Tony Jonesee959b02008-02-22 00:13:36 +0100406 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400409 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500410
James Smarta0683bf2015-04-07 15:07:16 -0400411 if (phba->sli_rev < LPFC_SLI_REV4)
412 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
413
414 lpfc_decode_firmware_rev(phba, fwrev, 1);
415 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500416}
James Smarte59058c2008-08-24 21:49:00 -0400417
418/**
James Smart3621a712009-04-06 18:47:14 -0400419 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400420 * @dev: class converted to a Scsi_host structure.
421 * @attr: device attribute, not used.
422 * @buf: on return contains text describing the state of the link.
423 *
424 * Notes:
425 * The switch statement has no default so zero will be returned.
426 *
427 * Returns: size of formatted string.
428 **/
dea31012005-04-17 16:05:31 -0500429static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100430lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
431 char *buf)
dea31012005-04-17 16:05:31 -0500432{
Tony Jonesee959b02008-02-22 00:13:36 +0100433 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500434 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
435 struct lpfc_hba *phba = vport->phba;
436 int len = 0;
437
438 switch (phba->link_state) {
439 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500440 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500441 case LPFC_INIT_START:
442 case LPFC_INIT_MBX_CMDS:
443 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500444 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400445 if (phba->hba_flag & LINK_DISABLED)
446 len += snprintf(buf + len, PAGE_SIZE-len,
447 "Link Down - User disabled\n");
448 else
449 len += snprintf(buf + len, PAGE_SIZE-len,
450 "Link Down\n");
dea31012005-04-17 16:05:31 -0500451 break;
452 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500453 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500454 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400455 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500456
457 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500458 case LPFC_LOCAL_CFG_LINK:
459 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500460 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500461 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500462 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500463 case LPFC_FLOGI:
464 case LPFC_FABRIC_CFG_LINK:
465 case LPFC_NS_REG:
466 case LPFC_NS_QRY:
467 case LPFC_BUILD_DISC_LIST:
468 case LPFC_DISC_AUTH:
469 len += snprintf(buf + len, PAGE_SIZE - len,
470 "Discovery\n");
471 break;
472 case LPFC_VPORT_READY:
473 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
474 break;
475
James Smart92d7f7b2007-06-17 19:56:38 -0500476 case LPFC_VPORT_FAILED:
477 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
478 break;
479
480 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500481 len += snprintf(buf + len, PAGE_SIZE - len,
482 "Unknown\n");
483 break;
484 }
James Smart84774a42008-08-24 21:50:06 -0400485 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
486 len += snprintf(buf + len, PAGE_SIZE-len,
487 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500488 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500489 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500490 len += snprintf(buf + len, PAGE_SIZE-len,
491 " Public Loop\n");
492 else
493 len += snprintf(buf + len, PAGE_SIZE-len,
494 " Private Loop\n");
495 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500496 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500497 len += snprintf(buf + len, PAGE_SIZE-len,
498 " Fabric\n");
499 else
500 len += snprintf(buf + len, PAGE_SIZE-len,
501 " Point-2-Point\n");
502 }
503 }
James Smart2e0fef82007-06-17 19:56:36 -0500504
dea31012005-04-17 16:05:31 -0500505 return len;
506}
507
James Smarte59058c2008-08-24 21:49:00 -0400508/**
James Smart026abb82011-12-13 13:20:45 -0500509 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
510 * @dev: class unused variable.
511 * @attr: device attribute, not used.
512 * @buf: on return contains the module description text.
513 *
514 * Returns: size of formatted string.
515 **/
516static ssize_t
517lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
518 char *buf)
519{
520 struct Scsi_Host *shost = class_to_shost(dev);
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
522 struct lpfc_hba *phba = vport->phba;
523
524 if (phba->sli_rev < LPFC_SLI_REV4)
525 return snprintf(buf, PAGE_SIZE, "fc\n");
526
527 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
528 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
529 return snprintf(buf, PAGE_SIZE, "fcoe\n");
530 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
531 return snprintf(buf, PAGE_SIZE, "fc\n");
532 }
533 return snprintf(buf, PAGE_SIZE, "unknown\n");
534}
535
536/**
James Smart1ba981f2014-02-20 09:56:45 -0500537 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
538 * (OAS) is supported.
539 * @dev: class unused variable.
540 * @attr: device attribute, not used.
541 * @buf: on return contains the module description text.
542 *
543 * Returns: size of formatted string.
544 **/
545static ssize_t
546lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
547 char *buf)
548{
549 struct Scsi_Host *shost = class_to_shost(dev);
550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
551 struct lpfc_hba *phba = vport->phba;
552
553 return snprintf(buf, PAGE_SIZE, "%d\n",
554 phba->sli4_hba.pc_sli4_params.oas_supported);
555}
556
557/**
James Smart84d1b002010-02-12 14:42:33 -0500558 * lpfc_link_state_store - Transition the link_state on an HBA port
559 * @dev: class device that is converted into a Scsi_host.
560 * @attr: device attribute, not used.
561 * @buf: one or more lpfc_polling_flags values.
562 * @count: not used.
563 *
564 * Returns:
565 * -EINVAL if the buffer is not "up" or "down"
566 * return from link state change function if non-zero
567 * length of the buf on success
568 **/
569static ssize_t
570lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
571 const char *buf, size_t count)
572{
573 struct Scsi_Host *shost = class_to_shost(dev);
574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
575 struct lpfc_hba *phba = vport->phba;
576
577 int status = -EINVAL;
578
579 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
580 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400581 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500582 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
583 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400584 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500585
586 if (status == 0)
587 return strlen(buf);
588 else
589 return status;
590}
591
592/**
James Smart3621a712009-04-06 18:47:14 -0400593 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400594 * @dev: class device that is converted into a Scsi_host.
595 * @attr: device attribute, not used.
596 * @buf: on return contains the sum of fc mapped and unmapped.
597 *
598 * Description:
599 * Returns the ascii text number of the sum of the fc mapped and unmapped
600 * vport counts.
601 *
602 * Returns: size of formatted string.
603 **/
dea31012005-04-17 16:05:31 -0500604static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100605lpfc_num_discovered_ports_show(struct device *dev,
606 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500607{
Tony Jonesee959b02008-02-22 00:13:36 +0100608 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
610
611 return snprintf(buf, PAGE_SIZE, "%d\n",
612 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500613}
614
James Smarte59058c2008-08-24 21:49:00 -0400615/**
James Smart3621a712009-04-06 18:47:14 -0400616 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400617 * @shost: Scsi_Host pointer.
618 *
619 * Description:
620 * Bring the link down gracefully then re-init the link. The firmware will
621 * re-init the fiber channel interface as required. Does not issue a LIP.
622 *
623 * Returns:
624 * -EPERM port offline or management commands are being blocked
625 * -ENOMEM cannot allocate memory for the mailbox command
626 * -EIO error sending the mailbox command
627 * zero for success
628 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700629static int
James Smart2e0fef82007-06-17 19:56:36 -0500630lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500631{
James Smart2e0fef82007-06-17 19:56:36 -0500632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500634 LPFC_MBOXQ_t *pmboxq;
635 int mbxstatus = MBXERR_ERROR;
636
James Smart2e0fef82007-06-17 19:56:36 -0500637 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500638 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500639 return -EPERM;
640
641 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
642
643 if (!pmboxq)
644 return -ENOMEM;
645
646 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400647 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
648 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400649
James Smart33ccf8d2006-08-17 11:57:58 -0400650 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500651
James Smart04c68492009-05-22 14:52:52 -0400652 if ((mbxstatus == MBX_SUCCESS) &&
653 (pmboxq->u.mb.mbxStatus == 0 ||
654 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400655 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
656 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
657 phba->cfg_link_speed);
658 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
659 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400660 if ((mbxstatus == MBX_SUCCESS) &&
661 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
662 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
663 "2859 SLI authentication is required "
664 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400665 }
666
James Smart5b8bd0c2007-04-25 09:52:49 -0400667 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500668 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400669 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500670
671 if (mbxstatus == MBXERR_ERROR)
672 return -EIO;
673
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700674 return 0;
dea31012005-04-17 16:05:31 -0500675}
676
James Smarte59058c2008-08-24 21:49:00 -0400677/**
James Smart3621a712009-04-06 18:47:14 -0400678 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400679 * @phba: lpfc_hba pointer.
680 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
681 *
682 * Notes:
683 * Assumes any error from lpfc_do_offline() will be negative.
684 * Can wait up to 5 seconds for the port ring buffers count
685 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400686 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400687 *
688 * Returns:
689 * -EIO error posting the event
690 * zero for success
691 **/
James Smart40496f02006-07-06 15:50:22 -0400692static int
James Smart46fa3112007-04-25 09:51:45 -0400693lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
694{
695 struct completion online_compl;
696 struct lpfc_sli_ring *pring;
697 struct lpfc_sli *psli;
698 int status = 0;
699 int cnt = 0;
700 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500701 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400702
703 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400705 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500706 if (rc == 0)
707 return -ENOMEM;
708
James Smart46fa3112007-04-25 09:51:45 -0400709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 psli = &phba->sli;
715
James Smart09372822008-01-11 01:52:54 -0500716 /* Wait a little for things to settle down, but not
717 * long enough for dev loss timeout to expire.
718 */
James Smart46fa3112007-04-25 09:51:45 -0400719 for (i = 0; i < psli->num_rings; i++) {
720 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500721 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400722 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500723 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400724 lpfc_printf_log(phba,
725 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400726 "0466 Outstanding IO when "
727 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400728 break;
729 }
730 }
731 }
732
733 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500734 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
735 if (rc == 0)
736 return -ENOMEM;
737
James Smart46fa3112007-04-25 09:51:45 -0400738 wait_for_completion(&online_compl);
739
740 if (status != 0)
741 return -EIO;
742
743 return 0;
744}
745
James Smarte59058c2008-08-24 21:49:00 -0400746/**
James Smart3621a712009-04-06 18:47:14 -0400747 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400748 * @phba: lpfc_hba pointer.
749 *
750 * Description:
751 * If the port is configured to allow a reset then the hba is brought
752 * offline then online.
753 *
754 * Notes:
755 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500756 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400757 *
758 * Returns:
759 * lpfc_do_offline() return code if not zero
760 * -EIO reset not configured or error posting the event
761 * zero for success
762 **/
James Smart7f860592011-03-11 16:05:52 -0500763int
James Smart40496f02006-07-06 15:50:22 -0400764lpfc_selective_reset(struct lpfc_hba *phba)
765{
766 struct completion online_compl;
767 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500768 int rc;
James Smart40496f02006-07-06 15:50:22 -0400769
James Smart71157c92013-07-15 18:34:36 -0400770 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400771 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500772
James Smart71157c92013-07-15 18:34:36 -0400773 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
774 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400775
James Smart71157c92013-07-15 18:34:36 -0400776 if (status != 0)
777 return status;
778 }
James Smart40496f02006-07-06 15:50:22 -0400779
780 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500781 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400782 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500783 if (rc == 0)
784 return -ENOMEM;
785
James Smart40496f02006-07-06 15:50:22 -0400786 wait_for_completion(&online_compl);
787
788 if (status != 0)
789 return -EIO;
790
791 return 0;
792}
793
James Smarte59058c2008-08-24 21:49:00 -0400794/**
James Smart3621a712009-04-06 18:47:14 -0400795 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400796 * @dev: class device that is converted into a Scsi_host.
797 * @attr: device attribute, not used.
798 * @buf: containing the string "selective".
799 * @count: unused variable.
800 *
801 * Description:
802 * If the buf contains the string "selective" then lpfc_selective_reset()
803 * is called to perform the reset.
804 *
805 * Notes:
806 * Assumes any error from lpfc_selective_reset() will be negative.
807 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200808 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400809 *
810 * Returns:
811 * -EINVAL if the buffer does not contain the string "selective"
812 * length of buf if lpfc-selective_reset() if the call succeeds
813 * return value of lpfc_selective_reset() if the call fails
814**/
James Smart40496f02006-07-06 15:50:22 -0400815static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100816lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
817 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400818{
Tony Jonesee959b02008-02-22 00:13:36 +0100819 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
821 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400822 int status = -EINVAL;
823
James Smart73d91e52011-10-10 21:32:10 -0400824 if (!phba->cfg_enable_hba_reset)
825 return -EACCES;
826
James Smart40496f02006-07-06 15:50:22 -0400827 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500828 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400829
830 if (status == 0)
831 return strlen(buf);
832 else
833 return status;
834}
835
James Smarte59058c2008-08-24 21:49:00 -0400836/**
James Smart88a2cfb2011-07-22 18:36:33 -0400837 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
838 * @phba: lpfc_hba pointer.
839 *
840 * Description:
841 * SLI4 interface type-2 device to wait on the sliport status register for
842 * the readyness after performing a firmware reset.
843 *
844 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +0900845 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -0500846 * reset, -EIO when port timeout from recovering from the reset.
847 *
848 * Note:
849 * As the caller will interpret the return code by value, be careful in making
850 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400851 **/
James Smart73d91e52011-10-10 21:32:10 -0400852int
James Smart88a2cfb2011-07-22 18:36:33 -0400853lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
854{
James Smartf7a919b2011-08-21 21:49:16 -0400855 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400856 int i;
857
James Smartf7a919b2011-08-21 21:49:16 -0400858 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400859 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
860 &portstat_reg.word0);
861
Masanari Iida0b1587b2013-07-17 04:37:44 +0900862 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -0400863 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
864 !bf_get(lpfc_sliport_status_err, &portstat_reg))
865 return -EPERM;
866
James Smart88a2cfb2011-07-22 18:36:33 -0400867 /* wait for the SLI port firmware ready after firmware reset */
868 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
869 msleep(10);
870 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
871 &portstat_reg.word0);
872 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
873 continue;
874 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
875 continue;
876 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
877 continue;
878 break;
879 }
880
881 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
882 return 0;
883 else
884 return -EIO;
885}
886
887/**
James Smart52d52442011-05-24 11:42:45 -0400888 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400889 * @phba: lpfc_hba pointer.
890 *
891 * Description:
James Smart52d52442011-05-24 11:42:45 -0400892 * Request SLI4 interface type-2 device to perform a physical register set
893 * access.
James Smartc0c11512011-05-24 11:41:34 -0400894 *
895 * Returns:
896 * zero for success
897 **/
898static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400899lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400900{
901 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400902 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500903 uint32_t before_fc_flag;
904 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400905 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500906 int status = 0, rc = 0;
907 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400908
909 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400910 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400911
James Smart52d52442011-05-24 11:42:45 -0400912 if ((phba->sli_rev < LPFC_SLI_REV4) ||
913 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
914 LPFC_SLI_INTF_IF_TYPE_2))
915 return -EPERM;
916
James Smart026abb82011-12-13 13:20:45 -0500917 /* Keep state if we need to restore back */
918 before_fc_flag = phba->pport->fc_flag;
919 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
920
James Smartb76f2dc2011-07-22 18:37:42 -0400921 /* Disable SR-IOV virtual functions if enabled */
922 if (phba->cfg_sriov_nr_virtfn) {
923 pci_disable_sriov(pdev);
924 phba->cfg_sriov_nr_virtfn = 0;
925 }
James Smart229adb02013-04-17 20:16:51 -0400926
James Smart02936352014-04-04 13:52:12 -0400927 if (opcode == LPFC_FW_DUMP)
928 phba->hba_flag |= HBA_FW_DUMP_OP;
929
James Smartc0c11512011-05-24 11:41:34 -0400930 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
931
James Smart02936352014-04-04 13:52:12 -0400932 if (status != 0) {
933 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -0400934 return status;
James Smart02936352014-04-04 13:52:12 -0400935 }
James Smartc0c11512011-05-24 11:41:34 -0400936
937 /* wait for the device to be quiesced before firmware reset */
938 msleep(100);
939
940 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
941 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400942
943 if (opcode == LPFC_FW_DUMP)
944 reg_val |= LPFC_FW_DUMP_REQUEST;
945 else if (opcode == LPFC_FW_RESET)
946 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
947 else if (opcode == LPFC_DV_RESET)
948 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
949
James Smartc0c11512011-05-24 11:41:34 -0400950 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
951 LPFC_CTL_PDEV_CTL_OFFSET);
952 /* flush */
953 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
954
955 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400956 rc = lpfc_sli4_pdev_status_reg_wait(phba);
957
James Smart026abb82011-12-13 13:20:45 -0500958 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +0900959 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -0500960 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +0900961 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -0500962 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500963 } else if (rc == -EIO) {
964 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
966 "3153 Fail to perform the requested "
967 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400968 return rc;
James Smart026abb82011-12-13 13:20:45 -0500969 }
970
971 /* keep the original port state */
972 if (before_fc_flag & FC_OFFLINE_MODE)
973 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400974
975 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500976 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
977 LPFC_EVT_ONLINE);
978 if (!job_posted)
979 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400980
981 wait_for_completion(&online_compl);
982
James Smart026abb82011-12-13 13:20:45 -0500983out:
984 /* in any case, restore the virtual functions enabled as before */
985 if (sriov_nr_virtfn) {
986 sriov_err =
987 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
988 if (!sriov_err)
989 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
990 }
James Smartc0c11512011-05-24 11:41:34 -0400991
James Smart026abb82011-12-13 13:20:45 -0500992 /* return proper error code */
993 if (!rc) {
994 if (!job_posted)
995 rc = -ENOMEM;
996 else if (status)
997 rc = -EIO;
998 }
999 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001000}
1001
1002/**
James Smart3621a712009-04-06 18:47:14 -04001003 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001004 * @dev: class device that is converted into a Scsi_host.
1005 * @attr: device attribute, not used.
1006 * @buf: on return contains the ascii number of nport events.
1007 *
1008 * Returns: size of formatted string.
1009 **/
dea31012005-04-17 16:05:31 -05001010static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001011lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1012 char *buf)
dea31012005-04-17 16:05:31 -05001013{
Tony Jonesee959b02008-02-22 00:13:36 +01001014 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001015 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1016 struct lpfc_hba *phba = vport->phba;
1017
dea31012005-04-17 16:05:31 -05001018 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the state of the adapter.
1026 *
1027 * Returns: size of formatted string.
1028 **/
dea31012005-04-17 16:05:31 -05001029static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001030lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1031 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001032{
Tony Jonesee959b02008-02-22 00:13:36 +01001033 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001034 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1035 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001036 char * state;
1037
James Smart2e0fef82007-06-17 19:56:36 -05001038 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001039 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001040 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001041 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001042 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001043 state = "offline";
1044 else
1045 state = "online";
1046
1047 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1048}
1049
James Smarte59058c2008-08-24 21:49:00 -04001050/**
James Smart3621a712009-04-06 18:47:14 -04001051 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001052 * @dev: class device that is converted into a Scsi_host.
1053 * @attr: device attribute, not used.
1054 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1055 * @count: unused variable.
1056 *
1057 * Returns:
1058 * -EACCES if enable hba reset not enabled
1059 * -EINVAL if the buffer does not contain a valid string (see above)
1060 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1061 * buf length greater than zero indicates success
1062 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001063static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001064lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1065 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001066{
Tony Jonesee959b02008-02-22 00:13:36 +01001067 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1069 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001070 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001071 char *board_mode_str = NULL;
1072 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001073 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001074
James Smart026abb82011-12-13 13:20:45 -05001075 if (!phba->cfg_enable_hba_reset) {
1076 status = -EACCES;
1077 goto board_mode_out;
1078 }
James Smart88a2cfb2011-07-22 18:36:33 -04001079
1080 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001081 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001082
Jamie Wellnitz41415862006-02-28 19:25:27 -05001083 init_completion(&online_compl);
1084
James Smart46fa3112007-04-25 09:51:45 -04001085 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001086 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001087 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001088 if (rc == 0) {
1089 status = -ENOMEM;
1090 goto board_mode_out;
1091 }
James Smart46fa3112007-04-25 09:51:45 -04001092 wait_for_completion(&online_compl);
1093 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1094 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001095 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001096 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001097 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001098 else
1099 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001100 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001101 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001102 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001103 else
1104 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001105 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001106 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1107 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1108 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1109 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1110 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001111 else
James Smart026abb82011-12-13 13:20:45 -05001112 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001113
James Smart026abb82011-12-13 13:20:45 -05001114board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001115 if (!status)
1116 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001117 else {
1118 board_mode_str = strchr(buf, '\n');
1119 if (board_mode_str)
1120 *board_mode_str = '\0';
1121 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1122 "3097 Failed \"%s\", status(%d), "
1123 "fc_flag(x%x)\n",
1124 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001125 return status;
James Smart026abb82011-12-13 13:20:45 -05001126 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001127}
1128
James Smarte59058c2008-08-24 21:49:00 -04001129/**
James Smart3621a712009-04-06 18:47:14 -04001130 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001131 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001132 * @mxri: max xri count.
1133 * @axri: available xri count.
1134 * @mrpi: max rpi count.
1135 * @arpi: available rpi count.
1136 * @mvpi: max vpi count.
1137 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001138 *
1139 * Description:
1140 * If an integer pointer for an count is not null then the value for the
1141 * count is returned.
1142 *
1143 * Returns:
1144 * zero on error
1145 * one for success
1146 **/
James Smart311464e2007-08-02 11:10:37 -04001147static int
James Smart858c9f62007-06-17 19:56:39 -05001148lpfc_get_hba_info(struct lpfc_hba *phba,
1149 uint32_t *mxri, uint32_t *axri,
1150 uint32_t *mrpi, uint32_t *arpi,
1151 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001152{
James Smart04c68492009-05-22 14:52:52 -04001153 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001154 LPFC_MBOXQ_t *pmboxq;
1155 MAILBOX_t *pmb;
1156 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001157 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001158
1159 /*
1160 * prevent udev from issuing mailbox commands until the port is
1161 * configured.
1162 */
1163 if (phba->link_state < LPFC_LINK_DOWN ||
1164 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001165 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001166 return 0;
1167
1168 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1169 return 0;
1170
1171 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1172 if (!pmboxq)
1173 return 0;
1174 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1175
James Smart04c68492009-05-22 14:52:52 -04001176 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001177 pmb->mbxCommand = MBX_READ_CONFIG;
1178 pmb->mbxOwner = OWN_HOST;
1179 pmboxq->context1 = NULL;
1180
James Smart75baf692010-06-08 18:31:21 -04001181 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001182 rc = MBX_NOT_FINISHED;
1183 else
1184 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1185
1186 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001187 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001188 mempool_free(pmboxq, phba->mbox_mem_pool);
1189 return 0;
1190 }
1191
James Smartda0436e2009-05-22 14:51:39 -04001192 if (phba->sli_rev == LPFC_SLI_REV4) {
1193 rd_config = &pmboxq->u.mqe.un.rd_config;
1194 if (mrpi)
1195 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1196 if (arpi)
1197 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1198 phba->sli4_hba.max_cfg_param.rpi_used;
1199 if (mxri)
1200 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1201 if (axri)
1202 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1203 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001204
1205 /* Account for differences with SLI-3. Get vpi count from
1206 * mailbox data and subtract one for max vpi value.
1207 */
1208 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1209 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1210
James Smartda0436e2009-05-22 14:51:39 -04001211 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001212 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001213 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001214 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001215 } else {
1216 if (mrpi)
1217 *mrpi = pmb->un.varRdConfig.max_rpi;
1218 if (arpi)
1219 *arpi = pmb->un.varRdConfig.avail_rpi;
1220 if (mxri)
1221 *mxri = pmb->un.varRdConfig.max_xri;
1222 if (axri)
1223 *axri = pmb->un.varRdConfig.avail_xri;
1224 if (mvpi)
1225 *mvpi = pmb->un.varRdConfig.max_vpi;
1226 if (avpi)
1227 *avpi = pmb->un.varRdConfig.avail_vpi;
1228 }
James Smart92d7f7b2007-06-17 19:56:38 -05001229
1230 mempool_free(pmboxq, phba->mbox_mem_pool);
1231 return 1;
1232}
1233
James Smarte59058c2008-08-24 21:49:00 -04001234/**
James Smart3621a712009-04-06 18:47:14 -04001235 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001236 * @dev: class device that is converted into a Scsi_host.
1237 * @attr: device attribute, not used.
1238 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1239 *
1240 * Description:
1241 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1242 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1243 * to "Unknown" and the buffer length is returned, therefore the caller
1244 * must check for "Unknown" in the buffer to detect a failure.
1245 *
1246 * Returns: size of formatted string.
1247 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001248static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001249lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1250 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001251{
Tony Jonesee959b02008-02-22 00:13:36 +01001252 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001253 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1254 struct lpfc_hba *phba = vport->phba;
1255 uint32_t cnt;
1256
James Smart858c9f62007-06-17 19:56:39 -05001257 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001258 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1259 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1260}
1261
James Smarte59058c2008-08-24 21:49:00 -04001262/**
James Smart3621a712009-04-06 18:47:14 -04001263 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001264 * @dev: class device that is converted into a Scsi_host.
1265 * @attr: device attribute, not used.
1266 * @buf: containing the used rpi count in decimal or "Unknown".
1267 *
1268 * Description:
1269 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1270 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1271 * to "Unknown" and the buffer length is returned, therefore the caller
1272 * must check for "Unknown" in the buffer to detect a failure.
1273 *
1274 * Returns: size of formatted string.
1275 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001276static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001277lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1278 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001279{
Tony Jonesee959b02008-02-22 00:13:36 +01001280 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001281 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1282 struct lpfc_hba *phba = vport->phba;
1283 uint32_t cnt, acnt;
1284
James Smart858c9f62007-06-17 19:56:39 -05001285 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001286 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1287 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1288}
1289
James Smarte59058c2008-08-24 21:49:00 -04001290/**
James Smart3621a712009-04-06 18:47:14 -04001291 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001292 * @dev: class device that is converted into a Scsi_host.
1293 * @attr: device attribute, not used.
1294 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1295 *
1296 * Description:
1297 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1298 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1299 * to "Unknown" and the buffer length is returned, therefore the caller
1300 * must check for "Unknown" in the buffer to detect a failure.
1301 *
1302 * Returns: size of formatted string.
1303 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001304static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001305lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1306 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001307{
Tony Jonesee959b02008-02-22 00:13:36 +01001308 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1310 struct lpfc_hba *phba = vport->phba;
1311 uint32_t cnt;
1312
James Smart858c9f62007-06-17 19:56:39 -05001313 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001314 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1315 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1316}
1317
James Smarte59058c2008-08-24 21:49:00 -04001318/**
James Smart3621a712009-04-06 18:47:14 -04001319 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001320 * @dev: class device that is converted into a Scsi_host.
1321 * @attr: device attribute, not used.
1322 * @buf: on return contains the used xri count in decimal or "Unknown".
1323 *
1324 * Description:
1325 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1326 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1327 * to "Unknown" and the buffer length is returned, therefore the caller
1328 * must check for "Unknown" in the buffer to detect a failure.
1329 *
1330 * Returns: size of formatted string.
1331 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001332static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001333lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1334 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001335{
Tony Jonesee959b02008-02-22 00:13:36 +01001336 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001337 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1338 struct lpfc_hba *phba = vport->phba;
1339 uint32_t cnt, acnt;
1340
James Smart858c9f62007-06-17 19:56:39 -05001341 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1342 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1343 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1344}
1345
James Smarte59058c2008-08-24 21:49:00 -04001346/**
James Smart3621a712009-04-06 18:47:14 -04001347 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001348 * @dev: class device that is converted into a Scsi_host.
1349 * @attr: device attribute, not used.
1350 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1351 *
1352 * Description:
1353 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1354 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1355 * to "Unknown" and the buffer length is returned, therefore the caller
1356 * must check for "Unknown" in the buffer to detect a failure.
1357 *
1358 * Returns: size of formatted string.
1359 **/
James Smart858c9f62007-06-17 19:56:39 -05001360static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001361lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1362 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001363{
Tony Jonesee959b02008-02-22 00:13:36 +01001364 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1366 struct lpfc_hba *phba = vport->phba;
1367 uint32_t cnt;
1368
1369 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1370 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1371 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1372}
1373
James Smarte59058c2008-08-24 21:49:00 -04001374/**
James Smart3621a712009-04-06 18:47:14 -04001375 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001376 * @dev: class device that is converted into a Scsi_host.
1377 * @attr: device attribute, not used.
1378 * @buf: on return contains the used vpi count in decimal or "Unknown".
1379 *
1380 * Description:
1381 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1382 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1383 * to "Unknown" and the buffer length is returned, therefore the caller
1384 * must check for "Unknown" in the buffer to detect a failure.
1385 *
1386 * Returns: size of formatted string.
1387 **/
James Smart858c9f62007-06-17 19:56:39 -05001388static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001389lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1390 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001391{
Tony Jonesee959b02008-02-22 00:13:36 +01001392 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1394 struct lpfc_hba *phba = vport->phba;
1395 uint32_t cnt, acnt;
1396
1397 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001398 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1399 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1400}
1401
James Smarte59058c2008-08-24 21:49:00 -04001402/**
James Smart3621a712009-04-06 18:47:14 -04001403 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001404 * @dev: class device that is converted into a Scsi_host.
1405 * @attr: device attribute, not used.
1406 * @buf: text that must be interpreted to determine if npiv is supported.
1407 *
1408 * Description:
1409 * Buffer will contain text indicating npiv is not suppoerted on the port,
1410 * the port is an NPIV physical port, or it is an npiv virtual port with
1411 * the id of the vport.
1412 *
1413 * Returns: size of formatted string.
1414 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001415static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001416lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1417 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001418{
Tony Jonesee959b02008-02-22 00:13:36 +01001419 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001420 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1421 struct lpfc_hba *phba = vport->phba;
1422
1423 if (!(phba->max_vpi))
1424 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1425 if (vport->port_type == LPFC_PHYSICAL_PORT)
1426 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1427 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1428}
1429
James Smarte59058c2008-08-24 21:49:00 -04001430/**
James Smart3621a712009-04-06 18:47:14 -04001431 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001432 * @dev: class device that is converted into a Scsi_host.
1433 * @attr: device attribute, not used.
1434 * @buf: on return contains the cfg_poll in hex.
1435 *
1436 * Notes:
1437 * cfg_poll should be a lpfc_polling_flags type.
1438 *
1439 * Returns: size of formatted string.
1440 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001441static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001442lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1443 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001444{
Tony Jonesee959b02008-02-22 00:13:36 +01001445 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1447 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001448
1449 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1450}
1451
James Smarte59058c2008-08-24 21:49:00 -04001452/**
James Smart3621a712009-04-06 18:47:14 -04001453 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001454 * @dev: class device that is converted into a Scsi_host.
1455 * @attr: device attribute, not used.
1456 * @buf: one or more lpfc_polling_flags values.
1457 * @count: not used.
1458 *
1459 * Notes:
1460 * buf contents converted to integer and checked for a valid value.
1461 *
1462 * Returns:
1463 * -EINVAL if the buffer connot be converted or is out of range
1464 * length of the buf on success
1465 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001466static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001467lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1468 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001469{
Tony Jonesee959b02008-02-22 00:13:36 +01001470 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1472 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001473 uint32_t creg_val;
1474 uint32_t old_val;
1475 int val=0;
1476
1477 if (!isdigit(buf[0]))
1478 return -EINVAL;
1479
1480 if (sscanf(buf, "%i", &val) != 1)
1481 return -EINVAL;
1482
1483 if ((val & 0x3) != val)
1484 return -EINVAL;
1485
James Smart45ed1192009-10-02 15:17:02 -04001486 if (phba->sli_rev == LPFC_SLI_REV4)
1487 val = 0;
1488
James Smart88a2cfb2011-07-22 18:36:33 -04001489 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1490 "3051 lpfc_poll changed from %d to %d\n",
1491 phba->cfg_poll, val);
1492
James Smart2e0fef82007-06-17 19:56:36 -05001493 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001494
1495 old_val = phba->cfg_poll;
1496
1497 if (val & ENABLE_FCP_RING_POLLING) {
1498 if ((val & DISABLE_FCP_RING_INT) &&
1499 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001500 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1501 spin_unlock_irq(&phba->hbalock);
1502 return -EINVAL;
1503 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001504 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1505 writel(creg_val, phba->HCregaddr);
1506 readl(phba->HCregaddr); /* flush */
1507
1508 lpfc_poll_start_timer(phba);
1509 }
1510 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001511 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001512 return -EINVAL;
1513 }
1514
1515 if (!(val & DISABLE_FCP_RING_INT) &&
1516 (old_val & DISABLE_FCP_RING_INT))
1517 {
James Smart2e0fef82007-06-17 19:56:36 -05001518 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001519 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001520 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001521 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1522 spin_unlock_irq(&phba->hbalock);
1523 return -EINVAL;
1524 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001525 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1526 writel(creg_val, phba->HCregaddr);
1527 readl(phba->HCregaddr); /* flush */
1528 }
1529
1530 phba->cfg_poll = val;
1531
James Smart2e0fef82007-06-17 19:56:36 -05001532 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001533
1534 return strlen(buf);
1535}
dea31012005-04-17 16:05:31 -05001536
James Smarte59058c2008-08-24 21:49:00 -04001537/**
James Smartbc739052010-08-04 16:11:18 -04001538 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1539 * @dev: class unused variable.
1540 * @attr: device attribute, not used.
1541 * @buf: on return contains the module description text.
1542 *
1543 * Returns: size of formatted string.
1544 **/
1545static ssize_t
1546lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1547 char *buf)
1548{
1549 struct Scsi_Host *shost = class_to_shost(dev);
1550 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1551 struct lpfc_hba *phba = vport->phba;
1552
1553 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1554}
1555
1556/**
1557 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1558 * @dev: class unused variable.
1559 * @attr: device attribute, not used.
1560 * @buf: on return contains the module description text.
1561 *
1562 * Returns: size of formatted string.
1563 **/
1564static ssize_t
1565lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1566 char *buf)
1567{
1568 struct Scsi_Host *shost = class_to_shost(dev);
1569 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1570 struct lpfc_hba *phba = vport->phba;
1571
1572 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1573}
1574
1575/**
James Smartab56dc22011-02-16 12:39:57 -05001576 * lpfc_dss_show - Return the current state of dss and the configured state
1577 * @dev: class converted to a Scsi_host structure.
1578 * @attr: device attribute, not used.
1579 * @buf: on return contains the formatted text.
1580 *
1581 * Returns: size of formatted string.
1582 **/
1583static ssize_t
1584lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1585 char *buf)
1586{
1587 struct Scsi_Host *shost = class_to_shost(dev);
1588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1589 struct lpfc_hba *phba = vport->phba;
1590
1591 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1592 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1593 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1594 "" : "Not ");
1595}
1596
1597/**
James Smart912e3ac2011-05-24 11:42:11 -04001598 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1599 * @dev: class converted to a Scsi_host structure.
1600 * @attr: device attribute, not used.
1601 * @buf: on return contains the formatted support level.
1602 *
1603 * Description:
1604 * Returns the maximum number of virtual functions a physical function can
1605 * support, 0 will be returned if called on virtual function.
1606 *
1607 * Returns: size of formatted string.
1608 **/
1609static ssize_t
1610lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1611 struct device_attribute *attr,
1612 char *buf)
1613{
1614 struct Scsi_Host *shost = class_to_shost(dev);
1615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001617 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001618
James Smart0a96e972011-07-22 18:37:28 -04001619 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1620 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001621}
1622
1623/**
James Smart3621a712009-04-06 18:47:14 -04001624 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001625 *
1626 * Description:
1627 * Macro that given an attr e.g. hba_queue_depth expands
1628 * into a function with the name lpfc_hba_queue_depth_show.
1629 *
1630 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1631 * @dev: class device that is converted into a Scsi_host.
1632 * @attr: device attribute, not used.
1633 * @buf: on return contains the attribute value in decimal.
1634 *
1635 * Returns: size of formatted string.
1636 **/
dea31012005-04-17 16:05:31 -05001637#define lpfc_param_show(attr) \
1638static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001639lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1640 char *buf) \
dea31012005-04-17 16:05:31 -05001641{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001642 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001643 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1644 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001645 return snprintf(buf, PAGE_SIZE, "%d\n",\
1646 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001647}
1648
James Smarte59058c2008-08-24 21:49:00 -04001649/**
James Smart3621a712009-04-06 18:47:14 -04001650 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001651 *
1652 * Description:
1653 * Macro that given an attr e.g. hba_queue_depth expands
1654 * into a function with the name lpfc_hba_queue_depth_show
1655 *
1656 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1657 * @dev: class device that is converted into a Scsi_host.
1658 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001659 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001660 *
1661 * Returns: size of formatted string.
1662 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001663#define lpfc_param_hex_show(attr) \
1664static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001665lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1666 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001667{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001668 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1670 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001671 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001672 val = phba->cfg_##attr;\
1673 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1674 phba->cfg_##attr);\
1675}
1676
James Smarte59058c2008-08-24 21:49:00 -04001677/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001678 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001679 *
1680 * Description:
1681 * Macro that given an attr e.g. hba_queue_depth expands
1682 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1683 * takes a default argument, a minimum and maximum argument.
1684 *
1685 * lpfc_##attr##_init: Initializes an attribute.
1686 * @phba: pointer the the adapter structure.
1687 * @val: integer attribute value.
1688 *
1689 * Validates the min and max values then sets the adapter config field
1690 * accordingly, or uses the default if out of range and prints an error message.
1691 *
1692 * Returns:
1693 * zero on success
1694 * -EINVAL if default used
1695 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001696#define lpfc_param_init(attr, default, minval, maxval) \
1697static int \
James Smart84d1b002010-02-12 14:42:33 -05001698lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001699{ \
1700 if (val >= minval && val <= maxval) {\
1701 phba->cfg_##attr = val;\
1702 return 0;\
1703 }\
1704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001705 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1706 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001707 phba->cfg_##attr = default;\
1708 return -EINVAL;\
1709}
1710
James Smarte59058c2008-08-24 21:49:00 -04001711/**
James Smart3621a712009-04-06 18:47:14 -04001712 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001713 *
1714 * Description:
1715 * Macro that given an attr e.g. hba_queue_depth expands
1716 * into a function with the name lpfc_hba_queue_depth_set
1717 *
1718 * lpfc_##attr##_set: Sets an attribute value.
1719 * @phba: pointer the the adapter structure.
1720 * @val: integer attribute value.
1721 *
1722 * Description:
1723 * Validates the min and max values then sets the
1724 * adapter config field if in the valid range. prints error message
1725 * and does not set the parameter if invalid.
1726 *
1727 * Returns:
1728 * zero on success
1729 * -EINVAL if val is invalid
1730 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001731#define lpfc_param_set(attr, default, minval, maxval) \
1732static int \
James Smart84d1b002010-02-12 14:42:33 -05001733lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001734{ \
1735 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1737 "3052 lpfc_" #attr " changed from %d to %d\n", \
1738 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001739 phba->cfg_##attr = val;\
1740 return 0;\
1741 }\
1742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001743 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1744 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001745 return -EINVAL;\
1746}
1747
James Smarte59058c2008-08-24 21:49:00 -04001748/**
James Smart3621a712009-04-06 18:47:14 -04001749 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001750 *
1751 * Description:
1752 * Macro that given an attr e.g. hba_queue_depth expands
1753 * into a function with the name lpfc_hba_queue_depth_store.
1754 *
1755 * lpfc_##attr##_store: Set an sttribute value.
1756 * @dev: class device that is converted into a Scsi_host.
1757 * @attr: device attribute, not used.
1758 * @buf: contains the attribute value in ascii.
1759 * @count: not used.
1760 *
1761 * Description:
1762 * Convert the ascii text number to an integer, then
1763 * use the lpfc_##attr##_set function to set the value.
1764 *
1765 * Returns:
1766 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1767 * length of buffer upon success.
1768 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001769#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001770static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001771lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1772 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001773{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001774 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1776 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001777 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001778 if (!isdigit(buf[0]))\
1779 return -EINVAL;\
1780 if (sscanf(buf, "%i", &val) != 1)\
1781 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001782 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001783 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001784 else \
1785 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001786}
1787
James Smarte59058c2008-08-24 21:49:00 -04001788/**
James Smart3621a712009-04-06 18:47:14 -04001789 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001790 *
1791 * Description:
1792 * Macro that given an attr e.g. hba_queue_depth expands
1793 * into a function with the name lpfc_hba_queue_depth_show
1794 *
1795 * lpfc_##attr##_show: prints the attribute value in decimal.
1796 * @dev: class device that is converted into a Scsi_host.
1797 * @attr: device attribute, not used.
1798 * @buf: on return contains the attribute value in decimal.
1799 *
1800 * Returns: length of formatted string.
1801 **/
James Smart3de2a652007-08-02 11:09:59 -04001802#define lpfc_vport_param_show(attr) \
1803static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001804lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1805 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001806{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001807 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001808 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001809 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1810}
1811
James Smarte59058c2008-08-24 21:49:00 -04001812/**
James Smart3621a712009-04-06 18:47:14 -04001813 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001814 *
1815 * Description:
1816 * Macro that given an attr e.g.
1817 * hba_queue_depth expands into a function with the name
1818 * lpfc_hba_queue_depth_show
1819 *
James Smart3621a712009-04-06 18:47:14 -04001820 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001821 * @dev: class device that is converted into a Scsi_host.
1822 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001823 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001824 *
1825 * Returns: length of formatted string.
1826 **/
James Smart3de2a652007-08-02 11:09:59 -04001827#define lpfc_vport_param_hex_show(attr) \
1828static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001829lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1830 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001831{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001832 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001833 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001834 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1835}
1836
James Smarte59058c2008-08-24 21:49:00 -04001837/**
James Smart3621a712009-04-06 18:47:14 -04001838 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001839 *
1840 * Description:
1841 * Macro that given an attr e.g. hba_queue_depth expands
1842 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1843 * takes a default argument, a minimum and maximum argument.
1844 *
1845 * lpfc_##attr##_init: validates the min and max values then sets the
1846 * adapter config field accordingly, or uses the default if out of range
1847 * and prints an error message.
1848 * @phba: pointer the the adapter structure.
1849 * @val: integer attribute value.
1850 *
1851 * Returns:
1852 * zero on success
1853 * -EINVAL if default used
1854 **/
James Smart3de2a652007-08-02 11:09:59 -04001855#define lpfc_vport_param_init(attr, default, minval, maxval) \
1856static int \
James Smart84d1b002010-02-12 14:42:33 -05001857lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001858{ \
1859 if (val >= minval && val <= maxval) {\
1860 vport->cfg_##attr = val;\
1861 return 0;\
1862 }\
James Smarte8b62012007-08-02 11:10:09 -04001863 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001864 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001865 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001866 vport->cfg_##attr = default;\
1867 return -EINVAL;\
1868}
1869
James Smarte59058c2008-08-24 21:49:00 -04001870/**
James Smart3621a712009-04-06 18:47:14 -04001871 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001872 *
1873 * Description:
1874 * Macro that given an attr e.g. hba_queue_depth expands
1875 * into a function with the name lpfc_hba_queue_depth_set
1876 *
1877 * lpfc_##attr##_set: validates the min and max values then sets the
1878 * adapter config field if in the valid range. prints error message
1879 * and does not set the parameter if invalid.
1880 * @phba: pointer the the adapter structure.
1881 * @val: integer attribute value.
1882 *
1883 * Returns:
1884 * zero on success
1885 * -EINVAL if val is invalid
1886 **/
James Smart3de2a652007-08-02 11:09:59 -04001887#define lpfc_vport_param_set(attr, default, minval, maxval) \
1888static int \
James Smart84d1b002010-02-12 14:42:33 -05001889lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001890{ \
1891 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001892 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04001893 "3053 lpfc_" #attr \
1894 " changed from %d (x%x) to %d (x%x)\n", \
1895 vport->cfg_##attr, vport->cfg_##attr, \
1896 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04001897 vport->cfg_##attr = val;\
1898 return 0;\
1899 }\
James Smarte8b62012007-08-02 11:10:09 -04001900 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001901 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001902 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001903 return -EINVAL;\
1904}
1905
James Smarte59058c2008-08-24 21:49:00 -04001906/**
James Smart3621a712009-04-06 18:47:14 -04001907 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001908 *
1909 * Description:
1910 * Macro that given an attr e.g. hba_queue_depth
1911 * expands into a function with the name lpfc_hba_queue_depth_store
1912 *
1913 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1914 * use the lpfc_##attr##_set function to set the value.
1915 * @cdev: class device that is converted into a Scsi_host.
1916 * @buf: contains the attribute value in decimal.
1917 * @count: not used.
1918 *
1919 * Returns:
1920 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1921 * length of buffer upon success.
1922 **/
James Smart3de2a652007-08-02 11:09:59 -04001923#define lpfc_vport_param_store(attr) \
1924static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001925lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1926 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001927{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001928 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001929 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001930 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001931 if (!isdigit(buf[0]))\
1932 return -EINVAL;\
1933 if (sscanf(buf, "%i", &val) != 1)\
1934 return -EINVAL;\
1935 if (lpfc_##attr##_set(vport, val) == 0) \
1936 return strlen(buf);\
1937 else \
1938 return -EINVAL;\
1939}
1940
1941
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001942#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001943static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001944module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001945MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001946lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001947
1948#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001949static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001950module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001951MODULE_PARM_DESC(lpfc_##name, desc);\
1952lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001953lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001954static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001955
1956#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001957static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001958module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001959MODULE_PARM_DESC(lpfc_##name, desc);\
1960lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001961lpfc_param_init(name, defval, minval, maxval)\
1962lpfc_param_set(name, defval, minval, maxval)\
1963lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001964static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1965 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001966
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001967#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001968static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001969module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001970MODULE_PARM_DESC(lpfc_##name, desc);\
1971lpfc_param_hex_show(name)\
1972lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001973static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001974
1975#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001976static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001977module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001978MODULE_PARM_DESC(lpfc_##name, desc);\
1979lpfc_param_hex_show(name)\
1980lpfc_param_init(name, defval, minval, maxval)\
1981lpfc_param_set(name, defval, minval, maxval)\
1982lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001983static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1984 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001985
James Smart3de2a652007-08-02 11:09:59 -04001986#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001987static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001988module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001989MODULE_PARM_DESC(lpfc_##name, desc);\
1990lpfc_vport_param_init(name, defval, minval, maxval)
1991
1992#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001993static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001994module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001995MODULE_PARM_DESC(lpfc_##name, desc);\
1996lpfc_vport_param_show(name)\
1997lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001998static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001999
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002000#define LPFC_VPORT_ULL_ATTR_R(name, defval, minval, maxval, desc) \
2001static uint64_t lpfc_##name = defval;\
2002module_param(lpfc_##name, ullong, S_IRUGO);\
2003MODULE_PARM_DESC(lpfc_##name, desc);\
2004lpfc_vport_param_show(name)\
2005lpfc_vport_param_init(name, defval, minval, maxval)\
2006static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
2007
James Smart3de2a652007-08-02 11:09:59 -04002008#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002009static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002010module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002011MODULE_PARM_DESC(lpfc_##name, desc);\
2012lpfc_vport_param_show(name)\
2013lpfc_vport_param_init(name, defval, minval, maxval)\
2014lpfc_vport_param_set(name, defval, minval, maxval)\
2015lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002016static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2017 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002018
2019#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002020static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002021module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002022MODULE_PARM_DESC(lpfc_##name, desc);\
2023lpfc_vport_param_hex_show(name)\
2024lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01002025static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04002026
2027#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002028static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002029module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002030MODULE_PARM_DESC(lpfc_##name, desc);\
2031lpfc_vport_param_hex_show(name)\
2032lpfc_vport_param_init(name, defval, minval, maxval)\
2033lpfc_vport_param_set(name, defval, minval, maxval)\
2034lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002035static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2036 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002037
James Smart81301a92008-12-04 22:39:46 -05002038static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2039static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2040static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2041static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002042static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2043static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2044static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2045static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2046static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2047static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2048static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2049static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002050static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2051 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002052static DEVICE_ATTR(option_rom_version, S_IRUGO,
2053 lpfc_option_rom_version_show, NULL);
2054static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2055 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002056static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002057static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2058static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002059static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002060static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2061 lpfc_board_mode_show, lpfc_board_mode_store);
2062static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2063static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2064static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2065static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2066static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2067static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2068static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2069static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2070static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002071static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2072static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002073static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002074static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2075 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002076static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002077static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2078 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002079
James Smarta12e07b2006-12-02 13:35:30 -05002080static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002081#define WWN_SZ 8
2082/**
2083 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2084 * @buf: WWN string.
2085 * @cnt: Length of string.
2086 * @wwn: Array to receive converted wwn value.
2087 *
2088 * Returns:
2089 * -EINVAL if the buffer does not contain a valid wwn
2090 * 0 success
2091 **/
2092static size_t
2093lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2094{
2095 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002096
James Smart1ba981f2014-02-20 09:56:45 -05002097 /* Count may include a LF at end of string */
2098 if (buf[cnt-1] == '\n')
2099 cnt--;
2100
2101 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2102 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2103 return -EINVAL;
2104
2105 memset(wwn, 0, WWN_SZ);
2106
2107 /* Validate and store the new name */
2108 for (i = 0, j = 0; i < 16; i++) {
2109 if ((*buf >= 'a') && (*buf <= 'f'))
2110 j = ((j << 4) | ((*buf++ - 'a') + 10));
2111 else if ((*buf >= 'A') && (*buf <= 'F'))
2112 j = ((j << 4) | ((*buf++ - 'A') + 10));
2113 else if ((*buf >= '0') && (*buf <= '9'))
2114 j = ((j << 4) | (*buf++ - '0'));
2115 else
2116 return -EINVAL;
2117 if (i % 2) {
2118 wwn[i/2] = j & 0xff;
2119 j = 0;
2120 }
2121 }
2122 return 0;
2123}
James Smarte59058c2008-08-24 21:49:00 -04002124/**
James Smart3621a712009-04-06 18:47:14 -04002125 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002126 * @dev: class device that is converted into a Scsi_host.
2127 * @attr: device attribute, not used.
2128 * @buf: containing the string lpfc_soft_wwn_key.
2129 * @count: must be size of lpfc_soft_wwn_key.
2130 *
2131 * Returns:
2132 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2133 * length of buf indicates success
2134 **/
James Smartc3f28af2006-08-18 17:47:18 -04002135static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002136lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2137 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002138{
Tony Jonesee959b02008-02-22 00:13:36 +01002139 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002140 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2141 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002142 unsigned int cnt = count;
2143
2144 /*
2145 * We're doing a simple sanity check for soft_wwpn setting.
2146 * We require that the user write a specific key to enable
2147 * the soft_wwpn attribute to be settable. Once the attribute
2148 * is written, the enable key resets. If further updates are
2149 * desired, the key must be written again to re-enable the
2150 * attribute.
2151 *
2152 * The "key" is not secret - it is a hardcoded string shown
2153 * here. The intent is to protect against the random user or
2154 * application that is just writing attributes.
2155 */
2156
2157 /* count may include a LF at end of string */
2158 if (buf[cnt-1] == '\n')
2159 cnt--;
2160
James Smarta12e07b2006-12-02 13:35:30 -05002161 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2162 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002163 return -EINVAL;
2164
James Smarta12e07b2006-12-02 13:35:30 -05002165 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002166 return count;
2167}
Tony Jonesee959b02008-02-22 00:13:36 +01002168static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2169 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002170
James Smarte59058c2008-08-24 21:49:00 -04002171/**
James Smart3621a712009-04-06 18:47:14 -04002172 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002173 * @dev: class device that is converted into a Scsi_host.
2174 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002175 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002176 *
2177 * Returns: size of formatted string.
2178 **/
James Smartc3f28af2006-08-18 17:47:18 -04002179static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002180lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2181 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002182{
Tony Jonesee959b02008-02-22 00:13:36 +01002183 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002184 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2185 struct lpfc_hba *phba = vport->phba;
2186
Randy Dunlapafc071e2006-10-23 21:47:13 -07002187 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2188 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002189}
2190
James Smarte59058c2008-08-24 21:49:00 -04002191/**
James Smart3621a712009-04-06 18:47:14 -04002192 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002193 * @dev class device that is converted into a Scsi_host.
2194 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002195 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002196 * @count: number of wwpn bytes in buf
2197 *
2198 * Returns:
2199 * -EACCES hba reset not enabled, adapter over temp
2200 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2201 * -EIO error taking adapter offline or online
2202 * value of count on success
2203 **/
James Smartc3f28af2006-08-18 17:47:18 -04002204static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002205lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2206 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002207{
Tony Jonesee959b02008-02-22 00:13:36 +01002208 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2210 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002211 struct completion online_compl;
James Smart1ba981f2014-02-20 09:56:45 -05002212 int stat1 = 0, stat2 = 0;
2213 unsigned int cnt = count;
2214 u8 wwpn[WWN_SZ];
James Smartfedd3b72011-02-16 12:39:24 -05002215 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002216
James Smart13815c82008-01-11 01:52:48 -05002217 if (!phba->cfg_enable_hba_reset)
2218 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002219 spin_lock_irq(&phba->hbalock);
2220 if (phba->over_temp_state == HBA_OVER_TEMP) {
2221 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002222 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002223 }
2224 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002225 /* count may include a LF at end of string */
2226 if (buf[cnt-1] == '\n')
2227 cnt--;
2228
James Smart1ba981f2014-02-20 09:56:45 -05002229 if (!phba->soft_wwn_enable)
James Smartc3f28af2006-08-18 17:47:18 -04002230 return -EINVAL;
2231
James Smart1ba981f2014-02-20 09:56:45 -05002232 /* lock setting wwpn, wwnn down */
James Smarta12e07b2006-12-02 13:35:30 -05002233 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002234
James Smart1ba981f2014-02-20 09:56:45 -05002235 rc = lpfc_wwn_set(buf, cnt, wwpn);
2236 if (!rc) {
2237 /* not able to set wwpn, unlock it */
2238 phba->soft_wwn_enable = 1;
2239 return rc;
James Smartc3f28af2006-08-18 17:47:18 -04002240 }
James Smart1ba981f2014-02-20 09:56:45 -05002241
James Smartc3f28af2006-08-18 17:47:18 -04002242 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002243 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002244 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002245 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002246
2247 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2248 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2249
James Smart46fa3112007-04-25 09:51:45 -04002250 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002251 if (stat1)
2252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002253 "0463 lpfc_soft_wwpn attribute set failed to "
2254 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002255 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002256 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2257 LPFC_EVT_ONLINE);
2258 if (rc == 0)
2259 return -ENOMEM;
2260
James Smartc3f28af2006-08-18 17:47:18 -04002261 wait_for_completion(&online_compl);
2262 if (stat2)
2263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002264 "0464 lpfc_soft_wwpn attribute set failed to "
2265 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002266 return (stat1 || stat2) ? -EIO : count;
2267}
James Smart1ba981f2014-02-20 09:56:45 -05002268static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002269 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002270
James Smarte59058c2008-08-24 21:49:00 -04002271/**
James Smart3621a712009-04-06 18:47:14 -04002272 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002273 * @dev: class device that is converted into a Scsi_host.
2274 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002275 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002276 *
2277 * Returns: size of formatted string.
2278 **/
James Smarta12e07b2006-12-02 13:35:30 -05002279static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002280lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2281 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002282{
Tony Jonesee959b02008-02-22 00:13:36 +01002283 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002284 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002285 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2286 (unsigned long long)phba->cfg_soft_wwnn);
2287}
2288
James Smarte59058c2008-08-24 21:49:00 -04002289/**
James Smart3621a712009-04-06 18:47:14 -04002290 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002291 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002292 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002293 * @count: number of wwnn bytes in buf.
2294 *
2295 * Returns:
2296 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2297 * value of count on success
2298 **/
James Smarta12e07b2006-12-02 13:35:30 -05002299static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002300lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2301 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002302{
Tony Jonesee959b02008-02-22 00:13:36 +01002303 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002304 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart1ba981f2014-02-20 09:56:45 -05002305 unsigned int cnt = count;
2306 u8 wwnn[WWN_SZ];
2307 int rc;
James Smarta12e07b2006-12-02 13:35:30 -05002308
2309 /* count may include a LF at end of string */
2310 if (buf[cnt-1] == '\n')
2311 cnt--;
2312
James Smart1ba981f2014-02-20 09:56:45 -05002313 if (!phba->soft_wwn_enable)
James Smarta12e07b2006-12-02 13:35:30 -05002314 return -EINVAL;
2315
James Smart1ba981f2014-02-20 09:56:45 -05002316 rc = lpfc_wwn_set(buf, cnt, wwnn);
2317 if (!rc) {
2318 /* Allow wwnn to be set many times, as long as the enable
2319 * is set. However, once the wwpn is set, everything locks.
2320 */
2321 return rc;
James Smarta12e07b2006-12-02 13:35:30 -05002322 }
James Smart1ba981f2014-02-20 09:56:45 -05002323
James Smarta12e07b2006-12-02 13:35:30 -05002324 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2325
2326 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2327 "lpfc%d: soft_wwnn set. Value will take effect upon "
2328 "setting of the soft_wwpn\n", phba->brd_no);
2329
2330 return count;
2331}
James Smart1ba981f2014-02-20 09:56:45 -05002332static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002333 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002334
James Smart1ba981f2014-02-20 09:56:45 -05002335/**
2336 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2337 * Optimized Access Storage (OAS) operations.
2338 * @dev: class device that is converted into a Scsi_host.
2339 * @attr: device attribute, not used.
2340 * @buf: buffer for passing information.
2341 *
2342 * Returns:
2343 * value of count
2344 **/
2345static ssize_t
2346lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2347 char *buf)
2348{
2349 struct Scsi_Host *shost = class_to_shost(dev);
2350 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2351
2352 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2353 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2354}
2355
2356/**
2357 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2358 * Optimized Access Storage (OAS) operations.
2359 * @dev: class device that is converted into a Scsi_host.
2360 * @attr: device attribute, not used.
2361 * @buf: buffer for passing information.
2362 * @count: Size of the data buffer.
2363 *
2364 * Returns:
2365 * -EINVAL count is invalid, invalid wwpn byte invalid
2366 * -EPERM oas is not supported by hba
2367 * value of count on success
2368 **/
2369static ssize_t
2370lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2371 const char *buf, size_t count)
2372{
2373 struct Scsi_Host *shost = class_to_shost(dev);
2374 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2375 unsigned int cnt = count;
2376 uint8_t wwpn[WWN_SZ];
2377 int rc;
2378
James Smartf38fa0b2014-04-04 13:52:21 -04002379 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002380 return -EPERM;
2381
2382 /* count may include a LF at end of string */
2383 if (buf[cnt-1] == '\n')
2384 cnt--;
2385
2386 rc = lpfc_wwn_set(buf, cnt, wwpn);
2387 if (rc)
2388 return rc;
2389
2390 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2391 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2392 if (wwn_to_u64(wwpn) == 0)
2393 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2394 else
2395 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2396 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2397 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2398 return count;
2399}
2400static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2401 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2402
2403/**
James Smartc92c8412016-07-06 12:36:05 -07002404 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2405 * Optimized Access Storage (OAS) operations.
2406 * @dev: class device that is converted into a Scsi_host.
2407 * @attr: device attribute, not used.
2408 * @buf: buffer for passing information.
2409 *
2410 * Returns:
2411 * value of count
2412 **/
2413static ssize_t
2414lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2415 char *buf)
2416{
2417 struct Scsi_Host *shost = class_to_shost(dev);
2418 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2419
2420 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2421}
2422
2423/**
2424 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2425 * Optimized Access Storage (OAS) operations.
2426 * @dev: class device that is converted into a Scsi_host.
2427 * @attr: device attribute, not used.
2428 * @buf: buffer for passing information.
2429 * @count: Size of the data buffer.
2430 *
2431 * Returns:
2432 * -EINVAL count is invalid, invalid wwpn byte invalid
2433 * -EPERM oas is not supported by hba
2434 * value of count on success
2435 **/
2436static ssize_t
2437lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2438 const char *buf, size_t count)
2439{
2440 struct Scsi_Host *shost = class_to_shost(dev);
2441 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2442 unsigned int cnt = count;
2443 unsigned long val;
2444 int ret;
2445
2446 if (!phba->cfg_fof)
2447 return -EPERM;
2448
2449 /* count may include a LF at end of string */
2450 if (buf[cnt-1] == '\n')
2451 cnt--;
2452
2453 ret = kstrtoul(buf, 0, &val);
2454 if (ret || (val > 0x7f))
2455 return -EINVAL;
2456
2457 if (val)
2458 phba->cfg_oas_priority = (uint8_t)val;
2459 else
2460 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2461 return count;
2462}
2463static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2464 lpfc_oas_priority_show, lpfc_oas_priority_store);
2465
2466/**
James Smart1ba981f2014-02-20 09:56:45 -05002467 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2468 * for Optimized Access Storage (OAS) operations.
2469 * @dev: class device that is converted into a Scsi_host.
2470 * @attr: device attribute, not used.
2471 * @buf: buffer for passing information.
2472 *
2473 * Returns:
2474 * value of count on success
2475 **/
2476static ssize_t
2477lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2478 char *buf)
2479{
2480 struct Scsi_Host *shost = class_to_shost(dev);
2481 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2482
2483 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2484 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2485}
2486
2487/**
2488 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2489 * for Optimized Access Storage (OAS) operations.
2490 * @dev: class device that is converted into a Scsi_host.
2491 * @attr: device attribute, not used.
2492 * @buf: buffer for passing information.
2493 * @count: Size of the data buffer.
2494 *
2495 * Returns:
2496 * -EINVAL count is invalid, invalid wwpn byte invalid
2497 * -EPERM oas is not supported by hba
2498 * value of count on success
2499 **/
2500static ssize_t
2501lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2502 const char *buf, size_t count)
2503{
2504 struct Scsi_Host *shost = class_to_shost(dev);
2505 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2506 unsigned int cnt = count;
2507 uint8_t wwpn[WWN_SZ];
2508 int rc;
2509
James Smartf38fa0b2014-04-04 13:52:21 -04002510 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002511 return -EPERM;
2512
2513 /* count may include a LF at end of string */
2514 if (buf[cnt-1] == '\n')
2515 cnt--;
2516
2517 rc = lpfc_wwn_set(buf, cnt, wwpn);
2518 if (rc)
2519 return rc;
2520
2521 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2522 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2523 if (wwn_to_u64(wwpn) == 0)
2524 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2525 else
2526 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2527 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartc92c8412016-07-06 12:36:05 -07002528 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002529 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2530 return count;
2531}
2532static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2533 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2534
2535/**
2536 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2537 * of whether luns will be enabled or disabled
2538 * for Optimized Access Storage (OAS) operations.
2539 * @dev: class device that is converted into a Scsi_host.
2540 * @attr: device attribute, not used.
2541 * @buf: buffer for passing information.
2542 *
2543 * Returns:
2544 * size of formatted string.
2545 **/
2546static ssize_t
2547lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2548 char *buf)
2549{
2550 struct Scsi_Host *shost = class_to_shost(dev);
2551 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2552
2553 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2554}
2555
2556/**
2557 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2558 * of whether luns will be enabled or disabled
2559 * for Optimized Access Storage (OAS) operations.
2560 * @dev: class device that is converted into a Scsi_host.
2561 * @attr: device attribute, not used.
2562 * @buf: buffer for passing information.
2563 * @count: Size of the data buffer.
2564 *
2565 * Returns:
2566 * -EINVAL count is invalid, invalid wwpn byte invalid
2567 * -EPERM oas is not supported by hba
2568 * value of count on success
2569 **/
2570static ssize_t
2571lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2572 const char *buf, size_t count)
2573{
2574 struct Scsi_Host *shost = class_to_shost(dev);
2575 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2576 int val = 0;
2577
James Smartf38fa0b2014-04-04 13:52:21 -04002578 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002579 return -EPERM;
2580
2581 if (!isdigit(buf[0]))
2582 return -EINVAL;
2583
2584 if (sscanf(buf, "%i", &val) != 1)
2585 return -EINVAL;
2586
2587 if ((val != 0) && (val != 1))
2588 return -EINVAL;
2589
2590 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002591 return strlen(buf);
2592}
2593static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2594 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2595
2596/**
2597 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2598 * Storage (OAS) lun returned by the
2599 * lpfc_oas_lun_show function.
2600 * @dev: class device that is converted into a Scsi_host.
2601 * @attr: device attribute, not used.
2602 * @buf: buffer for passing information.
2603 *
2604 * Returns:
2605 * size of formatted string.
2606 **/
2607static ssize_t
2608lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2609 char *buf)
2610{
2611 struct Scsi_Host *shost = class_to_shost(dev);
2612 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2613
2614 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2615 return -EFAULT;
2616
2617 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2618}
2619static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2620 lpfc_oas_lun_status_show, NULL);
2621
2622
2623/**
2624 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2625 * (OAS) operations.
2626 * @phba: lpfc_hba pointer.
2627 * @ndlp: pointer to fcp target node.
2628 * @lun: the fc lun for setting oas state.
2629 * @oas_state: the oas state to be set to the lun.
2630 *
2631 * Returns:
2632 * SUCCESS : 0
2633 * -EPERM OAS is not enabled or not supported by this port.
2634 *
2635 */
2636static size_t
2637lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002638 uint8_t tgt_wwpn[], uint64_t lun,
2639 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002640{
2641
2642 int rc = 0;
2643
James Smartf38fa0b2014-04-04 13:52:21 -04002644 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002645 return -EPERM;
2646
2647 if (oas_state) {
2648 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002649 (struct lpfc_name *)tgt_wwpn,
2650 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002651 rc = -ENOMEM;
2652 } else {
2653 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2654 (struct lpfc_name *)tgt_wwpn, lun);
2655 }
2656 return rc;
2657
2658}
2659
2660/**
2661 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2662 * Access Storage (OAS) operations.
2663 * @phba: lpfc_hba pointer.
2664 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2665 * @tgt_wwpn: wwpn of the target associated with the returned lun
2666 * @lun_status: status of the lun returned lun
2667 *
2668 * Returns the first or next lun enabled for OAS operations for the vport/target
2669 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2670 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2671 *
2672 * Return:
2673 * lun that is OAS enabled for the vport/target
2674 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2675 */
2676static uint64_t
2677lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2678 uint8_t tgt_wwpn[], uint32_t *lun_status)
2679{
2680 uint64_t found_lun;
2681
2682 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2683 return NOT_OAS_ENABLED_LUN;
2684 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2685 phba->sli4_hba.oas_next_vpt_wwpn,
2686 (struct lpfc_name *)
2687 phba->sli4_hba.oas_next_tgt_wwpn,
2688 &phba->sli4_hba.oas_next_lun,
2689 (struct lpfc_name *)vpt_wwpn,
2690 (struct lpfc_name *)tgt_wwpn,
2691 &found_lun, lun_status))
2692 return found_lun;
2693 else
2694 return NOT_OAS_ENABLED_LUN;
2695}
2696
2697/**
2698 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2699 * @phba: lpfc_hba pointer.
2700 * @vpt_wwpn: vport wwpn by reference.
2701 * @tgt_wwpn: target wwpn by reference.
2702 * @lun: the fc lun for setting oas state.
2703 * @oas_state: the oas state to be set to the oas_lun.
2704 *
2705 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2706 * a lun for OAS operations.
2707 *
2708 * Return:
2709 * SUCCESS: 0
2710 * -ENOMEM: failed to enable an lun for OAS operations
2711 * -EPERM: OAS is not enabled
2712 */
2713static ssize_t
2714lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2715 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002716 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002717{
2718
2719 int rc;
2720
2721 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002722 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002723 return rc;
2724}
2725
2726/**
2727 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2728 * @dev: class device that is converted into a Scsi_host.
2729 * @attr: device attribute, not used.
2730 * @buf: buffer for passing information.
2731 *
2732 * This routine returns a lun enabled for OAS each time the function
2733 * is called.
2734 *
2735 * Returns:
2736 * SUCCESS: size of formatted string.
2737 * -EFAULT: target or vport wwpn was not set properly.
2738 * -EPERM: oas is not enabled.
2739 **/
2740static ssize_t
2741lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2742 char *buf)
2743{
2744 struct Scsi_Host *shost = class_to_shost(dev);
2745 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2746
2747 uint64_t oas_lun;
2748 int len = 0;
2749
James Smartf38fa0b2014-04-04 13:52:21 -04002750 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002751 return -EPERM;
2752
2753 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2754 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2755 return -EFAULT;
2756
2757 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2758 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2759 return -EFAULT;
2760
2761 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2762 phba->cfg_oas_tgt_wwpn,
2763 &phba->cfg_oas_lun_status);
2764 if (oas_lun != NOT_OAS_ENABLED_LUN)
2765 phba->cfg_oas_flags |= OAS_LUN_VALID;
2766
2767 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2768
2769 return len;
2770}
2771
2772/**
2773 * lpfc_oas_lun_store - Sets the OAS state for lun
2774 * @dev: class device that is converted into a Scsi_host.
2775 * @attr: device attribute, not used.
2776 * @buf: buffer for passing information.
2777 *
2778 * This function sets the OAS state for lun. Before this function is called,
2779 * the vport wwpn, target wwpn, and oas state need to be set.
2780 *
2781 * Returns:
2782 * SUCCESS: size of formatted string.
2783 * -EFAULT: target or vport wwpn was not set properly.
2784 * -EPERM: oas is not enabled.
2785 * size of formatted string.
2786 **/
2787static ssize_t
2788lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2789 const char *buf, size_t count)
2790{
2791 struct Scsi_Host *shost = class_to_shost(dev);
2792 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2793 uint64_t scsi_lun;
2794 ssize_t rc;
2795
James Smartf38fa0b2014-04-04 13:52:21 -04002796 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002797 return -EPERM;
2798
2799 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2800 return -EFAULT;
2801
2802 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2803 return -EFAULT;
2804
2805 if (!isdigit(buf[0]))
2806 return -EINVAL;
2807
2808 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2809 return -EINVAL;
2810
2811 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002812 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2813 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002814 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2815 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartc92c8412016-07-06 12:36:05 -07002816 phba->cfg_oas_priority, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002817
2818 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002819 phba->cfg_oas_tgt_wwpn, scsi_lun,
2820 phba->cfg_oas_lun_state,
2821 phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002822 if (rc)
2823 return rc;
2824
2825 return count;
2826}
2827static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2828 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002829
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002830static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002831module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002832MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2833 " 0 - none,"
2834 " 1 - poll with interrupts enabled"
2835 " 3 - poll and disable FCP ring interrupts");
2836
Tony Jonesee959b02008-02-22 00:13:36 +01002837static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2838 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002839
James Smart92d7f7b2007-06-17 19:56:38 -05002840int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002841module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002842MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2843 " 0 - auto (SLI-3 if supported),"
2844 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2845 " 3 - select SLI-3");
2846
James Smart15672312010-04-06 14:49:03 -04002847int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002848module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002849MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2850lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002851lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002852static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002853
James Smart7d791df2011-07-22 18:37:52 -04002854LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2855 "FCF Fast failover=1 Priority failover=2");
2856
James Smartc14e9952013-03-01 16:38:01 -05002857int lpfc_enable_rrq = 2;
James Smartab56dc22011-02-16 12:39:57 -05002858module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002859MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2860lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002861/*
2862# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2863# 0x0 = disabled, XRI/OXID use not tracked.
2864# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2865# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2866*/
2867lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002868static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2869
dea31012005-04-17 16:05:31 -05002870/*
James Smart84d1b002010-02-12 14:42:33 -05002871# lpfc_suppress_link_up: Bring link up at initialization
2872# 0x0 = bring link up (issue MBX_INIT_LINK)
2873# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2874# 0x2 = never bring up link
2875# Default value is 0.
2876*/
James Smarte40a02c2010-02-26 14:13:54 -05002877LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2878 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2879 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002880/*
2881# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2882# 1 - (1024)
2883# 2 - (2048)
2884# 3 - (3072)
2885# 4 - (4096)
2886# 5 - (5120)
2887*/
2888static ssize_t
2889lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2890{
2891 struct Scsi_Host *shost = class_to_shost(dev);
2892 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2893
2894 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2895}
2896
2897static DEVICE_ATTR(iocb_hw, S_IRUGO,
2898 lpfc_iocb_hw_show, NULL);
2899static ssize_t
2900lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2901{
2902 struct Scsi_Host *shost = class_to_shost(dev);
2903 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2904
2905 return snprintf(buf, PAGE_SIZE, "%d\n",
2906 phba->sli.ring[LPFC_ELS_RING].txq_max);
2907}
2908
2909static DEVICE_ATTR(txq_hw, S_IRUGO,
2910 lpfc_txq_hw_show, NULL);
2911static ssize_t
2912lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2913 char *buf)
2914{
2915 struct Scsi_Host *shost = class_to_shost(dev);
2916 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2917
2918 return snprintf(buf, PAGE_SIZE, "%d\n",
2919 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2920}
2921
2922static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2923 lpfc_txcmplq_hw_show, NULL);
2924
2925int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002926module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002927MODULE_PARM_DESC(lpfc_iocb_cnt,
2928 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2929lpfc_param_show(iocb_cnt);
2930lpfc_param_init(iocb_cnt, 2, 1, 5);
2931static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2932 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002933
2934/*
James Smartc01f3202006-08-18 17:47:08 -04002935# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2936# until the timer expires. Value range is [0,255]. Default value is 30.
2937*/
2938static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2939static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2940module_param(lpfc_nodev_tmo, int, 0);
2941MODULE_PARM_DESC(lpfc_nodev_tmo,
2942 "Seconds driver will hold I/O waiting "
2943 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002944
2945/**
James Smart3621a712009-04-06 18:47:14 -04002946 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002947 * @dev: class converted to a Scsi_host structure.
2948 * @attr: device attribute, not used.
2949 * @buf: on return contains the dev loss timeout in decimal.
2950 *
2951 * Returns: size of formatted string.
2952 **/
James Smartc01f3202006-08-18 17:47:08 -04002953static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002954lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2955 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002956{
Tony Jonesee959b02008-02-22 00:13:36 +01002957 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002958 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002959
James Smart3de2a652007-08-02 11:09:59 -04002960 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002961}
2962
James Smarte59058c2008-08-24 21:49:00 -04002963/**
James Smart3621a712009-04-06 18:47:14 -04002964 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002965 * @vport: lpfc vport structure pointer.
2966 * @val: contains the nodev timeout value.
2967 *
2968 * Description:
2969 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2970 * a kernel error message is printed and zero is returned.
2971 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2972 * Otherwise nodev tmo is set to the default value.
2973 *
2974 * Returns:
2975 * zero if already set or if val is in range
2976 * -EINVAL val out of range
2977 **/
James Smartc01f3202006-08-18 17:47:08 -04002978static int
James Smart3de2a652007-08-02 11:09:59 -04002979lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002980{
James Smart3de2a652007-08-02 11:09:59 -04002981 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2982 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2983 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002984 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002985 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002986 "parameter because devloss_tmo is "
2987 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002988 return 0;
2989 }
2990
2991 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002992 vport->cfg_nodev_tmo = val;
2993 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002994 return 0;
2995 }
James Smarte8b62012007-08-02 11:10:09 -04002996 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2997 "0400 lpfc_nodev_tmo attribute cannot be set to"
2998 " %d, allowed range is [%d, %d]\n",
2999 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003000 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003001 return -EINVAL;
3002}
3003
James Smarte59058c2008-08-24 21:49:00 -04003004/**
James Smart3621a712009-04-06 18:47:14 -04003005 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003006 * @vport: lpfc vport structure pointer.
3007 *
3008 * Description:
3009 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3010 **/
James Smart7054a602007-04-25 09:52:34 -04003011static void
James Smart3de2a652007-08-02 11:09:59 -04003012lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003013{
James Smart858c9f62007-06-17 19:56:39 -05003014 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003015 struct lpfc_nodelist *ndlp;
3016
James Smart51ef4c22007-08-02 11:10:31 -04003017 shost = lpfc_shost_from_vport(vport);
3018 spin_lock_irq(shost->host_lock);
3019 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05003020 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003021 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3022 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003023}
3024
James Smarte59058c2008-08-24 21:49:00 -04003025/**
James Smart3621a712009-04-06 18:47:14 -04003026 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003027 * @vport: lpfc vport structure pointer.
3028 * @val: contains the tmo value.
3029 *
3030 * Description:
3031 * If the devloss tmo is already set or the vport dev loss tmo has changed
3032 * then a kernel error message is printed and zero is returned.
3033 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3034 * Otherwise nodev tmo is set to the default value.
3035 *
3036 * Returns:
3037 * zero if already set or if val is in range
3038 * -EINVAL val out of range
3039 **/
James Smartc01f3202006-08-18 17:47:08 -04003040static int
James Smart3de2a652007-08-02 11:09:59 -04003041lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003042{
James Smart3de2a652007-08-02 11:09:59 -04003043 if (vport->dev_loss_tmo_changed ||
3044 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003045 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3046 "0401 Ignoring change to nodev_tmo "
3047 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003048 return 0;
3049 }
James Smartc01f3202006-08-18 17:47:08 -04003050 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003051 vport->cfg_nodev_tmo = val;
3052 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003053 /*
3054 * For compat: set the fc_host dev loss so new rports
3055 * will get the value.
3056 */
3057 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003058 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003059 return 0;
3060 }
James Smarte8b62012007-08-02 11:10:09 -04003061 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3062 "0403 lpfc_nodev_tmo attribute cannot be set to"
3063 "%d, allowed range is [%d, %d]\n",
3064 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003065 return -EINVAL;
3066}
3067
James Smart3de2a652007-08-02 11:09:59 -04003068lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003069
Tony Jonesee959b02008-02-22 00:13:36 +01003070static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3071 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003072
3073/*
3074# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3075# disappear until the timer expires. Value range is [0,255]. Default
3076# value is 30.
3077*/
James Smartab56dc22011-02-16 12:39:57 -05003078module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003079MODULE_PARM_DESC(lpfc_devloss_tmo,
3080 "Seconds driver will hold I/O waiting "
3081 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003082lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3083 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3084lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003085
3086/**
James Smart3621a712009-04-06 18:47:14 -04003087 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003088 * @vport: lpfc vport structure pointer.
3089 * @val: contains the tmo value.
3090 *
3091 * Description:
3092 * If val is in a valid range then set the vport nodev tmo,
3093 * devloss tmo, also set the vport dev loss tmo changed flag.
3094 * Else a kernel error message is printed.
3095 *
3096 * Returns:
3097 * zero if val is in range
3098 * -EINVAL val out of range
3099 **/
James Smartc01f3202006-08-18 17:47:08 -04003100static int
James Smart3de2a652007-08-02 11:09:59 -04003101lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003102{
3103 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003104 vport->cfg_nodev_tmo = val;
3105 vport->cfg_devloss_tmo = val;
3106 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003107 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003108 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003109 return 0;
3110 }
3111
James Smarte8b62012007-08-02 11:10:09 -04003112 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3113 "0404 lpfc_devloss_tmo attribute cannot be set to"
3114 " %d, allowed range is [%d, %d]\n",
3115 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003116 return -EINVAL;
3117}
3118
James Smart3de2a652007-08-02 11:09:59 -04003119lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003120static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3121 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003122
3123/*
dea31012005-04-17 16:05:31 -05003124# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3125# deluged with LOTS of information.
3126# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003127# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003128*/
James Smartf4b4c682009-05-22 14:53:12 -04003129LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003130 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003131
3132/*
James Smart7ee5d432007-10-27 13:37:17 -04003133# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3134# objects that have been registered with the nameserver after login.
3135*/
James Smartcf971242012-03-01 22:37:32 -05003136LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003137 "Deregister nameserver objects before LOGO");
3138
3139/*
dea31012005-04-17 16:05:31 -05003140# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003141# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3142# If this parameter value is greater than 1/8th the maximum number of exchanges
3143# supported by the HBA port, then the lun queue depth will be reduced to
3144# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003145*/
James Smart572709e2013-07-15 18:32:43 -04003146LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003147 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003148
3149/*
James Smart7dc517d2010-07-14 15:32:10 -04003150# tgt_queue_depth: This parameter is used to limit the number of outstanding
3151# commands per target port. Value range is [10,65535]. Default value is 65535.
3152*/
3153LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003154 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003155
3156/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003157# hba_queue_depth: This parameter is used to limit the number of outstanding
3158# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3159# value is greater than the maximum number of exchanges supported by the HBA,
3160# then maximum number of exchanges supported by the HBA is used to determine
3161# the hba_queue_depth.
3162*/
3163LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3164 "Max number of FCP commands we can queue to a lpfc HBA");
3165
3166/*
James Smart92d7f7b2007-06-17 19:56:38 -05003167# peer_port_login: This parameter allows/prevents logins
3168# between peer ports hosted on the same physical port.
3169# When this parameter is set 0 peer ports of same physical port
3170# are not allowed to login to each other.
3171# When this parameter is set 1 peer ports of same physical port
3172# are allowed to login to each other.
3173# Default value of this parameter is 0.
3174*/
James Smart3de2a652007-08-02 11:09:59 -04003175LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3176 "Allow peer ports on the same physical port to login to each "
3177 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003178
3179/*
James Smart3de2a652007-08-02 11:09:59 -04003180# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003181# between Virtual Ports and remote initiators.
3182# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3183# other initiators and will attempt to PLOGI all remote ports.
3184# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3185# remote ports and will not attempt to PLOGI to other initiators.
3186# This parameter does not restrict to the physical port.
3187# This parameter does not restrict logins to Fabric resident remote ports.
3188# Default value of this parameter is 1.
3189*/
James Smart3de2a652007-08-02 11:09:59 -04003190static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003191module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003192MODULE_PARM_DESC(lpfc_restrict_login,
3193 "Restrict virtual ports login to remote initiators.");
3194lpfc_vport_param_show(restrict_login);
3195
James Smarte59058c2008-08-24 21:49:00 -04003196/**
James Smart3621a712009-04-06 18:47:14 -04003197 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003198 * @vport: lpfc vport structure pointer.
3199 * @val: contains the restrict login value.
3200 *
3201 * Description:
3202 * If val is not in a valid range then log a kernel error message and set
3203 * the vport restrict login to one.
3204 * If the port type is physical clear the restrict login flag and return.
3205 * Else set the restrict login flag to val.
3206 *
3207 * Returns:
3208 * zero if val is in range
3209 * -EINVAL val out of range
3210 **/
James Smart3de2a652007-08-02 11:09:59 -04003211static int
3212lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3213{
3214 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003215 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003216 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003217 "be set to %d, allowed range is [0, 1]\n",
3218 val);
James Smart3de2a652007-08-02 11:09:59 -04003219 vport->cfg_restrict_login = 1;
3220 return -EINVAL;
3221 }
3222 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3223 vport->cfg_restrict_login = 0;
3224 return 0;
3225 }
3226 vport->cfg_restrict_login = val;
3227 return 0;
3228}
3229
James Smarte59058c2008-08-24 21:49:00 -04003230/**
James Smart3621a712009-04-06 18:47:14 -04003231 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003232 * @vport: lpfc vport structure pointer.
3233 * @val: contains the restrict login value.
3234 *
3235 * Description:
3236 * If val is not in a valid range then log a kernel error message and set
3237 * the vport restrict login to one.
3238 * If the port type is physical and the val is not zero log a kernel
3239 * error message, clear the restrict login flag and return zero.
3240 * Else set the restrict login flag to val.
3241 *
3242 * Returns:
3243 * zero if val is in range
3244 * -EINVAL val out of range
3245 **/
James Smart3de2a652007-08-02 11:09:59 -04003246static int
3247lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3248{
3249 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003250 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003251 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003252 "be set to %d, allowed range is [0, 1]\n",
3253 val);
James Smart3de2a652007-08-02 11:09:59 -04003254 vport->cfg_restrict_login = 1;
3255 return -EINVAL;
3256 }
3257 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003258 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3259 "0468 lpfc_restrict_login must be 0 for "
3260 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003261 vport->cfg_restrict_login = 0;
3262 return 0;
3263 }
3264 vport->cfg_restrict_login = val;
3265 return 0;
3266}
3267lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003268static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3269 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003270
3271/*
dea31012005-04-17 16:05:31 -05003272# Some disk devices have a "select ID" or "select Target" capability.
3273# From a protocol standpoint "select ID" usually means select the
3274# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3275# annex" which contains a table that maps a "select ID" (a number
3276# between 0 and 7F) to an ALPA. By default, for compatibility with
3277# older drivers, the lpfc driver scans this table from low ALPA to high
3278# ALPA.
3279#
3280# Turning on the scan-down variable (on = 1, off = 0) will
3281# cause the lpfc driver to use an inverted table, effectively
3282# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3283#
3284# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3285# and will not work across a fabric. Also this parameter will take
3286# effect only in the case when ALPA map is not available.)
3287*/
James Smart3de2a652007-08-02 11:09:59 -04003288LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3289 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003290
3291/*
dea31012005-04-17 16:05:31 -05003292# lpfc_topology: link topology for init link
3293# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003294# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003295# 0x02 = attempt point-to-point mode only
3296# 0x04 = attempt loop mode only
3297# 0x06 = attempt point-to-point mode then loop
3298# Set point-to-point mode if you want to run as an N_Port.
3299# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3300# Default value is 0.
3301*/
James Smarte59058c2008-08-24 21:49:00 -04003302
3303/**
James Smart3621a712009-04-06 18:47:14 -04003304 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003305 * @phba: lpfc_hba pointer.
3306 * @val: topology value.
3307 *
3308 * Description:
3309 * If val is in a valid range then set the adapter's topology field and
3310 * issue a lip; if the lip fails reset the topology to the old value.
3311 *
3312 * If the value is not in range log a kernel error message and return an error.
3313 *
3314 * Returns:
3315 * zero if val is in range and lip okay
3316 * non-zero return value from lpfc_issue_lip()
3317 * -EINVAL val out of range
3318 **/
James Smarta257bf92009-04-06 18:48:10 -04003319static ssize_t
3320lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3321 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003322{
James Smarta257bf92009-04-06 18:48:10 -04003323 struct Scsi_Host *shost = class_to_shost(dev);
3324 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3325 struct lpfc_hba *phba = vport->phba;
3326 int val = 0;
3327 int nolip = 0;
3328 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003329 int err;
3330 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003331
3332 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3333 nolip = 1;
3334 val_buf = &buf[strlen("nolip ")];
3335 }
3336
3337 if (!isdigit(val_buf[0]))
3338 return -EINVAL;
3339 if (sscanf(val_buf, "%i", &val) != 1)
3340 return -EINVAL;
3341
James Smart83108bd2008-01-11 01:53:09 -05003342 if (val >= 0 && val <= 6) {
3343 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003344 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3345 val == 4) {
3346 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3347 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003348 val);
James Smartff78d8f2011-12-13 13:21:35 -05003349 return -EINVAL;
3350 }
James Smartd38dd522015-08-31 16:48:17 -04003351 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3352 val == 4) {
3353 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3354 "3114 Loop mode not supported\n");
3355 return -EINVAL;
3356 }
3357 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003358 if (nolip)
3359 return strlen(buf);
3360
James Smart88a2cfb2011-07-22 18:36:33 -04003361 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3362 "3054 lpfc_topology changed from %d to %d\n",
3363 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003364 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3365 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003366 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003367 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003368 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003369 return -EINVAL;
3370 } else
3371 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003372 }
3373 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3374 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3375 "allowed range is [0, 6]\n",
3376 phba->brd_no, val);
3377 return -EINVAL;
3378}
3379static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05003380module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003381MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
3382lpfc_param_show(topology)
3383lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01003384static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003385 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003386
James Smart21e9a0a2009-05-22 14:53:21 -04003387/**
3388 * lpfc_static_vport_show: Read callback function for
3389 * lpfc_static_vport sysfs file.
3390 * @dev: Pointer to class device object.
3391 * @attr: device attribute structure.
3392 * @buf: Data buffer.
3393 *
3394 * This function is the read call back function for
3395 * lpfc_static_vport sysfs file. The lpfc_static_vport
3396 * sysfs file report the mageability of the vport.
3397 **/
3398static ssize_t
3399lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3400 char *buf)
3401{
3402 struct Scsi_Host *shost = class_to_shost(dev);
3403 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3404 if (vport->vport_flag & STATIC_VPORT)
3405 sprintf(buf, "1\n");
3406 else
3407 sprintf(buf, "0\n");
3408
3409 return strlen(buf);
3410}
3411
3412/*
3413 * Sysfs attribute to control the statistical data collection.
3414 */
3415static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3416 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003417
3418/**
James Smart3621a712009-04-06 18:47:14 -04003419 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003420 * @dev: Pointer to class device.
3421 * @buf: Data buffer.
3422 * @count: Size of the data buffer.
3423 *
3424 * This function get called when an user write to the lpfc_stat_data_ctrl
3425 * sysfs file. This function parse the command written to the sysfs file
3426 * and take appropriate action. These commands are used for controlling
3427 * driver statistical data collection.
3428 * Following are the command this function handles.
3429 *
3430 * setbucket <bucket_type> <base> <step>
3431 * = Set the latency buckets.
3432 * destroybucket = destroy all the buckets.
3433 * start = start data collection
3434 * stop = stop data collection
3435 * reset = reset the collected data
3436 **/
3437static ssize_t
3438lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3439 const char *buf, size_t count)
3440{
3441 struct Scsi_Host *shost = class_to_shost(dev);
3442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3443 struct lpfc_hba *phba = vport->phba;
3444#define LPFC_MAX_DATA_CTRL_LEN 1024
3445 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3446 unsigned long i;
3447 char *str_ptr, *token;
3448 struct lpfc_vport **vports;
3449 struct Scsi_Host *v_shost;
3450 char *bucket_type_str, *base_str, *step_str;
3451 unsigned long base, step, bucket_type;
3452
3453 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003454 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003455 return -EINVAL;
3456
James Smarteb016562014-09-03 12:58:06 -04003457 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003458 str_ptr = &bucket_data[0];
3459 /* Ignore this token - this is command token */
3460 token = strsep(&str_ptr, "\t ");
3461 if (!token)
3462 return -EINVAL;
3463
3464 bucket_type_str = strsep(&str_ptr, "\t ");
3465 if (!bucket_type_str)
3466 return -EINVAL;
3467
3468 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3469 bucket_type = LPFC_LINEAR_BUCKET;
3470 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3471 bucket_type = LPFC_POWER2_BUCKET;
3472 else
3473 return -EINVAL;
3474
3475 base_str = strsep(&str_ptr, "\t ");
3476 if (!base_str)
3477 return -EINVAL;
3478 base = simple_strtoul(base_str, NULL, 0);
3479
3480 step_str = strsep(&str_ptr, "\t ");
3481 if (!step_str)
3482 return -EINVAL;
3483 step = simple_strtoul(step_str, NULL, 0);
3484 if (!step)
3485 return -EINVAL;
3486
3487 /* Block the data collection for every vport */
3488 vports = lpfc_create_vport_work_array(phba);
3489 if (vports == NULL)
3490 return -ENOMEM;
3491
James Smartf4b4c682009-05-22 14:53:12 -04003492 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003493 v_shost = lpfc_shost_from_vport(vports[i]);
3494 spin_lock_irq(v_shost->host_lock);
3495 /* Block and reset data collection */
3496 vports[i]->stat_data_blocked = 1;
3497 if (vports[i]->stat_data_enabled)
3498 lpfc_vport_reset_stat_data(vports[i]);
3499 spin_unlock_irq(v_shost->host_lock);
3500 }
3501
3502 /* Set the bucket attributes */
3503 phba->bucket_type = bucket_type;
3504 phba->bucket_base = base;
3505 phba->bucket_step = step;
3506
James Smartf4b4c682009-05-22 14:53:12 -04003507 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003508 v_shost = lpfc_shost_from_vport(vports[i]);
3509
3510 /* Unblock data collection */
3511 spin_lock_irq(v_shost->host_lock);
3512 vports[i]->stat_data_blocked = 0;
3513 spin_unlock_irq(v_shost->host_lock);
3514 }
3515 lpfc_destroy_vport_work_array(phba, vports);
3516 return strlen(buf);
3517 }
3518
3519 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3520 vports = lpfc_create_vport_work_array(phba);
3521 if (vports == NULL)
3522 return -ENOMEM;
3523
James Smartf4b4c682009-05-22 14:53:12 -04003524 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003525 v_shost = lpfc_shost_from_vport(vports[i]);
3526 spin_lock_irq(shost->host_lock);
3527 vports[i]->stat_data_blocked = 1;
3528 lpfc_free_bucket(vport);
3529 vport->stat_data_enabled = 0;
3530 vports[i]->stat_data_blocked = 0;
3531 spin_unlock_irq(shost->host_lock);
3532 }
3533 lpfc_destroy_vport_work_array(phba, vports);
3534 phba->bucket_type = LPFC_NO_BUCKET;
3535 phba->bucket_base = 0;
3536 phba->bucket_step = 0;
3537 return strlen(buf);
3538 }
3539
3540 if (!strncmp(buf, "start", strlen("start"))) {
3541 /* If no buckets configured return error */
3542 if (phba->bucket_type == LPFC_NO_BUCKET)
3543 return -EINVAL;
3544 spin_lock_irq(shost->host_lock);
3545 if (vport->stat_data_enabled) {
3546 spin_unlock_irq(shost->host_lock);
3547 return strlen(buf);
3548 }
3549 lpfc_alloc_bucket(vport);
3550 vport->stat_data_enabled = 1;
3551 spin_unlock_irq(shost->host_lock);
3552 return strlen(buf);
3553 }
3554
3555 if (!strncmp(buf, "stop", strlen("stop"))) {
3556 spin_lock_irq(shost->host_lock);
3557 if (vport->stat_data_enabled == 0) {
3558 spin_unlock_irq(shost->host_lock);
3559 return strlen(buf);
3560 }
3561 lpfc_free_bucket(vport);
3562 vport->stat_data_enabled = 0;
3563 spin_unlock_irq(shost->host_lock);
3564 return strlen(buf);
3565 }
3566
3567 if (!strncmp(buf, "reset", strlen("reset"))) {
3568 if ((phba->bucket_type == LPFC_NO_BUCKET)
3569 || !vport->stat_data_enabled)
3570 return strlen(buf);
3571 spin_lock_irq(shost->host_lock);
3572 vport->stat_data_blocked = 1;
3573 lpfc_vport_reset_stat_data(vport);
3574 vport->stat_data_blocked = 0;
3575 spin_unlock_irq(shost->host_lock);
3576 return strlen(buf);
3577 }
3578 return -EINVAL;
3579}
3580
3581
3582/**
James Smart3621a712009-04-06 18:47:14 -04003583 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003584 * @dev: Pointer to class device object.
3585 * @buf: Data buffer.
3586 *
3587 * This function is the read call back function for
3588 * lpfc_stat_data_ctrl sysfs file. This function report the
3589 * current statistical data collection state.
3590 **/
3591static ssize_t
3592lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3593 char *buf)
3594{
3595 struct Scsi_Host *shost = class_to_shost(dev);
3596 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3597 struct lpfc_hba *phba = vport->phba;
3598 int index = 0;
3599 int i;
3600 char *bucket_type;
3601 unsigned long bucket_value;
3602
3603 switch (phba->bucket_type) {
3604 case LPFC_LINEAR_BUCKET:
3605 bucket_type = "linear";
3606 break;
3607 case LPFC_POWER2_BUCKET:
3608 bucket_type = "power2";
3609 break;
3610 default:
3611 bucket_type = "No Bucket";
3612 break;
3613 }
3614
3615 sprintf(&buf[index], "Statistical Data enabled :%d, "
3616 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3617 " Bucket step :%d\nLatency Ranges :",
3618 vport->stat_data_enabled, vport->stat_data_blocked,
3619 bucket_type, phba->bucket_base, phba->bucket_step);
3620 index = strlen(buf);
3621 if (phba->bucket_type != LPFC_NO_BUCKET) {
3622 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3623 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3624 bucket_value = phba->bucket_base +
3625 phba->bucket_step * i;
3626 else
3627 bucket_value = phba->bucket_base +
3628 (1 << i) * phba->bucket_step;
3629
3630 if (index + 10 > PAGE_SIZE)
3631 break;
3632 sprintf(&buf[index], "%08ld ", bucket_value);
3633 index = strlen(buf);
3634 }
3635 }
3636 sprintf(&buf[index], "\n");
3637 return strlen(buf);
3638}
3639
3640/*
3641 * Sysfs attribute to control the statistical data collection.
3642 */
3643static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3644 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3645
3646/*
3647 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3648 */
3649
3650/*
3651 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3652 * for each target.
3653 */
3654#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3655#define MAX_STAT_DATA_SIZE_PER_TARGET \
3656 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3657
3658
3659/**
James Smart3621a712009-04-06 18:47:14 -04003660 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003661 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003662 * @kobj: Pointer to the kernel object
3663 * @bin_attr: Attribute object
3664 * @buff: Buffer pointer
3665 * @off: File offset
3666 * @count: Buffer size
3667 *
3668 * This function is the read call back function for lpfc_drvr_stat_data
3669 * sysfs file. This function export the statistical data to user
3670 * applications.
3671 **/
3672static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003673sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3674 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003675 char *buf, loff_t off, size_t count)
3676{
3677 struct device *dev = container_of(kobj, struct device,
3678 kobj);
3679 struct Scsi_Host *shost = class_to_shost(dev);
3680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3681 struct lpfc_hba *phba = vport->phba;
3682 int i = 0, index = 0;
3683 unsigned long nport_index;
3684 struct lpfc_nodelist *ndlp = NULL;
3685 nport_index = (unsigned long)off /
3686 MAX_STAT_DATA_SIZE_PER_TARGET;
3687
3688 if (!vport->stat_data_enabled || vport->stat_data_blocked
3689 || (phba->bucket_type == LPFC_NO_BUCKET))
3690 return 0;
3691
3692 spin_lock_irq(shost->host_lock);
3693 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3694 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3695 continue;
3696
3697 if (nport_index > 0) {
3698 nport_index--;
3699 continue;
3700 }
3701
3702 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3703 > count)
3704 break;
3705
3706 if (!ndlp->lat_data)
3707 continue;
3708
3709 /* Print the WWN */
3710 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3711 ndlp->nlp_portname.u.wwn[0],
3712 ndlp->nlp_portname.u.wwn[1],
3713 ndlp->nlp_portname.u.wwn[2],
3714 ndlp->nlp_portname.u.wwn[3],
3715 ndlp->nlp_portname.u.wwn[4],
3716 ndlp->nlp_portname.u.wwn[5],
3717 ndlp->nlp_portname.u.wwn[6],
3718 ndlp->nlp_portname.u.wwn[7]);
3719
3720 index = strlen(buf);
3721
3722 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3723 sprintf(&buf[index], "%010u,",
3724 ndlp->lat_data[i].cmd_count);
3725 index = strlen(buf);
3726 }
3727 sprintf(&buf[index], "\n");
3728 index = strlen(buf);
3729 }
3730 spin_unlock_irq(shost->host_lock);
3731 return index;
3732}
3733
3734static struct bin_attribute sysfs_drvr_stat_data_attr = {
3735 .attr = {
3736 .name = "lpfc_drvr_stat_data",
3737 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003738 },
3739 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3740 .read = sysfs_drvr_stat_data_read,
3741 .write = NULL,
3742};
3743
dea31012005-04-17 16:05:31 -05003744/*
3745# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3746# connection.
James Smart76a95d72010-11-20 23:11:48 -05003747# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003748*/
James Smarte59058c2008-08-24 21:49:00 -04003749/**
James Smart3621a712009-04-06 18:47:14 -04003750 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003751 * @phba: lpfc_hba pointer.
3752 * @val: link speed value.
3753 *
3754 * Description:
3755 * If val is in a valid range then set the adapter's link speed field and
3756 * issue a lip; if the lip fails reset the link speed to the old value.
3757 *
3758 * Notes:
3759 * If the value is not in range log a kernel error message and return an error.
3760 *
3761 * Returns:
3762 * zero if val is in range and lip okay.
3763 * non-zero return value from lpfc_issue_lip()
3764 * -EINVAL val out of range
3765 **/
James Smarta257bf92009-04-06 18:48:10 -04003766static ssize_t
3767lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3768 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003769{
James Smarta257bf92009-04-06 18:48:10 -04003770 struct Scsi_Host *shost = class_to_shost(dev);
3771 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3772 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003773 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003774 int nolip = 0;
3775 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003776 int err;
3777 uint32_t prev_val;
3778
James Smarta257bf92009-04-06 18:48:10 -04003779 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3780 nolip = 1;
3781 val_buf = &buf[strlen("nolip ")];
3782 }
3783
3784 if (!isdigit(val_buf[0]))
3785 return -EINVAL;
3786 if (sscanf(val_buf, "%i", &val) != 1)
3787 return -EINVAL;
3788
James Smart88a2cfb2011-07-22 18:36:33 -04003789 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3790 "3055 lpfc_link_speed changed from %d to %d %s\n",
3791 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3792
James Smart76a95d72010-11-20 23:11:48 -05003793 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3794 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3795 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3796 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3797 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04003798 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3799 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05003800 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3801 "2879 lpfc_link_speed attribute cannot be set "
3802 "to %d. Speed is not supported by this port.\n",
3803 val);
James Smart83108bd2008-01-11 01:53:09 -05003804 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003805 }
James Smartff78d8f2011-12-13 13:21:35 -05003806 if (val == LPFC_USER_LINK_SPEED_16G &&
3807 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3809 "3112 lpfc_link_speed attribute cannot be set "
3810 "to %d. Speed is not supported in loop mode.\n",
3811 val);
3812 return -EINVAL;
3813 }
James Smart76a95d72010-11-20 23:11:48 -05003814 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3815 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003816 prev_val = phba->cfg_link_speed;
3817 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003818 if (nolip)
3819 return strlen(buf);
3820
James Smart83108bd2008-01-11 01:53:09 -05003821 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003822 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003823 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003824 return -EINVAL;
3825 } else
3826 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003827 }
James Smart83108bd2008-01-11 01:53:09 -05003828 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003829 "0469 lpfc_link_speed attribute cannot be set to %d, "
3830 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003831 return -EINVAL;
3832}
3833
3834static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003835module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003836MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3837lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003838
3839/**
James Smart3621a712009-04-06 18:47:14 -04003840 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003841 * @phba: lpfc_hba pointer.
3842 * @val: link speed value.
3843 *
3844 * Description:
3845 * If val is in a valid range then set the adapter's link speed field.
3846 *
3847 * Notes:
3848 * If the value is not in range log a kernel error message, clear the link
3849 * speed and return an error.
3850 *
3851 * Returns:
3852 * zero if val saved.
3853 * -EINVAL val out of range
3854 **/
James Smart83108bd2008-01-11 01:53:09 -05003855static int
3856lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3857{
James Smartff78d8f2011-12-13 13:21:35 -05003858 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3859 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3860 "3111 lpfc_link_speed of %d cannot "
3861 "support loop mode, setting topology to default.\n",
3862 val);
3863 phba->cfg_topology = 0;
3864 }
James Smart76a95d72010-11-20 23:11:48 -05003865 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3866 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003867 phba->cfg_link_speed = val;
3868 return 0;
3869 }
3870 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003871 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003872 "be set to %d, allowed values are "
3873 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003874 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003875 return -EINVAL;
3876}
3877
Tony Jonesee959b02008-02-22 00:13:36 +01003878static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003879 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003880
3881/*
James Smart0d878412009-10-02 15:16:56 -04003882# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3883# 0 = aer disabled or not supported
3884# 1 = aer supported and enabled (default)
3885# Value range is [0,1]. Default value is 1.
3886*/
3887
3888/**
3889 * lpfc_aer_support_store - Set the adapter for aer support
3890 *
3891 * @dev: class device that is converted into a Scsi_host.
3892 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003893 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003894 * @count: unused variable.
3895 *
3896 * Description:
3897 * If the val is 1 and currently the device's AER capability was not
3898 * enabled, invoke the kernel's enable AER helper routine, trying to
3899 * enable the device's AER capability. If the helper routine enabling
3900 * AER returns success, update the device's cfg_aer_support flag to
3901 * indicate AER is supported by the device; otherwise, if the device
3902 * AER capability is already enabled to support AER, then do nothing.
3903 *
3904 * If the val is 0 and currently the device's AER support was enabled,
3905 * invoke the kernel's disable AER helper routine. After that, update
3906 * the device's cfg_aer_support flag to indicate AER is not supported
3907 * by the device; otherwise, if the device AER capability is already
3908 * disabled from supporting AER, then do nothing.
3909 *
3910 * Returns:
3911 * length of the buf on success if val is in range the intended mode
3912 * is supported.
3913 * -EINVAL if val out of range or intended mode is not supported.
3914 **/
3915static ssize_t
3916lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3917 const char *buf, size_t count)
3918{
3919 struct Scsi_Host *shost = class_to_shost(dev);
3920 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3921 struct lpfc_hba *phba = vport->phba;
3922 int val = 0, rc = -EINVAL;
3923
3924 if (!isdigit(buf[0]))
3925 return -EINVAL;
3926 if (sscanf(buf, "%i", &val) != 1)
3927 return -EINVAL;
3928
3929 switch (val) {
3930 case 0:
3931 if (phba->hba_flag & HBA_AER_ENABLED) {
3932 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3933 if (!rc) {
3934 spin_lock_irq(&phba->hbalock);
3935 phba->hba_flag &= ~HBA_AER_ENABLED;
3936 spin_unlock_irq(&phba->hbalock);
3937 phba->cfg_aer_support = 0;
3938 rc = strlen(buf);
3939 } else
James Smart891478a2009-11-18 15:40:23 -05003940 rc = -EPERM;
3941 } else {
James Smart0d878412009-10-02 15:16:56 -04003942 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003943 rc = strlen(buf);
3944 }
James Smart0d878412009-10-02 15:16:56 -04003945 break;
3946 case 1:
3947 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3948 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3949 if (!rc) {
3950 spin_lock_irq(&phba->hbalock);
3951 phba->hba_flag |= HBA_AER_ENABLED;
3952 spin_unlock_irq(&phba->hbalock);
3953 phba->cfg_aer_support = 1;
3954 rc = strlen(buf);
3955 } else
James Smart891478a2009-11-18 15:40:23 -05003956 rc = -EPERM;
3957 } else {
James Smart0d878412009-10-02 15:16:56 -04003958 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003959 rc = strlen(buf);
3960 }
James Smart0d878412009-10-02 15:16:56 -04003961 break;
3962 default:
3963 rc = -EINVAL;
3964 break;
3965 }
3966 return rc;
3967}
3968
3969static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003970module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003971MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3972lpfc_param_show(aer_support)
3973
3974/**
3975 * lpfc_aer_support_init - Set the initial adapters aer support flag
3976 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003977 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003978 *
3979 * Description:
3980 * If val is in a valid range [0,1], then set the adapter's initial
3981 * cfg_aer_support field. It will be up to the driver's probe_one
3982 * routine to determine whether the device's AER support can be set
3983 * or not.
3984 *
3985 * Notes:
3986 * If the value is not in range log a kernel error message, and
3987 * choose the default value of setting AER support and return.
3988 *
3989 * Returns:
3990 * zero if val saved.
3991 * -EINVAL val out of range
3992 **/
3993static int
3994lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3995{
3996 if (val == 0 || val == 1) {
3997 phba->cfg_aer_support = val;
3998 return 0;
3999 }
4000 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4001 "2712 lpfc_aer_support attribute value %d out "
4002 "of range, allowed values are 0|1, setting it "
4003 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05004004 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04004005 phba->cfg_aer_support = 1;
4006 return -EINVAL;
4007}
4008
4009static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4010 lpfc_aer_support_show, lpfc_aer_support_store);
4011
4012/**
4013 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4014 * @dev: class device that is converted into a Scsi_host.
4015 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004016 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004017 * @count: unused variable.
4018 *
4019 * Description:
4020 * If the @buf contains 1 and the device currently has the AER support
4021 * enabled, then invokes the kernel AER helper routine
4022 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4023 * error status register.
4024 *
4025 * Notes:
4026 *
4027 * Returns:
4028 * -EINVAL if the buf does not contain the 1 or the device is not currently
4029 * enabled with the AER support.
4030 **/
4031static ssize_t
4032lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4033 const char *buf, size_t count)
4034{
4035 struct Scsi_Host *shost = class_to_shost(dev);
4036 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4037 struct lpfc_hba *phba = vport->phba;
4038 int val, rc = -1;
4039
4040 if (!isdigit(buf[0]))
4041 return -EINVAL;
4042 if (sscanf(buf, "%i", &val) != 1)
4043 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004044 if (val != 1)
4045 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004046
James Smart891478a2009-11-18 15:40:23 -05004047 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004048 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4049
4050 if (rc == 0)
4051 return strlen(buf);
4052 else
James Smart891478a2009-11-18 15:40:23 -05004053 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004054}
4055
4056static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4057 lpfc_aer_cleanup_state);
4058
James Smart912e3ac2011-05-24 11:42:11 -04004059/**
4060 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4061 *
4062 * @dev: class device that is converted into a Scsi_host.
4063 * @attr: device attribute, not used.
4064 * @buf: containing the string the number of vfs to be enabled.
4065 * @count: unused variable.
4066 *
4067 * Description:
4068 * When this api is called either through user sysfs, the driver shall
4069 * try to enable or disable SR-IOV virtual functions according to the
4070 * following:
4071 *
4072 * If zero virtual function has been enabled to the physical function,
4073 * the driver shall invoke the pci enable virtual function api trying
4074 * to enable the virtual functions. If the nr_vfn provided is greater
4075 * than the maximum supported, the maximum virtual function number will
4076 * be used for invoking the api; otherwise, the nr_vfn provided shall
4077 * be used for invoking the api. If the api call returned success, the
4078 * actual number of virtual functions enabled will be set to the driver
4079 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4080 * cfg_sriov_nr_virtfn remains zero.
4081 *
4082 * If none-zero virtual functions have already been enabled to the
4083 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4084 * -EINVAL will be returned and the driver does nothing;
4085 *
4086 * If the nr_vfn provided is zero and none-zero virtual functions have
4087 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4088 * disabling virtual function api shall be invoded to disable all the
4089 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4090 * zero. Otherwise, if zero virtual function has been enabled, do
4091 * nothing.
4092 *
4093 * Returns:
4094 * length of the buf on success if val is in range the intended mode
4095 * is supported.
4096 * -EINVAL if val out of range or intended mode is not supported.
4097 **/
4098static ssize_t
4099lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4100 const char *buf, size_t count)
4101{
4102 struct Scsi_Host *shost = class_to_shost(dev);
4103 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4104 struct lpfc_hba *phba = vport->phba;
4105 struct pci_dev *pdev = phba->pcidev;
4106 int val = 0, rc = -EINVAL;
4107
4108 /* Sanity check on user data */
4109 if (!isdigit(buf[0]))
4110 return -EINVAL;
4111 if (sscanf(buf, "%i", &val) != 1)
4112 return -EINVAL;
4113 if (val < 0)
4114 return -EINVAL;
4115
4116 /* Request disabling virtual functions */
4117 if (val == 0) {
4118 if (phba->cfg_sriov_nr_virtfn > 0) {
4119 pci_disable_sriov(pdev);
4120 phba->cfg_sriov_nr_virtfn = 0;
4121 }
4122 return strlen(buf);
4123 }
4124
4125 /* Request enabling virtual functions */
4126 if (phba->cfg_sriov_nr_virtfn > 0) {
4127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4128 "3018 There are %d virtual functions "
4129 "enabled on physical function.\n",
4130 phba->cfg_sriov_nr_virtfn);
4131 return -EEXIST;
4132 }
4133
4134 if (val <= LPFC_MAX_VFN_PER_PFN)
4135 phba->cfg_sriov_nr_virtfn = val;
4136 else {
4137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4138 "3019 Enabling %d virtual functions is not "
4139 "allowed.\n", val);
4140 return -EINVAL;
4141 }
4142
4143 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4144 if (rc) {
4145 phba->cfg_sriov_nr_virtfn = 0;
4146 rc = -EPERM;
4147 } else
4148 rc = strlen(buf);
4149
4150 return rc;
4151}
4152
4153static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
4154module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
4155MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
4156lpfc_param_show(sriov_nr_virtfn)
4157
4158/**
4159 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
4160 * @phba: lpfc_hba pointer.
4161 * @val: link speed value.
4162 *
4163 * Description:
4164 * If val is in a valid range [0,255], then set the adapter's initial
4165 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
4166 * number shall be used instead. It will be up to the driver's probe_one
4167 * routine to determine whether the device's SR-IOV is supported or not.
4168 *
4169 * Returns:
4170 * zero if val saved.
4171 * -EINVAL val out of range
4172 **/
4173static int
4174lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
4175{
4176 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
4177 phba->cfg_sriov_nr_virtfn = val;
4178 return 0;
4179 }
4180
4181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4182 "3017 Enabling %d virtual functions is not "
4183 "allowed.\n", val);
4184 return -EINVAL;
4185}
4186static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4187 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4188
James Smart173edbb2012-06-12 13:54:50 -04004189/**
James Smartc71ab862012-10-31 14:44:33 -04004190 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4191 *
4192 * @dev: class device that is converted into a Scsi_host.
4193 * @attr: device attribute, not used.
4194 * @buf: containing the string the number of vfs to be enabled.
4195 * @count: unused variable.
4196 *
4197 * Description:
4198 *
4199 * Returns:
4200 * length of the buf on success if val is in range the intended mode
4201 * is supported.
4202 * -EINVAL if val out of range or intended mode is not supported.
4203 **/
4204static ssize_t
4205lpfc_request_firmware_upgrade_store(struct device *dev,
4206 struct device_attribute *attr,
4207 const char *buf, size_t count)
4208{
4209 struct Scsi_Host *shost = class_to_shost(dev);
4210 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4211 struct lpfc_hba *phba = vport->phba;
4212 int val = 0, rc = -EINVAL;
4213
4214 /* Sanity check on user data */
4215 if (!isdigit(buf[0]))
4216 return -EINVAL;
4217 if (sscanf(buf, "%i", &val) != 1)
4218 return -EINVAL;
4219 if (val != 1)
4220 return -EINVAL;
4221
4222 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4223 if (rc)
4224 rc = -EPERM;
4225 else
4226 rc = strlen(buf);
4227 return rc;
4228}
4229
4230static int lpfc_req_fw_upgrade;
4231module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4232MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4233lpfc_param_show(request_firmware_upgrade)
4234
4235/**
4236 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4237 * @phba: lpfc_hba pointer.
4238 * @val: 0 or 1.
4239 *
4240 * Description:
4241 * Set the initial Linux generic firmware upgrade enable or disable flag.
4242 *
4243 * Returns:
4244 * zero if val saved.
4245 * -EINVAL val out of range
4246 **/
4247static int
4248lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4249{
4250 if (val >= 0 && val <= 1) {
4251 phba->cfg_request_firmware_upgrade = val;
4252 return 0;
4253 }
4254 return -EINVAL;
4255}
4256static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4257 lpfc_request_firmware_upgrade_show,
4258 lpfc_request_firmware_upgrade_store);
4259
4260/**
James Smart173edbb2012-06-12 13:54:50 -04004261 * lpfc_fcp_imax_store
4262 *
4263 * @dev: class device that is converted into a Scsi_host.
4264 * @attr: device attribute, not used.
4265 * @buf: string with the number of fast-path FCP interrupts per second.
4266 * @count: unused variable.
4267 *
4268 * Description:
4269 * If val is in a valid range [636,651042], then set the adapter's
4270 * maximum number of fast-path FCP interrupts per second.
4271 *
4272 * Returns:
4273 * length of the buf on success if val is in range the intended mode
4274 * is supported.
4275 * -EINVAL if val out of range or intended mode is not supported.
4276 **/
4277static ssize_t
4278lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4279 const char *buf, size_t count)
4280{
4281 struct Scsi_Host *shost = class_to_shost(dev);
4282 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4283 struct lpfc_hba *phba = vport->phba;
4284 int val = 0, i;
4285
James Smartbf8dae82012-08-03 12:36:24 -04004286 /* fcp_imax is only valid for SLI4 */
4287 if (phba->sli_rev != LPFC_SLI_REV4)
4288 return -EINVAL;
4289
James Smart173edbb2012-06-12 13:54:50 -04004290 /* Sanity check on user data */
4291 if (!isdigit(buf[0]))
4292 return -EINVAL;
4293 if (sscanf(buf, "%i", &val) != 1)
4294 return -EINVAL;
4295
James Smartbf8dae82012-08-03 12:36:24 -04004296 /*
4297 * Value range for the HBA is [5000,5000000]
4298 * The value for each EQ depends on how many EQs are configured.
4299 */
4300 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04004301 return -EINVAL;
4302
4303 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04004304 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04004305 lpfc_modify_fcp_eq_delay(phba, i);
4306
4307 return strlen(buf);
4308}
4309
4310/*
4311# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004312# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004313#
James Smartbf8dae82012-08-03 12:36:24 -04004314# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004315*/
James Smartbf8dae82012-08-03 12:36:24 -04004316static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004317module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4318MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004319 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004320lpfc_param_show(fcp_imax)
4321
4322/**
4323 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4324 * @phba: lpfc_hba pointer.
4325 * @val: link speed value.
4326 *
4327 * Description:
4328 * If val is in a valid range [636,651042], then initialize the adapter's
4329 * maximum number of fast-path FCP interrupts per second.
4330 *
4331 * Returns:
4332 * zero if val saved.
4333 * -EINVAL val out of range
4334 **/
4335static int
4336lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4337{
James Smartbf8dae82012-08-03 12:36:24 -04004338 if (phba->sli_rev != LPFC_SLI_REV4) {
4339 phba->cfg_fcp_imax = 0;
4340 return 0;
4341 }
4342
4343 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04004344 phba->cfg_fcp_imax = val;
4345 return 0;
4346 }
4347
4348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4349 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04004350 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004351
4352 return 0;
4353}
4354
4355static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4356 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4357
James Smart7bb03bb2013-04-17 20:19:16 -04004358/**
4359 * lpfc_state_show - Display current driver CPU affinity
4360 * @dev: class converted to a Scsi_host structure.
4361 * @attr: device attribute, not used.
4362 * @buf: on return contains text describing the state of the link.
4363 *
4364 * Returns: size of formatted string.
4365 **/
4366static ssize_t
4367lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4368 char *buf)
4369{
4370 struct Scsi_Host *shost = class_to_shost(dev);
4371 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4372 struct lpfc_hba *phba = vport->phba;
4373 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004374 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004375
4376 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4377 (phba->intr_type != MSIX))
4378 return len;
4379
4380 switch (phba->cfg_fcp_cpu_map) {
4381 case 0:
4382 len += snprintf(buf + len, PAGE_SIZE-len,
4383 "fcp_cpu_map: No mapping (%d)\n",
4384 phba->cfg_fcp_cpu_map);
4385 return len;
4386 case 1:
4387 len += snprintf(buf + len, PAGE_SIZE-len,
4388 "fcp_cpu_map: HBA centric mapping (%d): "
4389 "%d online CPUs\n",
4390 phba->cfg_fcp_cpu_map,
4391 phba->sli4_hba.num_online_cpu);
4392 break;
4393 case 2:
4394 len += snprintf(buf + len, PAGE_SIZE-len,
4395 "fcp_cpu_map: Driver centric mapping (%d): "
4396 "%d online CPUs\n",
4397 phba->cfg_fcp_cpu_map,
4398 phba->sli4_hba.num_online_cpu);
4399 break;
4400 }
4401
James Smart76fd07a2014-02-20 09:57:18 -05004402 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4403 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4404
4405 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004406 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4407 len += snprintf(buf + len, PAGE_SIZE-len,
4408 "CPU %02d io_chan %02d "
4409 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004410 phba->sli4_hba.curr_disp_cpu,
4411 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004412 cpup->core_id);
4413 else
4414 len += snprintf(buf + len, PAGE_SIZE-len,
4415 "CPU %02d io_chan %02d "
4416 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004417 phba->sli4_hba.curr_disp_cpu,
4418 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004419 cpup->core_id, cpup->irq);
4420
James Smart76fd07a2014-02-20 09:57:18 -05004421 phba->sli4_hba.curr_disp_cpu++;
4422
4423 /* display max number of CPUs keeping some margin */
4424 if (phba->sli4_hba.curr_disp_cpu <
4425 phba->sli4_hba.num_present_cpu &&
4426 (len >= (PAGE_SIZE - 64))) {
4427 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4428 break;
4429 }
James Smart7bb03bb2013-04-17 20:19:16 -04004430 }
James Smart76fd07a2014-02-20 09:57:18 -05004431
4432 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4433 phba->sli4_hba.curr_disp_cpu = 0;
4434
James Smart7bb03bb2013-04-17 20:19:16 -04004435 return len;
4436}
4437
4438/**
4439 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4440 * @dev: class device that is converted into a Scsi_host.
4441 * @attr: device attribute, not used.
4442 * @buf: one or more lpfc_polling_flags values.
4443 * @count: not used.
4444 *
4445 * Returns:
4446 * -EINVAL - Not implemented yet.
4447 **/
4448static ssize_t
4449lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4450 const char *buf, size_t count)
4451{
4452 int status = -EINVAL;
4453 return status;
4454}
4455
4456/*
4457# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4458# for the HBA.
4459#
4460# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4461# 0 - Do not affinitze IRQ vectors
4462# 1 - Affintize HBA vectors with respect to each HBA
4463# (start with CPU0 for each HBA)
4464# 2 - Affintize HBA vectors with respect to the entire driver
4465# (round robin thru all CPUs across all HBAs)
4466*/
4467static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4468module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4469MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4470 "Defines how to map CPUs to IRQ vectors per HBA");
4471
4472/**
4473 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4474 * @phba: lpfc_hba pointer.
4475 * @val: link speed value.
4476 *
4477 * Description:
4478 * If val is in a valid range [0-2], then affinitze the adapter's
4479 * MSIX vectors.
4480 *
4481 * Returns:
4482 * zero if val saved.
4483 * -EINVAL val out of range
4484 **/
4485static int
4486lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4487{
4488 if (phba->sli_rev != LPFC_SLI_REV4) {
4489 phba->cfg_fcp_cpu_map = 0;
4490 return 0;
4491 }
4492
4493 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4494 phba->cfg_fcp_cpu_map = val;
4495 return 0;
4496 }
4497
4498 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4499 "3326 fcp_cpu_map: %d out of range, using default\n",
4500 val);
4501 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4502
4503 return 0;
4504}
4505
4506static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4507 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4508
James Smart0d878412009-10-02 15:16:56 -04004509/*
dea31012005-04-17 16:05:31 -05004510# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4511# Value range is [2,3]. Default value is 3.
4512*/
James Smart3de2a652007-08-02 11:09:59 -04004513LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4514 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004515
4516/*
4517# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4518# is [0,1]. Default value is 0.
4519*/
James Smart3de2a652007-08-02 11:09:59 -04004520LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4521 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004522
4523/*
James Smart3cb01c52013-07-15 18:35:04 -04004524# lpfc_first_burst_size: First burst size to use on the NPorts
4525# that support first burst.
4526# Value range is [0,65536]. Default value is 0.
4527*/
4528LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4529 "First burst size for Targets that support first burst");
4530
4531/*
James Smart977b5a02008-09-07 11:52:04 -04004532# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4533# depth. Default value is 0. When the value of this parameter is zero the
4534# SCSI command completion time is not used for controlling I/O queue depth. When
4535# the parameter is set to a non-zero value, the I/O queue depth is controlled
4536# to limit the I/O completion time to the parameter value.
4537# The value is set in milliseconds.
4538*/
4539static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05004540module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04004541MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
4542 "Use command completion time to control queue depth");
4543lpfc_vport_param_show(max_scsicmpl_time);
4544lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
4545static int
4546lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4547{
4548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4549 struct lpfc_nodelist *ndlp, *next_ndlp;
4550
4551 if (val == vport->cfg_max_scsicmpl_time)
4552 return 0;
4553 if ((val < 0) || (val > 60000))
4554 return -EINVAL;
4555 vport->cfg_max_scsicmpl_time = val;
4556
4557 spin_lock_irq(shost->host_lock);
4558 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4559 if (!NLP_CHK_NODE_ACT(ndlp))
4560 continue;
4561 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4562 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004563 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004564 }
4565 spin_unlock_irq(shost->host_lock);
4566 return 0;
4567}
4568lpfc_vport_param_store(max_scsicmpl_time);
4569static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4570 lpfc_max_scsicmpl_time_show,
4571 lpfc_max_scsicmpl_time_store);
4572
4573/*
dea31012005-04-17 16:05:31 -05004574# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4575# range is [0,1]. Default value is 0.
4576*/
4577LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4578
4579/*
James Smart49aa1432012-08-03 12:36:42 -04004580# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4581# range is [0,1]. Default value is 0.
4582# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4583# For [1], FCP commands are issued to a Work Queue associated with the
4584# current CPU.
James Smartec2087a2013-09-06 12:20:36 -04004585# It would be set to 1 by the driver if it's able to set up cpu affinity
4586# for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4587# roundrobin scheduling of FCP I/Os through WQs will be used.
James Smart49aa1432012-08-03 12:36:42 -04004588*/
James Smartec2087a2013-09-06 12:20:36 -04004589LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
James Smart49aa1432012-08-03 12:36:42 -04004590 "issuing commands [0] - Round Robin, [1] - Current CPU");
4591
4592/*
James Smarta6571c62012-10-31 14:44:42 -04004593# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4594# range is [0,1]. Default value is 0.
4595# For [0], bus reset issues target reset to ALL devices
4596# For [1], bus reset issues target reset to non-FCP2 devices
4597*/
4598LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4599 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4600
4601
4602/*
dea31012005-04-17 16:05:31 -05004603# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4604# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004605# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004606# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4607# cr_delay is set to 0.
4608*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004609LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004610 "interrupt response is generated");
4611
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004612LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004613 "interrupt response is generated");
4614
4615/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004616# lpfc_multi_ring_support: Determines how many rings to spread available
4617# cmd/rsp IOCB entries across.
4618# Value range is [1,2]. Default value is 1.
4619*/
4620LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4621 "SLI rings to spread IOCB entries across");
4622
4623/*
James Smarta4bc3372006-12-02 13:34:16 -05004624# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4625# identifies what rctl value to configure the additional ring for.
4626# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4627*/
James Smart6a9c52c2009-10-02 15:16:51 -04004628LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004629 255, "Identifies RCTL for additional ring configuration");
4630
4631/*
4632# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4633# identifies what type value to configure the additional ring for.
4634# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4635*/
James Smart6a9c52c2009-10-02 15:16:51 -04004636LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004637 255, "Identifies TYPE for additional ring configuration");
4638
4639/*
James Smart4258e982015-12-16 18:11:58 -05004640# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4641# 0 = SmartSAN functionality disabled (default)
4642# 1 = SmartSAN functionality enabled
4643# This parameter will override the value of lpfc_fdmi_on module parameter.
4644# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004645*/
James Smart4258e982015-12-16 18:11:58 -05004646LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4647
4648/*
4649# lpfc_fdmi_on: Controls FDMI support.
4650# 0 No FDMI support (default)
4651# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004652# Traditional FDMI support means the driver will assume FDMI-2 support;
4653# however, if that fails, it will fallback to FDMI-1.
4654# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4655# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4656# lpfc_fdmi_on.
4657# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004658*/
James Smart8663cbb2016-03-31 14:12:33 -07004659LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004660
4661/*
4662# Specifies the maximum number of ELS cmds we can have outstanding (for
4663# discovery). Value range is [1,64]. Default value = 32.
4664*/
James Smart3de2a652007-08-02 11:09:59 -04004665LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004666 "during discovery");
4667
4668/*
James Smartc4a7c922013-05-31 17:04:59 -04004669# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4670# will be scanned by the SCSI midlayer when sequential scanning is
4671# used; and is also the highest LUN ID allowed when the SCSI midlayer
4672# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4673# LUN ID limit, but the SCSI midlayer requires this field for the uses
4674# above. The lpfc driver limits the default value to 255 for two reasons.
4675# As it bounds the sequential scan loop, scanning for thousands of luns
4676# on a target can take minutes of wall clock time. Additionally,
4677# there are FC targets, such as JBODs, that only recognize 8-bits of
4678# LUN ID. When they receive a value greater than 8 bits, they chop off
4679# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4680# and so on all as LUN ID 0. This causes the linux kernel, which sees
4681# valid responses at each of the LUN IDs, to believe there are multiple
4682# devices present, when in fact, there is only 1.
4683# A customer that is aware of their target behaviors, and the results as
4684# indicated above, is welcome to increase the lpfc_max_luns value.
4685# As mentioned, this value is not used by the lpfc driver, only the
4686# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004687# Value range is [0,65535]. Default value is 255.
4688# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004689*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004690LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004691
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004692/*
4693# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4694# Value range is [1,255], default value is 10.
4695*/
4696LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4697 "Milliseconds driver will wait between polling FCP ring");
4698
James Smart4ff43242006-12-02 13:34:56 -05004699/*
James Smart0c411222013-09-06 12:22:46 -04004700# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4701# to complete in seconds. Value range is [5,180], default value is 60.
4702*/
4703LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4704 "Maximum time to wait for task management commands to complete");
4705/*
James Smart4ff43242006-12-02 13:34:56 -05004706# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4707# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004708# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004709# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004710# 2 = MSI-X enabled (default)
4711# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004712*/
George Kadianakis8605c462010-01-17 21:19:31 +02004713LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004714 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004715
James Smart13815c82008-01-11 01:52:48 -05004716/*
James Smart67d12732012-08-03 12:36:13 -04004717# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4718#
4719# Value range is [1,7]. Default value is 4.
4720*/
4721LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4722 LPFC_FCP_IO_CHAN_MAX,
4723 "Set the number of FCP I/O channels");
4724
4725/*
James Smart13815c82008-01-11 01:52:48 -05004726# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4727# 0 = HBA resets disabled
4728# 1 = HBA resets enabled (default)
4729# Value range is [0,1]. Default value is 1.
4730*/
4731LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004732
James Smart13815c82008-01-11 01:52:48 -05004733/*
James Smarteb7a3392010-11-20 23:12:02 -05004734# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004735# 0 = HBA Heartbeat disabled
4736# 1 = HBA Heartbeat enabled (default)
4737# Value range is [0,1]. Default value is 1.
4738*/
James Smarteb7a3392010-11-20 23:12:02 -05004739LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004740
James Smart83108bd2008-01-11 01:53:09 -05004741/*
James Smart1ba981f2014-02-20 09:56:45 -05004742# lpfc_EnableXLane: Enable Express Lane Feature
4743# 0x0 Express Lane Feature disabled
4744# 0x1 Express Lane Feature enabled
4745# Value range is [0,1]. Default value is 0.
4746*/
4747LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4748
4749/*
4750# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4751# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4752# Value range is [0x0,0x7f]. Default value is 0
4753*/
James Smart28d7f3d2014-05-21 08:05:28 -04004754LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004755
4756/*
James Smart81301a92008-12-04 22:39:46 -05004757# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4758# 0 = BlockGuard disabled (default)
4759# 1 = BlockGuard enabled
4760# Value range is [0,1]. Default value is 0.
4761*/
4762LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4763
James Smart6fb120a2009-05-22 14:52:59 -04004764/*
James Smartba20c852012-08-03 12:36:52 -04004765# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4766# 0 = disabled (default)
4767# 1 = enabled
4768# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004769#
4770# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004771*/
4772unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4773
James Smartba20c852012-08-03 12:36:52 -04004774/*
James Smart81301a92008-12-04 22:39:46 -05004775# lpfc_prot_mask: i
4776# - Bit mask of host protection capabilities used to register with the
4777# SCSI mid-layer
4778# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4779# - Allows you to ultimately specify which profiles to use
4780# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004781# - SHOST_DIF_TYPE1_PROTECTION 1
4782# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4783# - SHOST_DIX_TYPE0_PROTECTION 8
4784# HBA supports DIX Type 0: Host to HBA protection only
4785# - SHOST_DIX_TYPE1_PROTECTION 16
4786# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004787#
4788*/
James Smart7c56b9f2011-07-22 18:36:25 -04004789unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4790 SHOST_DIX_TYPE0_PROTECTION |
4791 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004792
James Smartab56dc22011-02-16 12:39:57 -05004793module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004794MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4795
4796/*
4797# lpfc_prot_guard: i
4798# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004799# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004800# - Allows you to ultimately specify which profiles to use
4801# - Default will result in registering capabilities for all guard types
4802#
4803*/
4804unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004805module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004806MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4807
James Smart92494142011-02-16 12:39:44 -05004808/*
4809 * Delay initial NPort discovery when Clean Address bit is cleared in
4810 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4811 * This parameter can have value 0 or 1.
4812 * When this parameter is set to 0, no delay is added to the initial
4813 * discovery.
4814 * When this parameter is set to non-zero value, initial Nport discovery is
4815 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4816 * accept and FCID/Fabric name/Fabric portname is changed.
4817 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4818 * when Clean Address bit is cleared in FLOGI/FDISC
4819 * accept and FCID/Fabric name/Fabric portname is changed.
4820 * Default value is 0.
4821 */
4822int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05004823module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05004824MODULE_PARM_DESC(lpfc_delay_discovery,
4825 "Delay NPort discovery when Clean Address bit is cleared. "
4826 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05004827
4828/*
James Smart3621a712009-04-06 18:47:14 -04004829 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004830 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004831 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4832 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004833 * Because of the additional overhead involved in setting up T10-DIF,
4834 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4835 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004836 */
4837LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4838 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4839
James Smart96f70772013-04-17 20:16:15 -04004840/*
4841 * This parameter will be depricated, the driver cannot limit the
4842 * protection data s/g list.
4843 */
4844LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4845 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4846 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004847
James Smart7bdedb32016-07-06 12:36:00 -07004848/*
4849 * lpfc_enable_mds_diags: Enable MDS Diagnostics
4850 * 0 = MDS Diagnostics disabled (default)
4851 * 1 = MDS Diagnostics enabled
4852 * Value range is [0,1]. Default value is 0.
4853 */
4854LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
4855
Tony Jonesee959b02008-02-22 00:13:36 +01004856struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004857 &dev_attr_bg_info,
4858 &dev_attr_bg_guard_err,
4859 &dev_attr_bg_apptag_err,
4860 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004861 &dev_attr_info,
4862 &dev_attr_serialnum,
4863 &dev_attr_modeldesc,
4864 &dev_attr_modelname,
4865 &dev_attr_programtype,
4866 &dev_attr_portnum,
4867 &dev_attr_fwrev,
4868 &dev_attr_hdw,
4869 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004870 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004871 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004872 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004873 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004874 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004875 &dev_attr_lpfc_temp_sensor,
4876 &dev_attr_lpfc_log_verbose,
4877 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004878 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004879 &dev_attr_lpfc_hba_queue_depth,
4880 &dev_attr_lpfc_peer_port_login,
4881 &dev_attr_lpfc_nodev_tmo,
4882 &dev_attr_lpfc_devloss_tmo,
4883 &dev_attr_lpfc_fcp_class,
4884 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004885 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004886 &dev_attr_lpfc_ack0,
4887 &dev_attr_lpfc_topology,
4888 &dev_attr_lpfc_scan_down,
4889 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004890 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004891 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004892 &dev_attr_lpfc_cr_delay,
4893 &dev_attr_lpfc_cr_count,
4894 &dev_attr_lpfc_multi_ring_support,
4895 &dev_attr_lpfc_multi_ring_rctl,
4896 &dev_attr_lpfc_multi_ring_type,
4897 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05004898 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01004899 &dev_attr_lpfc_max_luns,
4900 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004901 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004902 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004903 &dev_attr_nport_evt_cnt,
4904 &dev_attr_board_mode,
4905 &dev_attr_max_vpi,
4906 &dev_attr_used_vpi,
4907 &dev_attr_max_rpi,
4908 &dev_attr_used_rpi,
4909 &dev_attr_max_xri,
4910 &dev_attr_used_xri,
4911 &dev_attr_npiv_info,
4912 &dev_attr_issue_reset,
4913 &dev_attr_lpfc_poll,
4914 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04004915 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01004916 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004917 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004918 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04004919 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004920 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004921 &dev_attr_lpfc_soft_wwnn,
4922 &dev_attr_lpfc_soft_wwpn,
4923 &dev_attr_lpfc_soft_wwn_enable,
4924 &dev_attr_lpfc_enable_hba_reset,
4925 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05004926 &dev_attr_lpfc_EnableXLane,
4927 &dev_attr_lpfc_XLanePriority,
4928 &dev_attr_lpfc_xlane_lun,
4929 &dev_attr_lpfc_xlane_tgt,
4930 &dev_attr_lpfc_xlane_vpt,
4931 &dev_attr_lpfc_xlane_lun_state,
4932 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07004933 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01004934 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004935 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004936 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004937 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004938 &dev_attr_lpfc_aer_support,
4939 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004940 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004941 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004942 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004943 &dev_attr_lpfc_iocb_cnt,
4944 &dev_attr_iocb_hw,
4945 &dev_attr_txq_hw,
4946 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004947 &dev_attr_lpfc_fips_level,
4948 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004949 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004950 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004951 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05004952 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07004953 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05004954 NULL,
4955};
4956
Tony Jonesee959b02008-02-22 00:13:36 +01004957struct device_attribute *lpfc_vport_attrs[] = {
4958 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004959 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004960 &dev_attr_num_discovered_ports,
4961 &dev_attr_lpfc_drvr_version,
4962 &dev_attr_lpfc_log_verbose,
4963 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004964 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004965 &dev_attr_lpfc_nodev_tmo,
4966 &dev_attr_lpfc_devloss_tmo,
4967 &dev_attr_lpfc_hba_queue_depth,
4968 &dev_attr_lpfc_peer_port_login,
4969 &dev_attr_lpfc_restrict_login,
4970 &dev_attr_lpfc_fcp_class,
4971 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004972 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004973 &dev_attr_lpfc_max_luns,
4974 &dev_attr_nport_evt_cnt,
4975 &dev_attr_npiv_info,
4976 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004977 &dev_attr_lpfc_max_scsicmpl_time,
4978 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004979 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004980 &dev_attr_lpfc_fips_level,
4981 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004982 NULL,
4983};
4984
James Smarte59058c2008-08-24 21:49:00 -04004985/**
James Smart3621a712009-04-06 18:47:14 -04004986 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004987 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004988 * @kobj: kernel kobject that contains the kernel class device.
4989 * @bin_attr: kernel attributes passed to us.
4990 * @buf: contains the data to be written to the adapter IOREG space.
4991 * @off: offset into buffer to beginning of data.
4992 * @count: bytes to transfer.
4993 *
4994 * Description:
4995 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4996 * Uses the adapter io control registers to send buf contents to the adapter.
4997 *
4998 * Returns:
4999 * -ERANGE off and count combo out of range
5000 * -EINVAL off, count or buff address invalid
5001 * -EPERM adapter is offline
5002 * value of count, buf contents written
5003 **/
dea31012005-04-17 16:05:31 -05005004static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005005sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5006 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005007 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005008{
5009 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005010 struct device *dev = container_of(kobj, struct device, kobj);
5011 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005012 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5013 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005014
James Smartf1126682009-06-10 17:22:44 -04005015 if (phba->sli_rev >= LPFC_SLI_REV4)
5016 return -EPERM;
5017
dea31012005-04-17 16:05:31 -05005018 if ((off + count) > FF_REG_AREA_SIZE)
5019 return -ERANGE;
5020
James Smartf7a919b2011-08-21 21:49:16 -04005021 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5022 return 0;
dea31012005-04-17 16:05:31 -05005023
5024 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5025 return -EINVAL;
5026
James Smartf7a919b2011-08-21 21:49:16 -04005027 /* This is to protect HBA registers from accidental writes. */
5028 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5029 return -EINVAL;
5030
5031 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005032 return -EPERM;
dea31012005-04-17 16:05:31 -05005033
James Smart2e0fef82007-06-17 19:56:36 -05005034 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005035 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5036 buf_off += sizeof(uint32_t))
5037 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005038 phba->ctrl_regs_memmap_p + off + buf_off);
5039
James Smart2e0fef82007-06-17 19:56:36 -05005040 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005041
5042 return count;
5043}
5044
James Smarte59058c2008-08-24 21:49:00 -04005045/**
James Smart3621a712009-04-06 18:47:14 -04005046 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005047 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005048 * @kobj: kernel kobject that contains the kernel class device.
5049 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005050 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005051 * @off: offset into buffer to beginning of data.
5052 * @count: bytes to transfer.
5053 *
5054 * Description:
5055 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5056 * Uses the adapter io control registers to read data into buf.
5057 *
5058 * Returns:
5059 * -ERANGE off and count combo out of range
5060 * -EINVAL off, count or buff address invalid
5061 * value of count, buf contents read
5062 **/
dea31012005-04-17 16:05:31 -05005063static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005064sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5065 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005066 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005067{
5068 size_t buf_off;
5069 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005070 struct device *dev = container_of(kobj, struct device, kobj);
5071 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005072 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5073 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005074
James Smartf1126682009-06-10 17:22:44 -04005075 if (phba->sli_rev >= LPFC_SLI_REV4)
5076 return -EPERM;
5077
dea31012005-04-17 16:05:31 -05005078 if (off > FF_REG_AREA_SIZE)
5079 return -ERANGE;
5080
5081 if ((off + count) > FF_REG_AREA_SIZE)
5082 count = FF_REG_AREA_SIZE - off;
5083
5084 if (count == 0) return 0;
5085
5086 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5087 return -EINVAL;
5088
James Smart2e0fef82007-06-17 19:56:36 -05005089 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005090
5091 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5092 tmp_ptr = (uint32_t *)(buf + buf_off);
5093 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5094 }
5095
James Smart2e0fef82007-06-17 19:56:36 -05005096 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005097
5098 return count;
5099}
5100
5101static struct bin_attribute sysfs_ctlreg_attr = {
5102 .attr = {
5103 .name = "ctlreg",
5104 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005105 },
5106 .size = 256,
5107 .read = sysfs_ctlreg_read,
5108 .write = sysfs_ctlreg_write,
5109};
5110
James Smarte59058c2008-08-24 21:49:00 -04005111/**
James Smart3621a712009-04-06 18:47:14 -04005112 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005113 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005114 * @kobj: kernel kobject that contains the kernel class device.
5115 * @bin_attr: kernel attributes passed to us.
5116 * @buf: contains the data to be written to sysfs mbox.
5117 * @off: offset into buffer to beginning of data.
5118 * @count: bytes to transfer.
5119 *
5120 * Description:
James Smart026abb82011-12-13 13:20:45 -05005121 * Deprecated function. All mailbox access from user space is performed via the
5122 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005123 *
5124 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005125 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005126 **/
dea31012005-04-17 16:05:31 -05005127static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005128sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5129 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005130 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005131{
James Smart026abb82011-12-13 13:20:45 -05005132 return -EPERM;
dea31012005-04-17 16:05:31 -05005133}
5134
James Smarte59058c2008-08-24 21:49:00 -04005135/**
James Smart3621a712009-04-06 18:47:14 -04005136 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005137 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005138 * @kobj: kernel kobject that contains the kernel class device.
5139 * @bin_attr: kernel attributes passed to us.
5140 * @buf: contains the data to be read from sysfs mbox.
5141 * @off: offset into buffer to beginning of data.
5142 * @count: bytes to transfer.
5143 *
5144 * Description:
James Smart026abb82011-12-13 13:20:45 -05005145 * Deprecated function. All mailbox access from user space is performed via the
5146 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005147 *
5148 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005149 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005150 **/
dea31012005-04-17 16:05:31 -05005151static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005152sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5153 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005154 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005155{
James Smart026abb82011-12-13 13:20:45 -05005156 return -EPERM;
dea31012005-04-17 16:05:31 -05005157}
5158
5159static struct bin_attribute sysfs_mbox_attr = {
5160 .attr = {
5161 .name = "mbox",
5162 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005163 },
James Smartc0c11512011-05-24 11:41:34 -04005164 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005165 .read = sysfs_mbox_read,
5166 .write = sysfs_mbox_write,
5167};
5168
James Smarte59058c2008-08-24 21:49:00 -04005169/**
James Smart3621a712009-04-06 18:47:14 -04005170 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005171 * @vport: address of lpfc vport structure.
5172 *
5173 * Return codes:
5174 * zero on success
5175 * error return code from sysfs_create_bin_file()
5176 **/
dea31012005-04-17 16:05:31 -05005177int
James Smart2e0fef82007-06-17 19:56:36 -05005178lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005179{
James Smart2e0fef82007-06-17 19:56:36 -05005180 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005181 int error;
5182
Tony Jonesee959b02008-02-22 00:13:36 +01005183 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005184 &sysfs_drvr_stat_data_attr);
5185
5186 /* Virtual ports do not need ctrl_reg and mbox */
5187 if (error || vport->port_type == LPFC_NPIV_PORT)
5188 goto out;
5189
5190 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005191 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005192 if (error)
James Smarteada2722008-12-04 22:39:13 -05005193 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005194
Tony Jonesee959b02008-02-22 00:13:36 +01005195 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005196 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005197 if (error)
5198 goto out_remove_ctlreg_attr;
5199
5200 return 0;
5201out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005202 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005203out_remove_stat_attr:
5204 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5205 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005206out:
5207 return error;
5208}
5209
James Smarte59058c2008-08-24 21:49:00 -04005210/**
James Smart3621a712009-04-06 18:47:14 -04005211 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005212 * @vport: address of lpfc vport structure.
5213 **/
dea31012005-04-17 16:05:31 -05005214void
James Smart2e0fef82007-06-17 19:56:36 -05005215lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005216{
James Smart2e0fef82007-06-17 19:56:36 -05005217 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005218 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5219 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005220 /* Virtual ports do not need ctrl_reg and mbox */
5221 if (vport->port_type == LPFC_NPIV_PORT)
5222 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005223 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5224 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005225}
5226
dea31012005-04-17 16:05:31 -05005227/*
5228 * Dynamic FC Host Attributes Support
5229 */
5230
James Smarte59058c2008-08-24 21:49:00 -04005231/**
James Smart3621a712009-04-06 18:47:14 -04005232 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005233 * @shost: kernel scsi host pointer.
5234 **/
dea31012005-04-17 16:05:31 -05005235static void
5236lpfc_get_host_port_id(struct Scsi_Host *shost)
5237{
James Smart2e0fef82007-06-17 19:56:36 -05005238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5239
dea31012005-04-17 16:05:31 -05005240 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005241 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005242}
5243
James Smarte59058c2008-08-24 21:49:00 -04005244/**
James Smart3621a712009-04-06 18:47:14 -04005245 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005246 * @shost: kernel scsi host pointer.
5247 **/
dea31012005-04-17 16:05:31 -05005248static void
5249lpfc_get_host_port_type(struct Scsi_Host *shost)
5250{
James Smart2e0fef82007-06-17 19:56:36 -05005251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5252 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005253
5254 spin_lock_irq(shost->host_lock);
5255
James Smart92d7f7b2007-06-17 19:56:38 -05005256 if (vport->port_type == LPFC_NPIV_PORT) {
5257 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5258 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005259 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005260 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005261 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5262 else
5263 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5264 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005265 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005266 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5267 else
5268 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5269 }
5270 } else
5271 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5272
5273 spin_unlock_irq(shost->host_lock);
5274}
5275
James Smarte59058c2008-08-24 21:49:00 -04005276/**
James Smart3621a712009-04-06 18:47:14 -04005277 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005278 * @shost: kernel scsi host pointer.
5279 **/
dea31012005-04-17 16:05:31 -05005280static void
5281lpfc_get_host_port_state(struct Scsi_Host *shost)
5282{
James Smart2e0fef82007-06-17 19:56:36 -05005283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5284 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005285
5286 spin_lock_irq(shost->host_lock);
5287
James Smart2e0fef82007-06-17 19:56:36 -05005288 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005289 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5290 else {
James Smart2e0fef82007-06-17 19:56:36 -05005291 switch (phba->link_state) {
5292 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005293 case LPFC_LINK_DOWN:
5294 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5295 break;
5296 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005297 case LPFC_CLEAR_LA:
5298 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005299 /* Links up, reports port state accordingly */
5300 if (vport->port_state < LPFC_VPORT_READY)
5301 fc_host_port_state(shost) =
5302 FC_PORTSTATE_BYPASSED;
5303 else
5304 fc_host_port_state(shost) =
5305 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005306 break;
5307 case LPFC_HBA_ERROR:
5308 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5309 break;
5310 default:
5311 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5312 break;
5313 }
5314 }
5315
5316 spin_unlock_irq(shost->host_lock);
5317}
5318
James Smarte59058c2008-08-24 21:49:00 -04005319/**
James Smart3621a712009-04-06 18:47:14 -04005320 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005321 * @shost: kernel scsi host pointer.
5322 **/
dea31012005-04-17 16:05:31 -05005323static void
5324lpfc_get_host_speed(struct Scsi_Host *shost)
5325{
James Smart2e0fef82007-06-17 19:56:36 -05005326 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5327 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005328
5329 spin_lock_irq(shost->host_lock);
5330
James Smarta085e872015-12-16 18:12:02 -05005331 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005332 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005333 case LPFC_LINK_SPEED_1GHZ:
5334 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005335 break;
James Smart76a95d72010-11-20 23:11:48 -05005336 case LPFC_LINK_SPEED_2GHZ:
5337 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005338 break;
James Smart76a95d72010-11-20 23:11:48 -05005339 case LPFC_LINK_SPEED_4GHZ:
5340 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005341 break;
James Smart76a95d72010-11-20 23:11:48 -05005342 case LPFC_LINK_SPEED_8GHZ:
5343 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005344 break;
James Smart76a95d72010-11-20 23:11:48 -05005345 case LPFC_LINK_SPEED_10GHZ:
5346 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005347 break;
James Smart76a95d72010-11-20 23:11:48 -05005348 case LPFC_LINK_SPEED_16GHZ:
5349 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5350 break;
James Smartd38dd522015-08-31 16:48:17 -04005351 case LPFC_LINK_SPEED_32GHZ:
5352 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5353 break;
James Smart76a95d72010-11-20 23:11:48 -05005354 default:
5355 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005356 break;
5357 }
James Smart09372822008-01-11 01:52:54 -05005358 } else
5359 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005360
5361 spin_unlock_irq(shost->host_lock);
5362}
5363
James Smarte59058c2008-08-24 21:49:00 -04005364/**
James Smart3621a712009-04-06 18:47:14 -04005365 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005366 * @shost: kernel scsi host pointer.
5367 **/
dea31012005-04-17 16:05:31 -05005368static void
5369lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5370{
James Smart2e0fef82007-06-17 19:56:36 -05005371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5372 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005373 u64 node_name;
dea31012005-04-17 16:05:31 -05005374
5375 spin_lock_irq(shost->host_lock);
5376
James Smart73d91e52011-10-10 21:32:10 -04005377 if ((vport->port_state > LPFC_FLOGI) &&
5378 ((vport->fc_flag & FC_FABRIC) ||
5379 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5380 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005381 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005382 else
5383 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005384 node_name = 0;
dea31012005-04-17 16:05:31 -05005385
5386 spin_unlock_irq(shost->host_lock);
5387
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005388 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005389}
5390
James Smarte59058c2008-08-24 21:49:00 -04005391/**
James Smart3621a712009-04-06 18:47:14 -04005392 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005393 * @shost: kernel scsi host pointer.
5394 *
5395 * Notes:
5396 * NULL on error for link down, no mbox pool, sli2 active,
5397 * management not allowed, memory allocation error, or mbox error.
5398 *
5399 * Returns:
5400 * NULL for error
5401 * address of the adapter host statistics
5402 **/
dea31012005-04-17 16:05:31 -05005403static struct fc_host_statistics *
5404lpfc_get_stats(struct Scsi_Host *shost)
5405{
James Smart2e0fef82007-06-17 19:56:36 -05005406 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5407 struct lpfc_hba *phba = vport->phba;
5408 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005409 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005410 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005411 LPFC_MBOXQ_t *pmboxq;
5412 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005413 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005414 int rc = 0;
dea31012005-04-17 16:05:31 -05005415
James Smart92d7f7b2007-06-17 19:56:38 -05005416 /*
5417 * prevent udev from issuing mailbox commands until the port is
5418 * configured.
5419 */
James Smart2e0fef82007-06-17 19:56:36 -05005420 if (phba->link_state < LPFC_LINK_DOWN ||
5421 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005422 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005423 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005424
5425 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005426 return NULL;
5427
dea31012005-04-17 16:05:31 -05005428 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5429 if (!pmboxq)
5430 return NULL;
5431 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5432
James Smart04c68492009-05-22 14:52:52 -04005433 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005434 pmb->mbxCommand = MBX_READ_STATUS;
5435 pmb->mbxOwner = OWN_HOST;
5436 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005437 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005438
James Smart75baf692010-06-08 18:31:21 -04005439 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005440 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005441 else
dea31012005-04-17 16:05:31 -05005442 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5443
5444 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005445 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005446 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005447 return NULL;
5448 }
5449
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005450 memset(hs, 0, sizeof (struct fc_host_statistics));
5451
dea31012005-04-17 16:05:31 -05005452 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005453 /*
5454 * The MBX_READ_STATUS returns tx_k_bytes which has to
5455 * converted to words
5456 */
5457 hs->tx_words = (uint64_t)
5458 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5459 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005460 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005461 hs->rx_words = (uint64_t)
5462 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5463 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005464
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005465 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005466 pmb->mbxCommand = MBX_READ_LNK_STAT;
5467 pmb->mbxOwner = OWN_HOST;
5468 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005469 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005470
James Smart75baf692010-06-08 18:31:21 -04005471 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005472 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005473 else
dea31012005-04-17 16:05:31 -05005474 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5475
5476 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005477 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005478 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005479 return NULL;
5480 }
5481
5482 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5483 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5484 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5485 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5486 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5487 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5488 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5489
James Smart64ba8812006-08-02 15:24:34 -04005490 hs->link_failure_count -= lso->link_failure_count;
5491 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5492 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5493 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5494 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5495 hs->invalid_crc_count -= lso->invalid_crc_count;
5496 hs->error_frames -= lso->error_frames;
5497
James Smart76a95d72010-11-20 23:11:48 -05005498 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005499 hs->lip_count = -1;
5500 hs->nos_count = (phba->link_events >> 1);
5501 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005502 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005503 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005504 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005505 hs->nos_count = -1;
5506 } else {
5507 hs->lip_count = -1;
5508 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005509 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005510 }
5511
5512 hs->dumped_frames = -1;
5513
James Smart64ba8812006-08-02 15:24:34 -04005514 seconds = get_seconds();
5515 if (seconds < psli->stats_start)
5516 hs->seconds_since_last_reset = seconds +
5517 ((unsigned long)-1 - psli->stats_start);
5518 else
5519 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005520
James Smart1dcb58e2007-04-25 09:51:30 -04005521 mempool_free(pmboxq, phba->mbox_mem_pool);
5522
dea31012005-04-17 16:05:31 -05005523 return hs;
5524}
5525
James Smarte59058c2008-08-24 21:49:00 -04005526/**
James Smart3621a712009-04-06 18:47:14 -04005527 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005528 * @shost: kernel scsi host pointer.
5529 **/
James Smart64ba8812006-08-02 15:24:34 -04005530static void
5531lpfc_reset_stats(struct Scsi_Host *shost)
5532{
James Smart2e0fef82007-06-17 19:56:36 -05005533 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5534 struct lpfc_hba *phba = vport->phba;
5535 struct lpfc_sli *psli = &phba->sli;
5536 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005537 LPFC_MBOXQ_t *pmboxq;
5538 MAILBOX_t *pmb;
5539 int rc = 0;
5540
James Smart2e0fef82007-06-17 19:56:36 -05005541 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005542 return;
5543
James Smart64ba8812006-08-02 15:24:34 -04005544 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5545 if (!pmboxq)
5546 return;
5547 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5548
James Smart04c68492009-05-22 14:52:52 -04005549 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005550 pmb->mbxCommand = MBX_READ_STATUS;
5551 pmb->mbxOwner = OWN_HOST;
5552 pmb->un.varWords[0] = 0x1; /* reset request */
5553 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005554 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005555
James Smart2e0fef82007-06-17 19:56:36 -05005556 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005557 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005558 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5559 else
5560 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5561
5562 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005563 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005564 mempool_free(pmboxq, phba->mbox_mem_pool);
5565 return;
5566 }
5567
5568 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5569 pmb->mbxCommand = MBX_READ_LNK_STAT;
5570 pmb->mbxOwner = OWN_HOST;
5571 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005572 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005573
James Smart2e0fef82007-06-17 19:56:36 -05005574 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005575 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005576 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5577 else
5578 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5579
5580 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005581 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005582 mempool_free( pmboxq, phba->mbox_mem_pool);
5583 return;
5584 }
5585
5586 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5587 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5588 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5589 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5590 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5591 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5592 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005593 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005594 lso->link_events = (phba->link_events >> 1);
5595 else
5596 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005597
5598 psli->stats_start = get_seconds();
5599
James Smart1dcb58e2007-04-25 09:51:30 -04005600 mempool_free(pmboxq, phba->mbox_mem_pool);
5601
James Smart64ba8812006-08-02 15:24:34 -04005602 return;
5603}
dea31012005-04-17 16:05:31 -05005604
5605/*
5606 * The LPFC driver treats linkdown handling as target loss events so there
5607 * are no sysfs handlers for link_down_tmo.
5608 */
James Smart685f0bf2007-04-25 09:53:08 -04005609
James Smarte59058c2008-08-24 21:49:00 -04005610/**
James Smart3621a712009-04-06 18:47:14 -04005611 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005612 * @starget: kernel scsi target pointer.
5613 *
5614 * Returns:
5615 * address of the node list if found
5616 * NULL target not found
5617 **/
James Smart685f0bf2007-04-25 09:53:08 -04005618static struct lpfc_nodelist *
5619lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005620{
James Smart2e0fef82007-06-17 19:56:36 -05005621 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5622 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005623 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005624
5625 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005626 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005627 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005628 if (NLP_CHK_NODE_ACT(ndlp) &&
5629 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005630 starget->id == ndlp->nlp_sid) {
5631 spin_unlock_irq(shost->host_lock);
5632 return ndlp;
dea31012005-04-17 16:05:31 -05005633 }
5634 }
5635 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005636 return NULL;
5637}
dea31012005-04-17 16:05:31 -05005638
James Smarte59058c2008-08-24 21:49:00 -04005639/**
James Smart3621a712009-04-06 18:47:14 -04005640 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005641 * @starget: kernel scsi target pointer.
5642 **/
James Smart685f0bf2007-04-25 09:53:08 -04005643static void
5644lpfc_get_starget_port_id(struct scsi_target *starget)
5645{
5646 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5647
5648 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005649}
5650
James Smarte59058c2008-08-24 21:49:00 -04005651/**
James Smart3621a712009-04-06 18:47:14 -04005652 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005653 * @starget: kernel scsi target pointer.
5654 *
5655 * Description: Set the target node name to the ndlp node name wwn or zero.
5656 **/
dea31012005-04-17 16:05:31 -05005657static void
5658lpfc_get_starget_node_name(struct scsi_target *starget)
5659{
James Smart685f0bf2007-04-25 09:53:08 -04005660 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005661
James Smart685f0bf2007-04-25 09:53:08 -04005662 fc_starget_node_name(starget) =
5663 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005664}
5665
James Smarte59058c2008-08-24 21:49:00 -04005666/**
James Smart3621a712009-04-06 18:47:14 -04005667 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005668 * @starget: kernel scsi target pointer.
5669 *
5670 * Description: set the target port name to the ndlp port name wwn or zero.
5671 **/
dea31012005-04-17 16:05:31 -05005672static void
5673lpfc_get_starget_port_name(struct scsi_target *starget)
5674{
James Smart685f0bf2007-04-25 09:53:08 -04005675 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005676
James Smart685f0bf2007-04-25 09:53:08 -04005677 fc_starget_port_name(starget) =
5678 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005679}
5680
James Smarte59058c2008-08-24 21:49:00 -04005681/**
James Smart3621a712009-04-06 18:47:14 -04005682 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005683 * @rport: fc rport address.
5684 * @timeout: new value for dev loss tmo.
5685 *
5686 * Description:
5687 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5688 * dev_loss_tmo to one.
5689 **/
dea31012005-04-17 16:05:31 -05005690static void
dea31012005-04-17 16:05:31 -05005691lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5692{
dea31012005-04-17 16:05:31 -05005693 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005694 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005695 else
James Smartc01f3202006-08-18 17:47:08 -04005696 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005697}
5698
James Smarte59058c2008-08-24 21:49:00 -04005699/**
James Smart3621a712009-04-06 18:47:14 -04005700 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005701 *
5702 * Description:
5703 * Macro that uses field to generate a function with the name lpfc_show_rport_
5704 *
5705 * lpfc_show_rport_##field: returns the bytes formatted in buf
5706 * @cdev: class converted to an fc_rport.
5707 * @buf: on return contains the target_field or zero.
5708 *
5709 * Returns: size of formatted string.
5710 **/
dea31012005-04-17 16:05:31 -05005711#define lpfc_rport_show_function(field, format_string, sz, cast) \
5712static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005713lpfc_show_rport_##field (struct device *dev, \
5714 struct device_attribute *attr, \
5715 char *buf) \
dea31012005-04-17 16:05:31 -05005716{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005717 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005718 struct lpfc_rport_data *rdata = rport->hostdata; \
5719 return snprintf(buf, sz, format_string, \
5720 (rdata->target) ? cast rdata->target->field : 0); \
5721}
5722
5723#define lpfc_rport_rd_attr(field, format_string, sz) \
5724 lpfc_rport_show_function(field, format_string, sz, ) \
5725static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5726
James Smarteada2722008-12-04 22:39:13 -05005727/**
James Smart3621a712009-04-06 18:47:14 -04005728 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005729 * @fc_vport: The fc_vport who's symbolic name has been changed.
5730 *
5731 * Description:
5732 * This function is called by the transport after the @fc_vport's symbolic name
5733 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005734 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005735 **/
5736static void
5737lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5738{
5739 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5740
5741 if (vport->port_state == LPFC_VPORT_READY)
5742 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5743}
dea31012005-04-17 16:05:31 -05005744
James Smartf4b4c682009-05-22 14:53:12 -04005745/**
5746 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5747 * @phba: Pointer to lpfc_hba struct.
5748 *
5749 * This function is called by the lpfc_get_cfgparam() routine to set the
5750 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005751 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005752 * before hba port or vport created.
5753 **/
5754static void
5755lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5756{
5757 phba->cfg_log_verbose = verbose;
5758}
5759
dea31012005-04-17 16:05:31 -05005760struct fc_function_template lpfc_transport_functions = {
5761 /* fixed attributes the driver supports */
5762 .show_host_node_name = 1,
5763 .show_host_port_name = 1,
5764 .show_host_supported_classes = 1,
5765 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005766 .show_host_supported_speeds = 1,
5767 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005768 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005769
5770 /* dynamic attributes the driver supports */
5771 .get_host_port_id = lpfc_get_host_port_id,
5772 .show_host_port_id = 1,
5773
5774 .get_host_port_type = lpfc_get_host_port_type,
5775 .show_host_port_type = 1,
5776
5777 .get_host_port_state = lpfc_get_host_port_state,
5778 .show_host_port_state = 1,
5779
5780 /* active_fc4s is shown but doesn't change (thus no get function) */
5781 .show_host_active_fc4s = 1,
5782
5783 .get_host_speed = lpfc_get_host_speed,
5784 .show_host_speed = 1,
5785
5786 .get_host_fabric_name = lpfc_get_host_fabric_name,
5787 .show_host_fabric_name = 1,
5788
5789 /*
5790 * The LPFC driver treats linkdown handling as target loss events
5791 * so there are no sysfs handlers for link_down_tmo.
5792 */
5793
5794 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005795 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005796
5797 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5798 .show_rport_maxframe_size = 1,
5799 .show_rport_supported_classes = 1,
5800
dea31012005-04-17 16:05:31 -05005801 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5802 .show_rport_dev_loss_tmo = 1,
5803
5804 .get_starget_port_id = lpfc_get_starget_port_id,
5805 .show_starget_port_id = 1,
5806
5807 .get_starget_node_name = lpfc_get_starget_node_name,
5808 .show_starget_node_name = 1,
5809
5810 .get_starget_port_name = lpfc_get_starget_port_name,
5811 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005812
5813 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005814 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5815 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005816
James Smart92d7f7b2007-06-17 19:56:38 -05005817 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005818
5819 .vport_disable = lpfc_vport_disable,
5820
5821 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005822
5823 .bsg_request = lpfc_bsg_request,
5824 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005825};
5826
James Smart98c9ea52007-10-27 13:37:33 -04005827struct fc_function_template lpfc_vport_transport_functions = {
5828 /* fixed attributes the driver supports */
5829 .show_host_node_name = 1,
5830 .show_host_port_name = 1,
5831 .show_host_supported_classes = 1,
5832 .show_host_supported_fc4s = 1,
5833 .show_host_supported_speeds = 1,
5834 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005835 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005836
5837 /* dynamic attributes the driver supports */
5838 .get_host_port_id = lpfc_get_host_port_id,
5839 .show_host_port_id = 1,
5840
5841 .get_host_port_type = lpfc_get_host_port_type,
5842 .show_host_port_type = 1,
5843
5844 .get_host_port_state = lpfc_get_host_port_state,
5845 .show_host_port_state = 1,
5846
5847 /* active_fc4s is shown but doesn't change (thus no get function) */
5848 .show_host_active_fc4s = 1,
5849
5850 .get_host_speed = lpfc_get_host_speed,
5851 .show_host_speed = 1,
5852
5853 .get_host_fabric_name = lpfc_get_host_fabric_name,
5854 .show_host_fabric_name = 1,
5855
5856 /*
5857 * The LPFC driver treats linkdown handling as target loss events
5858 * so there are no sysfs handlers for link_down_tmo.
5859 */
5860
5861 .get_fc_host_stats = lpfc_get_stats,
5862 .reset_fc_host_stats = lpfc_reset_stats,
5863
5864 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5865 .show_rport_maxframe_size = 1,
5866 .show_rport_supported_classes = 1,
5867
5868 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5869 .show_rport_dev_loss_tmo = 1,
5870
5871 .get_starget_port_id = lpfc_get_starget_port_id,
5872 .show_starget_port_id = 1,
5873
5874 .get_starget_node_name = lpfc_get_starget_node_name,
5875 .show_starget_node_name = 1,
5876
5877 .get_starget_port_name = lpfc_get_starget_port_name,
5878 .show_starget_port_name = 1,
5879
5880 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5881 .terminate_rport_io = lpfc_terminate_rport_io,
5882
5883 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005884
5885 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005886};
5887
James Smarte59058c2008-08-24 21:49:00 -04005888/**
James Smart3621a712009-04-06 18:47:14 -04005889 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005890 * @phba: lpfc_hba pointer.
5891 **/
dea31012005-04-17 16:05:31 -05005892void
5893lpfc_get_cfgparam(struct lpfc_hba *phba)
5894{
James Smart49aa1432012-08-03 12:36:42 -04005895 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005896 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005897 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5898 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005899 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005900 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5901 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005902 lpfc_ack0_init(phba, lpfc_ack0);
5903 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005904 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005905 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04005906 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005907 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005908 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005909 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05005910 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
5911 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05005912 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005913 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005914 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart67d12732012-08-03 12:36:13 -04005915 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005916 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5917 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart1ba981f2014-02-20 09:56:45 -05005918 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5919 if (phba->sli_rev != LPFC_SLI_REV4)
5920 phba->cfg_EnableXLane = 0;
5921 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5922 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5923 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5924 phba->cfg_oas_lun_state = 0;
5925 phba->cfg_oas_lun_status = 0;
5926 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07005927 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05005928 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005929 if (phba->sli_rev == LPFC_SLI_REV4)
5930 phba->cfg_poll = 0;
5931 else
James Smart1ba981f2014-02-20 09:56:45 -05005932 phba->cfg_poll = lpfc_poll;
James Smart4258e982015-12-16 18:11:58 -05005933
James Smarta12e07b2006-12-02 13:35:30 -05005934 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005935 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005936 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005937 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005938 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005939 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005940 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005941 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005942 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005943 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005944 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005945 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07005946 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04005947 return;
5948}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005949
James Smarte59058c2008-08-24 21:49:00 -04005950/**
James Smart3621a712009-04-06 18:47:14 -04005951 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005952 * @vport: lpfc_vport pointer.
5953 **/
James Smart3de2a652007-08-02 11:09:59 -04005954void
5955lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5956{
James Smarte8b62012007-08-02 11:10:09 -04005957 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005958 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005959 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005960 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5961 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5962 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5963 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5964 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5965 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04005966 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04005967 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005968 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5969 lpfc_max_luns_init(vport, lpfc_max_luns);
5970 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005971 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005972 return;
5973}