blob: af3eb8545689afd61d1c171bdf3658fd1fa81a78 [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 Smart2e61f502014-04-04 13:53:03 -04004 * Copyright (C) 2004-2014 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;
409
dea31012005-04-17 16:05:31 -0500410 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
411}
James Smarte59058c2008-08-24 21:49:00 -0400412
413/**
James Smart3621a712009-04-06 18:47:14 -0400414 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400415 * @dev: class converted to a Scsi_host structure.
416 * @attr: device attribute, not used.
417 * @buf: on return contains text describing the state of the link.
418 *
419 * Notes:
420 * The switch statement has no default so zero will be returned.
421 *
422 * Returns: size of formatted string.
423 **/
dea31012005-04-17 16:05:31 -0500424static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100425lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
426 char *buf)
dea31012005-04-17 16:05:31 -0500427{
Tony Jonesee959b02008-02-22 00:13:36 +0100428 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
430 struct lpfc_hba *phba = vport->phba;
431 int len = 0;
432
433 switch (phba->link_state) {
434 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500435 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500436 case LPFC_INIT_START:
437 case LPFC_INIT_MBX_CMDS:
438 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500439 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400440 if (phba->hba_flag & LINK_DISABLED)
441 len += snprintf(buf + len, PAGE_SIZE-len,
442 "Link Down - User disabled\n");
443 else
444 len += snprintf(buf + len, PAGE_SIZE-len,
445 "Link Down\n");
dea31012005-04-17 16:05:31 -0500446 break;
447 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500448 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500449 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400450 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500451
452 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500453 case LPFC_LOCAL_CFG_LINK:
454 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500455 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500456 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500457 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500458 case LPFC_FLOGI:
459 case LPFC_FABRIC_CFG_LINK:
460 case LPFC_NS_REG:
461 case LPFC_NS_QRY:
462 case LPFC_BUILD_DISC_LIST:
463 case LPFC_DISC_AUTH:
464 len += snprintf(buf + len, PAGE_SIZE - len,
465 "Discovery\n");
466 break;
467 case LPFC_VPORT_READY:
468 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
469 break;
470
James Smart92d7f7b2007-06-17 19:56:38 -0500471 case LPFC_VPORT_FAILED:
472 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
473 break;
474
475 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500476 len += snprintf(buf + len, PAGE_SIZE - len,
477 "Unknown\n");
478 break;
479 }
James Smart84774a42008-08-24 21:50:06 -0400480 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
481 len += snprintf(buf + len, PAGE_SIZE-len,
482 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500483 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500484 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500485 len += snprintf(buf + len, PAGE_SIZE-len,
486 " Public Loop\n");
487 else
488 len += snprintf(buf + len, PAGE_SIZE-len,
489 " Private Loop\n");
490 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500491 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500492 len += snprintf(buf + len, PAGE_SIZE-len,
493 " Fabric\n");
494 else
495 len += snprintf(buf + len, PAGE_SIZE-len,
496 " Point-2-Point\n");
497 }
498 }
James Smart2e0fef82007-06-17 19:56:36 -0500499
dea31012005-04-17 16:05:31 -0500500 return len;
501}
502
James Smarte59058c2008-08-24 21:49:00 -0400503/**
James Smart026abb82011-12-13 13:20:45 -0500504 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
505 * @dev: class unused variable.
506 * @attr: device attribute, not used.
507 * @buf: on return contains the module description text.
508 *
509 * Returns: size of formatted string.
510 **/
511static ssize_t
512lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
513 char *buf)
514{
515 struct Scsi_Host *shost = class_to_shost(dev);
516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
518
519 if (phba->sli_rev < LPFC_SLI_REV4)
520 return snprintf(buf, PAGE_SIZE, "fc\n");
521
522 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
523 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
524 return snprintf(buf, PAGE_SIZE, "fcoe\n");
525 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
526 return snprintf(buf, PAGE_SIZE, "fc\n");
527 }
528 return snprintf(buf, PAGE_SIZE, "unknown\n");
529}
530
531/**
James Smart1ba981f2014-02-20 09:56:45 -0500532 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
533 * (OAS) is supported.
534 * @dev: class unused variable.
535 * @attr: device attribute, not used.
536 * @buf: on return contains the module description text.
537 *
538 * Returns: size of formatted string.
539 **/
540static ssize_t
541lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
542 char *buf)
543{
544 struct Scsi_Host *shost = class_to_shost(dev);
545 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
546 struct lpfc_hba *phba = vport->phba;
547
548 return snprintf(buf, PAGE_SIZE, "%d\n",
549 phba->sli4_hba.pc_sli4_params.oas_supported);
550}
551
552/**
James Smart84d1b002010-02-12 14:42:33 -0500553 * lpfc_link_state_store - Transition the link_state on an HBA port
554 * @dev: class device that is converted into a Scsi_host.
555 * @attr: device attribute, not used.
556 * @buf: one or more lpfc_polling_flags values.
557 * @count: not used.
558 *
559 * Returns:
560 * -EINVAL if the buffer is not "up" or "down"
561 * return from link state change function if non-zero
562 * length of the buf on success
563 **/
564static ssize_t
565lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
566 const char *buf, size_t count)
567{
568 struct Scsi_Host *shost = class_to_shost(dev);
569 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
570 struct lpfc_hba *phba = vport->phba;
571
572 int status = -EINVAL;
573
574 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
575 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400576 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500577 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
578 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400579 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500580
581 if (status == 0)
582 return strlen(buf);
583 else
584 return status;
585}
586
587/**
James Smart3621a712009-04-06 18:47:14 -0400588 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400589 * @dev: class device that is converted into a Scsi_host.
590 * @attr: device attribute, not used.
591 * @buf: on return contains the sum of fc mapped and unmapped.
592 *
593 * Description:
594 * Returns the ascii text number of the sum of the fc mapped and unmapped
595 * vport counts.
596 *
597 * Returns: size of formatted string.
598 **/
dea31012005-04-17 16:05:31 -0500599static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100600lpfc_num_discovered_ports_show(struct device *dev,
601 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500602{
Tony Jonesee959b02008-02-22 00:13:36 +0100603 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
605
606 return snprintf(buf, PAGE_SIZE, "%d\n",
607 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500608}
609
James Smarte59058c2008-08-24 21:49:00 -0400610/**
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400612 * @shost: Scsi_Host pointer.
613 *
614 * Description:
615 * Bring the link down gracefully then re-init the link. The firmware will
616 * re-init the fiber channel interface as required. Does not issue a LIP.
617 *
618 * Returns:
619 * -EPERM port offline or management commands are being blocked
620 * -ENOMEM cannot allocate memory for the mailbox command
621 * -EIO error sending the mailbox command
622 * zero for success
623 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700624static int
James Smart2e0fef82007-06-17 19:56:36 -0500625lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500626{
James Smart2e0fef82007-06-17 19:56:36 -0500627 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
628 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500629 LPFC_MBOXQ_t *pmboxq;
630 int mbxstatus = MBXERR_ERROR;
631
James Smart2e0fef82007-06-17 19:56:36 -0500632 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500633 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500634 return -EPERM;
635
636 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
637
638 if (!pmboxq)
639 return -ENOMEM;
640
641 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400642 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
643 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400644
James Smart33ccf8d2006-08-17 11:57:58 -0400645 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500646
James Smart04c68492009-05-22 14:52:52 -0400647 if ((mbxstatus == MBX_SUCCESS) &&
648 (pmboxq->u.mb.mbxStatus == 0 ||
649 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400650 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
651 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
652 phba->cfg_link_speed);
653 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
654 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400655 if ((mbxstatus == MBX_SUCCESS) &&
656 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
657 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
658 "2859 SLI authentication is required "
659 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400660 }
661
James Smart5b8bd0c2007-04-25 09:52:49 -0400662 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500663 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400664 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500665
666 if (mbxstatus == MBXERR_ERROR)
667 return -EIO;
668
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700669 return 0;
dea31012005-04-17 16:05:31 -0500670}
671
James Smarte59058c2008-08-24 21:49:00 -0400672/**
James Smart3621a712009-04-06 18:47:14 -0400673 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400674 * @phba: lpfc_hba pointer.
675 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
676 *
677 * Notes:
678 * Assumes any error from lpfc_do_offline() will be negative.
679 * Can wait up to 5 seconds for the port ring buffers count
680 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400681 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400682 *
683 * Returns:
684 * -EIO error posting the event
685 * zero for success
686 **/
James Smart40496f02006-07-06 15:50:22 -0400687static int
James Smart46fa3112007-04-25 09:51:45 -0400688lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
689{
690 struct completion online_compl;
691 struct lpfc_sli_ring *pring;
692 struct lpfc_sli *psli;
693 int status = 0;
694 int cnt = 0;
695 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500696 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400697
698 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500699 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400700 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500701 if (rc == 0)
702 return -ENOMEM;
703
James Smart46fa3112007-04-25 09:51:45 -0400704 wait_for_completion(&online_compl);
705
706 if (status != 0)
707 return -EIO;
708
709 psli = &phba->sli;
710
James Smart09372822008-01-11 01:52:54 -0500711 /* Wait a little for things to settle down, but not
712 * long enough for dev loss timeout to expire.
713 */
James Smart46fa3112007-04-25 09:51:45 -0400714 for (i = 0; i < psli->num_rings; i++) {
715 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500716 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400717 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500718 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400719 lpfc_printf_log(phba,
720 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400721 "0466 Outstanding IO when "
722 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400723 break;
724 }
725 }
726 }
727
728 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500729 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
730 if (rc == 0)
731 return -ENOMEM;
732
James Smart46fa3112007-04-25 09:51:45 -0400733 wait_for_completion(&online_compl);
734
735 if (status != 0)
736 return -EIO;
737
738 return 0;
739}
740
James Smarte59058c2008-08-24 21:49:00 -0400741/**
James Smart3621a712009-04-06 18:47:14 -0400742 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400743 * @phba: lpfc_hba pointer.
744 *
745 * Description:
746 * If the port is configured to allow a reset then the hba is brought
747 * offline then online.
748 *
749 * Notes:
750 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500751 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400752 *
753 * Returns:
754 * lpfc_do_offline() return code if not zero
755 * -EIO reset not configured or error posting the event
756 * zero for success
757 **/
James Smart7f860592011-03-11 16:05:52 -0500758int
James Smart40496f02006-07-06 15:50:22 -0400759lpfc_selective_reset(struct lpfc_hba *phba)
760{
761 struct completion online_compl;
762 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500763 int rc;
James Smart40496f02006-07-06 15:50:22 -0400764
James Smart71157c92013-07-15 18:34:36 -0400765 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400766 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500767
James Smart71157c92013-07-15 18:34:36 -0400768 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
769 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400770
James Smart71157c92013-07-15 18:34:36 -0400771 if (status != 0)
772 return status;
773 }
James Smart40496f02006-07-06 15:50:22 -0400774
775 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500776 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400777 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500778 if (rc == 0)
779 return -ENOMEM;
780
James Smart40496f02006-07-06 15:50:22 -0400781 wait_for_completion(&online_compl);
782
783 if (status != 0)
784 return -EIO;
785
786 return 0;
787}
788
James Smarte59058c2008-08-24 21:49:00 -0400789/**
James Smart3621a712009-04-06 18:47:14 -0400790 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400791 * @dev: class device that is converted into a Scsi_host.
792 * @attr: device attribute, not used.
793 * @buf: containing the string "selective".
794 * @count: unused variable.
795 *
796 * Description:
797 * If the buf contains the string "selective" then lpfc_selective_reset()
798 * is called to perform the reset.
799 *
800 * Notes:
801 * Assumes any error from lpfc_selective_reset() will be negative.
802 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200803 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400804 *
805 * Returns:
806 * -EINVAL if the buffer does not contain the string "selective"
807 * length of buf if lpfc-selective_reset() if the call succeeds
808 * return value of lpfc_selective_reset() if the call fails
809**/
James Smart40496f02006-07-06 15:50:22 -0400810static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100811lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
812 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400813{
Tony Jonesee959b02008-02-22 00:13:36 +0100814 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500815 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
816 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400817 int status = -EINVAL;
818
James Smart73d91e52011-10-10 21:32:10 -0400819 if (!phba->cfg_enable_hba_reset)
820 return -EACCES;
821
James Smart40496f02006-07-06 15:50:22 -0400822 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500823 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400824
825 if (status == 0)
826 return strlen(buf);
827 else
828 return status;
829}
830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart88a2cfb2011-07-22 18:36:33 -0400832 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
833 * @phba: lpfc_hba pointer.
834 *
835 * Description:
836 * SLI4 interface type-2 device to wait on the sliport status register for
837 * the readyness after performing a firmware reset.
838 *
839 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +0900840 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -0500841 * reset, -EIO when port timeout from recovering from the reset.
842 *
843 * Note:
844 * As the caller will interpret the return code by value, be careful in making
845 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400846 **/
James Smart73d91e52011-10-10 21:32:10 -0400847int
James Smart88a2cfb2011-07-22 18:36:33 -0400848lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
849{
James Smartf7a919b2011-08-21 21:49:16 -0400850 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400851 int i;
852
James Smartf7a919b2011-08-21 21:49:16 -0400853 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400854 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
855 &portstat_reg.word0);
856
Masanari Iida0b1587b2013-07-17 04:37:44 +0900857 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -0400858 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
859 !bf_get(lpfc_sliport_status_err, &portstat_reg))
860 return -EPERM;
861
James Smart88a2cfb2011-07-22 18:36:33 -0400862 /* wait for the SLI port firmware ready after firmware reset */
863 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
864 msleep(10);
865 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
866 &portstat_reg.word0);
867 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
868 continue;
869 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
870 continue;
871 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
872 continue;
873 break;
874 }
875
876 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
877 return 0;
878 else
879 return -EIO;
880}
881
882/**
James Smart52d52442011-05-24 11:42:45 -0400883 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400884 * @phba: lpfc_hba pointer.
885 *
886 * Description:
James Smart52d52442011-05-24 11:42:45 -0400887 * Request SLI4 interface type-2 device to perform a physical register set
888 * access.
James Smartc0c11512011-05-24 11:41:34 -0400889 *
890 * Returns:
891 * zero for success
892 **/
893static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400894lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400895{
896 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400897 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500898 uint32_t before_fc_flag;
899 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400900 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500901 int status = 0, rc = 0;
902 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400903
904 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400905 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400906
James Smart52d52442011-05-24 11:42:45 -0400907 if ((phba->sli_rev < LPFC_SLI_REV4) ||
908 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
909 LPFC_SLI_INTF_IF_TYPE_2))
910 return -EPERM;
911
James Smart026abb82011-12-13 13:20:45 -0500912 /* Keep state if we need to restore back */
913 before_fc_flag = phba->pport->fc_flag;
914 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
915
James Smartb76f2dc2011-07-22 18:37:42 -0400916 /* Disable SR-IOV virtual functions if enabled */
917 if (phba->cfg_sriov_nr_virtfn) {
918 pci_disable_sriov(pdev);
919 phba->cfg_sriov_nr_virtfn = 0;
920 }
James Smart229adb02013-04-17 20:16:51 -0400921
James Smart02936352014-04-04 13:52:12 -0400922 if (opcode == LPFC_FW_DUMP)
923 phba->hba_flag |= HBA_FW_DUMP_OP;
924
James Smartc0c11512011-05-24 11:41:34 -0400925 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
926
James Smart02936352014-04-04 13:52:12 -0400927 if (status != 0) {
928 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -0400929 return status;
James Smart02936352014-04-04 13:52:12 -0400930 }
James Smartc0c11512011-05-24 11:41:34 -0400931
932 /* wait for the device to be quiesced before firmware reset */
933 msleep(100);
934
935 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
936 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400937
938 if (opcode == LPFC_FW_DUMP)
939 reg_val |= LPFC_FW_DUMP_REQUEST;
940 else if (opcode == LPFC_FW_RESET)
941 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
942 else if (opcode == LPFC_DV_RESET)
943 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
944
James Smartc0c11512011-05-24 11:41:34 -0400945 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
946 LPFC_CTL_PDEV_CTL_OFFSET);
947 /* flush */
948 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
949
950 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400951 rc = lpfc_sli4_pdev_status_reg_wait(phba);
952
James Smart026abb82011-12-13 13:20:45 -0500953 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +0900954 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -0500955 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +0900956 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -0500957 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500958 } else if (rc == -EIO) {
959 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500960 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
961 "3153 Fail to perform the requested "
962 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400963 return rc;
James Smart026abb82011-12-13 13:20:45 -0500964 }
965
966 /* keep the original port state */
967 if (before_fc_flag & FC_OFFLINE_MODE)
968 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400969
970 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500971 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
972 LPFC_EVT_ONLINE);
973 if (!job_posted)
974 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400975
976 wait_for_completion(&online_compl);
977
James Smart026abb82011-12-13 13:20:45 -0500978out:
979 /* in any case, restore the virtual functions enabled as before */
980 if (sriov_nr_virtfn) {
981 sriov_err =
982 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
983 if (!sriov_err)
984 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
985 }
James Smartc0c11512011-05-24 11:41:34 -0400986
James Smart026abb82011-12-13 13:20:45 -0500987 /* return proper error code */
988 if (!rc) {
989 if (!job_posted)
990 rc = -ENOMEM;
991 else if (status)
992 rc = -EIO;
993 }
994 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400995}
996
997/**
James Smart3621a712009-04-06 18:47:14 -0400998 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400999 * @dev: class device that is converted into a Scsi_host.
1000 * @attr: device attribute, not used.
1001 * @buf: on return contains the ascii number of nport events.
1002 *
1003 * Returns: size of formatted string.
1004 **/
dea31012005-04-17 16:05:31 -05001005static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001006lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1007 char *buf)
dea31012005-04-17 16:05:31 -05001008{
Tony Jonesee959b02008-02-22 00:13:36 +01001009 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1011 struct lpfc_hba *phba = vport->phba;
1012
dea31012005-04-17 16:05:31 -05001013 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1014}
1015
James Smarte59058c2008-08-24 21:49:00 -04001016/**
James Smart3621a712009-04-06 18:47:14 -04001017 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001018 * @dev: class device that is converted into a Scsi_host.
1019 * @attr: device attribute, not used.
1020 * @buf: on return contains the state of the adapter.
1021 *
1022 * Returns: size of formatted string.
1023 **/
dea31012005-04-17 16:05:31 -05001024static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001025lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1026 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001027{
Tony Jonesee959b02008-02-22 00:13:36 +01001028 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001029 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1030 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001031 char * state;
1032
James Smart2e0fef82007-06-17 19:56:36 -05001033 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001034 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001035 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001036 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001037 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001038 state = "offline";
1039 else
1040 state = "online";
1041
1042 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1043}
1044
James Smarte59058c2008-08-24 21:49:00 -04001045/**
James Smart3621a712009-04-06 18:47:14 -04001046 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001047 * @dev: class device that is converted into a Scsi_host.
1048 * @attr: device attribute, not used.
1049 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1050 * @count: unused variable.
1051 *
1052 * Returns:
1053 * -EACCES if enable hba reset not enabled
1054 * -EINVAL if the buffer does not contain a valid string (see above)
1055 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1056 * buf length greater than zero indicates success
1057 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001058static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001059lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1060 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001061{
Tony Jonesee959b02008-02-22 00:13:36 +01001062 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1064 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001065 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001066 char *board_mode_str = NULL;
1067 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001068 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001069
James Smart026abb82011-12-13 13:20:45 -05001070 if (!phba->cfg_enable_hba_reset) {
1071 status = -EACCES;
1072 goto board_mode_out;
1073 }
James Smart88a2cfb2011-07-22 18:36:33 -04001074
1075 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001076 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001077
Jamie Wellnitz41415862006-02-28 19:25:27 -05001078 init_completion(&online_compl);
1079
James Smart46fa3112007-04-25 09:51:45 -04001080 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001081 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001082 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001083 if (rc == 0) {
1084 status = -ENOMEM;
1085 goto board_mode_out;
1086 }
James Smart46fa3112007-04-25 09:51:45 -04001087 wait_for_completion(&online_compl);
1088 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1089 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001090 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001091 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001092 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001093 else
1094 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001095 else if (strncmp(buf, "error", sizeof("error") - 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_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001100 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001101 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1102 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1103 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1104 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1105 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001106 else
James Smart026abb82011-12-13 13:20:45 -05001107 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001108
James Smart026abb82011-12-13 13:20:45 -05001109board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001110 if (!status)
1111 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001112 else {
1113 board_mode_str = strchr(buf, '\n');
1114 if (board_mode_str)
1115 *board_mode_str = '\0';
1116 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1117 "3097 Failed \"%s\", status(%d), "
1118 "fc_flag(x%x)\n",
1119 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001120 return status;
James Smart026abb82011-12-13 13:20:45 -05001121 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001122}
1123
James Smarte59058c2008-08-24 21:49:00 -04001124/**
James Smart3621a712009-04-06 18:47:14 -04001125 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001126 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001127 * @mxri: max xri count.
1128 * @axri: available xri count.
1129 * @mrpi: max rpi count.
1130 * @arpi: available rpi count.
1131 * @mvpi: max vpi count.
1132 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001133 *
1134 * Description:
1135 * If an integer pointer for an count is not null then the value for the
1136 * count is returned.
1137 *
1138 * Returns:
1139 * zero on error
1140 * one for success
1141 **/
James Smart311464e2007-08-02 11:10:37 -04001142static int
James Smart858c9f62007-06-17 19:56:39 -05001143lpfc_get_hba_info(struct lpfc_hba *phba,
1144 uint32_t *mxri, uint32_t *axri,
1145 uint32_t *mrpi, uint32_t *arpi,
1146 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001147{
James Smart04c68492009-05-22 14:52:52 -04001148 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001149 LPFC_MBOXQ_t *pmboxq;
1150 MAILBOX_t *pmb;
1151 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001152 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001153
1154 /*
1155 * prevent udev from issuing mailbox commands until the port is
1156 * configured.
1157 */
1158 if (phba->link_state < LPFC_LINK_DOWN ||
1159 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001160 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001161 return 0;
1162
1163 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1164 return 0;
1165
1166 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1167 if (!pmboxq)
1168 return 0;
1169 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1170
James Smart04c68492009-05-22 14:52:52 -04001171 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001172 pmb->mbxCommand = MBX_READ_CONFIG;
1173 pmb->mbxOwner = OWN_HOST;
1174 pmboxq->context1 = NULL;
1175
James Smart75baf692010-06-08 18:31:21 -04001176 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001177 rc = MBX_NOT_FINISHED;
1178 else
1179 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1180
1181 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001182 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001183 mempool_free(pmboxq, phba->mbox_mem_pool);
1184 return 0;
1185 }
1186
James Smartda0436e2009-05-22 14:51:39 -04001187 if (phba->sli_rev == LPFC_SLI_REV4) {
1188 rd_config = &pmboxq->u.mqe.un.rd_config;
1189 if (mrpi)
1190 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1191 if (arpi)
1192 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1193 phba->sli4_hba.max_cfg_param.rpi_used;
1194 if (mxri)
1195 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1196 if (axri)
1197 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1198 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001199
1200 /* Account for differences with SLI-3. Get vpi count from
1201 * mailbox data and subtract one for max vpi value.
1202 */
1203 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1204 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1205
James Smartda0436e2009-05-22 14:51:39 -04001206 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001207 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001208 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001209 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001210 } else {
1211 if (mrpi)
1212 *mrpi = pmb->un.varRdConfig.max_rpi;
1213 if (arpi)
1214 *arpi = pmb->un.varRdConfig.avail_rpi;
1215 if (mxri)
1216 *mxri = pmb->un.varRdConfig.max_xri;
1217 if (axri)
1218 *axri = pmb->un.varRdConfig.avail_xri;
1219 if (mvpi)
1220 *mvpi = pmb->un.varRdConfig.max_vpi;
1221 if (avpi)
1222 *avpi = pmb->un.varRdConfig.avail_vpi;
1223 }
James Smart92d7f7b2007-06-17 19:56:38 -05001224
1225 mempool_free(pmboxq, phba->mbox_mem_pool);
1226 return 1;
1227}
1228
James Smarte59058c2008-08-24 21:49:00 -04001229/**
James Smart3621a712009-04-06 18:47:14 -04001230 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001231 * @dev: class device that is converted into a Scsi_host.
1232 * @attr: device attribute, not used.
1233 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1234 *
1235 * Description:
1236 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1237 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1238 * to "Unknown" and the buffer length is returned, therefore the caller
1239 * must check for "Unknown" in the buffer to detect a failure.
1240 *
1241 * Returns: size of formatted string.
1242 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001243static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001244lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1245 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001246{
Tony Jonesee959b02008-02-22 00:13:36 +01001247 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1249 struct lpfc_hba *phba = vport->phba;
1250 uint32_t cnt;
1251
James Smart858c9f62007-06-17 19:56:39 -05001252 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001253 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1254 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1255}
1256
James Smarte59058c2008-08-24 21:49:00 -04001257/**
James Smart3621a712009-04-06 18:47:14 -04001258 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001259 * @dev: class device that is converted into a Scsi_host.
1260 * @attr: device attribute, not used.
1261 * @buf: containing the used rpi count in decimal or "Unknown".
1262 *
1263 * Description:
1264 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1265 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1266 * to "Unknown" and the buffer length is returned, therefore the caller
1267 * must check for "Unknown" in the buffer to detect a failure.
1268 *
1269 * Returns: size of formatted string.
1270 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001271static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001272lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1273 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001274{
Tony Jonesee959b02008-02-22 00:13:36 +01001275 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1277 struct lpfc_hba *phba = vport->phba;
1278 uint32_t cnt, acnt;
1279
James Smart858c9f62007-06-17 19:56:39 -05001280 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001281 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1282 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1283}
1284
James Smarte59058c2008-08-24 21:49:00 -04001285/**
James Smart3621a712009-04-06 18:47:14 -04001286 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001287 * @dev: class device that is converted into a Scsi_host.
1288 * @attr: device attribute, not used.
1289 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1290 *
1291 * Description:
1292 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1293 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1294 * to "Unknown" and the buffer length is returned, therefore the caller
1295 * must check for "Unknown" in the buffer to detect a failure.
1296 *
1297 * Returns: size of formatted string.
1298 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001299static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001300lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1301 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001302{
Tony Jonesee959b02008-02-22 00:13:36 +01001303 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001304 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1305 struct lpfc_hba *phba = vport->phba;
1306 uint32_t cnt;
1307
James Smart858c9f62007-06-17 19:56:39 -05001308 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001309 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1310 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001315 * @dev: class device that is converted into a Scsi_host.
1316 * @attr: device attribute, not used.
1317 * @buf: on return contains the used xri count in decimal or "Unknown".
1318 *
1319 * Description:
1320 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1321 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1322 * to "Unknown" and the buffer length is returned, therefore the caller
1323 * must check for "Unknown" in the buffer to detect a failure.
1324 *
1325 * Returns: size of formatted string.
1326 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001327static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001328lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1329 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001330{
Tony Jonesee959b02008-02-22 00:13:36 +01001331 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001332 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1333 struct lpfc_hba *phba = vport->phba;
1334 uint32_t cnt, acnt;
1335
James Smart858c9f62007-06-17 19:56:39 -05001336 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1337 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1338 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1339}
1340
James Smarte59058c2008-08-24 21:49:00 -04001341/**
James Smart3621a712009-04-06 18:47:14 -04001342 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001343 * @dev: class device that is converted into a Scsi_host.
1344 * @attr: device attribute, not used.
1345 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1346 *
1347 * Description:
1348 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1349 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1350 * to "Unknown" and the buffer length is returned, therefore the caller
1351 * must check for "Unknown" in the buffer to detect a failure.
1352 *
1353 * Returns: size of formatted string.
1354 **/
James Smart858c9f62007-06-17 19:56:39 -05001355static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001356lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1357 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001358{
Tony Jonesee959b02008-02-22 00:13:36 +01001359 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001360 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1361 struct lpfc_hba *phba = vport->phba;
1362 uint32_t cnt;
1363
1364 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1365 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1366 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1367}
1368
James Smarte59058c2008-08-24 21:49:00 -04001369/**
James Smart3621a712009-04-06 18:47:14 -04001370 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001371 * @dev: class device that is converted into a Scsi_host.
1372 * @attr: device attribute, not used.
1373 * @buf: on return contains the used vpi count in decimal or "Unknown".
1374 *
1375 * Description:
1376 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1377 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1378 * to "Unknown" and the buffer length is returned, therefore the caller
1379 * must check for "Unknown" in the buffer to detect a failure.
1380 *
1381 * Returns: size of formatted string.
1382 **/
James Smart858c9f62007-06-17 19:56:39 -05001383static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001384lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1385 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001386{
Tony Jonesee959b02008-02-22 00:13:36 +01001387 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1389 struct lpfc_hba *phba = vport->phba;
1390 uint32_t cnt, acnt;
1391
1392 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001393 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1394 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1395}
1396
James Smarte59058c2008-08-24 21:49:00 -04001397/**
James Smart3621a712009-04-06 18:47:14 -04001398 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001399 * @dev: class device that is converted into a Scsi_host.
1400 * @attr: device attribute, not used.
1401 * @buf: text that must be interpreted to determine if npiv is supported.
1402 *
1403 * Description:
1404 * Buffer will contain text indicating npiv is not suppoerted on the port,
1405 * the port is an NPIV physical port, or it is an npiv virtual port with
1406 * the id of the vport.
1407 *
1408 * Returns: size of formatted string.
1409 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001410static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001411lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1412 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001413{
Tony Jonesee959b02008-02-22 00:13:36 +01001414 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1416 struct lpfc_hba *phba = vport->phba;
1417
1418 if (!(phba->max_vpi))
1419 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1420 if (vport->port_type == LPFC_PHYSICAL_PORT)
1421 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1422 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1423}
1424
James Smarte59058c2008-08-24 21:49:00 -04001425/**
James Smart3621a712009-04-06 18:47:14 -04001426 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001427 * @dev: class device that is converted into a Scsi_host.
1428 * @attr: device attribute, not used.
1429 * @buf: on return contains the cfg_poll in hex.
1430 *
1431 * Notes:
1432 * cfg_poll should be a lpfc_polling_flags type.
1433 *
1434 * Returns: size of formatted string.
1435 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001436static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001437lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1438 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001439{
Tony Jonesee959b02008-02-22 00:13:36 +01001440 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1442 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001443
1444 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1445}
1446
James Smarte59058c2008-08-24 21:49:00 -04001447/**
James Smart3621a712009-04-06 18:47:14 -04001448 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001449 * @dev: class device that is converted into a Scsi_host.
1450 * @attr: device attribute, not used.
1451 * @buf: one or more lpfc_polling_flags values.
1452 * @count: not used.
1453 *
1454 * Notes:
1455 * buf contents converted to integer and checked for a valid value.
1456 *
1457 * Returns:
1458 * -EINVAL if the buffer connot be converted or is out of range
1459 * length of the buf on success
1460 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001461static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001462lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1463 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001464{
Tony Jonesee959b02008-02-22 00:13:36 +01001465 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001466 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1467 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001468 uint32_t creg_val;
1469 uint32_t old_val;
1470 int val=0;
1471
1472 if (!isdigit(buf[0]))
1473 return -EINVAL;
1474
1475 if (sscanf(buf, "%i", &val) != 1)
1476 return -EINVAL;
1477
1478 if ((val & 0x3) != val)
1479 return -EINVAL;
1480
James Smart45ed1192009-10-02 15:17:02 -04001481 if (phba->sli_rev == LPFC_SLI_REV4)
1482 val = 0;
1483
James Smart88a2cfb2011-07-22 18:36:33 -04001484 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1485 "3051 lpfc_poll changed from %d to %d\n",
1486 phba->cfg_poll, val);
1487
James Smart2e0fef82007-06-17 19:56:36 -05001488 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001489
1490 old_val = phba->cfg_poll;
1491
1492 if (val & ENABLE_FCP_RING_POLLING) {
1493 if ((val & DISABLE_FCP_RING_INT) &&
1494 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001495 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1496 spin_unlock_irq(&phba->hbalock);
1497 return -EINVAL;
1498 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001499 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1500 writel(creg_val, phba->HCregaddr);
1501 readl(phba->HCregaddr); /* flush */
1502
1503 lpfc_poll_start_timer(phba);
1504 }
1505 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001506 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001507 return -EINVAL;
1508 }
1509
1510 if (!(val & DISABLE_FCP_RING_INT) &&
1511 (old_val & DISABLE_FCP_RING_INT))
1512 {
James Smart2e0fef82007-06-17 19:56:36 -05001513 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001514 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001515 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001516 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1517 spin_unlock_irq(&phba->hbalock);
1518 return -EINVAL;
1519 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001520 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1521 writel(creg_val, phba->HCregaddr);
1522 readl(phba->HCregaddr); /* flush */
1523 }
1524
1525 phba->cfg_poll = val;
1526
James Smart2e0fef82007-06-17 19:56:36 -05001527 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001528
1529 return strlen(buf);
1530}
dea31012005-04-17 16:05:31 -05001531
James Smarte59058c2008-08-24 21:49:00 -04001532/**
James Smartbc739052010-08-04 16:11:18 -04001533 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1534 * @dev: class unused variable.
1535 * @attr: device attribute, not used.
1536 * @buf: on return contains the module description text.
1537 *
1538 * Returns: size of formatted string.
1539 **/
1540static ssize_t
1541lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1542 char *buf)
1543{
1544 struct Scsi_Host *shost = class_to_shost(dev);
1545 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1546 struct lpfc_hba *phba = vport->phba;
1547
1548 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1549}
1550
1551/**
1552 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1553 * @dev: class unused variable.
1554 * @attr: device attribute, not used.
1555 * @buf: on return contains the module description text.
1556 *
1557 * Returns: size of formatted string.
1558 **/
1559static ssize_t
1560lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1561 char *buf)
1562{
1563 struct Scsi_Host *shost = class_to_shost(dev);
1564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1565 struct lpfc_hba *phba = vport->phba;
1566
1567 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1568}
1569
1570/**
James Smartab56dc22011-02-16 12:39:57 -05001571 * lpfc_dss_show - Return the current state of dss and the configured state
1572 * @dev: class converted to a Scsi_host structure.
1573 * @attr: device attribute, not used.
1574 * @buf: on return contains the formatted text.
1575 *
1576 * Returns: size of formatted string.
1577 **/
1578static ssize_t
1579lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1580 char *buf)
1581{
1582 struct Scsi_Host *shost = class_to_shost(dev);
1583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1584 struct lpfc_hba *phba = vport->phba;
1585
1586 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1587 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1588 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1589 "" : "Not ");
1590}
1591
1592/**
James Smart912e3ac2011-05-24 11:42:11 -04001593 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1594 * @dev: class converted to a Scsi_host structure.
1595 * @attr: device attribute, not used.
1596 * @buf: on return contains the formatted support level.
1597 *
1598 * Description:
1599 * Returns the maximum number of virtual functions a physical function can
1600 * support, 0 will be returned if called on virtual function.
1601 *
1602 * Returns: size of formatted string.
1603 **/
1604static ssize_t
1605lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1606 struct device_attribute *attr,
1607 char *buf)
1608{
1609 struct Scsi_Host *shost = class_to_shost(dev);
1610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1611 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001612 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001613
James Smart0a96e972011-07-22 18:37:28 -04001614 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1615 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001616}
1617
1618/**
James Smart3621a712009-04-06 18:47:14 -04001619 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001620 *
1621 * Description:
1622 * Macro that given an attr e.g. hba_queue_depth expands
1623 * into a function with the name lpfc_hba_queue_depth_show.
1624 *
1625 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1626 * @dev: class device that is converted into a Scsi_host.
1627 * @attr: device attribute, not used.
1628 * @buf: on return contains the attribute value in decimal.
1629 *
1630 * Returns: size of formatted string.
1631 **/
dea31012005-04-17 16:05:31 -05001632#define lpfc_param_show(attr) \
1633static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001634lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1635 char *buf) \
dea31012005-04-17 16:05:31 -05001636{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001637 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1639 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001640 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001641 val = phba->cfg_##attr;\
1642 return snprintf(buf, PAGE_SIZE, "%d\n",\
1643 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001644}
1645
James Smarte59058c2008-08-24 21:49:00 -04001646/**
James Smart3621a712009-04-06 18:47:14 -04001647 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001648 *
1649 * Description:
1650 * Macro that given an attr e.g. hba_queue_depth expands
1651 * into a function with the name lpfc_hba_queue_depth_show
1652 *
1653 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1654 * @dev: class device that is converted into a Scsi_host.
1655 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001656 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001657 *
1658 * Returns: size of formatted string.
1659 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001660#define lpfc_param_hex_show(attr) \
1661static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001662lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1663 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001664{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001665 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1667 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001668 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001669 val = phba->cfg_##attr;\
1670 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1671 phba->cfg_##attr);\
1672}
1673
James Smarte59058c2008-08-24 21:49:00 -04001674/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001675 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001676 *
1677 * Description:
1678 * Macro that given an attr e.g. hba_queue_depth expands
1679 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1680 * takes a default argument, a minimum and maximum argument.
1681 *
1682 * lpfc_##attr##_init: Initializes an attribute.
1683 * @phba: pointer the the adapter structure.
1684 * @val: integer attribute value.
1685 *
1686 * Validates the min and max values then sets the adapter config field
1687 * accordingly, or uses the default if out of range and prints an error message.
1688 *
1689 * Returns:
1690 * zero on success
1691 * -EINVAL if default used
1692 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001693#define lpfc_param_init(attr, default, minval, maxval) \
1694static int \
James Smart84d1b002010-02-12 14:42:33 -05001695lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001696{ \
1697 if (val >= minval && val <= maxval) {\
1698 phba->cfg_##attr = val;\
1699 return 0;\
1700 }\
1701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001702 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1703 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001704 phba->cfg_##attr = default;\
1705 return -EINVAL;\
1706}
1707
James Smarte59058c2008-08-24 21:49:00 -04001708/**
James Smart3621a712009-04-06 18:47:14 -04001709 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001710 *
1711 * Description:
1712 * Macro that given an attr e.g. hba_queue_depth expands
1713 * into a function with the name lpfc_hba_queue_depth_set
1714 *
1715 * lpfc_##attr##_set: Sets an attribute value.
1716 * @phba: pointer the the adapter structure.
1717 * @val: integer attribute value.
1718 *
1719 * Description:
1720 * Validates the min and max values then sets the
1721 * adapter config field if in the valid range. prints error message
1722 * and does not set the parameter if invalid.
1723 *
1724 * Returns:
1725 * zero on success
1726 * -EINVAL if val is invalid
1727 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001728#define lpfc_param_set(attr, default, minval, maxval) \
1729static int \
James Smart84d1b002010-02-12 14:42:33 -05001730lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001731{ \
1732 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1734 "3052 lpfc_" #attr " changed from %d to %d\n", \
1735 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001736 phba->cfg_##attr = val;\
1737 return 0;\
1738 }\
1739 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001740 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1741 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001742 return -EINVAL;\
1743}
1744
James Smarte59058c2008-08-24 21:49:00 -04001745/**
James Smart3621a712009-04-06 18:47:14 -04001746 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001747 *
1748 * Description:
1749 * Macro that given an attr e.g. hba_queue_depth expands
1750 * into a function with the name lpfc_hba_queue_depth_store.
1751 *
1752 * lpfc_##attr##_store: Set an sttribute value.
1753 * @dev: class device that is converted into a Scsi_host.
1754 * @attr: device attribute, not used.
1755 * @buf: contains the attribute value in ascii.
1756 * @count: not used.
1757 *
1758 * Description:
1759 * Convert the ascii text number to an integer, then
1760 * use the lpfc_##attr##_set function to set the value.
1761 *
1762 * Returns:
1763 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1764 * length of buffer upon success.
1765 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001766#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001767static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001768lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1769 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001770{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001771 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001772 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1773 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001774 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001775 if (!isdigit(buf[0]))\
1776 return -EINVAL;\
1777 if (sscanf(buf, "%i", &val) != 1)\
1778 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001779 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001780 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001781 else \
1782 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001783}
1784
James Smarte59058c2008-08-24 21:49:00 -04001785/**
James Smart3621a712009-04-06 18:47:14 -04001786 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001787 *
1788 * Description:
1789 * Macro that given an attr e.g. hba_queue_depth expands
1790 * into a function with the name lpfc_hba_queue_depth_show
1791 *
1792 * lpfc_##attr##_show: prints the attribute value in decimal.
1793 * @dev: class device that is converted into a Scsi_host.
1794 * @attr: device attribute, not used.
1795 * @buf: on return contains the attribute value in decimal.
1796 *
1797 * Returns: length of formatted string.
1798 **/
James Smart3de2a652007-08-02 11:09:59 -04001799#define lpfc_vport_param_show(attr) \
1800static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001801lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1802 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001803{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001804 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001806 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001807 val = vport->cfg_##attr;\
1808 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1809}
1810
James Smarte59058c2008-08-24 21:49:00 -04001811/**
James Smart3621a712009-04-06 18:47:14 -04001812 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001813 *
1814 * Description:
1815 * Macro that given an attr e.g.
1816 * hba_queue_depth expands into a function with the name
1817 * lpfc_hba_queue_depth_show
1818 *
James Smart3621a712009-04-06 18:47:14 -04001819 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001820 * @dev: class device that is converted into a Scsi_host.
1821 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001822 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001823 *
1824 * Returns: length of formatted string.
1825 **/
James Smart3de2a652007-08-02 11:09:59 -04001826#define lpfc_vport_param_hex_show(attr) \
1827static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001828lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1829 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001830{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001831 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001832 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001833 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001834 val = vport->cfg_##attr;\
1835 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1836}
1837
James Smarte59058c2008-08-24 21:49:00 -04001838/**
James Smart3621a712009-04-06 18:47:14 -04001839 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001840 *
1841 * Description:
1842 * Macro that given an attr e.g. hba_queue_depth expands
1843 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1844 * takes a default argument, a minimum and maximum argument.
1845 *
1846 * lpfc_##attr##_init: validates the min and max values then sets the
1847 * adapter config field accordingly, or uses the default if out of range
1848 * and prints an error message.
1849 * @phba: pointer the the adapter structure.
1850 * @val: integer attribute value.
1851 *
1852 * Returns:
1853 * zero on success
1854 * -EINVAL if default used
1855 **/
James Smart3de2a652007-08-02 11:09:59 -04001856#define lpfc_vport_param_init(attr, default, minval, maxval) \
1857static int \
James Smart84d1b002010-02-12 14:42:33 -05001858lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001859{ \
1860 if (val >= minval && val <= maxval) {\
1861 vport->cfg_##attr = val;\
1862 return 0;\
1863 }\
James Smarte8b62012007-08-02 11:10:09 -04001864 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001865 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001866 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001867 vport->cfg_##attr = default;\
1868 return -EINVAL;\
1869}
1870
James Smarte59058c2008-08-24 21:49:00 -04001871/**
James Smart3621a712009-04-06 18:47:14 -04001872 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001873 *
1874 * Description:
1875 * Macro that given an attr e.g. hba_queue_depth expands
1876 * into a function with the name lpfc_hba_queue_depth_set
1877 *
1878 * lpfc_##attr##_set: validates the min and max values then sets the
1879 * adapter config field if in the valid range. prints error message
1880 * and does not set the parameter if invalid.
1881 * @phba: pointer the the adapter structure.
1882 * @val: integer attribute value.
1883 *
1884 * Returns:
1885 * zero on success
1886 * -EINVAL if val is invalid
1887 **/
James Smart3de2a652007-08-02 11:09:59 -04001888#define lpfc_vport_param_set(attr, default, minval, maxval) \
1889static int \
James Smart84d1b002010-02-12 14:42:33 -05001890lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001891{ \
1892 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001893 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04001894 "3053 lpfc_" #attr \
1895 " changed from %d (x%x) to %d (x%x)\n", \
1896 vport->cfg_##attr, vport->cfg_##attr, \
1897 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04001898 vport->cfg_##attr = val;\
1899 return 0;\
1900 }\
James Smarte8b62012007-08-02 11:10:09 -04001901 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001902 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001903 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001904 return -EINVAL;\
1905}
1906
James Smarte59058c2008-08-24 21:49:00 -04001907/**
James Smart3621a712009-04-06 18:47:14 -04001908 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001909 *
1910 * Description:
1911 * Macro that given an attr e.g. hba_queue_depth
1912 * expands into a function with the name lpfc_hba_queue_depth_store
1913 *
1914 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1915 * use the lpfc_##attr##_set function to set the value.
1916 * @cdev: class device that is converted into a Scsi_host.
1917 * @buf: contains the attribute value in decimal.
1918 * @count: not used.
1919 *
1920 * Returns:
1921 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1922 * length of buffer upon success.
1923 **/
James Smart3de2a652007-08-02 11:09:59 -04001924#define lpfc_vport_param_store(attr) \
1925static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001926lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1927 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001928{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001929 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001930 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001931 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001932 if (!isdigit(buf[0]))\
1933 return -EINVAL;\
1934 if (sscanf(buf, "%i", &val) != 1)\
1935 return -EINVAL;\
1936 if (lpfc_##attr##_set(vport, val) == 0) \
1937 return strlen(buf);\
1938 else \
1939 return -EINVAL;\
1940}
1941
1942
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001943#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001944static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001945module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001946MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001947lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001948
1949#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001950static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001951module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001952MODULE_PARM_DESC(lpfc_##name, desc);\
1953lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001954lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001955static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001956
1957#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001958static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001959module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001960MODULE_PARM_DESC(lpfc_##name, desc);\
1961lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001962lpfc_param_init(name, defval, minval, maxval)\
1963lpfc_param_set(name, defval, minval, maxval)\
1964lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001965static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1966 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001967
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001968#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001969static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001970module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001971MODULE_PARM_DESC(lpfc_##name, desc);\
1972lpfc_param_hex_show(name)\
1973lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001974static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001975
1976#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001977static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001978module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001979MODULE_PARM_DESC(lpfc_##name, desc);\
1980lpfc_param_hex_show(name)\
1981lpfc_param_init(name, defval, minval, maxval)\
1982lpfc_param_set(name, defval, minval, maxval)\
1983lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001984static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1985 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001986
James Smart3de2a652007-08-02 11:09:59 -04001987#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001988static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001989module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001990MODULE_PARM_DESC(lpfc_##name, desc);\
1991lpfc_vport_param_init(name, defval, minval, maxval)
1992
1993#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001994static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001995module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001996MODULE_PARM_DESC(lpfc_##name, desc);\
1997lpfc_vport_param_show(name)\
1998lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001999static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04002000
2001#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002002static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002003module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002004MODULE_PARM_DESC(lpfc_##name, desc);\
2005lpfc_vport_param_show(name)\
2006lpfc_vport_param_init(name, defval, minval, maxval)\
2007lpfc_vport_param_set(name, defval, minval, maxval)\
2008lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002009static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2010 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002011
2012#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002013static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002014module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002015MODULE_PARM_DESC(lpfc_##name, desc);\
2016lpfc_vport_param_hex_show(name)\
2017lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01002018static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04002019
2020#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002021static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002022module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002023MODULE_PARM_DESC(lpfc_##name, desc);\
2024lpfc_vport_param_hex_show(name)\
2025lpfc_vport_param_init(name, defval, minval, maxval)\
2026lpfc_vport_param_set(name, defval, minval, maxval)\
2027lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002028static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2029 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002030
James Smart81301a92008-12-04 22:39:46 -05002031static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2032static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2033static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2034static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002035static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2036static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2037static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2038static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2039static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2040static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2041static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2042static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002043static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2044 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002045static DEVICE_ATTR(option_rom_version, S_IRUGO,
2046 lpfc_option_rom_version_show, NULL);
2047static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2048 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002049static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002050static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2051static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002052static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002053static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2054 lpfc_board_mode_show, lpfc_board_mode_store);
2055static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2056static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2057static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2058static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2059static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2060static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2061static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2062static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2063static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002064static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2065static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002066static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002067static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2068 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002069static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002070static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2071 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002072
James Smarta12e07b2006-12-02 13:35:30 -05002073static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002074#define WWN_SZ 8
2075/**
2076 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2077 * @buf: WWN string.
2078 * @cnt: Length of string.
2079 * @wwn: Array to receive converted wwn value.
2080 *
2081 * Returns:
2082 * -EINVAL if the buffer does not contain a valid wwn
2083 * 0 success
2084 **/
2085static size_t
2086lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2087{
2088 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002089
James Smart1ba981f2014-02-20 09:56:45 -05002090 /* Count may include a LF at end of string */
2091 if (buf[cnt-1] == '\n')
2092 cnt--;
2093
2094 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2095 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2096 return -EINVAL;
2097
2098 memset(wwn, 0, WWN_SZ);
2099
2100 /* Validate and store the new name */
2101 for (i = 0, j = 0; i < 16; i++) {
2102 if ((*buf >= 'a') && (*buf <= 'f'))
2103 j = ((j << 4) | ((*buf++ - 'a') + 10));
2104 else if ((*buf >= 'A') && (*buf <= 'F'))
2105 j = ((j << 4) | ((*buf++ - 'A') + 10));
2106 else if ((*buf >= '0') && (*buf <= '9'))
2107 j = ((j << 4) | (*buf++ - '0'));
2108 else
2109 return -EINVAL;
2110 if (i % 2) {
2111 wwn[i/2] = j & 0xff;
2112 j = 0;
2113 }
2114 }
2115 return 0;
2116}
James Smarte59058c2008-08-24 21:49:00 -04002117/**
James Smart3621a712009-04-06 18:47:14 -04002118 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002119 * @dev: class device that is converted into a Scsi_host.
2120 * @attr: device attribute, not used.
2121 * @buf: containing the string lpfc_soft_wwn_key.
2122 * @count: must be size of lpfc_soft_wwn_key.
2123 *
2124 * Returns:
2125 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2126 * length of buf indicates success
2127 **/
James Smartc3f28af2006-08-18 17:47:18 -04002128static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002129lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2130 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002131{
Tony Jonesee959b02008-02-22 00:13:36 +01002132 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2134 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002135 unsigned int cnt = count;
2136
2137 /*
2138 * We're doing a simple sanity check for soft_wwpn setting.
2139 * We require that the user write a specific key to enable
2140 * the soft_wwpn attribute to be settable. Once the attribute
2141 * is written, the enable key resets. If further updates are
2142 * desired, the key must be written again to re-enable the
2143 * attribute.
2144 *
2145 * The "key" is not secret - it is a hardcoded string shown
2146 * here. The intent is to protect against the random user or
2147 * application that is just writing attributes.
2148 */
2149
2150 /* count may include a LF at end of string */
2151 if (buf[cnt-1] == '\n')
2152 cnt--;
2153
James Smarta12e07b2006-12-02 13:35:30 -05002154 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2155 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002156 return -EINVAL;
2157
James Smarta12e07b2006-12-02 13:35:30 -05002158 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002159 return count;
2160}
Tony Jonesee959b02008-02-22 00:13:36 +01002161static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2162 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002163
James Smarte59058c2008-08-24 21:49:00 -04002164/**
James Smart3621a712009-04-06 18:47:14 -04002165 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002166 * @dev: class device that is converted into a Scsi_host.
2167 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002168 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002169 *
2170 * Returns: size of formatted string.
2171 **/
James Smartc3f28af2006-08-18 17:47:18 -04002172static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002173lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2174 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002175{
Tony Jonesee959b02008-02-22 00:13:36 +01002176 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002177 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2178 struct lpfc_hba *phba = vport->phba;
2179
Randy Dunlapafc071e2006-10-23 21:47:13 -07002180 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2181 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002182}
2183
James Smarte59058c2008-08-24 21:49:00 -04002184/**
James Smart3621a712009-04-06 18:47:14 -04002185 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002186 * @dev class device that is converted into a Scsi_host.
2187 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002188 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002189 * @count: number of wwpn bytes in buf
2190 *
2191 * Returns:
2192 * -EACCES hba reset not enabled, adapter over temp
2193 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2194 * -EIO error taking adapter offline or online
2195 * value of count on success
2196 **/
James Smartc3f28af2006-08-18 17:47:18 -04002197static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002198lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2199 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002200{
Tony Jonesee959b02008-02-22 00:13:36 +01002201 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2203 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002204 struct completion online_compl;
James Smart1ba981f2014-02-20 09:56:45 -05002205 int stat1 = 0, stat2 = 0;
2206 unsigned int cnt = count;
2207 u8 wwpn[WWN_SZ];
James Smartfedd3b72011-02-16 12:39:24 -05002208 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002209
James Smart13815c82008-01-11 01:52:48 -05002210 if (!phba->cfg_enable_hba_reset)
2211 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002212 spin_lock_irq(&phba->hbalock);
2213 if (phba->over_temp_state == HBA_OVER_TEMP) {
2214 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002215 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002216 }
2217 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002218 /* count may include a LF at end of string */
2219 if (buf[cnt-1] == '\n')
2220 cnt--;
2221
James Smart1ba981f2014-02-20 09:56:45 -05002222 if (!phba->soft_wwn_enable)
James Smartc3f28af2006-08-18 17:47:18 -04002223 return -EINVAL;
2224
James Smart1ba981f2014-02-20 09:56:45 -05002225 /* lock setting wwpn, wwnn down */
James Smarta12e07b2006-12-02 13:35:30 -05002226 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002227
James Smart1ba981f2014-02-20 09:56:45 -05002228 rc = lpfc_wwn_set(buf, cnt, wwpn);
2229 if (!rc) {
2230 /* not able to set wwpn, unlock it */
2231 phba->soft_wwn_enable = 1;
2232 return rc;
James Smartc3f28af2006-08-18 17:47:18 -04002233 }
James Smart1ba981f2014-02-20 09:56:45 -05002234
James Smartc3f28af2006-08-18 17:47:18 -04002235 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002236 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002237 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002238 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002239
2240 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2241 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2242
James Smart46fa3112007-04-25 09:51:45 -04002243 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002244 if (stat1)
2245 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002246 "0463 lpfc_soft_wwpn attribute set failed to "
2247 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002248 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002249 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2250 LPFC_EVT_ONLINE);
2251 if (rc == 0)
2252 return -ENOMEM;
2253
James Smartc3f28af2006-08-18 17:47:18 -04002254 wait_for_completion(&online_compl);
2255 if (stat2)
2256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002257 "0464 lpfc_soft_wwpn attribute set failed to "
2258 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002259 return (stat1 || stat2) ? -EIO : count;
2260}
James Smart1ba981f2014-02-20 09:56:45 -05002261static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002262 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002263
James Smarte59058c2008-08-24 21:49:00 -04002264/**
James Smart3621a712009-04-06 18:47:14 -04002265 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002266 * @dev: class device that is converted into a Scsi_host.
2267 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002268 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002269 *
2270 * Returns: size of formatted string.
2271 **/
James Smarta12e07b2006-12-02 13:35:30 -05002272static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002273lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2274 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002275{
Tony Jonesee959b02008-02-22 00:13:36 +01002276 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002277 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002278 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2279 (unsigned long long)phba->cfg_soft_wwnn);
2280}
2281
James Smarte59058c2008-08-24 21:49:00 -04002282/**
James Smart3621a712009-04-06 18:47:14 -04002283 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002284 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002285 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002286 * @count: number of wwnn bytes in buf.
2287 *
2288 * Returns:
2289 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2290 * value of count on success
2291 **/
James Smarta12e07b2006-12-02 13:35:30 -05002292static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002293lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2294 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002295{
Tony Jonesee959b02008-02-22 00:13:36 +01002296 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002297 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart1ba981f2014-02-20 09:56:45 -05002298 unsigned int cnt = count;
2299 u8 wwnn[WWN_SZ];
2300 int rc;
James Smarta12e07b2006-12-02 13:35:30 -05002301
2302 /* count may include a LF at end of string */
2303 if (buf[cnt-1] == '\n')
2304 cnt--;
2305
James Smart1ba981f2014-02-20 09:56:45 -05002306 if (!phba->soft_wwn_enable)
James Smarta12e07b2006-12-02 13:35:30 -05002307 return -EINVAL;
2308
James Smart1ba981f2014-02-20 09:56:45 -05002309 rc = lpfc_wwn_set(buf, cnt, wwnn);
2310 if (!rc) {
2311 /* Allow wwnn to be set many times, as long as the enable
2312 * is set. However, once the wwpn is set, everything locks.
2313 */
2314 return rc;
James Smarta12e07b2006-12-02 13:35:30 -05002315 }
James Smart1ba981f2014-02-20 09:56:45 -05002316
James Smarta12e07b2006-12-02 13:35:30 -05002317 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2318
2319 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2320 "lpfc%d: soft_wwnn set. Value will take effect upon "
2321 "setting of the soft_wwpn\n", phba->brd_no);
2322
2323 return count;
2324}
James Smart1ba981f2014-02-20 09:56:45 -05002325static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002326 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002327
James Smart1ba981f2014-02-20 09:56:45 -05002328/**
2329 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2330 * Optimized Access Storage (OAS) operations.
2331 * @dev: class device that is converted into a Scsi_host.
2332 * @attr: device attribute, not used.
2333 * @buf: buffer for passing information.
2334 *
2335 * Returns:
2336 * value of count
2337 **/
2338static ssize_t
2339lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2340 char *buf)
2341{
2342 struct Scsi_Host *shost = class_to_shost(dev);
2343 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2344
2345 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2346 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2347}
2348
2349/**
2350 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2351 * Optimized Access Storage (OAS) operations.
2352 * @dev: class device that is converted into a Scsi_host.
2353 * @attr: device attribute, not used.
2354 * @buf: buffer for passing information.
2355 * @count: Size of the data buffer.
2356 *
2357 * Returns:
2358 * -EINVAL count is invalid, invalid wwpn byte invalid
2359 * -EPERM oas is not supported by hba
2360 * value of count on success
2361 **/
2362static ssize_t
2363lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2364 const char *buf, size_t count)
2365{
2366 struct Scsi_Host *shost = class_to_shost(dev);
2367 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2368 unsigned int cnt = count;
2369 uint8_t wwpn[WWN_SZ];
2370 int rc;
2371
James Smartf38fa0b2014-04-04 13:52:21 -04002372 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002373 return -EPERM;
2374
2375 /* count may include a LF at end of string */
2376 if (buf[cnt-1] == '\n')
2377 cnt--;
2378
2379 rc = lpfc_wwn_set(buf, cnt, wwpn);
2380 if (rc)
2381 return rc;
2382
2383 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2384 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2385 if (wwn_to_u64(wwpn) == 0)
2386 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2387 else
2388 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2389 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2390 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2391 return count;
2392}
2393static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2394 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2395
2396/**
2397 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2398 * for Optimized Access Storage (OAS) operations.
2399 * @dev: class device that is converted into a Scsi_host.
2400 * @attr: device attribute, not used.
2401 * @buf: buffer for passing information.
2402 *
2403 * Returns:
2404 * value of count on success
2405 **/
2406static ssize_t
2407lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2408 char *buf)
2409{
2410 struct Scsi_Host *shost = class_to_shost(dev);
2411 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2412
2413 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2414 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2415}
2416
2417/**
2418 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2419 * for Optimized Access Storage (OAS) operations.
2420 * @dev: class device that is converted into a Scsi_host.
2421 * @attr: device attribute, not used.
2422 * @buf: buffer for passing information.
2423 * @count: Size of the data buffer.
2424 *
2425 * Returns:
2426 * -EINVAL count is invalid, invalid wwpn byte invalid
2427 * -EPERM oas is not supported by hba
2428 * value of count on success
2429 **/
2430static ssize_t
2431lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2432 const char *buf, size_t count)
2433{
2434 struct Scsi_Host *shost = class_to_shost(dev);
2435 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2436 unsigned int cnt = count;
2437 uint8_t wwpn[WWN_SZ];
2438 int rc;
2439
James Smartf38fa0b2014-04-04 13:52:21 -04002440 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002441 return -EPERM;
2442
2443 /* count may include a LF at end of string */
2444 if (buf[cnt-1] == '\n')
2445 cnt--;
2446
2447 rc = lpfc_wwn_set(buf, cnt, wwpn);
2448 if (rc)
2449 return rc;
2450
2451 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2452 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2453 if (wwn_to_u64(wwpn) == 0)
2454 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2455 else
2456 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2457 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2458 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2459 return count;
2460}
2461static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2462 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2463
2464/**
2465 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2466 * of whether luns will be enabled or disabled
2467 * for Optimized Access Storage (OAS) operations.
2468 * @dev: class device that is converted into a Scsi_host.
2469 * @attr: device attribute, not used.
2470 * @buf: buffer for passing information.
2471 *
2472 * Returns:
2473 * size of formatted string.
2474 **/
2475static ssize_t
2476lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2477 char *buf)
2478{
2479 struct Scsi_Host *shost = class_to_shost(dev);
2480 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2481
2482 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2483}
2484
2485/**
2486 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2487 * of whether luns will be enabled or disabled
2488 * for Optimized Access Storage (OAS) operations.
2489 * @dev: class device that is converted into a Scsi_host.
2490 * @attr: device attribute, not used.
2491 * @buf: buffer for passing information.
2492 * @count: Size of the data buffer.
2493 *
2494 * Returns:
2495 * -EINVAL count is invalid, invalid wwpn byte invalid
2496 * -EPERM oas is not supported by hba
2497 * value of count on success
2498 **/
2499static ssize_t
2500lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2501 const char *buf, size_t count)
2502{
2503 struct Scsi_Host *shost = class_to_shost(dev);
2504 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2505 int val = 0;
2506
James Smartf38fa0b2014-04-04 13:52:21 -04002507 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002508 return -EPERM;
2509
2510 if (!isdigit(buf[0]))
2511 return -EINVAL;
2512
2513 if (sscanf(buf, "%i", &val) != 1)
2514 return -EINVAL;
2515
2516 if ((val != 0) && (val != 1))
2517 return -EINVAL;
2518
2519 phba->cfg_oas_lun_state = val;
2520
2521 return strlen(buf);
2522}
2523static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2524 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2525
2526/**
2527 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2528 * Storage (OAS) lun returned by the
2529 * lpfc_oas_lun_show function.
2530 * @dev: class device that is converted into a Scsi_host.
2531 * @attr: device attribute, not used.
2532 * @buf: buffer for passing information.
2533 *
2534 * Returns:
2535 * size of formatted string.
2536 **/
2537static ssize_t
2538lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2539 char *buf)
2540{
2541 struct Scsi_Host *shost = class_to_shost(dev);
2542 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2543
2544 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2545 return -EFAULT;
2546
2547 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2548}
2549static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2550 lpfc_oas_lun_status_show, NULL);
2551
2552
2553/**
2554 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2555 * (OAS) operations.
2556 * @phba: lpfc_hba pointer.
2557 * @ndlp: pointer to fcp target node.
2558 * @lun: the fc lun for setting oas state.
2559 * @oas_state: the oas state to be set to the lun.
2560 *
2561 * Returns:
2562 * SUCCESS : 0
2563 * -EPERM OAS is not enabled or not supported by this port.
2564 *
2565 */
2566static size_t
2567lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2568 uint8_t tgt_wwpn[], uint64_t lun, uint32_t oas_state)
2569{
2570
2571 int rc = 0;
2572
James Smartf38fa0b2014-04-04 13:52:21 -04002573 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002574 return -EPERM;
2575
2576 if (oas_state) {
2577 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2578 (struct lpfc_name *)tgt_wwpn, lun))
2579 rc = -ENOMEM;
2580 } else {
2581 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2582 (struct lpfc_name *)tgt_wwpn, lun);
2583 }
2584 return rc;
2585
2586}
2587
2588/**
2589 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2590 * Access Storage (OAS) operations.
2591 * @phba: lpfc_hba pointer.
2592 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2593 * @tgt_wwpn: wwpn of the target associated with the returned lun
2594 * @lun_status: status of the lun returned lun
2595 *
2596 * Returns the first or next lun enabled for OAS operations for the vport/target
2597 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2598 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2599 *
2600 * Return:
2601 * lun that is OAS enabled for the vport/target
2602 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2603 */
2604static uint64_t
2605lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2606 uint8_t tgt_wwpn[], uint32_t *lun_status)
2607{
2608 uint64_t found_lun;
2609
2610 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2611 return NOT_OAS_ENABLED_LUN;
2612 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2613 phba->sli4_hba.oas_next_vpt_wwpn,
2614 (struct lpfc_name *)
2615 phba->sli4_hba.oas_next_tgt_wwpn,
2616 &phba->sli4_hba.oas_next_lun,
2617 (struct lpfc_name *)vpt_wwpn,
2618 (struct lpfc_name *)tgt_wwpn,
2619 &found_lun, lun_status))
2620 return found_lun;
2621 else
2622 return NOT_OAS_ENABLED_LUN;
2623}
2624
2625/**
2626 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2627 * @phba: lpfc_hba pointer.
2628 * @vpt_wwpn: vport wwpn by reference.
2629 * @tgt_wwpn: target wwpn by reference.
2630 * @lun: the fc lun for setting oas state.
2631 * @oas_state: the oas state to be set to the oas_lun.
2632 *
2633 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2634 * a lun for OAS operations.
2635 *
2636 * Return:
2637 * SUCCESS: 0
2638 * -ENOMEM: failed to enable an lun for OAS operations
2639 * -EPERM: OAS is not enabled
2640 */
2641static ssize_t
2642lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2643 uint8_t tgt_wwpn[], uint64_t lun,
2644 uint32_t oas_state)
2645{
2646
2647 int rc;
2648
2649 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2650 oas_state);
2651 return rc;
2652}
2653
2654/**
2655 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2656 * @dev: class device that is converted into a Scsi_host.
2657 * @attr: device attribute, not used.
2658 * @buf: buffer for passing information.
2659 *
2660 * This routine returns a lun enabled for OAS each time the function
2661 * is called.
2662 *
2663 * Returns:
2664 * SUCCESS: size of formatted string.
2665 * -EFAULT: target or vport wwpn was not set properly.
2666 * -EPERM: oas is not enabled.
2667 **/
2668static ssize_t
2669lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2670 char *buf)
2671{
2672 struct Scsi_Host *shost = class_to_shost(dev);
2673 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2674
2675 uint64_t oas_lun;
2676 int len = 0;
2677
James Smartf38fa0b2014-04-04 13:52:21 -04002678 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002679 return -EPERM;
2680
2681 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2682 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2683 return -EFAULT;
2684
2685 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2686 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2687 return -EFAULT;
2688
2689 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2690 phba->cfg_oas_tgt_wwpn,
2691 &phba->cfg_oas_lun_status);
2692 if (oas_lun != NOT_OAS_ENABLED_LUN)
2693 phba->cfg_oas_flags |= OAS_LUN_VALID;
2694
2695 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2696
2697 return len;
2698}
2699
2700/**
2701 * lpfc_oas_lun_store - Sets the OAS state for lun
2702 * @dev: class device that is converted into a Scsi_host.
2703 * @attr: device attribute, not used.
2704 * @buf: buffer for passing information.
2705 *
2706 * This function sets the OAS state for lun. Before this function is called,
2707 * the vport wwpn, target wwpn, and oas state need to be set.
2708 *
2709 * Returns:
2710 * SUCCESS: size of formatted string.
2711 * -EFAULT: target or vport wwpn was not set properly.
2712 * -EPERM: oas is not enabled.
2713 * size of formatted string.
2714 **/
2715static ssize_t
2716lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2717 const char *buf, size_t count)
2718{
2719 struct Scsi_Host *shost = class_to_shost(dev);
2720 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2721 uint64_t scsi_lun;
2722 ssize_t rc;
2723
James Smartf38fa0b2014-04-04 13:52:21 -04002724 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002725 return -EPERM;
2726
2727 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2728 return -EFAULT;
2729
2730 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2731 return -EFAULT;
2732
2733 if (!isdigit(buf[0]))
2734 return -EINVAL;
2735
2736 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2737 return -EINVAL;
2738
2739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2740 "3372 Try to set vport 0x%llx target 0x%llx lun:%lld "
2741 "with oas set to %d\n",
2742 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2743 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
2744 phba->cfg_oas_lun_state);
2745
2746 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
2747 phba->cfg_oas_tgt_wwpn, scsi_lun,
2748 phba->cfg_oas_lun_state);
2749
2750 if (rc)
2751 return rc;
2752
2753 return count;
2754}
2755static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2756 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002757
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002758static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002759module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002760MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2761 " 0 - none,"
2762 " 1 - poll with interrupts enabled"
2763 " 3 - poll and disable FCP ring interrupts");
2764
Tony Jonesee959b02008-02-22 00:13:36 +01002765static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2766 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002767
James Smart92d7f7b2007-06-17 19:56:38 -05002768int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002769module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002770MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2771 " 0 - auto (SLI-3 if supported),"
2772 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2773 " 3 - select SLI-3");
2774
James Smart15672312010-04-06 14:49:03 -04002775int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002776module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002777MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2778lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002779lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002780static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002781
James Smart7d791df2011-07-22 18:37:52 -04002782LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2783 "FCF Fast failover=1 Priority failover=2");
2784
James Smartc14e9952013-03-01 16:38:01 -05002785int lpfc_enable_rrq = 2;
James Smartab56dc22011-02-16 12:39:57 -05002786module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002787MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2788lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002789/*
2790# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2791# 0x0 = disabled, XRI/OXID use not tracked.
2792# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2793# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2794*/
2795lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002796static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2797
dea31012005-04-17 16:05:31 -05002798/*
James Smart84d1b002010-02-12 14:42:33 -05002799# lpfc_suppress_link_up: Bring link up at initialization
2800# 0x0 = bring link up (issue MBX_INIT_LINK)
2801# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2802# 0x2 = never bring up link
2803# Default value is 0.
2804*/
James Smarte40a02c2010-02-26 14:13:54 -05002805LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2806 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2807 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002808/*
2809# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2810# 1 - (1024)
2811# 2 - (2048)
2812# 3 - (3072)
2813# 4 - (4096)
2814# 5 - (5120)
2815*/
2816static ssize_t
2817lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2818{
2819 struct Scsi_Host *shost = class_to_shost(dev);
2820 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2821
2822 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2823}
2824
2825static DEVICE_ATTR(iocb_hw, S_IRUGO,
2826 lpfc_iocb_hw_show, NULL);
2827static ssize_t
2828lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2829{
2830 struct Scsi_Host *shost = class_to_shost(dev);
2831 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2832
2833 return snprintf(buf, PAGE_SIZE, "%d\n",
2834 phba->sli.ring[LPFC_ELS_RING].txq_max);
2835}
2836
2837static DEVICE_ATTR(txq_hw, S_IRUGO,
2838 lpfc_txq_hw_show, NULL);
2839static ssize_t
2840lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2841 char *buf)
2842{
2843 struct Scsi_Host *shost = class_to_shost(dev);
2844 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2845
2846 return snprintf(buf, PAGE_SIZE, "%d\n",
2847 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2848}
2849
2850static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2851 lpfc_txcmplq_hw_show, NULL);
2852
2853int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002854module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002855MODULE_PARM_DESC(lpfc_iocb_cnt,
2856 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2857lpfc_param_show(iocb_cnt);
2858lpfc_param_init(iocb_cnt, 2, 1, 5);
2859static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2860 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002861
2862/*
James Smartc01f3202006-08-18 17:47:08 -04002863# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2864# until the timer expires. Value range is [0,255]. Default value is 30.
2865*/
2866static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2867static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2868module_param(lpfc_nodev_tmo, int, 0);
2869MODULE_PARM_DESC(lpfc_nodev_tmo,
2870 "Seconds driver will hold I/O waiting "
2871 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002872
2873/**
James Smart3621a712009-04-06 18:47:14 -04002874 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002875 * @dev: class converted to a Scsi_host structure.
2876 * @attr: device attribute, not used.
2877 * @buf: on return contains the dev loss timeout in decimal.
2878 *
2879 * Returns: size of formatted string.
2880 **/
James Smartc01f3202006-08-18 17:47:08 -04002881static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002882lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2883 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002884{
Tony Jonesee959b02008-02-22 00:13:36 +01002885 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002887
James Smart3de2a652007-08-02 11:09:59 -04002888 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002889}
2890
James Smarte59058c2008-08-24 21:49:00 -04002891/**
James Smart3621a712009-04-06 18:47:14 -04002892 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002893 * @vport: lpfc vport structure pointer.
2894 * @val: contains the nodev timeout value.
2895 *
2896 * Description:
2897 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2898 * a kernel error message is printed and zero is returned.
2899 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2900 * Otherwise nodev tmo is set to the default value.
2901 *
2902 * Returns:
2903 * zero if already set or if val is in range
2904 * -EINVAL val out of range
2905 **/
James Smartc01f3202006-08-18 17:47:08 -04002906static int
James Smart3de2a652007-08-02 11:09:59 -04002907lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002908{
James Smart3de2a652007-08-02 11:09:59 -04002909 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2910 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2911 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002912 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002913 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002914 "parameter because devloss_tmo is "
2915 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002916 return 0;
2917 }
2918
2919 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002920 vport->cfg_nodev_tmo = val;
2921 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002922 return 0;
2923 }
James Smarte8b62012007-08-02 11:10:09 -04002924 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2925 "0400 lpfc_nodev_tmo attribute cannot be set to"
2926 " %d, allowed range is [%d, %d]\n",
2927 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002928 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002929 return -EINVAL;
2930}
2931
James Smarte59058c2008-08-24 21:49:00 -04002932/**
James Smart3621a712009-04-06 18:47:14 -04002933 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002934 * @vport: lpfc vport structure pointer.
2935 *
2936 * Description:
2937 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2938 **/
James Smart7054a602007-04-25 09:52:34 -04002939static void
James Smart3de2a652007-08-02 11:09:59 -04002940lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002941{
James Smart858c9f62007-06-17 19:56:39 -05002942 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002943 struct lpfc_nodelist *ndlp;
2944
James Smart51ef4c22007-08-02 11:10:31 -04002945 shost = lpfc_shost_from_vport(vport);
2946 spin_lock_irq(shost->host_lock);
2947 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002948 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002949 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2950 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002951}
2952
James Smarte59058c2008-08-24 21:49:00 -04002953/**
James Smart3621a712009-04-06 18:47:14 -04002954 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002955 * @vport: lpfc vport structure pointer.
2956 * @val: contains the tmo value.
2957 *
2958 * Description:
2959 * If the devloss tmo is already set or the vport dev loss tmo has changed
2960 * then a kernel error message is printed and zero is returned.
2961 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2962 * Otherwise nodev tmo is set to the default value.
2963 *
2964 * Returns:
2965 * zero if already set or if val is in range
2966 * -EINVAL val out of range
2967 **/
James Smartc01f3202006-08-18 17:47:08 -04002968static int
James Smart3de2a652007-08-02 11:09:59 -04002969lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002970{
James Smart3de2a652007-08-02 11:09:59 -04002971 if (vport->dev_loss_tmo_changed ||
2972 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002973 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2974 "0401 Ignoring change to nodev_tmo "
2975 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002976 return 0;
2977 }
James Smartc01f3202006-08-18 17:47:08 -04002978 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002979 vport->cfg_nodev_tmo = val;
2980 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002981 /*
2982 * For compat: set the fc_host dev loss so new rports
2983 * will get the value.
2984 */
2985 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002986 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002987 return 0;
2988 }
James Smarte8b62012007-08-02 11:10:09 -04002989 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2990 "0403 lpfc_nodev_tmo attribute cannot be set to"
2991 "%d, allowed range is [%d, %d]\n",
2992 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002993 return -EINVAL;
2994}
2995
James Smart3de2a652007-08-02 11:09:59 -04002996lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002997
Tony Jonesee959b02008-02-22 00:13:36 +01002998static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2999 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003000
3001/*
3002# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3003# disappear until the timer expires. Value range is [0,255]. Default
3004# value is 30.
3005*/
James Smartab56dc22011-02-16 12:39:57 -05003006module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003007MODULE_PARM_DESC(lpfc_devloss_tmo,
3008 "Seconds driver will hold I/O waiting "
3009 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003010lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3011 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3012lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003013
3014/**
James Smart3621a712009-04-06 18:47:14 -04003015 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003016 * @vport: lpfc vport structure pointer.
3017 * @val: contains the tmo value.
3018 *
3019 * Description:
3020 * If val is in a valid range then set the vport nodev tmo,
3021 * devloss tmo, also set the vport dev loss tmo changed flag.
3022 * Else a kernel error message is printed.
3023 *
3024 * Returns:
3025 * zero if val is in range
3026 * -EINVAL val out of range
3027 **/
James Smartc01f3202006-08-18 17:47:08 -04003028static int
James Smart3de2a652007-08-02 11:09:59 -04003029lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003030{
3031 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003032 vport->cfg_nodev_tmo = val;
3033 vport->cfg_devloss_tmo = val;
3034 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003035 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003036 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003037 return 0;
3038 }
3039
James Smarte8b62012007-08-02 11:10:09 -04003040 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3041 "0404 lpfc_devloss_tmo attribute cannot be set to"
3042 " %d, allowed range is [%d, %d]\n",
3043 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003044 return -EINVAL;
3045}
3046
James Smart3de2a652007-08-02 11:09:59 -04003047lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003048static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3049 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003050
3051/*
dea31012005-04-17 16:05:31 -05003052# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3053# deluged with LOTS of information.
3054# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003055# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003056*/
James Smartf4b4c682009-05-22 14:53:12 -04003057LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003058 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003059
3060/*
James Smart7ee5d432007-10-27 13:37:17 -04003061# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3062# objects that have been registered with the nameserver after login.
3063*/
James Smartcf971242012-03-01 22:37:32 -05003064LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003065 "Deregister nameserver objects before LOGO");
3066
3067/*
dea31012005-04-17 16:05:31 -05003068# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003069# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3070# If this parameter value is greater than 1/8th the maximum number of exchanges
3071# supported by the HBA port, then the lun queue depth will be reduced to
3072# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003073*/
James Smart572709e2013-07-15 18:32:43 -04003074LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003075 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003076
3077/*
James Smart7dc517d2010-07-14 15:32:10 -04003078# tgt_queue_depth: This parameter is used to limit the number of outstanding
3079# commands per target port. Value range is [10,65535]. Default value is 65535.
3080*/
3081LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003082 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003083
3084/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003085# hba_queue_depth: This parameter is used to limit the number of outstanding
3086# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3087# value is greater than the maximum number of exchanges supported by the HBA,
3088# then maximum number of exchanges supported by the HBA is used to determine
3089# the hba_queue_depth.
3090*/
3091LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3092 "Max number of FCP commands we can queue to a lpfc HBA");
3093
3094/*
James Smart92d7f7b2007-06-17 19:56:38 -05003095# peer_port_login: This parameter allows/prevents logins
3096# between peer ports hosted on the same physical port.
3097# When this parameter is set 0 peer ports of same physical port
3098# are not allowed to login to each other.
3099# When this parameter is set 1 peer ports of same physical port
3100# are allowed to login to each other.
3101# Default value of this parameter is 0.
3102*/
James Smart3de2a652007-08-02 11:09:59 -04003103LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3104 "Allow peer ports on the same physical port to login to each "
3105 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003106
3107/*
James Smart3de2a652007-08-02 11:09:59 -04003108# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003109# between Virtual Ports and remote initiators.
3110# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3111# other initiators and will attempt to PLOGI all remote ports.
3112# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3113# remote ports and will not attempt to PLOGI to other initiators.
3114# This parameter does not restrict to the physical port.
3115# This parameter does not restrict logins to Fabric resident remote ports.
3116# Default value of this parameter is 1.
3117*/
James Smart3de2a652007-08-02 11:09:59 -04003118static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003119module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003120MODULE_PARM_DESC(lpfc_restrict_login,
3121 "Restrict virtual ports login to remote initiators.");
3122lpfc_vport_param_show(restrict_login);
3123
James Smarte59058c2008-08-24 21:49:00 -04003124/**
James Smart3621a712009-04-06 18:47:14 -04003125 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003126 * @vport: lpfc vport structure pointer.
3127 * @val: contains the restrict login value.
3128 *
3129 * Description:
3130 * If val is not in a valid range then log a kernel error message and set
3131 * the vport restrict login to one.
3132 * If the port type is physical clear the restrict login flag and return.
3133 * Else set the restrict login flag to val.
3134 *
3135 * Returns:
3136 * zero if val is in range
3137 * -EINVAL val out of range
3138 **/
James Smart3de2a652007-08-02 11:09:59 -04003139static int
3140lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3141{
3142 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003143 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003144 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003145 "be set to %d, allowed range is [0, 1]\n",
3146 val);
James Smart3de2a652007-08-02 11:09:59 -04003147 vport->cfg_restrict_login = 1;
3148 return -EINVAL;
3149 }
3150 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3151 vport->cfg_restrict_login = 0;
3152 return 0;
3153 }
3154 vport->cfg_restrict_login = val;
3155 return 0;
3156}
3157
James Smarte59058c2008-08-24 21:49:00 -04003158/**
James Smart3621a712009-04-06 18:47:14 -04003159 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003160 * @vport: lpfc vport structure pointer.
3161 * @val: contains the restrict login value.
3162 *
3163 * Description:
3164 * If val is not in a valid range then log a kernel error message and set
3165 * the vport restrict login to one.
3166 * If the port type is physical and the val is not zero log a kernel
3167 * error message, clear the restrict login flag and return zero.
3168 * Else set the restrict login flag to val.
3169 *
3170 * Returns:
3171 * zero if val is in range
3172 * -EINVAL val out of range
3173 **/
James Smart3de2a652007-08-02 11:09:59 -04003174static int
3175lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3176{
3177 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003178 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003179 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003180 "be set to %d, allowed range is [0, 1]\n",
3181 val);
James Smart3de2a652007-08-02 11:09:59 -04003182 vport->cfg_restrict_login = 1;
3183 return -EINVAL;
3184 }
3185 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003186 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3187 "0468 lpfc_restrict_login must be 0 for "
3188 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003189 vport->cfg_restrict_login = 0;
3190 return 0;
3191 }
3192 vport->cfg_restrict_login = val;
3193 return 0;
3194}
3195lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003196static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3197 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003198
3199/*
dea31012005-04-17 16:05:31 -05003200# Some disk devices have a "select ID" or "select Target" capability.
3201# From a protocol standpoint "select ID" usually means select the
3202# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3203# annex" which contains a table that maps a "select ID" (a number
3204# between 0 and 7F) to an ALPA. By default, for compatibility with
3205# older drivers, the lpfc driver scans this table from low ALPA to high
3206# ALPA.
3207#
3208# Turning on the scan-down variable (on = 1, off = 0) will
3209# cause the lpfc driver to use an inverted table, effectively
3210# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3211#
3212# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3213# and will not work across a fabric. Also this parameter will take
3214# effect only in the case when ALPA map is not available.)
3215*/
James Smart3de2a652007-08-02 11:09:59 -04003216LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3217 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003218
3219/*
dea31012005-04-17 16:05:31 -05003220# lpfc_topology: link topology for init link
3221# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003222# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003223# 0x02 = attempt point-to-point mode only
3224# 0x04 = attempt loop mode only
3225# 0x06 = attempt point-to-point mode then loop
3226# Set point-to-point mode if you want to run as an N_Port.
3227# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3228# Default value is 0.
3229*/
James Smarte59058c2008-08-24 21:49:00 -04003230
3231/**
James Smart3621a712009-04-06 18:47:14 -04003232 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003233 * @phba: lpfc_hba pointer.
3234 * @val: topology value.
3235 *
3236 * Description:
3237 * If val is in a valid range then set the adapter's topology field and
3238 * issue a lip; if the lip fails reset the topology to the old value.
3239 *
3240 * If the value is not in range log a kernel error message and return an error.
3241 *
3242 * Returns:
3243 * zero if val is in range and lip okay
3244 * non-zero return value from lpfc_issue_lip()
3245 * -EINVAL val out of range
3246 **/
James Smarta257bf92009-04-06 18:48:10 -04003247static ssize_t
3248lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3249 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003250{
James Smarta257bf92009-04-06 18:48:10 -04003251 struct Scsi_Host *shost = class_to_shost(dev);
3252 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3253 struct lpfc_hba *phba = vport->phba;
3254 int val = 0;
3255 int nolip = 0;
3256 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003257 int err;
3258 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003259
3260 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3261 nolip = 1;
3262 val_buf = &buf[strlen("nolip ")];
3263 }
3264
3265 if (!isdigit(val_buf[0]))
3266 return -EINVAL;
3267 if (sscanf(val_buf, "%i", &val) != 1)
3268 return -EINVAL;
3269
James Smart83108bd2008-01-11 01:53:09 -05003270 if (val >= 0 && val <= 6) {
3271 prev_val = phba->cfg_topology;
3272 phba->cfg_topology = val;
James Smartff78d8f2011-12-13 13:21:35 -05003273 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3274 val == 4) {
3275 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3276 "3113 Loop mode not supported at speed %d\n",
3277 phba->cfg_link_speed);
3278 phba->cfg_topology = prev_val;
3279 return -EINVAL;
3280 }
James Smarta257bf92009-04-06 18:48:10 -04003281 if (nolip)
3282 return strlen(buf);
3283
James Smart88a2cfb2011-07-22 18:36:33 -04003284 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3285 "3054 lpfc_topology changed from %d to %d\n",
3286 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003287 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3288 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003289 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003290 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003291 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003292 return -EINVAL;
3293 } else
3294 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003295 }
3296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3297 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3298 "allowed range is [0, 6]\n",
3299 phba->brd_no, val);
3300 return -EINVAL;
3301}
3302static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05003303module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003304MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
3305lpfc_param_show(topology)
3306lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01003307static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003308 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003309
James Smart21e9a0a2009-05-22 14:53:21 -04003310/**
3311 * lpfc_static_vport_show: Read callback function for
3312 * lpfc_static_vport sysfs file.
3313 * @dev: Pointer to class device object.
3314 * @attr: device attribute structure.
3315 * @buf: Data buffer.
3316 *
3317 * This function is the read call back function for
3318 * lpfc_static_vport sysfs file. The lpfc_static_vport
3319 * sysfs file report the mageability of the vport.
3320 **/
3321static ssize_t
3322lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3323 char *buf)
3324{
3325 struct Scsi_Host *shost = class_to_shost(dev);
3326 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3327 if (vport->vport_flag & STATIC_VPORT)
3328 sprintf(buf, "1\n");
3329 else
3330 sprintf(buf, "0\n");
3331
3332 return strlen(buf);
3333}
3334
3335/*
3336 * Sysfs attribute to control the statistical data collection.
3337 */
3338static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3339 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003340
3341/**
James Smart3621a712009-04-06 18:47:14 -04003342 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003343 * @dev: Pointer to class device.
3344 * @buf: Data buffer.
3345 * @count: Size of the data buffer.
3346 *
3347 * This function get called when an user write to the lpfc_stat_data_ctrl
3348 * sysfs file. This function parse the command written to the sysfs file
3349 * and take appropriate action. These commands are used for controlling
3350 * driver statistical data collection.
3351 * Following are the command this function handles.
3352 *
3353 * setbucket <bucket_type> <base> <step>
3354 * = Set the latency buckets.
3355 * destroybucket = destroy all the buckets.
3356 * start = start data collection
3357 * stop = stop data collection
3358 * reset = reset the collected data
3359 **/
3360static ssize_t
3361lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3362 const char *buf, size_t count)
3363{
3364 struct Scsi_Host *shost = class_to_shost(dev);
3365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3366 struct lpfc_hba *phba = vport->phba;
3367#define LPFC_MAX_DATA_CTRL_LEN 1024
3368 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3369 unsigned long i;
3370 char *str_ptr, *token;
3371 struct lpfc_vport **vports;
3372 struct Scsi_Host *v_shost;
3373 char *bucket_type_str, *base_str, *step_str;
3374 unsigned long base, step, bucket_type;
3375
3376 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003377 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003378 return -EINVAL;
3379
3380 strcpy(bucket_data, buf);
3381 str_ptr = &bucket_data[0];
3382 /* Ignore this token - this is command token */
3383 token = strsep(&str_ptr, "\t ");
3384 if (!token)
3385 return -EINVAL;
3386
3387 bucket_type_str = strsep(&str_ptr, "\t ");
3388 if (!bucket_type_str)
3389 return -EINVAL;
3390
3391 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3392 bucket_type = LPFC_LINEAR_BUCKET;
3393 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3394 bucket_type = LPFC_POWER2_BUCKET;
3395 else
3396 return -EINVAL;
3397
3398 base_str = strsep(&str_ptr, "\t ");
3399 if (!base_str)
3400 return -EINVAL;
3401 base = simple_strtoul(base_str, NULL, 0);
3402
3403 step_str = strsep(&str_ptr, "\t ");
3404 if (!step_str)
3405 return -EINVAL;
3406 step = simple_strtoul(step_str, NULL, 0);
3407 if (!step)
3408 return -EINVAL;
3409
3410 /* Block the data collection for every vport */
3411 vports = lpfc_create_vport_work_array(phba);
3412 if (vports == NULL)
3413 return -ENOMEM;
3414
James Smartf4b4c682009-05-22 14:53:12 -04003415 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003416 v_shost = lpfc_shost_from_vport(vports[i]);
3417 spin_lock_irq(v_shost->host_lock);
3418 /* Block and reset data collection */
3419 vports[i]->stat_data_blocked = 1;
3420 if (vports[i]->stat_data_enabled)
3421 lpfc_vport_reset_stat_data(vports[i]);
3422 spin_unlock_irq(v_shost->host_lock);
3423 }
3424
3425 /* Set the bucket attributes */
3426 phba->bucket_type = bucket_type;
3427 phba->bucket_base = base;
3428 phba->bucket_step = step;
3429
James Smartf4b4c682009-05-22 14:53:12 -04003430 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003431 v_shost = lpfc_shost_from_vport(vports[i]);
3432
3433 /* Unblock data collection */
3434 spin_lock_irq(v_shost->host_lock);
3435 vports[i]->stat_data_blocked = 0;
3436 spin_unlock_irq(v_shost->host_lock);
3437 }
3438 lpfc_destroy_vport_work_array(phba, vports);
3439 return strlen(buf);
3440 }
3441
3442 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3443 vports = lpfc_create_vport_work_array(phba);
3444 if (vports == NULL)
3445 return -ENOMEM;
3446
James Smartf4b4c682009-05-22 14:53:12 -04003447 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003448 v_shost = lpfc_shost_from_vport(vports[i]);
3449 spin_lock_irq(shost->host_lock);
3450 vports[i]->stat_data_blocked = 1;
3451 lpfc_free_bucket(vport);
3452 vport->stat_data_enabled = 0;
3453 vports[i]->stat_data_blocked = 0;
3454 spin_unlock_irq(shost->host_lock);
3455 }
3456 lpfc_destroy_vport_work_array(phba, vports);
3457 phba->bucket_type = LPFC_NO_BUCKET;
3458 phba->bucket_base = 0;
3459 phba->bucket_step = 0;
3460 return strlen(buf);
3461 }
3462
3463 if (!strncmp(buf, "start", strlen("start"))) {
3464 /* If no buckets configured return error */
3465 if (phba->bucket_type == LPFC_NO_BUCKET)
3466 return -EINVAL;
3467 spin_lock_irq(shost->host_lock);
3468 if (vport->stat_data_enabled) {
3469 spin_unlock_irq(shost->host_lock);
3470 return strlen(buf);
3471 }
3472 lpfc_alloc_bucket(vport);
3473 vport->stat_data_enabled = 1;
3474 spin_unlock_irq(shost->host_lock);
3475 return strlen(buf);
3476 }
3477
3478 if (!strncmp(buf, "stop", strlen("stop"))) {
3479 spin_lock_irq(shost->host_lock);
3480 if (vport->stat_data_enabled == 0) {
3481 spin_unlock_irq(shost->host_lock);
3482 return strlen(buf);
3483 }
3484 lpfc_free_bucket(vport);
3485 vport->stat_data_enabled = 0;
3486 spin_unlock_irq(shost->host_lock);
3487 return strlen(buf);
3488 }
3489
3490 if (!strncmp(buf, "reset", strlen("reset"))) {
3491 if ((phba->bucket_type == LPFC_NO_BUCKET)
3492 || !vport->stat_data_enabled)
3493 return strlen(buf);
3494 spin_lock_irq(shost->host_lock);
3495 vport->stat_data_blocked = 1;
3496 lpfc_vport_reset_stat_data(vport);
3497 vport->stat_data_blocked = 0;
3498 spin_unlock_irq(shost->host_lock);
3499 return strlen(buf);
3500 }
3501 return -EINVAL;
3502}
3503
3504
3505/**
James Smart3621a712009-04-06 18:47:14 -04003506 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003507 * @dev: Pointer to class device object.
3508 * @buf: Data buffer.
3509 *
3510 * This function is the read call back function for
3511 * lpfc_stat_data_ctrl sysfs file. This function report the
3512 * current statistical data collection state.
3513 **/
3514static ssize_t
3515lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3516 char *buf)
3517{
3518 struct Scsi_Host *shost = class_to_shost(dev);
3519 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3520 struct lpfc_hba *phba = vport->phba;
3521 int index = 0;
3522 int i;
3523 char *bucket_type;
3524 unsigned long bucket_value;
3525
3526 switch (phba->bucket_type) {
3527 case LPFC_LINEAR_BUCKET:
3528 bucket_type = "linear";
3529 break;
3530 case LPFC_POWER2_BUCKET:
3531 bucket_type = "power2";
3532 break;
3533 default:
3534 bucket_type = "No Bucket";
3535 break;
3536 }
3537
3538 sprintf(&buf[index], "Statistical Data enabled :%d, "
3539 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3540 " Bucket step :%d\nLatency Ranges :",
3541 vport->stat_data_enabled, vport->stat_data_blocked,
3542 bucket_type, phba->bucket_base, phba->bucket_step);
3543 index = strlen(buf);
3544 if (phba->bucket_type != LPFC_NO_BUCKET) {
3545 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3546 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3547 bucket_value = phba->bucket_base +
3548 phba->bucket_step * i;
3549 else
3550 bucket_value = phba->bucket_base +
3551 (1 << i) * phba->bucket_step;
3552
3553 if (index + 10 > PAGE_SIZE)
3554 break;
3555 sprintf(&buf[index], "%08ld ", bucket_value);
3556 index = strlen(buf);
3557 }
3558 }
3559 sprintf(&buf[index], "\n");
3560 return strlen(buf);
3561}
3562
3563/*
3564 * Sysfs attribute to control the statistical data collection.
3565 */
3566static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3567 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3568
3569/*
3570 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3571 */
3572
3573/*
3574 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3575 * for each target.
3576 */
3577#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3578#define MAX_STAT_DATA_SIZE_PER_TARGET \
3579 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3580
3581
3582/**
James Smart3621a712009-04-06 18:47:14 -04003583 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003584 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003585 * @kobj: Pointer to the kernel object
3586 * @bin_attr: Attribute object
3587 * @buff: Buffer pointer
3588 * @off: File offset
3589 * @count: Buffer size
3590 *
3591 * This function is the read call back function for lpfc_drvr_stat_data
3592 * sysfs file. This function export the statistical data to user
3593 * applications.
3594 **/
3595static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003596sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3597 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003598 char *buf, loff_t off, size_t count)
3599{
3600 struct device *dev = container_of(kobj, struct device,
3601 kobj);
3602 struct Scsi_Host *shost = class_to_shost(dev);
3603 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3604 struct lpfc_hba *phba = vport->phba;
3605 int i = 0, index = 0;
3606 unsigned long nport_index;
3607 struct lpfc_nodelist *ndlp = NULL;
3608 nport_index = (unsigned long)off /
3609 MAX_STAT_DATA_SIZE_PER_TARGET;
3610
3611 if (!vport->stat_data_enabled || vport->stat_data_blocked
3612 || (phba->bucket_type == LPFC_NO_BUCKET))
3613 return 0;
3614
3615 spin_lock_irq(shost->host_lock);
3616 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3617 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3618 continue;
3619
3620 if (nport_index > 0) {
3621 nport_index--;
3622 continue;
3623 }
3624
3625 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3626 > count)
3627 break;
3628
3629 if (!ndlp->lat_data)
3630 continue;
3631
3632 /* Print the WWN */
3633 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3634 ndlp->nlp_portname.u.wwn[0],
3635 ndlp->nlp_portname.u.wwn[1],
3636 ndlp->nlp_portname.u.wwn[2],
3637 ndlp->nlp_portname.u.wwn[3],
3638 ndlp->nlp_portname.u.wwn[4],
3639 ndlp->nlp_portname.u.wwn[5],
3640 ndlp->nlp_portname.u.wwn[6],
3641 ndlp->nlp_portname.u.wwn[7]);
3642
3643 index = strlen(buf);
3644
3645 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3646 sprintf(&buf[index], "%010u,",
3647 ndlp->lat_data[i].cmd_count);
3648 index = strlen(buf);
3649 }
3650 sprintf(&buf[index], "\n");
3651 index = strlen(buf);
3652 }
3653 spin_unlock_irq(shost->host_lock);
3654 return index;
3655}
3656
3657static struct bin_attribute sysfs_drvr_stat_data_attr = {
3658 .attr = {
3659 .name = "lpfc_drvr_stat_data",
3660 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003661 },
3662 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3663 .read = sysfs_drvr_stat_data_read,
3664 .write = NULL,
3665};
3666
dea31012005-04-17 16:05:31 -05003667/*
3668# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3669# connection.
James Smart76a95d72010-11-20 23:11:48 -05003670# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003671*/
James Smarte59058c2008-08-24 21:49:00 -04003672/**
James Smart3621a712009-04-06 18:47:14 -04003673 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003674 * @phba: lpfc_hba pointer.
3675 * @val: link speed value.
3676 *
3677 * Description:
3678 * If val is in a valid range then set the adapter's link speed field and
3679 * issue a lip; if the lip fails reset the link speed to the old value.
3680 *
3681 * Notes:
3682 * If the value is not in range log a kernel error message and return an error.
3683 *
3684 * Returns:
3685 * zero if val is in range and lip okay.
3686 * non-zero return value from lpfc_issue_lip()
3687 * -EINVAL val out of range
3688 **/
James Smarta257bf92009-04-06 18:48:10 -04003689static ssize_t
3690lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3691 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003692{
James Smarta257bf92009-04-06 18:48:10 -04003693 struct Scsi_Host *shost = class_to_shost(dev);
3694 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3695 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003696 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003697 int nolip = 0;
3698 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003699 int err;
3700 uint32_t prev_val;
3701
James Smarta257bf92009-04-06 18:48:10 -04003702 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3703 nolip = 1;
3704 val_buf = &buf[strlen("nolip ")];
3705 }
3706
3707 if (!isdigit(val_buf[0]))
3708 return -EINVAL;
3709 if (sscanf(val_buf, "%i", &val) != 1)
3710 return -EINVAL;
3711
James Smart88a2cfb2011-07-22 18:36:33 -04003712 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3713 "3055 lpfc_link_speed changed from %d to %d %s\n",
3714 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3715
James Smart76a95d72010-11-20 23:11:48 -05003716 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3717 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3718 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3719 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3720 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3721 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3723 "2879 lpfc_link_speed attribute cannot be set "
3724 "to %d. Speed is not supported by this port.\n",
3725 val);
James Smart83108bd2008-01-11 01:53:09 -05003726 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003727 }
James Smartff78d8f2011-12-13 13:21:35 -05003728 if (val == LPFC_USER_LINK_SPEED_16G &&
3729 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3731 "3112 lpfc_link_speed attribute cannot be set "
3732 "to %d. Speed is not supported in loop mode.\n",
3733 val);
3734 return -EINVAL;
3735 }
James Smart76a95d72010-11-20 23:11:48 -05003736 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3737 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003738 prev_val = phba->cfg_link_speed;
3739 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003740 if (nolip)
3741 return strlen(buf);
3742
James Smart83108bd2008-01-11 01:53:09 -05003743 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003744 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003745 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003746 return -EINVAL;
3747 } else
3748 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003749 }
James Smart83108bd2008-01-11 01:53:09 -05003750 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003751 "0469 lpfc_link_speed attribute cannot be set to %d, "
3752 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003753 return -EINVAL;
3754}
3755
3756static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003757module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003758MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3759lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003760
3761/**
James Smart3621a712009-04-06 18:47:14 -04003762 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003763 * @phba: lpfc_hba pointer.
3764 * @val: link speed value.
3765 *
3766 * Description:
3767 * If val is in a valid range then set the adapter's link speed field.
3768 *
3769 * Notes:
3770 * If the value is not in range log a kernel error message, clear the link
3771 * speed and return an error.
3772 *
3773 * Returns:
3774 * zero if val saved.
3775 * -EINVAL val out of range
3776 **/
James Smart83108bd2008-01-11 01:53:09 -05003777static int
3778lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3779{
James Smartff78d8f2011-12-13 13:21:35 -05003780 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3781 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3782 "3111 lpfc_link_speed of %d cannot "
3783 "support loop mode, setting topology to default.\n",
3784 val);
3785 phba->cfg_topology = 0;
3786 }
James Smart76a95d72010-11-20 23:11:48 -05003787 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3788 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003789 phba->cfg_link_speed = val;
3790 return 0;
3791 }
3792 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003793 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003794 "be set to %d, allowed values are "
3795 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003796 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003797 return -EINVAL;
3798}
3799
Tony Jonesee959b02008-02-22 00:13:36 +01003800static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003801 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003802
3803/*
James Smart0d878412009-10-02 15:16:56 -04003804# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3805# 0 = aer disabled or not supported
3806# 1 = aer supported and enabled (default)
3807# Value range is [0,1]. Default value is 1.
3808*/
3809
3810/**
3811 * lpfc_aer_support_store - Set the adapter for aer support
3812 *
3813 * @dev: class device that is converted into a Scsi_host.
3814 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003815 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003816 * @count: unused variable.
3817 *
3818 * Description:
3819 * If the val is 1 and currently the device's AER capability was not
3820 * enabled, invoke the kernel's enable AER helper routine, trying to
3821 * enable the device's AER capability. If the helper routine enabling
3822 * AER returns success, update the device's cfg_aer_support flag to
3823 * indicate AER is supported by the device; otherwise, if the device
3824 * AER capability is already enabled to support AER, then do nothing.
3825 *
3826 * If the val is 0 and currently the device's AER support was enabled,
3827 * invoke the kernel's disable AER helper routine. After that, update
3828 * the device's cfg_aer_support flag to indicate AER is not supported
3829 * by the device; otherwise, if the device AER capability is already
3830 * disabled from supporting AER, then do nothing.
3831 *
3832 * Returns:
3833 * length of the buf on success if val is in range the intended mode
3834 * is supported.
3835 * -EINVAL if val out of range or intended mode is not supported.
3836 **/
3837static ssize_t
3838lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3839 const char *buf, size_t count)
3840{
3841 struct Scsi_Host *shost = class_to_shost(dev);
3842 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3843 struct lpfc_hba *phba = vport->phba;
3844 int val = 0, rc = -EINVAL;
3845
3846 if (!isdigit(buf[0]))
3847 return -EINVAL;
3848 if (sscanf(buf, "%i", &val) != 1)
3849 return -EINVAL;
3850
3851 switch (val) {
3852 case 0:
3853 if (phba->hba_flag & HBA_AER_ENABLED) {
3854 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3855 if (!rc) {
3856 spin_lock_irq(&phba->hbalock);
3857 phba->hba_flag &= ~HBA_AER_ENABLED;
3858 spin_unlock_irq(&phba->hbalock);
3859 phba->cfg_aer_support = 0;
3860 rc = strlen(buf);
3861 } else
James Smart891478a2009-11-18 15:40:23 -05003862 rc = -EPERM;
3863 } else {
James Smart0d878412009-10-02 15:16:56 -04003864 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003865 rc = strlen(buf);
3866 }
James Smart0d878412009-10-02 15:16:56 -04003867 break;
3868 case 1:
3869 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3870 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3871 if (!rc) {
3872 spin_lock_irq(&phba->hbalock);
3873 phba->hba_flag |= HBA_AER_ENABLED;
3874 spin_unlock_irq(&phba->hbalock);
3875 phba->cfg_aer_support = 1;
3876 rc = strlen(buf);
3877 } else
James Smart891478a2009-11-18 15:40:23 -05003878 rc = -EPERM;
3879 } else {
James Smart0d878412009-10-02 15:16:56 -04003880 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003881 rc = strlen(buf);
3882 }
James Smart0d878412009-10-02 15:16:56 -04003883 break;
3884 default:
3885 rc = -EINVAL;
3886 break;
3887 }
3888 return rc;
3889}
3890
3891static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003892module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003893MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3894lpfc_param_show(aer_support)
3895
3896/**
3897 * lpfc_aer_support_init - Set the initial adapters aer support flag
3898 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003899 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003900 *
3901 * Description:
3902 * If val is in a valid range [0,1], then set the adapter's initial
3903 * cfg_aer_support field. It will be up to the driver's probe_one
3904 * routine to determine whether the device's AER support can be set
3905 * or not.
3906 *
3907 * Notes:
3908 * If the value is not in range log a kernel error message, and
3909 * choose the default value of setting AER support and return.
3910 *
3911 * Returns:
3912 * zero if val saved.
3913 * -EINVAL val out of range
3914 **/
3915static int
3916lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3917{
3918 if (val == 0 || val == 1) {
3919 phba->cfg_aer_support = val;
3920 return 0;
3921 }
3922 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3923 "2712 lpfc_aer_support attribute value %d out "
3924 "of range, allowed values are 0|1, setting it "
3925 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003926 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003927 phba->cfg_aer_support = 1;
3928 return -EINVAL;
3929}
3930
3931static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3932 lpfc_aer_support_show, lpfc_aer_support_store);
3933
3934/**
3935 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3936 * @dev: class device that is converted into a Scsi_host.
3937 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003938 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003939 * @count: unused variable.
3940 *
3941 * Description:
3942 * If the @buf contains 1 and the device currently has the AER support
3943 * enabled, then invokes the kernel AER helper routine
3944 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3945 * error status register.
3946 *
3947 * Notes:
3948 *
3949 * Returns:
3950 * -EINVAL if the buf does not contain the 1 or the device is not currently
3951 * enabled with the AER support.
3952 **/
3953static ssize_t
3954lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3955 const char *buf, size_t count)
3956{
3957 struct Scsi_Host *shost = class_to_shost(dev);
3958 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3959 struct lpfc_hba *phba = vport->phba;
3960 int val, rc = -1;
3961
3962 if (!isdigit(buf[0]))
3963 return -EINVAL;
3964 if (sscanf(buf, "%i", &val) != 1)
3965 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003966 if (val != 1)
3967 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003968
James Smart891478a2009-11-18 15:40:23 -05003969 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003970 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3971
3972 if (rc == 0)
3973 return strlen(buf);
3974 else
James Smart891478a2009-11-18 15:40:23 -05003975 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003976}
3977
3978static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3979 lpfc_aer_cleanup_state);
3980
James Smart912e3ac2011-05-24 11:42:11 -04003981/**
3982 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3983 *
3984 * @dev: class device that is converted into a Scsi_host.
3985 * @attr: device attribute, not used.
3986 * @buf: containing the string the number of vfs to be enabled.
3987 * @count: unused variable.
3988 *
3989 * Description:
3990 * When this api is called either through user sysfs, the driver shall
3991 * try to enable or disable SR-IOV virtual functions according to the
3992 * following:
3993 *
3994 * If zero virtual function has been enabled to the physical function,
3995 * the driver shall invoke the pci enable virtual function api trying
3996 * to enable the virtual functions. If the nr_vfn provided is greater
3997 * than the maximum supported, the maximum virtual function number will
3998 * be used for invoking the api; otherwise, the nr_vfn provided shall
3999 * be used for invoking the api. If the api call returned success, the
4000 * actual number of virtual functions enabled will be set to the driver
4001 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4002 * cfg_sriov_nr_virtfn remains zero.
4003 *
4004 * If none-zero virtual functions have already been enabled to the
4005 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4006 * -EINVAL will be returned and the driver does nothing;
4007 *
4008 * If the nr_vfn provided is zero and none-zero virtual functions have
4009 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4010 * disabling virtual function api shall be invoded to disable all the
4011 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4012 * zero. Otherwise, if zero virtual function has been enabled, do
4013 * nothing.
4014 *
4015 * Returns:
4016 * length of the buf on success if val is in range the intended mode
4017 * is supported.
4018 * -EINVAL if val out of range or intended mode is not supported.
4019 **/
4020static ssize_t
4021lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4022 const char *buf, size_t count)
4023{
4024 struct Scsi_Host *shost = class_to_shost(dev);
4025 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4026 struct lpfc_hba *phba = vport->phba;
4027 struct pci_dev *pdev = phba->pcidev;
4028 int val = 0, rc = -EINVAL;
4029
4030 /* Sanity check on user data */
4031 if (!isdigit(buf[0]))
4032 return -EINVAL;
4033 if (sscanf(buf, "%i", &val) != 1)
4034 return -EINVAL;
4035 if (val < 0)
4036 return -EINVAL;
4037
4038 /* Request disabling virtual functions */
4039 if (val == 0) {
4040 if (phba->cfg_sriov_nr_virtfn > 0) {
4041 pci_disable_sriov(pdev);
4042 phba->cfg_sriov_nr_virtfn = 0;
4043 }
4044 return strlen(buf);
4045 }
4046
4047 /* Request enabling virtual functions */
4048 if (phba->cfg_sriov_nr_virtfn > 0) {
4049 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4050 "3018 There are %d virtual functions "
4051 "enabled on physical function.\n",
4052 phba->cfg_sriov_nr_virtfn);
4053 return -EEXIST;
4054 }
4055
4056 if (val <= LPFC_MAX_VFN_PER_PFN)
4057 phba->cfg_sriov_nr_virtfn = val;
4058 else {
4059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4060 "3019 Enabling %d virtual functions is not "
4061 "allowed.\n", val);
4062 return -EINVAL;
4063 }
4064
4065 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4066 if (rc) {
4067 phba->cfg_sriov_nr_virtfn = 0;
4068 rc = -EPERM;
4069 } else
4070 rc = strlen(buf);
4071
4072 return rc;
4073}
4074
4075static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
4076module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
4077MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
4078lpfc_param_show(sriov_nr_virtfn)
4079
4080/**
4081 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
4082 * @phba: lpfc_hba pointer.
4083 * @val: link speed value.
4084 *
4085 * Description:
4086 * If val is in a valid range [0,255], then set the adapter's initial
4087 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
4088 * number shall be used instead. It will be up to the driver's probe_one
4089 * routine to determine whether the device's SR-IOV is supported or not.
4090 *
4091 * Returns:
4092 * zero if val saved.
4093 * -EINVAL val out of range
4094 **/
4095static int
4096lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
4097{
4098 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
4099 phba->cfg_sriov_nr_virtfn = val;
4100 return 0;
4101 }
4102
4103 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4104 "3017 Enabling %d virtual functions is not "
4105 "allowed.\n", val);
4106 return -EINVAL;
4107}
4108static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4109 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4110
James Smart173edbb2012-06-12 13:54:50 -04004111/**
James Smartc71ab862012-10-31 14:44:33 -04004112 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4113 *
4114 * @dev: class device that is converted into a Scsi_host.
4115 * @attr: device attribute, not used.
4116 * @buf: containing the string the number of vfs to be enabled.
4117 * @count: unused variable.
4118 *
4119 * Description:
4120 *
4121 * Returns:
4122 * length of the buf on success if val is in range the intended mode
4123 * is supported.
4124 * -EINVAL if val out of range or intended mode is not supported.
4125 **/
4126static ssize_t
4127lpfc_request_firmware_upgrade_store(struct device *dev,
4128 struct device_attribute *attr,
4129 const char *buf, size_t count)
4130{
4131 struct Scsi_Host *shost = class_to_shost(dev);
4132 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4133 struct lpfc_hba *phba = vport->phba;
4134 int val = 0, rc = -EINVAL;
4135
4136 /* Sanity check on user data */
4137 if (!isdigit(buf[0]))
4138 return -EINVAL;
4139 if (sscanf(buf, "%i", &val) != 1)
4140 return -EINVAL;
4141 if (val != 1)
4142 return -EINVAL;
4143
4144 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4145 if (rc)
4146 rc = -EPERM;
4147 else
4148 rc = strlen(buf);
4149 return rc;
4150}
4151
4152static int lpfc_req_fw_upgrade;
4153module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4154MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4155lpfc_param_show(request_firmware_upgrade)
4156
4157/**
4158 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4159 * @phba: lpfc_hba pointer.
4160 * @val: 0 or 1.
4161 *
4162 * Description:
4163 * Set the initial Linux generic firmware upgrade enable or disable flag.
4164 *
4165 * Returns:
4166 * zero if val saved.
4167 * -EINVAL val out of range
4168 **/
4169static int
4170lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4171{
4172 if (val >= 0 && val <= 1) {
4173 phba->cfg_request_firmware_upgrade = val;
4174 return 0;
4175 }
4176 return -EINVAL;
4177}
4178static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4179 lpfc_request_firmware_upgrade_show,
4180 lpfc_request_firmware_upgrade_store);
4181
4182/**
James Smart173edbb2012-06-12 13:54:50 -04004183 * lpfc_fcp_imax_store
4184 *
4185 * @dev: class device that is converted into a Scsi_host.
4186 * @attr: device attribute, not used.
4187 * @buf: string with the number of fast-path FCP interrupts per second.
4188 * @count: unused variable.
4189 *
4190 * Description:
4191 * If val is in a valid range [636,651042], then set the adapter's
4192 * maximum number of fast-path FCP interrupts per second.
4193 *
4194 * Returns:
4195 * length of the buf on success if val is in range the intended mode
4196 * is supported.
4197 * -EINVAL if val out of range or intended mode is not supported.
4198 **/
4199static ssize_t
4200lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4201 const char *buf, size_t count)
4202{
4203 struct Scsi_Host *shost = class_to_shost(dev);
4204 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4205 struct lpfc_hba *phba = vport->phba;
4206 int val = 0, i;
4207
James Smartbf8dae82012-08-03 12:36:24 -04004208 /* fcp_imax is only valid for SLI4 */
4209 if (phba->sli_rev != LPFC_SLI_REV4)
4210 return -EINVAL;
4211
James Smart173edbb2012-06-12 13:54:50 -04004212 /* Sanity check on user data */
4213 if (!isdigit(buf[0]))
4214 return -EINVAL;
4215 if (sscanf(buf, "%i", &val) != 1)
4216 return -EINVAL;
4217
James Smartbf8dae82012-08-03 12:36:24 -04004218 /*
4219 * Value range for the HBA is [5000,5000000]
4220 * The value for each EQ depends on how many EQs are configured.
4221 */
4222 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04004223 return -EINVAL;
4224
4225 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04004226 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04004227 lpfc_modify_fcp_eq_delay(phba, i);
4228
4229 return strlen(buf);
4230}
4231
4232/*
4233# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004234# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004235#
James Smartbf8dae82012-08-03 12:36:24 -04004236# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004237*/
James Smartbf8dae82012-08-03 12:36:24 -04004238static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004239module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4240MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004241 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004242lpfc_param_show(fcp_imax)
4243
4244/**
4245 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4246 * @phba: lpfc_hba pointer.
4247 * @val: link speed value.
4248 *
4249 * Description:
4250 * If val is in a valid range [636,651042], then initialize the adapter's
4251 * maximum number of fast-path FCP interrupts per second.
4252 *
4253 * Returns:
4254 * zero if val saved.
4255 * -EINVAL val out of range
4256 **/
4257static int
4258lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4259{
James Smartbf8dae82012-08-03 12:36:24 -04004260 if (phba->sli_rev != LPFC_SLI_REV4) {
4261 phba->cfg_fcp_imax = 0;
4262 return 0;
4263 }
4264
4265 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04004266 phba->cfg_fcp_imax = val;
4267 return 0;
4268 }
4269
4270 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4271 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04004272 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004273
4274 return 0;
4275}
4276
4277static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4278 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4279
James Smart7bb03bb2013-04-17 20:19:16 -04004280/**
4281 * lpfc_state_show - Display current driver CPU affinity
4282 * @dev: class converted to a Scsi_host structure.
4283 * @attr: device attribute, not used.
4284 * @buf: on return contains text describing the state of the link.
4285 *
4286 * Returns: size of formatted string.
4287 **/
4288static ssize_t
4289lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4290 char *buf)
4291{
4292 struct Scsi_Host *shost = class_to_shost(dev);
4293 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4294 struct lpfc_hba *phba = vport->phba;
4295 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004296 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004297
4298 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4299 (phba->intr_type != MSIX))
4300 return len;
4301
4302 switch (phba->cfg_fcp_cpu_map) {
4303 case 0:
4304 len += snprintf(buf + len, PAGE_SIZE-len,
4305 "fcp_cpu_map: No mapping (%d)\n",
4306 phba->cfg_fcp_cpu_map);
4307 return len;
4308 case 1:
4309 len += snprintf(buf + len, PAGE_SIZE-len,
4310 "fcp_cpu_map: HBA centric mapping (%d): "
4311 "%d online CPUs\n",
4312 phba->cfg_fcp_cpu_map,
4313 phba->sli4_hba.num_online_cpu);
4314 break;
4315 case 2:
4316 len += snprintf(buf + len, PAGE_SIZE-len,
4317 "fcp_cpu_map: Driver centric mapping (%d): "
4318 "%d online CPUs\n",
4319 phba->cfg_fcp_cpu_map,
4320 phba->sli4_hba.num_online_cpu);
4321 break;
4322 }
4323
James Smart76fd07a2014-02-20 09:57:18 -05004324 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4325 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4326
4327 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004328 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4329 len += snprintf(buf + len, PAGE_SIZE-len,
4330 "CPU %02d io_chan %02d "
4331 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004332 phba->sli4_hba.curr_disp_cpu,
4333 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004334 cpup->core_id);
4335 else
4336 len += snprintf(buf + len, PAGE_SIZE-len,
4337 "CPU %02d io_chan %02d "
4338 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004339 phba->sli4_hba.curr_disp_cpu,
4340 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004341 cpup->core_id, cpup->irq);
4342
James Smart76fd07a2014-02-20 09:57:18 -05004343 phba->sli4_hba.curr_disp_cpu++;
4344
4345 /* display max number of CPUs keeping some margin */
4346 if (phba->sli4_hba.curr_disp_cpu <
4347 phba->sli4_hba.num_present_cpu &&
4348 (len >= (PAGE_SIZE - 64))) {
4349 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4350 break;
4351 }
James Smart7bb03bb2013-04-17 20:19:16 -04004352 }
James Smart76fd07a2014-02-20 09:57:18 -05004353
4354 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4355 phba->sli4_hba.curr_disp_cpu = 0;
4356
James Smart7bb03bb2013-04-17 20:19:16 -04004357 return len;
4358}
4359
4360/**
4361 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4362 * @dev: class device that is converted into a Scsi_host.
4363 * @attr: device attribute, not used.
4364 * @buf: one or more lpfc_polling_flags values.
4365 * @count: not used.
4366 *
4367 * Returns:
4368 * -EINVAL - Not implemented yet.
4369 **/
4370static ssize_t
4371lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4372 const char *buf, size_t count)
4373{
4374 int status = -EINVAL;
4375 return status;
4376}
4377
4378/*
4379# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4380# for the HBA.
4381#
4382# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4383# 0 - Do not affinitze IRQ vectors
4384# 1 - Affintize HBA vectors with respect to each HBA
4385# (start with CPU0 for each HBA)
4386# 2 - Affintize HBA vectors with respect to the entire driver
4387# (round robin thru all CPUs across all HBAs)
4388*/
4389static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4390module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4391MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4392 "Defines how to map CPUs to IRQ vectors per HBA");
4393
4394/**
4395 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4396 * @phba: lpfc_hba pointer.
4397 * @val: link speed value.
4398 *
4399 * Description:
4400 * If val is in a valid range [0-2], then affinitze the adapter's
4401 * MSIX vectors.
4402 *
4403 * Returns:
4404 * zero if val saved.
4405 * -EINVAL val out of range
4406 **/
4407static int
4408lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4409{
4410 if (phba->sli_rev != LPFC_SLI_REV4) {
4411 phba->cfg_fcp_cpu_map = 0;
4412 return 0;
4413 }
4414
4415 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4416 phba->cfg_fcp_cpu_map = val;
4417 return 0;
4418 }
4419
4420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4421 "3326 fcp_cpu_map: %d out of range, using default\n",
4422 val);
4423 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4424
4425 return 0;
4426}
4427
4428static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4429 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4430
James Smart0d878412009-10-02 15:16:56 -04004431/*
dea31012005-04-17 16:05:31 -05004432# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4433# Value range is [2,3]. Default value is 3.
4434*/
James Smart3de2a652007-08-02 11:09:59 -04004435LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4436 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004437
4438/*
4439# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4440# is [0,1]. Default value is 0.
4441*/
James Smart3de2a652007-08-02 11:09:59 -04004442LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4443 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004444
4445/*
James Smart3cb01c52013-07-15 18:35:04 -04004446# lpfc_first_burst_size: First burst size to use on the NPorts
4447# that support first burst.
4448# Value range is [0,65536]. Default value is 0.
4449*/
4450LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4451 "First burst size for Targets that support first burst");
4452
4453/*
James Smart977b5a02008-09-07 11:52:04 -04004454# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4455# depth. Default value is 0. When the value of this parameter is zero the
4456# SCSI command completion time is not used for controlling I/O queue depth. When
4457# the parameter is set to a non-zero value, the I/O queue depth is controlled
4458# to limit the I/O completion time to the parameter value.
4459# The value is set in milliseconds.
4460*/
4461static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05004462module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04004463MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
4464 "Use command completion time to control queue depth");
4465lpfc_vport_param_show(max_scsicmpl_time);
4466lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
4467static int
4468lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4469{
4470 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4471 struct lpfc_nodelist *ndlp, *next_ndlp;
4472
4473 if (val == vport->cfg_max_scsicmpl_time)
4474 return 0;
4475 if ((val < 0) || (val > 60000))
4476 return -EINVAL;
4477 vport->cfg_max_scsicmpl_time = val;
4478
4479 spin_lock_irq(shost->host_lock);
4480 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4481 if (!NLP_CHK_NODE_ACT(ndlp))
4482 continue;
4483 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4484 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004485 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004486 }
4487 spin_unlock_irq(shost->host_lock);
4488 return 0;
4489}
4490lpfc_vport_param_store(max_scsicmpl_time);
4491static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4492 lpfc_max_scsicmpl_time_show,
4493 lpfc_max_scsicmpl_time_store);
4494
4495/*
dea31012005-04-17 16:05:31 -05004496# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4497# range is [0,1]. Default value is 0.
4498*/
4499LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4500
4501/*
James Smart49aa1432012-08-03 12:36:42 -04004502# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4503# range is [0,1]. Default value is 0.
4504# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4505# For [1], FCP commands are issued to a Work Queue associated with the
4506# current CPU.
James Smartec2087a2013-09-06 12:20:36 -04004507# It would be set to 1 by the driver if it's able to set up cpu affinity
4508# for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4509# roundrobin scheduling of FCP I/Os through WQs will be used.
James Smart49aa1432012-08-03 12:36:42 -04004510*/
James Smartec2087a2013-09-06 12:20:36 -04004511LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
James Smart49aa1432012-08-03 12:36:42 -04004512 "issuing commands [0] - Round Robin, [1] - Current CPU");
4513
4514/*
James Smarta6571c62012-10-31 14:44:42 -04004515# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4516# range is [0,1]. Default value is 0.
4517# For [0], bus reset issues target reset to ALL devices
4518# For [1], bus reset issues target reset to non-FCP2 devices
4519*/
4520LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4521 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4522
4523
4524/*
dea31012005-04-17 16:05:31 -05004525# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4526# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004527# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004528# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4529# cr_delay is set to 0.
4530*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004531LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004532 "interrupt response is generated");
4533
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004534LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004535 "interrupt response is generated");
4536
4537/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004538# lpfc_multi_ring_support: Determines how many rings to spread available
4539# cmd/rsp IOCB entries across.
4540# Value range is [1,2]. Default value is 1.
4541*/
4542LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4543 "SLI rings to spread IOCB entries across");
4544
4545/*
James Smarta4bc3372006-12-02 13:34:16 -05004546# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4547# identifies what rctl value to configure the additional ring for.
4548# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4549*/
James Smart6a9c52c2009-10-02 15:16:51 -04004550LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004551 255, "Identifies RCTL for additional ring configuration");
4552
4553/*
4554# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4555# identifies what type value to configure the additional ring for.
4556# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4557*/
James Smart6a9c52c2009-10-02 15:16:51 -04004558LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004559 255, "Identifies TYPE for additional ring configuration");
4560
4561/*
dea31012005-04-17 16:05:31 -05004562# lpfc_fdmi_on: controls FDMI support.
4563# 0 = no FDMI support
4564# 1 = support FDMI without attribute of hostname
4565# 2 = support FDMI with attribute of hostname
4566# Value range [0,2]. Default value is 0.
4567*/
James Smart3de2a652007-08-02 11:09:59 -04004568LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004569
4570/*
4571# Specifies the maximum number of ELS cmds we can have outstanding (for
4572# discovery). Value range is [1,64]. Default value = 32.
4573*/
James Smart3de2a652007-08-02 11:09:59 -04004574LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004575 "during discovery");
4576
4577/*
James Smartc4a7c922013-05-31 17:04:59 -04004578# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4579# will be scanned by the SCSI midlayer when sequential scanning is
4580# used; and is also the highest LUN ID allowed when the SCSI midlayer
4581# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4582# LUN ID limit, but the SCSI midlayer requires this field for the uses
4583# above. The lpfc driver limits the default value to 255 for two reasons.
4584# As it bounds the sequential scan loop, scanning for thousands of luns
4585# on a target can take minutes of wall clock time. Additionally,
4586# there are FC targets, such as JBODs, that only recognize 8-bits of
4587# LUN ID. When they receive a value greater than 8 bits, they chop off
4588# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4589# and so on all as LUN ID 0. This causes the linux kernel, which sees
4590# valid responses at each of the LUN IDs, to believe there are multiple
4591# devices present, when in fact, there is only 1.
4592# A customer that is aware of their target behaviors, and the results as
4593# indicated above, is welcome to increase the lpfc_max_luns value.
4594# As mentioned, this value is not used by the lpfc driver, only the
4595# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004596# Value range is [0,65535]. Default value is 255.
4597# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004598*/
James Smartc4a7c922013-05-31 17:04:59 -04004599LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004600
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004601/*
4602# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4603# Value range is [1,255], default value is 10.
4604*/
4605LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4606 "Milliseconds driver will wait between polling FCP ring");
4607
James Smart4ff43242006-12-02 13:34:56 -05004608/*
James Smart0c411222013-09-06 12:22:46 -04004609# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4610# to complete in seconds. Value range is [5,180], default value is 60.
4611*/
4612LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4613 "Maximum time to wait for task management commands to complete");
4614/*
James Smart4ff43242006-12-02 13:34:56 -05004615# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4616# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004617# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004618# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004619# 2 = MSI-X enabled (default)
4620# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004621*/
George Kadianakis8605c462010-01-17 21:19:31 +02004622LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004623 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004624
James Smart13815c82008-01-11 01:52:48 -05004625/*
James Smart67d12732012-08-03 12:36:13 -04004626# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4627#
4628# Value range is [1,7]. Default value is 4.
4629*/
4630LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4631 LPFC_FCP_IO_CHAN_MAX,
4632 "Set the number of FCP I/O channels");
4633
4634/*
James Smart13815c82008-01-11 01:52:48 -05004635# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4636# 0 = HBA resets disabled
4637# 1 = HBA resets enabled (default)
4638# Value range is [0,1]. Default value is 1.
4639*/
4640LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004641
James Smart13815c82008-01-11 01:52:48 -05004642/*
James Smarteb7a3392010-11-20 23:12:02 -05004643# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004644# 0 = HBA Heartbeat disabled
4645# 1 = HBA Heartbeat enabled (default)
4646# Value range is [0,1]. Default value is 1.
4647*/
James Smarteb7a3392010-11-20 23:12:02 -05004648LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004649
James Smart83108bd2008-01-11 01:53:09 -05004650/*
James Smart1ba981f2014-02-20 09:56:45 -05004651# lpfc_EnableXLane: Enable Express Lane Feature
4652# 0x0 Express Lane Feature disabled
4653# 0x1 Express Lane Feature enabled
4654# Value range is [0,1]. Default value is 0.
4655*/
4656LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4657
4658/*
4659# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4660# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4661# Value range is [0x0,0x7f]. Default value is 0
4662*/
4663LPFC_ATTR_R(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
4664
4665/*
James Smart81301a92008-12-04 22:39:46 -05004666# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4667# 0 = BlockGuard disabled (default)
4668# 1 = BlockGuard enabled
4669# Value range is [0,1]. Default value is 0.
4670*/
4671LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4672
James Smart6fb120a2009-05-22 14:52:59 -04004673/*
James Smartba20c852012-08-03 12:36:52 -04004674# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4675# 0 = disabled (default)
4676# 1 = enabled
4677# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004678#
4679# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004680*/
4681unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4682
James Smartba20c852012-08-03 12:36:52 -04004683/*
James Smart81301a92008-12-04 22:39:46 -05004684# lpfc_prot_mask: i
4685# - Bit mask of host protection capabilities used to register with the
4686# SCSI mid-layer
4687# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4688# - Allows you to ultimately specify which profiles to use
4689# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004690# - SHOST_DIF_TYPE1_PROTECTION 1
4691# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4692# - SHOST_DIX_TYPE0_PROTECTION 8
4693# HBA supports DIX Type 0: Host to HBA protection only
4694# - SHOST_DIX_TYPE1_PROTECTION 16
4695# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004696#
4697*/
James Smart7c56b9f2011-07-22 18:36:25 -04004698unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4699 SHOST_DIX_TYPE0_PROTECTION |
4700 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004701
James Smartab56dc22011-02-16 12:39:57 -05004702module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004703MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4704
4705/*
4706# lpfc_prot_guard: i
4707# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004708# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004709# - Allows you to ultimately specify which profiles to use
4710# - Default will result in registering capabilities for all guard types
4711#
4712*/
4713unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004714module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004715MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4716
James Smart92494142011-02-16 12:39:44 -05004717/*
4718 * Delay initial NPort discovery when Clean Address bit is cleared in
4719 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4720 * This parameter can have value 0 or 1.
4721 * When this parameter is set to 0, no delay is added to the initial
4722 * discovery.
4723 * When this parameter is set to non-zero value, initial Nport discovery is
4724 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4725 * accept and FCID/Fabric name/Fabric portname is changed.
4726 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4727 * when Clean Address bit is cleared in FLOGI/FDISC
4728 * accept and FCID/Fabric name/Fabric portname is changed.
4729 * Default value is 0.
4730 */
4731int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05004732module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05004733MODULE_PARM_DESC(lpfc_delay_discovery,
4734 "Delay NPort discovery when Clean Address bit is cleared. "
4735 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05004736
4737/*
James Smart3621a712009-04-06 18:47:14 -04004738 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004739 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004740 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4741 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004742 * Because of the additional overhead involved in setting up T10-DIF,
4743 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4744 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004745 */
4746LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4747 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4748
James Smart96f70772013-04-17 20:16:15 -04004749/*
4750 * This parameter will be depricated, the driver cannot limit the
4751 * protection data s/g list.
4752 */
4753LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4754 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4755 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004756
Tony Jonesee959b02008-02-22 00:13:36 +01004757struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004758 &dev_attr_bg_info,
4759 &dev_attr_bg_guard_err,
4760 &dev_attr_bg_apptag_err,
4761 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004762 &dev_attr_info,
4763 &dev_attr_serialnum,
4764 &dev_attr_modeldesc,
4765 &dev_attr_modelname,
4766 &dev_attr_programtype,
4767 &dev_attr_portnum,
4768 &dev_attr_fwrev,
4769 &dev_attr_hdw,
4770 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004771 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004772 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004773 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004774 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004775 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004776 &dev_attr_lpfc_temp_sensor,
4777 &dev_attr_lpfc_log_verbose,
4778 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004779 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004780 &dev_attr_lpfc_hba_queue_depth,
4781 &dev_attr_lpfc_peer_port_login,
4782 &dev_attr_lpfc_nodev_tmo,
4783 &dev_attr_lpfc_devloss_tmo,
4784 &dev_attr_lpfc_fcp_class,
4785 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004786 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004787 &dev_attr_lpfc_ack0,
4788 &dev_attr_lpfc_topology,
4789 &dev_attr_lpfc_scan_down,
4790 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004791 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004792 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004793 &dev_attr_lpfc_cr_delay,
4794 &dev_attr_lpfc_cr_count,
4795 &dev_attr_lpfc_multi_ring_support,
4796 &dev_attr_lpfc_multi_ring_rctl,
4797 &dev_attr_lpfc_multi_ring_type,
4798 &dev_attr_lpfc_fdmi_on,
4799 &dev_attr_lpfc_max_luns,
4800 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004801 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004802 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004803 &dev_attr_nport_evt_cnt,
4804 &dev_attr_board_mode,
4805 &dev_attr_max_vpi,
4806 &dev_attr_used_vpi,
4807 &dev_attr_max_rpi,
4808 &dev_attr_used_rpi,
4809 &dev_attr_max_xri,
4810 &dev_attr_used_xri,
4811 &dev_attr_npiv_info,
4812 &dev_attr_issue_reset,
4813 &dev_attr_lpfc_poll,
4814 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04004815 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01004816 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004817 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004818 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04004819 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004820 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004821 &dev_attr_lpfc_soft_wwnn,
4822 &dev_attr_lpfc_soft_wwpn,
4823 &dev_attr_lpfc_soft_wwn_enable,
4824 &dev_attr_lpfc_enable_hba_reset,
4825 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05004826 &dev_attr_lpfc_EnableXLane,
4827 &dev_attr_lpfc_XLanePriority,
4828 &dev_attr_lpfc_xlane_lun,
4829 &dev_attr_lpfc_xlane_tgt,
4830 &dev_attr_lpfc_xlane_vpt,
4831 &dev_attr_lpfc_xlane_lun_state,
4832 &dev_attr_lpfc_xlane_lun_status,
Tony Jonesee959b02008-02-22 00:13:36 +01004833 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004834 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004835 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004836 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004837 &dev_attr_lpfc_aer_support,
4838 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004839 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004840 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004841 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004842 &dev_attr_lpfc_iocb_cnt,
4843 &dev_attr_iocb_hw,
4844 &dev_attr_txq_hw,
4845 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004846 &dev_attr_lpfc_fips_level,
4847 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004848 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004849 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004850 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05004851 &dev_attr_lpfc_xlane_supported,
dea31012005-04-17 16:05:31 -05004852 NULL,
4853};
4854
Tony Jonesee959b02008-02-22 00:13:36 +01004855struct device_attribute *lpfc_vport_attrs[] = {
4856 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004857 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004858 &dev_attr_num_discovered_ports,
4859 &dev_attr_lpfc_drvr_version,
4860 &dev_attr_lpfc_log_verbose,
4861 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004862 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004863 &dev_attr_lpfc_nodev_tmo,
4864 &dev_attr_lpfc_devloss_tmo,
4865 &dev_attr_lpfc_hba_queue_depth,
4866 &dev_attr_lpfc_peer_port_login,
4867 &dev_attr_lpfc_restrict_login,
4868 &dev_attr_lpfc_fcp_class,
4869 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004870 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004871 &dev_attr_lpfc_fdmi_on,
4872 &dev_attr_lpfc_max_luns,
4873 &dev_attr_nport_evt_cnt,
4874 &dev_attr_npiv_info,
4875 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004876 &dev_attr_lpfc_max_scsicmpl_time,
4877 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004878 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004879 &dev_attr_lpfc_fips_level,
4880 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004881 NULL,
4882};
4883
James Smarte59058c2008-08-24 21:49:00 -04004884/**
James Smart3621a712009-04-06 18:47:14 -04004885 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004886 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004887 * @kobj: kernel kobject that contains the kernel class device.
4888 * @bin_attr: kernel attributes passed to us.
4889 * @buf: contains the data to be written to the adapter IOREG space.
4890 * @off: offset into buffer to beginning of data.
4891 * @count: bytes to transfer.
4892 *
4893 * Description:
4894 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4895 * Uses the adapter io control registers to send buf contents to the adapter.
4896 *
4897 * Returns:
4898 * -ERANGE off and count combo out of range
4899 * -EINVAL off, count or buff address invalid
4900 * -EPERM adapter is offline
4901 * value of count, buf contents written
4902 **/
dea31012005-04-17 16:05:31 -05004903static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004904sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4905 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004906 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004907{
4908 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004909 struct device *dev = container_of(kobj, struct device, kobj);
4910 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004911 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4912 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004913
James Smartf1126682009-06-10 17:22:44 -04004914 if (phba->sli_rev >= LPFC_SLI_REV4)
4915 return -EPERM;
4916
dea31012005-04-17 16:05:31 -05004917 if ((off + count) > FF_REG_AREA_SIZE)
4918 return -ERANGE;
4919
James Smartf7a919b2011-08-21 21:49:16 -04004920 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4921 return 0;
dea31012005-04-17 16:05:31 -05004922
4923 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4924 return -EINVAL;
4925
James Smartf7a919b2011-08-21 21:49:16 -04004926 /* This is to protect HBA registers from accidental writes. */
4927 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4928 return -EINVAL;
4929
4930 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004931 return -EPERM;
dea31012005-04-17 16:05:31 -05004932
James Smart2e0fef82007-06-17 19:56:36 -05004933 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004934 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4935 buf_off += sizeof(uint32_t))
4936 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004937 phba->ctrl_regs_memmap_p + off + buf_off);
4938
James Smart2e0fef82007-06-17 19:56:36 -05004939 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004940
4941 return count;
4942}
4943
James Smarte59058c2008-08-24 21:49:00 -04004944/**
James Smart3621a712009-04-06 18:47:14 -04004945 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004946 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004947 * @kobj: kernel kobject that contains the kernel class device.
4948 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004949 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004950 * @off: offset into buffer to beginning of data.
4951 * @count: bytes to transfer.
4952 *
4953 * Description:
4954 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4955 * Uses the adapter io control registers to read data into buf.
4956 *
4957 * Returns:
4958 * -ERANGE off and count combo out of range
4959 * -EINVAL off, count or buff address invalid
4960 * value of count, buf contents read
4961 **/
dea31012005-04-17 16:05:31 -05004962static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004963sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4964 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004965 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004966{
4967 size_t buf_off;
4968 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004969 struct device *dev = container_of(kobj, struct device, kobj);
4970 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004971 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4972 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004973
James Smartf1126682009-06-10 17:22:44 -04004974 if (phba->sli_rev >= LPFC_SLI_REV4)
4975 return -EPERM;
4976
dea31012005-04-17 16:05:31 -05004977 if (off > FF_REG_AREA_SIZE)
4978 return -ERANGE;
4979
4980 if ((off + count) > FF_REG_AREA_SIZE)
4981 count = FF_REG_AREA_SIZE - off;
4982
4983 if (count == 0) return 0;
4984
4985 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4986 return -EINVAL;
4987
James Smart2e0fef82007-06-17 19:56:36 -05004988 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004989
4990 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4991 tmp_ptr = (uint32_t *)(buf + buf_off);
4992 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4993 }
4994
James Smart2e0fef82007-06-17 19:56:36 -05004995 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004996
4997 return count;
4998}
4999
5000static struct bin_attribute sysfs_ctlreg_attr = {
5001 .attr = {
5002 .name = "ctlreg",
5003 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005004 },
5005 .size = 256,
5006 .read = sysfs_ctlreg_read,
5007 .write = sysfs_ctlreg_write,
5008};
5009
James Smarte59058c2008-08-24 21:49:00 -04005010/**
James Smart3621a712009-04-06 18:47:14 -04005011 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005012 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005013 * @kobj: kernel kobject that contains the kernel class device.
5014 * @bin_attr: kernel attributes passed to us.
5015 * @buf: contains the data to be written to sysfs mbox.
5016 * @off: offset into buffer to beginning of data.
5017 * @count: bytes to transfer.
5018 *
5019 * Description:
James Smart026abb82011-12-13 13:20:45 -05005020 * Deprecated function. All mailbox access from user space is performed via the
5021 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005022 *
5023 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005024 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005025 **/
dea31012005-04-17 16:05:31 -05005026static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005027sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5028 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005029 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005030{
James Smart026abb82011-12-13 13:20:45 -05005031 return -EPERM;
dea31012005-04-17 16:05:31 -05005032}
5033
James Smarte59058c2008-08-24 21:49:00 -04005034/**
James Smart3621a712009-04-06 18:47:14 -04005035 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005036 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005037 * @kobj: kernel kobject that contains the kernel class device.
5038 * @bin_attr: kernel attributes passed to us.
5039 * @buf: contains the data to be read from sysfs mbox.
5040 * @off: offset into buffer to beginning of data.
5041 * @count: bytes to transfer.
5042 *
5043 * Description:
James Smart026abb82011-12-13 13:20:45 -05005044 * Deprecated function. All mailbox access from user space is performed via the
5045 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005046 *
5047 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005048 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005049 **/
dea31012005-04-17 16:05:31 -05005050static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005051sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5052 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005053 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005054{
James Smart026abb82011-12-13 13:20:45 -05005055 return -EPERM;
dea31012005-04-17 16:05:31 -05005056}
5057
5058static struct bin_attribute sysfs_mbox_attr = {
5059 .attr = {
5060 .name = "mbox",
5061 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005062 },
James Smartc0c11512011-05-24 11:41:34 -04005063 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005064 .read = sysfs_mbox_read,
5065 .write = sysfs_mbox_write,
5066};
5067
James Smarte59058c2008-08-24 21:49:00 -04005068/**
James Smart3621a712009-04-06 18:47:14 -04005069 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005070 * @vport: address of lpfc vport structure.
5071 *
5072 * Return codes:
5073 * zero on success
5074 * error return code from sysfs_create_bin_file()
5075 **/
dea31012005-04-17 16:05:31 -05005076int
James Smart2e0fef82007-06-17 19:56:36 -05005077lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005078{
James Smart2e0fef82007-06-17 19:56:36 -05005079 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005080 int error;
5081
Tony Jonesee959b02008-02-22 00:13:36 +01005082 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005083 &sysfs_drvr_stat_data_attr);
5084
5085 /* Virtual ports do not need ctrl_reg and mbox */
5086 if (error || vport->port_type == LPFC_NPIV_PORT)
5087 goto out;
5088
5089 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005090 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005091 if (error)
James Smarteada2722008-12-04 22:39:13 -05005092 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005093
Tony Jonesee959b02008-02-22 00:13:36 +01005094 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005095 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005096 if (error)
5097 goto out_remove_ctlreg_attr;
5098
5099 return 0;
5100out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005101 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005102out_remove_stat_attr:
5103 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5104 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005105out:
5106 return error;
5107}
5108
James Smarte59058c2008-08-24 21:49:00 -04005109/**
James Smart3621a712009-04-06 18:47:14 -04005110 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005111 * @vport: address of lpfc vport structure.
5112 **/
dea31012005-04-17 16:05:31 -05005113void
James Smart2e0fef82007-06-17 19:56:36 -05005114lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005115{
James Smart2e0fef82007-06-17 19:56:36 -05005116 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005117 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5118 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005119 /* Virtual ports do not need ctrl_reg and mbox */
5120 if (vport->port_type == LPFC_NPIV_PORT)
5121 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005122 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5123 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005124}
5125
5126
5127/*
5128 * Dynamic FC Host Attributes Support
5129 */
5130
James Smarte59058c2008-08-24 21:49:00 -04005131/**
James Smart3621a712009-04-06 18:47:14 -04005132 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005133 * @shost: kernel scsi host pointer.
5134 **/
dea31012005-04-17 16:05:31 -05005135static void
5136lpfc_get_host_port_id(struct Scsi_Host *shost)
5137{
James Smart2e0fef82007-06-17 19:56:36 -05005138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5139
dea31012005-04-17 16:05:31 -05005140 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005141 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005142}
5143
James Smarte59058c2008-08-24 21:49:00 -04005144/**
James Smart3621a712009-04-06 18:47:14 -04005145 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005146 * @shost: kernel scsi host pointer.
5147 **/
dea31012005-04-17 16:05:31 -05005148static void
5149lpfc_get_host_port_type(struct Scsi_Host *shost)
5150{
James Smart2e0fef82007-06-17 19:56:36 -05005151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5152 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005153
5154 spin_lock_irq(shost->host_lock);
5155
James Smart92d7f7b2007-06-17 19:56:38 -05005156 if (vport->port_type == LPFC_NPIV_PORT) {
5157 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5158 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005159 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005160 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005161 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5162 else
5163 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5164 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005165 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005166 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5167 else
5168 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5169 }
5170 } else
5171 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5172
5173 spin_unlock_irq(shost->host_lock);
5174}
5175
James Smarte59058c2008-08-24 21:49:00 -04005176/**
James Smart3621a712009-04-06 18:47:14 -04005177 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005178 * @shost: kernel scsi host pointer.
5179 **/
dea31012005-04-17 16:05:31 -05005180static void
5181lpfc_get_host_port_state(struct Scsi_Host *shost)
5182{
James Smart2e0fef82007-06-17 19:56:36 -05005183 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5184 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005185
5186 spin_lock_irq(shost->host_lock);
5187
James Smart2e0fef82007-06-17 19:56:36 -05005188 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005189 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5190 else {
James Smart2e0fef82007-06-17 19:56:36 -05005191 switch (phba->link_state) {
5192 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005193 case LPFC_LINK_DOWN:
5194 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5195 break;
5196 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005197 case LPFC_CLEAR_LA:
5198 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005199 /* Links up, reports port state accordingly */
5200 if (vport->port_state < LPFC_VPORT_READY)
5201 fc_host_port_state(shost) =
5202 FC_PORTSTATE_BYPASSED;
5203 else
5204 fc_host_port_state(shost) =
5205 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005206 break;
5207 case LPFC_HBA_ERROR:
5208 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5209 break;
5210 default:
5211 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5212 break;
5213 }
5214 }
5215
5216 spin_unlock_irq(shost->host_lock);
5217}
5218
James Smarte59058c2008-08-24 21:49:00 -04005219/**
James Smart3621a712009-04-06 18:47:14 -04005220 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005221 * @shost: kernel scsi host pointer.
5222 **/
dea31012005-04-17 16:05:31 -05005223static void
5224lpfc_get_host_speed(struct Scsi_Host *shost)
5225{
James Smart2e0fef82007-06-17 19:56:36 -05005226 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5227 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005228
5229 spin_lock_irq(shost->host_lock);
5230
James Smart2e0fef82007-06-17 19:56:36 -05005231 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05005232 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005233 case LPFC_LINK_SPEED_1GHZ:
5234 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005235 break;
James Smart76a95d72010-11-20 23:11:48 -05005236 case LPFC_LINK_SPEED_2GHZ:
5237 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005238 break;
James Smart76a95d72010-11-20 23:11:48 -05005239 case LPFC_LINK_SPEED_4GHZ:
5240 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005241 break;
James Smart76a95d72010-11-20 23:11:48 -05005242 case LPFC_LINK_SPEED_8GHZ:
5243 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005244 break;
James Smart76a95d72010-11-20 23:11:48 -05005245 case LPFC_LINK_SPEED_10GHZ:
5246 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005247 break;
James Smart76a95d72010-11-20 23:11:48 -05005248 case LPFC_LINK_SPEED_16GHZ:
5249 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5250 break;
5251 default:
5252 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005253 break;
5254 }
James Smart09372822008-01-11 01:52:54 -05005255 } else
5256 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005257
5258 spin_unlock_irq(shost->host_lock);
5259}
5260
James Smarte59058c2008-08-24 21:49:00 -04005261/**
James Smart3621a712009-04-06 18:47:14 -04005262 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005263 * @shost: kernel scsi host pointer.
5264 **/
dea31012005-04-17 16:05:31 -05005265static void
5266lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5267{
James Smart2e0fef82007-06-17 19:56:36 -05005268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5269 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005270 u64 node_name;
dea31012005-04-17 16:05:31 -05005271
5272 spin_lock_irq(shost->host_lock);
5273
James Smart73d91e52011-10-10 21:32:10 -04005274 if ((vport->port_state > LPFC_FLOGI) &&
5275 ((vport->fc_flag & FC_FABRIC) ||
5276 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5277 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005278 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005279 else
5280 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005281 node_name = 0;
dea31012005-04-17 16:05:31 -05005282
5283 spin_unlock_irq(shost->host_lock);
5284
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005285 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005286}
5287
James Smarte59058c2008-08-24 21:49:00 -04005288/**
James Smart3621a712009-04-06 18:47:14 -04005289 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005290 * @shost: kernel scsi host pointer.
5291 *
5292 * Notes:
5293 * NULL on error for link down, no mbox pool, sli2 active,
5294 * management not allowed, memory allocation error, or mbox error.
5295 *
5296 * Returns:
5297 * NULL for error
5298 * address of the adapter host statistics
5299 **/
dea31012005-04-17 16:05:31 -05005300static struct fc_host_statistics *
5301lpfc_get_stats(struct Scsi_Host *shost)
5302{
James Smart2e0fef82007-06-17 19:56:36 -05005303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5304 struct lpfc_hba *phba = vport->phba;
5305 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005306 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005307 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005308 LPFC_MBOXQ_t *pmboxq;
5309 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005310 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005311 int rc = 0;
dea31012005-04-17 16:05:31 -05005312
James Smart92d7f7b2007-06-17 19:56:38 -05005313 /*
5314 * prevent udev from issuing mailbox commands until the port is
5315 * configured.
5316 */
James Smart2e0fef82007-06-17 19:56:36 -05005317 if (phba->link_state < LPFC_LINK_DOWN ||
5318 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005319 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005320 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005321
5322 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005323 return NULL;
5324
dea31012005-04-17 16:05:31 -05005325 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5326 if (!pmboxq)
5327 return NULL;
5328 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5329
James Smart04c68492009-05-22 14:52:52 -04005330 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005331 pmb->mbxCommand = MBX_READ_STATUS;
5332 pmb->mbxOwner = OWN_HOST;
5333 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005334 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005335
James Smart75baf692010-06-08 18:31:21 -04005336 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005337 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005338 else
dea31012005-04-17 16:05:31 -05005339 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5340
5341 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005342 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005343 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005344 return NULL;
5345 }
5346
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005347 memset(hs, 0, sizeof (struct fc_host_statistics));
5348
dea31012005-04-17 16:05:31 -05005349 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005350 /*
5351 * The MBX_READ_STATUS returns tx_k_bytes which has to
5352 * converted to words
5353 */
5354 hs->tx_words = (uint64_t)
5355 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5356 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005357 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005358 hs->rx_words = (uint64_t)
5359 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5360 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005361
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005362 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005363 pmb->mbxCommand = MBX_READ_LNK_STAT;
5364 pmb->mbxOwner = OWN_HOST;
5365 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005366 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005367
James Smart75baf692010-06-08 18:31:21 -04005368 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005369 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005370 else
dea31012005-04-17 16:05:31 -05005371 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5372
5373 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005374 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005375 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005376 return NULL;
5377 }
5378
5379 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5380 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5381 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5382 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5383 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5384 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5385 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5386
James Smart64ba8812006-08-02 15:24:34 -04005387 hs->link_failure_count -= lso->link_failure_count;
5388 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5389 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5390 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5391 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5392 hs->invalid_crc_count -= lso->invalid_crc_count;
5393 hs->error_frames -= lso->error_frames;
5394
James Smart76a95d72010-11-20 23:11:48 -05005395 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005396 hs->lip_count = -1;
5397 hs->nos_count = (phba->link_events >> 1);
5398 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005399 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005400 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005401 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005402 hs->nos_count = -1;
5403 } else {
5404 hs->lip_count = -1;
5405 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005406 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005407 }
5408
5409 hs->dumped_frames = -1;
5410
James Smart64ba8812006-08-02 15:24:34 -04005411 seconds = get_seconds();
5412 if (seconds < psli->stats_start)
5413 hs->seconds_since_last_reset = seconds +
5414 ((unsigned long)-1 - psli->stats_start);
5415 else
5416 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005417
James Smart1dcb58e2007-04-25 09:51:30 -04005418 mempool_free(pmboxq, phba->mbox_mem_pool);
5419
dea31012005-04-17 16:05:31 -05005420 return hs;
5421}
5422
James Smarte59058c2008-08-24 21:49:00 -04005423/**
James Smart3621a712009-04-06 18:47:14 -04005424 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005425 * @shost: kernel scsi host pointer.
5426 **/
James Smart64ba8812006-08-02 15:24:34 -04005427static void
5428lpfc_reset_stats(struct Scsi_Host *shost)
5429{
James Smart2e0fef82007-06-17 19:56:36 -05005430 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5431 struct lpfc_hba *phba = vport->phba;
5432 struct lpfc_sli *psli = &phba->sli;
5433 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005434 LPFC_MBOXQ_t *pmboxq;
5435 MAILBOX_t *pmb;
5436 int rc = 0;
5437
James Smart2e0fef82007-06-17 19:56:36 -05005438 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005439 return;
5440
James Smart64ba8812006-08-02 15:24:34 -04005441 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5442 if (!pmboxq)
5443 return;
5444 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5445
James Smart04c68492009-05-22 14:52:52 -04005446 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005447 pmb->mbxCommand = MBX_READ_STATUS;
5448 pmb->mbxOwner = OWN_HOST;
5449 pmb->un.varWords[0] = 0x1; /* reset request */
5450 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005451 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005452
James Smart2e0fef82007-06-17 19:56:36 -05005453 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005454 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005455 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5456 else
5457 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5458
5459 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005460 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005461 mempool_free(pmboxq, phba->mbox_mem_pool);
5462 return;
5463 }
5464
5465 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5466 pmb->mbxCommand = MBX_READ_LNK_STAT;
5467 pmb->mbxOwner = OWN_HOST;
5468 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005469 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005470
James Smart2e0fef82007-06-17 19:56:36 -05005471 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005472 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005473 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5474 else
5475 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5476
5477 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005478 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005479 mempool_free( pmboxq, phba->mbox_mem_pool);
5480 return;
5481 }
5482
5483 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5484 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5485 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5486 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5487 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5488 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5489 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005490 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005491 lso->link_events = (phba->link_events >> 1);
5492 else
5493 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005494
5495 psli->stats_start = get_seconds();
5496
James Smart1dcb58e2007-04-25 09:51:30 -04005497 mempool_free(pmboxq, phba->mbox_mem_pool);
5498
James Smart64ba8812006-08-02 15:24:34 -04005499 return;
5500}
dea31012005-04-17 16:05:31 -05005501
5502/*
5503 * The LPFC driver treats linkdown handling as target loss events so there
5504 * are no sysfs handlers for link_down_tmo.
5505 */
James Smart685f0bf2007-04-25 09:53:08 -04005506
James Smarte59058c2008-08-24 21:49:00 -04005507/**
James Smart3621a712009-04-06 18:47:14 -04005508 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005509 * @starget: kernel scsi target pointer.
5510 *
5511 * Returns:
5512 * address of the node list if found
5513 * NULL target not found
5514 **/
James Smart685f0bf2007-04-25 09:53:08 -04005515static struct lpfc_nodelist *
5516lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005517{
James Smart2e0fef82007-06-17 19:56:36 -05005518 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5519 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005520 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005521
5522 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005523 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005524 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005525 if (NLP_CHK_NODE_ACT(ndlp) &&
5526 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005527 starget->id == ndlp->nlp_sid) {
5528 spin_unlock_irq(shost->host_lock);
5529 return ndlp;
dea31012005-04-17 16:05:31 -05005530 }
5531 }
5532 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005533 return NULL;
5534}
dea31012005-04-17 16:05:31 -05005535
James Smarte59058c2008-08-24 21:49:00 -04005536/**
James Smart3621a712009-04-06 18:47:14 -04005537 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005538 * @starget: kernel scsi target pointer.
5539 **/
James Smart685f0bf2007-04-25 09:53:08 -04005540static void
5541lpfc_get_starget_port_id(struct scsi_target *starget)
5542{
5543 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5544
5545 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005546}
5547
James Smarte59058c2008-08-24 21:49:00 -04005548/**
James Smart3621a712009-04-06 18:47:14 -04005549 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005550 * @starget: kernel scsi target pointer.
5551 *
5552 * Description: Set the target node name to the ndlp node name wwn or zero.
5553 **/
dea31012005-04-17 16:05:31 -05005554static void
5555lpfc_get_starget_node_name(struct scsi_target *starget)
5556{
James Smart685f0bf2007-04-25 09:53:08 -04005557 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005558
James Smart685f0bf2007-04-25 09:53:08 -04005559 fc_starget_node_name(starget) =
5560 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005561}
5562
James Smarte59058c2008-08-24 21:49:00 -04005563/**
James Smart3621a712009-04-06 18:47:14 -04005564 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005565 * @starget: kernel scsi target pointer.
5566 *
5567 * Description: set the target port name to the ndlp port name wwn or zero.
5568 **/
dea31012005-04-17 16:05:31 -05005569static void
5570lpfc_get_starget_port_name(struct scsi_target *starget)
5571{
James Smart685f0bf2007-04-25 09:53:08 -04005572 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005573
James Smart685f0bf2007-04-25 09:53:08 -04005574 fc_starget_port_name(starget) =
5575 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005576}
5577
James Smarte59058c2008-08-24 21:49:00 -04005578/**
James Smart3621a712009-04-06 18:47:14 -04005579 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005580 * @rport: fc rport address.
5581 * @timeout: new value for dev loss tmo.
5582 *
5583 * Description:
5584 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5585 * dev_loss_tmo to one.
5586 **/
dea31012005-04-17 16:05:31 -05005587static void
dea31012005-04-17 16:05:31 -05005588lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5589{
dea31012005-04-17 16:05:31 -05005590 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005591 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005592 else
James Smartc01f3202006-08-18 17:47:08 -04005593 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005594}
5595
James Smarte59058c2008-08-24 21:49:00 -04005596/**
James Smart3621a712009-04-06 18:47:14 -04005597 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005598 *
5599 * Description:
5600 * Macro that uses field to generate a function with the name lpfc_show_rport_
5601 *
5602 * lpfc_show_rport_##field: returns the bytes formatted in buf
5603 * @cdev: class converted to an fc_rport.
5604 * @buf: on return contains the target_field or zero.
5605 *
5606 * Returns: size of formatted string.
5607 **/
dea31012005-04-17 16:05:31 -05005608#define lpfc_rport_show_function(field, format_string, sz, cast) \
5609static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005610lpfc_show_rport_##field (struct device *dev, \
5611 struct device_attribute *attr, \
5612 char *buf) \
dea31012005-04-17 16:05:31 -05005613{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005614 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005615 struct lpfc_rport_data *rdata = rport->hostdata; \
5616 return snprintf(buf, sz, format_string, \
5617 (rdata->target) ? cast rdata->target->field : 0); \
5618}
5619
5620#define lpfc_rport_rd_attr(field, format_string, sz) \
5621 lpfc_rport_show_function(field, format_string, sz, ) \
5622static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5623
James Smarteada2722008-12-04 22:39:13 -05005624/**
James Smart3621a712009-04-06 18:47:14 -04005625 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005626 * @fc_vport: The fc_vport who's symbolic name has been changed.
5627 *
5628 * Description:
5629 * This function is called by the transport after the @fc_vport's symbolic name
5630 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005631 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005632 **/
5633static void
5634lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5635{
5636 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5637
5638 if (vport->port_state == LPFC_VPORT_READY)
5639 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5640}
dea31012005-04-17 16:05:31 -05005641
James Smartf4b4c682009-05-22 14:53:12 -04005642/**
5643 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5644 * @phba: Pointer to lpfc_hba struct.
5645 *
5646 * This function is called by the lpfc_get_cfgparam() routine to set the
5647 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005648 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005649 * before hba port or vport created.
5650 **/
5651static void
5652lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5653{
5654 phba->cfg_log_verbose = verbose;
5655}
5656
dea31012005-04-17 16:05:31 -05005657struct fc_function_template lpfc_transport_functions = {
5658 /* fixed attributes the driver supports */
5659 .show_host_node_name = 1,
5660 .show_host_port_name = 1,
5661 .show_host_supported_classes = 1,
5662 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005663 .show_host_supported_speeds = 1,
5664 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005665 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005666
5667 /* dynamic attributes the driver supports */
5668 .get_host_port_id = lpfc_get_host_port_id,
5669 .show_host_port_id = 1,
5670
5671 .get_host_port_type = lpfc_get_host_port_type,
5672 .show_host_port_type = 1,
5673
5674 .get_host_port_state = lpfc_get_host_port_state,
5675 .show_host_port_state = 1,
5676
5677 /* active_fc4s is shown but doesn't change (thus no get function) */
5678 .show_host_active_fc4s = 1,
5679
5680 .get_host_speed = lpfc_get_host_speed,
5681 .show_host_speed = 1,
5682
5683 .get_host_fabric_name = lpfc_get_host_fabric_name,
5684 .show_host_fabric_name = 1,
5685
5686 /*
5687 * The LPFC driver treats linkdown handling as target loss events
5688 * so there are no sysfs handlers for link_down_tmo.
5689 */
5690
5691 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005692 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005693
5694 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5695 .show_rport_maxframe_size = 1,
5696 .show_rport_supported_classes = 1,
5697
dea31012005-04-17 16:05:31 -05005698 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5699 .show_rport_dev_loss_tmo = 1,
5700
5701 .get_starget_port_id = lpfc_get_starget_port_id,
5702 .show_starget_port_id = 1,
5703
5704 .get_starget_node_name = lpfc_get_starget_node_name,
5705 .show_starget_node_name = 1,
5706
5707 .get_starget_port_name = lpfc_get_starget_port_name,
5708 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005709
5710 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005711 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5712 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005713
James Smart92d7f7b2007-06-17 19:56:38 -05005714 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005715
5716 .vport_disable = lpfc_vport_disable,
5717
5718 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005719
5720 .bsg_request = lpfc_bsg_request,
5721 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005722};
5723
James Smart98c9ea52007-10-27 13:37:33 -04005724struct fc_function_template lpfc_vport_transport_functions = {
5725 /* fixed attributes the driver supports */
5726 .show_host_node_name = 1,
5727 .show_host_port_name = 1,
5728 .show_host_supported_classes = 1,
5729 .show_host_supported_fc4s = 1,
5730 .show_host_supported_speeds = 1,
5731 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005732 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005733
5734 /* dynamic attributes the driver supports */
5735 .get_host_port_id = lpfc_get_host_port_id,
5736 .show_host_port_id = 1,
5737
5738 .get_host_port_type = lpfc_get_host_port_type,
5739 .show_host_port_type = 1,
5740
5741 .get_host_port_state = lpfc_get_host_port_state,
5742 .show_host_port_state = 1,
5743
5744 /* active_fc4s is shown but doesn't change (thus no get function) */
5745 .show_host_active_fc4s = 1,
5746
5747 .get_host_speed = lpfc_get_host_speed,
5748 .show_host_speed = 1,
5749
5750 .get_host_fabric_name = lpfc_get_host_fabric_name,
5751 .show_host_fabric_name = 1,
5752
5753 /*
5754 * The LPFC driver treats linkdown handling as target loss events
5755 * so there are no sysfs handlers for link_down_tmo.
5756 */
5757
5758 .get_fc_host_stats = lpfc_get_stats,
5759 .reset_fc_host_stats = lpfc_reset_stats,
5760
5761 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5762 .show_rport_maxframe_size = 1,
5763 .show_rport_supported_classes = 1,
5764
5765 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5766 .show_rport_dev_loss_tmo = 1,
5767
5768 .get_starget_port_id = lpfc_get_starget_port_id,
5769 .show_starget_port_id = 1,
5770
5771 .get_starget_node_name = lpfc_get_starget_node_name,
5772 .show_starget_node_name = 1,
5773
5774 .get_starget_port_name = lpfc_get_starget_port_name,
5775 .show_starget_port_name = 1,
5776
5777 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5778 .terminate_rport_io = lpfc_terminate_rport_io,
5779
5780 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005781
5782 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005783};
5784
James Smarte59058c2008-08-24 21:49:00 -04005785/**
James Smart3621a712009-04-06 18:47:14 -04005786 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005787 * @phba: lpfc_hba pointer.
5788 **/
dea31012005-04-17 16:05:31 -05005789void
5790lpfc_get_cfgparam(struct lpfc_hba *phba)
5791{
James Smart49aa1432012-08-03 12:36:42 -04005792 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005793 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005794 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5795 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005796 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005797 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5798 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005799 lpfc_ack0_init(phba, lpfc_ack0);
5800 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005801 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005802 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04005803 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005804 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005805 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005806 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005807 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005808 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005809 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart67d12732012-08-03 12:36:13 -04005810 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005811 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5812 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart1ba981f2014-02-20 09:56:45 -05005813 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5814 if (phba->sli_rev != LPFC_SLI_REV4)
5815 phba->cfg_EnableXLane = 0;
5816 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5817 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5818 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5819 phba->cfg_oas_lun_state = 0;
5820 phba->cfg_oas_lun_status = 0;
5821 phba->cfg_oas_flags = 0;
James Smart81301a92008-12-04 22:39:46 -05005822 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005823 if (phba->sli_rev == LPFC_SLI_REV4)
5824 phba->cfg_poll = 0;
5825 else
James Smart1ba981f2014-02-20 09:56:45 -05005826 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005827 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005828 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005829 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005830 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005831 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005832 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005833 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005834 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005835 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005836 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005837 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005838 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005839 return;
5840}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005841
James Smarte59058c2008-08-24 21:49:00 -04005842/**
James Smart3621a712009-04-06 18:47:14 -04005843 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005844 * @vport: lpfc_vport pointer.
5845 **/
James Smart3de2a652007-08-02 11:09:59 -04005846void
5847lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5848{
James Smarte8b62012007-08-02 11:10:09 -04005849 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005850 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005851 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005852 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5853 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5854 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5855 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5856 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5857 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04005858 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04005859 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005860 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5861 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5862 lpfc_max_luns_init(vport, lpfc_max_luns);
5863 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005864 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005865 return;
5866}