blob: d65bd178d131a04a1b9f137c73aa9cac6a0510b8 [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 Smartf25e8e72015-04-07 15:07:28 -04004 * Copyright (C) 2004-2015 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040026#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040027#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070029#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050030
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_tcq.h>
35#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040036#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050037
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_hw.h"
40#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040041#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040042#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_disc.h"
44#include "lpfc_scsi.h"
45#include "lpfc.h"
46#include "lpfc_logmsg.h"
47#include "lpfc_version.h"
48#include "lpfc_compat.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050051
James Smartc01f3202006-08-18 17:47:08 -040052#define LPFC_DEF_DEVLOSS_TMO 30
53#define LPFC_MIN_DEVLOSS_TMO 1
54#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050055
James Smartf7a919b2011-08-21 21:49:16 -040056/*
57 * Write key size should be multiple of 4. If write key is changed
58 * make sure that library write key is also changed.
59 */
60#define LPFC_REG_WRITE_KEY_SIZE 4
61#define LPFC_REG_WRITE_KEY "EMLX"
62
James Smarte59058c2008-08-24 21:49:00 -040063/**
James Smart3621a712009-04-06 18:47:14 -040064 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040065 * @incr: integer to convert.
66 * @hdw: ascii string holding converted integer plus a string terminator.
67 *
68 * Description:
69 * JEDEC Joint Electron Device Engineering Council.
70 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71 * character string. The string is then terminated with a NULL in byte 9.
72 * Hex 0-9 becomes ascii '0' to '9'.
73 * Hex a-f becomes ascii '=' to 'B' capital B.
74 *
75 * Notes:
76 * Coded for 32 bit integers only.
77 **/
dea31012005-04-17 16:05:31 -050078static void
79lpfc_jedec_to_ascii(int incr, char hdw[])
80{
81 int i, j;
82 for (i = 0; i < 8; i++) {
83 j = (incr & 0xf);
84 if (j <= 9)
85 hdw[7 - i] = 0x30 + j;
86 else
87 hdw[7 - i] = 0x61 + j - 10;
88 incr = (incr >> 4);
89 }
90 hdw[8] = 0;
91 return;
92}
93
James Smarte59058c2008-08-24 21:49:00 -040094/**
James Smart3621a712009-04-06 18:47:14 -040095 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040096 * @dev: class unused variable.
97 * @attr: device attribute, not used.
98 * @buf: on return contains the module description text.
99 *
100 * Returns: size of formatted string.
101 **/
dea31012005-04-17 16:05:31 -0500102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100103lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
dea31012005-04-17 16:05:31 -0500105{
106 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
107}
108
James Smart45ed1192009-10-02 15:17:02 -0400109/**
110 * lpfc_enable_fip_show - Return the fip mode of the HBA
111 * @dev: class unused variable.
112 * @attr: device attribute, not used.
113 * @buf: on return contains the module description text.
114 *
115 * Returns: size of formatted string.
116 **/
117static ssize_t
118lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119 char *buf)
120{
121 struct Scsi_Host *shost = class_to_shost(dev);
122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
124
125 if (phba->hba_flag & HBA_FIP_SUPPORT)
126 return snprintf(buf, PAGE_SIZE, "1\n");
127 else
128 return snprintf(buf, PAGE_SIZE, "0\n");
129}
130
James Smart81301a92008-12-04 22:39:46 -0500131static ssize_t
132lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133 char *buf)
134{
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
138
139 if (phba->cfg_enable_bg)
140 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142 else
143 return snprintf(buf, PAGE_SIZE,
144 "BlockGuard Not Supported\n");
145 else
146 return snprintf(buf, PAGE_SIZE,
147 "BlockGuard Disabled\n");
148}
149
150static ssize_t
151lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152 char *buf)
153{
154 struct Scsi_Host *shost = class_to_shost(dev);
155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156 struct lpfc_hba *phba = vport->phba;
157
James Smart87b5c322008-12-16 10:34:09 -0500158 return snprintf(buf, PAGE_SIZE, "%llu\n",
159 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500160}
161
162static ssize_t
163lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164 char *buf)
165{
166 struct Scsi_Host *shost = class_to_shost(dev);
167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 struct lpfc_hba *phba = vport->phba;
169
James Smart87b5c322008-12-16 10:34:09 -0500170 return snprintf(buf, PAGE_SIZE, "%llu\n",
171 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500172}
173
174static ssize_t
175lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176 char *buf)
177{
178 struct Scsi_Host *shost = class_to_shost(dev);
179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 struct lpfc_hba *phba = vport->phba;
181
James Smart87b5c322008-12-16 10:34:09 -0500182 return snprintf(buf, PAGE_SIZE, "%llu\n",
183 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500184}
185
James Smarte59058c2008-08-24 21:49:00 -0400186/**
James Smart3621a712009-04-06 18:47:14 -0400187 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400188 * @dev: class converted to a Scsi_host structure.
189 * @attr: device attribute, not used.
190 * @buf: on return contains the formatted text from lpfc_info().
191 *
192 * Returns: size of formatted string.
193 **/
dea31012005-04-17 16:05:31 -0500194static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100195lpfc_info_show(struct device *dev, struct device_attribute *attr,
196 char *buf)
dea31012005-04-17 16:05:31 -0500197{
Tony Jonesee959b02008-02-22 00:13:36 +0100198 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500199
dea31012005-04-17 16:05:31 -0500200 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
201}
202
James Smarte59058c2008-08-24 21:49:00 -0400203/**
James Smart3621a712009-04-06 18:47:14 -0400204 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400205 * @dev: class converted to a Scsi_host structure.
206 * @attr: device attribute, not used.
207 * @buf: on return contains the formatted text serial number.
208 *
209 * Returns: size of formatted string.
210 **/
dea31012005-04-17 16:05:31 -0500211static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100212lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213 char *buf)
dea31012005-04-17 16:05:31 -0500214{
Tony Jonesee959b02008-02-22 00:13:36 +0100215 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217 struct lpfc_hba *phba = vport->phba;
218
dea31012005-04-17 16:05:31 -0500219 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
220}
221
James Smarte59058c2008-08-24 21:49:00 -0400222/**
James Smart3621a712009-04-06 18:47:14 -0400223 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400224 * @dev: class converted to a Scsi_host structure.
225 * @attr: device attribute, not used.
226 * @buf: on return contains the formatted support level.
227 *
228 * Description:
229 * Returns a number indicating the temperature sensor level currently
230 * supported, zero or one in ascii.
231 *
232 * Returns: size of formatted string.
233 **/
dea31012005-04-17 16:05:31 -0500234static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100235lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400237{
Tony Jonesee959b02008-02-22 00:13:36 +0100238 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 struct lpfc_hba *phba = vport->phba;
241 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
242}
243
James Smarte59058c2008-08-24 21:49:00 -0400244/**
James Smart3621a712009-04-06 18:47:14 -0400245 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400246 * @dev: class converted to a Scsi_host structure.
247 * @attr: device attribute, not used.
248 * @buf: on return contains the scsi vpd model description.
249 *
250 * Returns: size of formatted string.
251 **/
James Smart57127f12007-10-27 13:37:05 -0400252static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100253lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254 char *buf)
dea31012005-04-17 16:05:31 -0500255{
Tony Jonesee959b02008-02-22 00:13:36 +0100256 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258 struct lpfc_hba *phba = vport->phba;
259
dea31012005-04-17 16:05:31 -0500260 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
261}
262
James Smarte59058c2008-08-24 21:49:00 -0400263/**
James Smart3621a712009-04-06 18:47:14 -0400264 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400265 * @dev: class converted to a Scsi_host structure.
266 * @attr: device attribute, not used.
267 * @buf: on return contains the scsi vpd model name.
268 *
269 * Returns: size of formatted string.
270 **/
dea31012005-04-17 16:05:31 -0500271static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100272lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273 char *buf)
dea31012005-04-17 16:05:31 -0500274{
Tony Jonesee959b02008-02-22 00:13:36 +0100275 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277 struct lpfc_hba *phba = vport->phba;
278
dea31012005-04-17 16:05:31 -0500279 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
280}
281
James Smarte59058c2008-08-24 21:49:00 -0400282/**
James Smart3621a712009-04-06 18:47:14 -0400283 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400284 * @dev: class converted to a Scsi_host structure.
285 * @attr: device attribute, not used.
286 * @buf: on return contains the scsi vpd program type.
287 *
288 * Returns: size of formatted string.
289 **/
dea31012005-04-17 16:05:31 -0500290static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100291lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292 char *buf)
dea31012005-04-17 16:05:31 -0500293{
Tony Jonesee959b02008-02-22 00:13:36 +0100294 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500295 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296 struct lpfc_hba *phba = vport->phba;
297
dea31012005-04-17 16:05:31 -0500298 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
299}
300
James Smarte59058c2008-08-24 21:49:00 -0400301/**
James Smart3621a712009-04-06 18:47:14 -0400302 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400303 * @dev: class converted to a Scsi_host structure.
304 * @attr: device attribute, not used.
305 * @buf: on return contains the Menlo Maintenance sli flag.
306 *
307 * Returns: size of formatted string.
308 **/
309static ssize_t
310lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311{
312 struct Scsi_Host *shost = class_to_shost(dev);
313 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314 struct lpfc_hba *phba = vport->phba;
315
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
318}
319
320/**
James Smart3621a712009-04-06 18:47:14 -0400321 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400322 * @dev: class converted to a Scsi_host structure.
323 * @attr: device attribute, not used.
324 * @buf: on return contains scsi vpd program type.
325 *
326 * Returns: size of formatted string.
327 **/
dea31012005-04-17 16:05:31 -0500328static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100329lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330 char *buf)
dea31012005-04-17 16:05:31 -0500331{
Tony Jonesee959b02008-02-22 00:13:36 +0100332 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500333 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334 struct lpfc_hba *phba = vport->phba;
335
dea31012005-04-17 16:05:31 -0500336 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
337}
338
James Smarte59058c2008-08-24 21:49:00 -0400339/**
James Smart3621a712009-04-06 18:47:14 -0400340 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400341 * @dev: class converted to a Scsi_host structure.
342 * @attr: device attribute, not used.
343 * @buf: on return contains the scsi vpd program type.
344 *
345 * Returns: size of formatted string.
346 **/
dea31012005-04-17 16:05:31 -0500347static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100348lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349 char *buf)
dea31012005-04-17 16:05:31 -0500350{
Tony Jonesee959b02008-02-22 00:13:36 +0100351 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500354 uint32_t if_type;
355 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500356 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500357 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500358
dea31012005-04-17 16:05:31 -0500359 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500360 if_type = phba->sli4_hba.pc_sli4_params.if_type;
361 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
362
363 if (phba->sli_rev < LPFC_SLI_REV4)
364 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
365 fwrev, phba->sli_rev);
366 else
367 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
368 fwrev, phba->sli_rev, if_type, sli_family);
369
370 return len;
dea31012005-04-17 16:05:31 -0500371}
372
James Smarte59058c2008-08-24 21:49:00 -0400373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the scsi vpd program type.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500383{
384 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500388 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500389
dea31012005-04-17 16:05:31 -0500390 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
391 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
392}
James Smarte59058c2008-08-24 21:49:00 -0400393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains the ROM and FCode ascii strings.
399 *
400 * Returns: size of formatted string.
401 **/
dea31012005-04-17 16:05:31 -0500402static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100403lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
404 char *buf)
dea31012005-04-17 16:05:31 -0500405{
Tony Jonesee959b02008-02-22 00:13:36 +0100406 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400409 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500410
James Smarta0683bf2015-04-07 15:07:16 -0400411 if (phba->sli_rev < LPFC_SLI_REV4)
412 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
413
414 lpfc_decode_firmware_rev(phba, fwrev, 1);
415 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500416}
James Smarte59058c2008-08-24 21:49:00 -0400417
418/**
James Smart3621a712009-04-06 18:47:14 -0400419 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400420 * @dev: class converted to a Scsi_host structure.
421 * @attr: device attribute, not used.
422 * @buf: on return contains text describing the state of the link.
423 *
424 * Notes:
425 * The switch statement has no default so zero will be returned.
426 *
427 * Returns: size of formatted string.
428 **/
dea31012005-04-17 16:05:31 -0500429static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100430lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
431 char *buf)
dea31012005-04-17 16:05:31 -0500432{
Tony Jonesee959b02008-02-22 00:13:36 +0100433 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500434 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
435 struct lpfc_hba *phba = vport->phba;
436 int len = 0;
437
438 switch (phba->link_state) {
439 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500440 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500441 case LPFC_INIT_START:
442 case LPFC_INIT_MBX_CMDS:
443 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500444 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400445 if (phba->hba_flag & LINK_DISABLED)
446 len += snprintf(buf + len, PAGE_SIZE-len,
447 "Link Down - User disabled\n");
448 else
449 len += snprintf(buf + len, PAGE_SIZE-len,
450 "Link Down\n");
dea31012005-04-17 16:05:31 -0500451 break;
452 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500453 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500454 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400455 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500456
457 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500458 case LPFC_LOCAL_CFG_LINK:
459 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500460 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500461 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500462 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500463 case LPFC_FLOGI:
464 case LPFC_FABRIC_CFG_LINK:
465 case LPFC_NS_REG:
466 case LPFC_NS_QRY:
467 case LPFC_BUILD_DISC_LIST:
468 case LPFC_DISC_AUTH:
469 len += snprintf(buf + len, PAGE_SIZE - len,
470 "Discovery\n");
471 break;
472 case LPFC_VPORT_READY:
473 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
474 break;
475
James Smart92d7f7b2007-06-17 19:56:38 -0500476 case LPFC_VPORT_FAILED:
477 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
478 break;
479
480 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500481 len += snprintf(buf + len, PAGE_SIZE - len,
482 "Unknown\n");
483 break;
484 }
James Smart84774a42008-08-24 21:50:06 -0400485 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
486 len += snprintf(buf + len, PAGE_SIZE-len,
487 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500488 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500489 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500490 len += snprintf(buf + len, PAGE_SIZE-len,
491 " Public Loop\n");
492 else
493 len += snprintf(buf + len, PAGE_SIZE-len,
494 " Private Loop\n");
495 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500496 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500497 len += snprintf(buf + len, PAGE_SIZE-len,
498 " Fabric\n");
499 else
500 len += snprintf(buf + len, PAGE_SIZE-len,
501 " Point-2-Point\n");
502 }
503 }
James Smart2e0fef82007-06-17 19:56:36 -0500504
dea31012005-04-17 16:05:31 -0500505 return len;
506}
507
James Smarte59058c2008-08-24 21:49:00 -0400508/**
James Smart026abb82011-12-13 13:20:45 -0500509 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
510 * @dev: class unused variable.
511 * @attr: device attribute, not used.
512 * @buf: on return contains the module description text.
513 *
514 * Returns: size of formatted string.
515 **/
516static ssize_t
517lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
518 char *buf)
519{
520 struct Scsi_Host *shost = class_to_shost(dev);
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
522 struct lpfc_hba *phba = vport->phba;
523
524 if (phba->sli_rev < LPFC_SLI_REV4)
525 return snprintf(buf, PAGE_SIZE, "fc\n");
526
527 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
528 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
529 return snprintf(buf, PAGE_SIZE, "fcoe\n");
530 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
531 return snprintf(buf, PAGE_SIZE, "fc\n");
532 }
533 return snprintf(buf, PAGE_SIZE, "unknown\n");
534}
535
536/**
James Smart1ba981f2014-02-20 09:56:45 -0500537 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
538 * (OAS) is supported.
539 * @dev: class unused variable.
540 * @attr: device attribute, not used.
541 * @buf: on return contains the module description text.
542 *
543 * Returns: size of formatted string.
544 **/
545static ssize_t
546lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
547 char *buf)
548{
549 struct Scsi_Host *shost = class_to_shost(dev);
550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
551 struct lpfc_hba *phba = vport->phba;
552
553 return snprintf(buf, PAGE_SIZE, "%d\n",
554 phba->sli4_hba.pc_sli4_params.oas_supported);
555}
556
557/**
James Smart84d1b002010-02-12 14:42:33 -0500558 * lpfc_link_state_store - Transition the link_state on an HBA port
559 * @dev: class device that is converted into a Scsi_host.
560 * @attr: device attribute, not used.
561 * @buf: one or more lpfc_polling_flags values.
562 * @count: not used.
563 *
564 * Returns:
565 * -EINVAL if the buffer is not "up" or "down"
566 * return from link state change function if non-zero
567 * length of the buf on success
568 **/
569static ssize_t
570lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
571 const char *buf, size_t count)
572{
573 struct Scsi_Host *shost = class_to_shost(dev);
574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
575 struct lpfc_hba *phba = vport->phba;
576
577 int status = -EINVAL;
578
579 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
580 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400581 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500582 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
583 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400584 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500585
586 if (status == 0)
587 return strlen(buf);
588 else
589 return status;
590}
591
592/**
James Smart3621a712009-04-06 18:47:14 -0400593 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400594 * @dev: class device that is converted into a Scsi_host.
595 * @attr: device attribute, not used.
596 * @buf: on return contains the sum of fc mapped and unmapped.
597 *
598 * Description:
599 * Returns the ascii text number of the sum of the fc mapped and unmapped
600 * vport counts.
601 *
602 * Returns: size of formatted string.
603 **/
dea31012005-04-17 16:05:31 -0500604static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100605lpfc_num_discovered_ports_show(struct device *dev,
606 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500607{
Tony Jonesee959b02008-02-22 00:13:36 +0100608 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
610
611 return snprintf(buf, PAGE_SIZE, "%d\n",
612 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500613}
614
James Smarte59058c2008-08-24 21:49:00 -0400615/**
James Smart3621a712009-04-06 18:47:14 -0400616 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400617 * @shost: Scsi_Host pointer.
618 *
619 * Description:
620 * Bring the link down gracefully then re-init the link. The firmware will
621 * re-init the fiber channel interface as required. Does not issue a LIP.
622 *
623 * Returns:
624 * -EPERM port offline or management commands are being blocked
625 * -ENOMEM cannot allocate memory for the mailbox command
626 * -EIO error sending the mailbox command
627 * zero for success
628 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700629static int
James Smart2e0fef82007-06-17 19:56:36 -0500630lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500631{
James Smart2e0fef82007-06-17 19:56:36 -0500632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500634 LPFC_MBOXQ_t *pmboxq;
635 int mbxstatus = MBXERR_ERROR;
636
James Smart2e0fef82007-06-17 19:56:36 -0500637 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500638 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500639 return -EPERM;
640
641 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
642
643 if (!pmboxq)
644 return -ENOMEM;
645
646 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400647 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
648 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400649
James Smart33ccf8d2006-08-17 11:57:58 -0400650 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500651
James Smart04c68492009-05-22 14:52:52 -0400652 if ((mbxstatus == MBX_SUCCESS) &&
653 (pmboxq->u.mb.mbxStatus == 0 ||
654 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400655 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
656 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
657 phba->cfg_link_speed);
658 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
659 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400660 if ((mbxstatus == MBX_SUCCESS) &&
661 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
662 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
663 "2859 SLI authentication is required "
664 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400665 }
666
James Smart5b8bd0c2007-04-25 09:52:49 -0400667 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500668 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400669 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500670
671 if (mbxstatus == MBXERR_ERROR)
672 return -EIO;
673
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700674 return 0;
dea31012005-04-17 16:05:31 -0500675}
676
James Smarte59058c2008-08-24 21:49:00 -0400677/**
James Smart3621a712009-04-06 18:47:14 -0400678 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400679 * @phba: lpfc_hba pointer.
680 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
681 *
682 * Notes:
683 * Assumes any error from lpfc_do_offline() will be negative.
684 * Can wait up to 5 seconds for the port ring buffers count
685 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400686 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400687 *
688 * Returns:
689 * -EIO error posting the event
690 * zero for success
691 **/
James Smart40496f02006-07-06 15:50:22 -0400692static int
James Smart46fa3112007-04-25 09:51:45 -0400693lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
694{
695 struct completion online_compl;
696 struct lpfc_sli_ring *pring;
697 struct lpfc_sli *psli;
698 int status = 0;
699 int cnt = 0;
700 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500701 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400702
703 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400705 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500706 if (rc == 0)
707 return -ENOMEM;
708
James Smart46fa3112007-04-25 09:51:45 -0400709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 psli = &phba->sli;
715
James Smart09372822008-01-11 01:52:54 -0500716 /* Wait a little for things to settle down, but not
717 * long enough for dev loss timeout to expire.
718 */
James Smart46fa3112007-04-25 09:51:45 -0400719 for (i = 0; i < psli->num_rings; i++) {
720 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500721 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400722 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500723 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400724 lpfc_printf_log(phba,
725 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400726 "0466 Outstanding IO when "
727 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400728 break;
729 }
730 }
731 }
732
733 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500734 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
735 if (rc == 0)
736 return -ENOMEM;
737
James Smart46fa3112007-04-25 09:51:45 -0400738 wait_for_completion(&online_compl);
739
740 if (status != 0)
741 return -EIO;
742
743 return 0;
744}
745
James Smarte59058c2008-08-24 21:49:00 -0400746/**
James Smart3621a712009-04-06 18:47:14 -0400747 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400748 * @phba: lpfc_hba pointer.
749 *
750 * Description:
751 * If the port is configured to allow a reset then the hba is brought
752 * offline then online.
753 *
754 * Notes:
755 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500756 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400757 *
758 * Returns:
759 * lpfc_do_offline() return code if not zero
760 * -EIO reset not configured or error posting the event
761 * zero for success
762 **/
James Smart7f860592011-03-11 16:05:52 -0500763int
James Smart40496f02006-07-06 15:50:22 -0400764lpfc_selective_reset(struct lpfc_hba *phba)
765{
766 struct completion online_compl;
767 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500768 int rc;
James Smart40496f02006-07-06 15:50:22 -0400769
James Smart71157c92013-07-15 18:34:36 -0400770 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400771 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500772
James Smart71157c92013-07-15 18:34:36 -0400773 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
774 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400775
James Smart71157c92013-07-15 18:34:36 -0400776 if (status != 0)
777 return status;
778 }
James Smart40496f02006-07-06 15:50:22 -0400779
780 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500781 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400782 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500783 if (rc == 0)
784 return -ENOMEM;
785
James Smart40496f02006-07-06 15:50:22 -0400786 wait_for_completion(&online_compl);
787
788 if (status != 0)
789 return -EIO;
790
791 return 0;
792}
793
James Smarte59058c2008-08-24 21:49:00 -0400794/**
James Smart3621a712009-04-06 18:47:14 -0400795 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400796 * @dev: class device that is converted into a Scsi_host.
797 * @attr: device attribute, not used.
798 * @buf: containing the string "selective".
799 * @count: unused variable.
800 *
801 * Description:
802 * If the buf contains the string "selective" then lpfc_selective_reset()
803 * is called to perform the reset.
804 *
805 * Notes:
806 * Assumes any error from lpfc_selective_reset() will be negative.
807 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200808 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400809 *
810 * Returns:
811 * -EINVAL if the buffer does not contain the string "selective"
812 * length of buf if lpfc-selective_reset() if the call succeeds
813 * return value of lpfc_selective_reset() if the call fails
814**/
James Smart40496f02006-07-06 15:50:22 -0400815static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100816lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
817 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400818{
Tony Jonesee959b02008-02-22 00:13:36 +0100819 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
821 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400822 int status = -EINVAL;
823
James Smart73d91e52011-10-10 21:32:10 -0400824 if (!phba->cfg_enable_hba_reset)
825 return -EACCES;
826
James Smart40496f02006-07-06 15:50:22 -0400827 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500828 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400829
830 if (status == 0)
831 return strlen(buf);
832 else
833 return status;
834}
835
James Smarte59058c2008-08-24 21:49:00 -0400836/**
James Smart88a2cfb2011-07-22 18:36:33 -0400837 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
838 * @phba: lpfc_hba pointer.
839 *
840 * Description:
841 * SLI4 interface type-2 device to wait on the sliport status register for
842 * the readyness after performing a firmware reset.
843 *
844 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +0900845 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -0500846 * reset, -EIO when port timeout from recovering from the reset.
847 *
848 * Note:
849 * As the caller will interpret the return code by value, be careful in making
850 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400851 **/
James Smart73d91e52011-10-10 21:32:10 -0400852int
James Smart88a2cfb2011-07-22 18:36:33 -0400853lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
854{
James Smartf7a919b2011-08-21 21:49:16 -0400855 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400856 int i;
857
James Smartf7a919b2011-08-21 21:49:16 -0400858 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400859 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
860 &portstat_reg.word0);
861
Masanari Iida0b1587b2013-07-17 04:37:44 +0900862 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -0400863 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
864 !bf_get(lpfc_sliport_status_err, &portstat_reg))
865 return -EPERM;
866
James Smart88a2cfb2011-07-22 18:36:33 -0400867 /* wait for the SLI port firmware ready after firmware reset */
868 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
869 msleep(10);
870 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
871 &portstat_reg.word0);
872 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
873 continue;
874 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
875 continue;
876 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
877 continue;
878 break;
879 }
880
881 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
882 return 0;
883 else
884 return -EIO;
885}
886
887/**
James Smart52d52442011-05-24 11:42:45 -0400888 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400889 * @phba: lpfc_hba pointer.
890 *
891 * Description:
James Smart52d52442011-05-24 11:42:45 -0400892 * Request SLI4 interface type-2 device to perform a physical register set
893 * access.
James Smartc0c11512011-05-24 11:41:34 -0400894 *
895 * Returns:
896 * zero for success
897 **/
898static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400899lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400900{
901 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400902 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500903 uint32_t before_fc_flag;
904 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400905 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500906 int status = 0, rc = 0;
907 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400908
909 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400910 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400911
James Smart52d52442011-05-24 11:42:45 -0400912 if ((phba->sli_rev < LPFC_SLI_REV4) ||
913 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
914 LPFC_SLI_INTF_IF_TYPE_2))
915 return -EPERM;
916
James Smart026abb82011-12-13 13:20:45 -0500917 /* Keep state if we need to restore back */
918 before_fc_flag = phba->pport->fc_flag;
919 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
920
James Smartb76f2dc2011-07-22 18:37:42 -0400921 /* Disable SR-IOV virtual functions if enabled */
922 if (phba->cfg_sriov_nr_virtfn) {
923 pci_disable_sriov(pdev);
924 phba->cfg_sriov_nr_virtfn = 0;
925 }
James Smart229adb02013-04-17 20:16:51 -0400926
James Smart02936352014-04-04 13:52:12 -0400927 if (opcode == LPFC_FW_DUMP)
928 phba->hba_flag |= HBA_FW_DUMP_OP;
929
James Smartc0c11512011-05-24 11:41:34 -0400930 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
931
James Smart02936352014-04-04 13:52:12 -0400932 if (status != 0) {
933 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -0400934 return status;
James Smart02936352014-04-04 13:52:12 -0400935 }
James Smartc0c11512011-05-24 11:41:34 -0400936
937 /* wait for the device to be quiesced before firmware reset */
938 msleep(100);
939
940 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
941 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400942
943 if (opcode == LPFC_FW_DUMP)
944 reg_val |= LPFC_FW_DUMP_REQUEST;
945 else if (opcode == LPFC_FW_RESET)
946 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
947 else if (opcode == LPFC_DV_RESET)
948 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
949
James Smartc0c11512011-05-24 11:41:34 -0400950 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
951 LPFC_CTL_PDEV_CTL_OFFSET);
952 /* flush */
953 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
954
955 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400956 rc = lpfc_sli4_pdev_status_reg_wait(phba);
957
James Smart026abb82011-12-13 13:20:45 -0500958 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +0900959 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -0500960 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +0900961 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -0500962 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500963 } else if (rc == -EIO) {
964 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
966 "3153 Fail to perform the requested "
967 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400968 return rc;
James Smart026abb82011-12-13 13:20:45 -0500969 }
970
971 /* keep the original port state */
972 if (before_fc_flag & FC_OFFLINE_MODE)
973 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400974
975 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500976 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
977 LPFC_EVT_ONLINE);
978 if (!job_posted)
979 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400980
981 wait_for_completion(&online_compl);
982
James Smart026abb82011-12-13 13:20:45 -0500983out:
984 /* in any case, restore the virtual functions enabled as before */
985 if (sriov_nr_virtfn) {
986 sriov_err =
987 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
988 if (!sriov_err)
989 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
990 }
James Smartc0c11512011-05-24 11:41:34 -0400991
James Smart026abb82011-12-13 13:20:45 -0500992 /* return proper error code */
993 if (!rc) {
994 if (!job_posted)
995 rc = -ENOMEM;
996 else if (status)
997 rc = -EIO;
998 }
999 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001000}
1001
1002/**
James Smart3621a712009-04-06 18:47:14 -04001003 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001004 * @dev: class device that is converted into a Scsi_host.
1005 * @attr: device attribute, not used.
1006 * @buf: on return contains the ascii number of nport events.
1007 *
1008 * Returns: size of formatted string.
1009 **/
dea31012005-04-17 16:05:31 -05001010static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001011lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1012 char *buf)
dea31012005-04-17 16:05:31 -05001013{
Tony Jonesee959b02008-02-22 00:13:36 +01001014 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001015 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1016 struct lpfc_hba *phba = vport->phba;
1017
dea31012005-04-17 16:05:31 -05001018 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the state of the adapter.
1026 *
1027 * Returns: size of formatted string.
1028 **/
dea31012005-04-17 16:05:31 -05001029static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001030lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1031 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001032{
Tony Jonesee959b02008-02-22 00:13:36 +01001033 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001034 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1035 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001036 char * state;
1037
James Smart2e0fef82007-06-17 19:56:36 -05001038 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001039 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001040 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001041 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001042 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001043 state = "offline";
1044 else
1045 state = "online";
1046
1047 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1048}
1049
James Smarte59058c2008-08-24 21:49:00 -04001050/**
James Smart3621a712009-04-06 18:47:14 -04001051 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001052 * @dev: class device that is converted into a Scsi_host.
1053 * @attr: device attribute, not used.
1054 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1055 * @count: unused variable.
1056 *
1057 * Returns:
1058 * -EACCES if enable hba reset not enabled
1059 * -EINVAL if the buffer does not contain a valid string (see above)
1060 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1061 * buf length greater than zero indicates success
1062 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001063static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001064lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1065 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001066{
Tony Jonesee959b02008-02-22 00:13:36 +01001067 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1069 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001070 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001071 char *board_mode_str = NULL;
1072 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001073 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001074
James Smart026abb82011-12-13 13:20:45 -05001075 if (!phba->cfg_enable_hba_reset) {
1076 status = -EACCES;
1077 goto board_mode_out;
1078 }
James Smart88a2cfb2011-07-22 18:36:33 -04001079
1080 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001081 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001082
Jamie Wellnitz41415862006-02-28 19:25:27 -05001083 init_completion(&online_compl);
1084
James Smart46fa3112007-04-25 09:51:45 -04001085 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001086 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001087 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001088 if (rc == 0) {
1089 status = -ENOMEM;
1090 goto board_mode_out;
1091 }
James Smart46fa3112007-04-25 09:51:45 -04001092 wait_for_completion(&online_compl);
1093 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1094 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001095 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001096 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001097 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001098 else
1099 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001100 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001101 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001102 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001103 else
1104 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001105 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001106 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1107 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1108 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1109 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1110 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001111 else
James Smart026abb82011-12-13 13:20:45 -05001112 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001113
James Smart026abb82011-12-13 13:20:45 -05001114board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001115 if (!status)
1116 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001117 else {
1118 board_mode_str = strchr(buf, '\n');
1119 if (board_mode_str)
1120 *board_mode_str = '\0';
1121 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1122 "3097 Failed \"%s\", status(%d), "
1123 "fc_flag(x%x)\n",
1124 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001125 return status;
James Smart026abb82011-12-13 13:20:45 -05001126 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001127}
1128
James Smarte59058c2008-08-24 21:49:00 -04001129/**
James Smart3621a712009-04-06 18:47:14 -04001130 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001131 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001132 * @mxri: max xri count.
1133 * @axri: available xri count.
1134 * @mrpi: max rpi count.
1135 * @arpi: available rpi count.
1136 * @mvpi: max vpi count.
1137 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001138 *
1139 * Description:
1140 * If an integer pointer for an count is not null then the value for the
1141 * count is returned.
1142 *
1143 * Returns:
1144 * zero on error
1145 * one for success
1146 **/
James Smart311464e2007-08-02 11:10:37 -04001147static int
James Smart858c9f62007-06-17 19:56:39 -05001148lpfc_get_hba_info(struct lpfc_hba *phba,
1149 uint32_t *mxri, uint32_t *axri,
1150 uint32_t *mrpi, uint32_t *arpi,
1151 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001152{
James Smart04c68492009-05-22 14:52:52 -04001153 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001154 LPFC_MBOXQ_t *pmboxq;
1155 MAILBOX_t *pmb;
1156 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001157 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001158
1159 /*
1160 * prevent udev from issuing mailbox commands until the port is
1161 * configured.
1162 */
1163 if (phba->link_state < LPFC_LINK_DOWN ||
1164 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001165 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001166 return 0;
1167
1168 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1169 return 0;
1170
1171 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1172 if (!pmboxq)
1173 return 0;
1174 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1175
James Smart04c68492009-05-22 14:52:52 -04001176 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001177 pmb->mbxCommand = MBX_READ_CONFIG;
1178 pmb->mbxOwner = OWN_HOST;
1179 pmboxq->context1 = NULL;
1180
James Smart75baf692010-06-08 18:31:21 -04001181 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001182 rc = MBX_NOT_FINISHED;
1183 else
1184 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1185
1186 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001187 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001188 mempool_free(pmboxq, phba->mbox_mem_pool);
1189 return 0;
1190 }
1191
James Smartda0436e2009-05-22 14:51:39 -04001192 if (phba->sli_rev == LPFC_SLI_REV4) {
1193 rd_config = &pmboxq->u.mqe.un.rd_config;
1194 if (mrpi)
1195 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1196 if (arpi)
1197 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1198 phba->sli4_hba.max_cfg_param.rpi_used;
1199 if (mxri)
1200 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1201 if (axri)
1202 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1203 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001204
1205 /* Account for differences with SLI-3. Get vpi count from
1206 * mailbox data and subtract one for max vpi value.
1207 */
1208 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1209 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1210
James Smartda0436e2009-05-22 14:51:39 -04001211 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001212 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001213 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001214 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001215 } else {
1216 if (mrpi)
1217 *mrpi = pmb->un.varRdConfig.max_rpi;
1218 if (arpi)
1219 *arpi = pmb->un.varRdConfig.avail_rpi;
1220 if (mxri)
1221 *mxri = pmb->un.varRdConfig.max_xri;
1222 if (axri)
1223 *axri = pmb->un.varRdConfig.avail_xri;
1224 if (mvpi)
1225 *mvpi = pmb->un.varRdConfig.max_vpi;
1226 if (avpi)
1227 *avpi = pmb->un.varRdConfig.avail_vpi;
1228 }
James Smart92d7f7b2007-06-17 19:56:38 -05001229
1230 mempool_free(pmboxq, phba->mbox_mem_pool);
1231 return 1;
1232}
1233
James Smarte59058c2008-08-24 21:49:00 -04001234/**
James Smart3621a712009-04-06 18:47:14 -04001235 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001236 * @dev: class device that is converted into a Scsi_host.
1237 * @attr: device attribute, not used.
1238 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1239 *
1240 * Description:
1241 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1242 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1243 * to "Unknown" and the buffer length is returned, therefore the caller
1244 * must check for "Unknown" in the buffer to detect a failure.
1245 *
1246 * Returns: size of formatted string.
1247 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001248static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001249lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1250 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001251{
Tony Jonesee959b02008-02-22 00:13:36 +01001252 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001253 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1254 struct lpfc_hba *phba = vport->phba;
1255 uint32_t cnt;
1256
James Smart858c9f62007-06-17 19:56:39 -05001257 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001258 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1259 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1260}
1261
James Smarte59058c2008-08-24 21:49:00 -04001262/**
James Smart3621a712009-04-06 18:47:14 -04001263 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001264 * @dev: class device that is converted into a Scsi_host.
1265 * @attr: device attribute, not used.
1266 * @buf: containing the used rpi count in decimal or "Unknown".
1267 *
1268 * Description:
1269 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1270 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1271 * to "Unknown" and the buffer length is returned, therefore the caller
1272 * must check for "Unknown" in the buffer to detect a failure.
1273 *
1274 * Returns: size of formatted string.
1275 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001276static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001277lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1278 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001279{
Tony Jonesee959b02008-02-22 00:13:36 +01001280 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001281 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1282 struct lpfc_hba *phba = vport->phba;
1283 uint32_t cnt, acnt;
1284
James Smart858c9f62007-06-17 19:56:39 -05001285 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001286 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1287 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1288}
1289
James Smarte59058c2008-08-24 21:49:00 -04001290/**
James Smart3621a712009-04-06 18:47:14 -04001291 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001292 * @dev: class device that is converted into a Scsi_host.
1293 * @attr: device attribute, not used.
1294 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1295 *
1296 * Description:
1297 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1298 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1299 * to "Unknown" and the buffer length is returned, therefore the caller
1300 * must check for "Unknown" in the buffer to detect a failure.
1301 *
1302 * Returns: size of formatted string.
1303 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001304static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001305lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1306 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001307{
Tony Jonesee959b02008-02-22 00:13:36 +01001308 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1310 struct lpfc_hba *phba = vport->phba;
1311 uint32_t cnt;
1312
James Smart858c9f62007-06-17 19:56:39 -05001313 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001314 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1315 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1316}
1317
James Smarte59058c2008-08-24 21:49:00 -04001318/**
James Smart3621a712009-04-06 18:47:14 -04001319 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001320 * @dev: class device that is converted into a Scsi_host.
1321 * @attr: device attribute, not used.
1322 * @buf: on return contains the used xri count in decimal or "Unknown".
1323 *
1324 * Description:
1325 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1326 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1327 * to "Unknown" and the buffer length is returned, therefore the caller
1328 * must check for "Unknown" in the buffer to detect a failure.
1329 *
1330 * Returns: size of formatted string.
1331 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001332static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001333lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1334 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001335{
Tony Jonesee959b02008-02-22 00:13:36 +01001336 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001337 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1338 struct lpfc_hba *phba = vport->phba;
1339 uint32_t cnt, acnt;
1340
James Smart858c9f62007-06-17 19:56:39 -05001341 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1342 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1343 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1344}
1345
James Smarte59058c2008-08-24 21:49:00 -04001346/**
James Smart3621a712009-04-06 18:47:14 -04001347 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001348 * @dev: class device that is converted into a Scsi_host.
1349 * @attr: device attribute, not used.
1350 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1351 *
1352 * Description:
1353 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1354 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1355 * to "Unknown" and the buffer length is returned, therefore the caller
1356 * must check for "Unknown" in the buffer to detect a failure.
1357 *
1358 * Returns: size of formatted string.
1359 **/
James Smart858c9f62007-06-17 19:56:39 -05001360static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001361lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1362 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001363{
Tony Jonesee959b02008-02-22 00:13:36 +01001364 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1366 struct lpfc_hba *phba = vport->phba;
1367 uint32_t cnt;
1368
1369 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1370 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1371 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1372}
1373
James Smarte59058c2008-08-24 21:49:00 -04001374/**
James Smart3621a712009-04-06 18:47:14 -04001375 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001376 * @dev: class device that is converted into a Scsi_host.
1377 * @attr: device attribute, not used.
1378 * @buf: on return contains the used vpi count in decimal or "Unknown".
1379 *
1380 * Description:
1381 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1382 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1383 * to "Unknown" and the buffer length is returned, therefore the caller
1384 * must check for "Unknown" in the buffer to detect a failure.
1385 *
1386 * Returns: size of formatted string.
1387 **/
James Smart858c9f62007-06-17 19:56:39 -05001388static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001389lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1390 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001391{
Tony Jonesee959b02008-02-22 00:13:36 +01001392 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1394 struct lpfc_hba *phba = vport->phba;
1395 uint32_t cnt, acnt;
1396
1397 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001398 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1399 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1400}
1401
James Smarte59058c2008-08-24 21:49:00 -04001402/**
James Smart3621a712009-04-06 18:47:14 -04001403 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001404 * @dev: class device that is converted into a Scsi_host.
1405 * @attr: device attribute, not used.
1406 * @buf: text that must be interpreted to determine if npiv is supported.
1407 *
1408 * Description:
1409 * Buffer will contain text indicating npiv is not suppoerted on the port,
1410 * the port is an NPIV physical port, or it is an npiv virtual port with
1411 * the id of the vport.
1412 *
1413 * Returns: size of formatted string.
1414 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001415static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001416lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1417 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001418{
Tony Jonesee959b02008-02-22 00:13:36 +01001419 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001420 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1421 struct lpfc_hba *phba = vport->phba;
1422
1423 if (!(phba->max_vpi))
1424 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1425 if (vport->port_type == LPFC_PHYSICAL_PORT)
1426 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1427 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1428}
1429
James Smarte59058c2008-08-24 21:49:00 -04001430/**
James Smart3621a712009-04-06 18:47:14 -04001431 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001432 * @dev: class device that is converted into a Scsi_host.
1433 * @attr: device attribute, not used.
1434 * @buf: on return contains the cfg_poll in hex.
1435 *
1436 * Notes:
1437 * cfg_poll should be a lpfc_polling_flags type.
1438 *
1439 * Returns: size of formatted string.
1440 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001441static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001442lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1443 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001444{
Tony Jonesee959b02008-02-22 00:13:36 +01001445 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1447 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001448
1449 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1450}
1451
James Smarte59058c2008-08-24 21:49:00 -04001452/**
James Smart3621a712009-04-06 18:47:14 -04001453 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001454 * @dev: class device that is converted into a Scsi_host.
1455 * @attr: device attribute, not used.
1456 * @buf: one or more lpfc_polling_flags values.
1457 * @count: not used.
1458 *
1459 * Notes:
1460 * buf contents converted to integer and checked for a valid value.
1461 *
1462 * Returns:
1463 * -EINVAL if the buffer connot be converted or is out of range
1464 * length of the buf on success
1465 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001466static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001467lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1468 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001469{
Tony Jonesee959b02008-02-22 00:13:36 +01001470 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1472 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001473 uint32_t creg_val;
1474 uint32_t old_val;
1475 int val=0;
1476
1477 if (!isdigit(buf[0]))
1478 return -EINVAL;
1479
1480 if (sscanf(buf, "%i", &val) != 1)
1481 return -EINVAL;
1482
1483 if ((val & 0x3) != val)
1484 return -EINVAL;
1485
James Smart45ed1192009-10-02 15:17:02 -04001486 if (phba->sli_rev == LPFC_SLI_REV4)
1487 val = 0;
1488
James Smart88a2cfb2011-07-22 18:36:33 -04001489 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1490 "3051 lpfc_poll changed from %d to %d\n",
1491 phba->cfg_poll, val);
1492
James Smart2e0fef82007-06-17 19:56:36 -05001493 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001494
1495 old_val = phba->cfg_poll;
1496
1497 if (val & ENABLE_FCP_RING_POLLING) {
1498 if ((val & DISABLE_FCP_RING_INT) &&
1499 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001500 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1501 spin_unlock_irq(&phba->hbalock);
1502 return -EINVAL;
1503 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001504 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1505 writel(creg_val, phba->HCregaddr);
1506 readl(phba->HCregaddr); /* flush */
1507
1508 lpfc_poll_start_timer(phba);
1509 }
1510 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001511 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001512 return -EINVAL;
1513 }
1514
1515 if (!(val & DISABLE_FCP_RING_INT) &&
1516 (old_val & DISABLE_FCP_RING_INT))
1517 {
James Smart2e0fef82007-06-17 19:56:36 -05001518 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001519 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001520 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001521 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1522 spin_unlock_irq(&phba->hbalock);
1523 return -EINVAL;
1524 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001525 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1526 writel(creg_val, phba->HCregaddr);
1527 readl(phba->HCregaddr); /* flush */
1528 }
1529
1530 phba->cfg_poll = val;
1531
James Smart2e0fef82007-06-17 19:56:36 -05001532 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001533
1534 return strlen(buf);
1535}
dea31012005-04-17 16:05:31 -05001536
James Smarte59058c2008-08-24 21:49:00 -04001537/**
James Smartbc739052010-08-04 16:11:18 -04001538 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1539 * @dev: class unused variable.
1540 * @attr: device attribute, not used.
1541 * @buf: on return contains the module description text.
1542 *
1543 * Returns: size of formatted string.
1544 **/
1545static ssize_t
1546lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1547 char *buf)
1548{
1549 struct Scsi_Host *shost = class_to_shost(dev);
1550 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1551 struct lpfc_hba *phba = vport->phba;
1552
1553 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1554}
1555
1556/**
1557 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1558 * @dev: class unused variable.
1559 * @attr: device attribute, not used.
1560 * @buf: on return contains the module description text.
1561 *
1562 * Returns: size of formatted string.
1563 **/
1564static ssize_t
1565lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1566 char *buf)
1567{
1568 struct Scsi_Host *shost = class_to_shost(dev);
1569 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1570 struct lpfc_hba *phba = vport->phba;
1571
1572 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1573}
1574
1575/**
James Smartab56dc22011-02-16 12:39:57 -05001576 * lpfc_dss_show - Return the current state of dss and the configured state
1577 * @dev: class converted to a Scsi_host structure.
1578 * @attr: device attribute, not used.
1579 * @buf: on return contains the formatted text.
1580 *
1581 * Returns: size of formatted string.
1582 **/
1583static ssize_t
1584lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1585 char *buf)
1586{
1587 struct Scsi_Host *shost = class_to_shost(dev);
1588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1589 struct lpfc_hba *phba = vport->phba;
1590
1591 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1592 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1593 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1594 "" : "Not ");
1595}
1596
1597/**
James Smart912e3ac2011-05-24 11:42:11 -04001598 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1599 * @dev: class converted to a Scsi_host structure.
1600 * @attr: device attribute, not used.
1601 * @buf: on return contains the formatted support level.
1602 *
1603 * Description:
1604 * Returns the maximum number of virtual functions a physical function can
1605 * support, 0 will be returned if called on virtual function.
1606 *
1607 * Returns: size of formatted string.
1608 **/
1609static ssize_t
1610lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1611 struct device_attribute *attr,
1612 char *buf)
1613{
1614 struct Scsi_Host *shost = class_to_shost(dev);
1615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001617 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001618
James Smart0a96e972011-07-22 18:37:28 -04001619 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1620 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001621}
1622
1623/**
James Smart3621a712009-04-06 18:47:14 -04001624 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001625 *
1626 * Description:
1627 * Macro that given an attr e.g. hba_queue_depth expands
1628 * into a function with the name lpfc_hba_queue_depth_show.
1629 *
1630 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1631 * @dev: class device that is converted into a Scsi_host.
1632 * @attr: device attribute, not used.
1633 * @buf: on return contains the attribute value in decimal.
1634 *
1635 * Returns: size of formatted string.
1636 **/
dea31012005-04-17 16:05:31 -05001637#define lpfc_param_show(attr) \
1638static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001639lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1640 char *buf) \
dea31012005-04-17 16:05:31 -05001641{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001642 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001643 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1644 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001645 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001646 val = phba->cfg_##attr;\
1647 return snprintf(buf, PAGE_SIZE, "%d\n",\
1648 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001649}
1650
James Smarte59058c2008-08-24 21:49:00 -04001651/**
James Smart3621a712009-04-06 18:47:14 -04001652 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001653 *
1654 * Description:
1655 * Macro that given an attr e.g. hba_queue_depth expands
1656 * into a function with the name lpfc_hba_queue_depth_show
1657 *
1658 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1659 * @dev: class device that is converted into a Scsi_host.
1660 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001661 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001662 *
1663 * Returns: size of formatted string.
1664 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001665#define lpfc_param_hex_show(attr) \
1666static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001667lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1668 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001669{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001670 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1672 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001673 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001674 val = phba->cfg_##attr;\
1675 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1676 phba->cfg_##attr);\
1677}
1678
James Smarte59058c2008-08-24 21:49:00 -04001679/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001680 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001681 *
1682 * Description:
1683 * Macro that given an attr e.g. hba_queue_depth expands
1684 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1685 * takes a default argument, a minimum and maximum argument.
1686 *
1687 * lpfc_##attr##_init: Initializes an attribute.
1688 * @phba: pointer the the adapter structure.
1689 * @val: integer attribute value.
1690 *
1691 * Validates the min and max values then sets the adapter config field
1692 * accordingly, or uses the default if out of range and prints an error message.
1693 *
1694 * Returns:
1695 * zero on success
1696 * -EINVAL if default used
1697 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001698#define lpfc_param_init(attr, default, minval, maxval) \
1699static int \
James Smart84d1b002010-02-12 14:42:33 -05001700lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001701{ \
1702 if (val >= minval && val <= maxval) {\
1703 phba->cfg_##attr = val;\
1704 return 0;\
1705 }\
1706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001707 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1708 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001709 phba->cfg_##attr = default;\
1710 return -EINVAL;\
1711}
1712
James Smarte59058c2008-08-24 21:49:00 -04001713/**
James Smart3621a712009-04-06 18:47:14 -04001714 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001715 *
1716 * Description:
1717 * Macro that given an attr e.g. hba_queue_depth expands
1718 * into a function with the name lpfc_hba_queue_depth_set
1719 *
1720 * lpfc_##attr##_set: Sets an attribute value.
1721 * @phba: pointer the the adapter structure.
1722 * @val: integer attribute value.
1723 *
1724 * Description:
1725 * Validates the min and max values then sets the
1726 * adapter config field if in the valid range. prints error message
1727 * and does not set the parameter if invalid.
1728 *
1729 * Returns:
1730 * zero on success
1731 * -EINVAL if val is invalid
1732 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001733#define lpfc_param_set(attr, default, minval, maxval) \
1734static int \
James Smart84d1b002010-02-12 14:42:33 -05001735lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001736{ \
1737 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001738 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1739 "3052 lpfc_" #attr " changed from %d to %d\n", \
1740 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001741 phba->cfg_##attr = val;\
1742 return 0;\
1743 }\
1744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001745 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1746 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001747 return -EINVAL;\
1748}
1749
James Smarte59058c2008-08-24 21:49:00 -04001750/**
James Smart3621a712009-04-06 18:47:14 -04001751 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001752 *
1753 * Description:
1754 * Macro that given an attr e.g. hba_queue_depth expands
1755 * into a function with the name lpfc_hba_queue_depth_store.
1756 *
1757 * lpfc_##attr##_store: Set an sttribute value.
1758 * @dev: class device that is converted into a Scsi_host.
1759 * @attr: device attribute, not used.
1760 * @buf: contains the attribute value in ascii.
1761 * @count: not used.
1762 *
1763 * Description:
1764 * Convert the ascii text number to an integer, then
1765 * use the lpfc_##attr##_set function to set the value.
1766 *
1767 * Returns:
1768 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1769 * length of buffer upon success.
1770 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001771#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001772static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001773lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1774 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001775{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001776 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1778 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001779 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001780 if (!isdigit(buf[0]))\
1781 return -EINVAL;\
1782 if (sscanf(buf, "%i", &val) != 1)\
1783 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001784 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001785 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001786 else \
1787 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001788}
1789
James Smarte59058c2008-08-24 21:49:00 -04001790/**
James Smart3621a712009-04-06 18:47:14 -04001791 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001792 *
1793 * Description:
1794 * Macro that given an attr e.g. hba_queue_depth expands
1795 * into a function with the name lpfc_hba_queue_depth_show
1796 *
1797 * lpfc_##attr##_show: prints the attribute value in decimal.
1798 * @dev: class device that is converted into a Scsi_host.
1799 * @attr: device attribute, not used.
1800 * @buf: on return contains the attribute value in decimal.
1801 *
1802 * Returns: length of formatted string.
1803 **/
James Smart3de2a652007-08-02 11:09:59 -04001804#define lpfc_vport_param_show(attr) \
1805static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001806lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1807 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001808{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001809 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001810 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001811 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001812 val = vport->cfg_##attr;\
1813 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1814}
1815
James Smarte59058c2008-08-24 21:49:00 -04001816/**
James Smart3621a712009-04-06 18:47:14 -04001817 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001818 *
1819 * Description:
1820 * Macro that given an attr e.g.
1821 * hba_queue_depth expands into a function with the name
1822 * lpfc_hba_queue_depth_show
1823 *
James Smart3621a712009-04-06 18:47:14 -04001824 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001825 * @dev: class device that is converted into a Scsi_host.
1826 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001827 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001828 *
1829 * Returns: length of formatted string.
1830 **/
James Smart3de2a652007-08-02 11:09:59 -04001831#define lpfc_vport_param_hex_show(attr) \
1832static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001833lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1834 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001835{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001836 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001837 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001838 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001839 val = vport->cfg_##attr;\
1840 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1841}
1842
James Smarte59058c2008-08-24 21:49:00 -04001843/**
James Smart3621a712009-04-06 18:47:14 -04001844 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001845 *
1846 * Description:
1847 * Macro that given an attr e.g. hba_queue_depth expands
1848 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1849 * takes a default argument, a minimum and maximum argument.
1850 *
1851 * lpfc_##attr##_init: validates the min and max values then sets the
1852 * adapter config field accordingly, or uses the default if out of range
1853 * and prints an error message.
1854 * @phba: pointer the the adapter structure.
1855 * @val: integer attribute value.
1856 *
1857 * Returns:
1858 * zero on success
1859 * -EINVAL if default used
1860 **/
James Smart3de2a652007-08-02 11:09:59 -04001861#define lpfc_vport_param_init(attr, default, minval, maxval) \
1862static int \
James Smart84d1b002010-02-12 14:42:33 -05001863lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001864{ \
1865 if (val >= minval && val <= maxval) {\
1866 vport->cfg_##attr = val;\
1867 return 0;\
1868 }\
James Smarte8b62012007-08-02 11:10:09 -04001869 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001870 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001871 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001872 vport->cfg_##attr = default;\
1873 return -EINVAL;\
1874}
1875
James Smarte59058c2008-08-24 21:49:00 -04001876/**
James Smart3621a712009-04-06 18:47:14 -04001877 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001878 *
1879 * Description:
1880 * Macro that given an attr e.g. hba_queue_depth expands
1881 * into a function with the name lpfc_hba_queue_depth_set
1882 *
1883 * lpfc_##attr##_set: validates the min and max values then sets the
1884 * adapter config field if in the valid range. prints error message
1885 * and does not set the parameter if invalid.
1886 * @phba: pointer the the adapter structure.
1887 * @val: integer attribute value.
1888 *
1889 * Returns:
1890 * zero on success
1891 * -EINVAL if val is invalid
1892 **/
James Smart3de2a652007-08-02 11:09:59 -04001893#define lpfc_vport_param_set(attr, default, minval, maxval) \
1894static int \
James Smart84d1b002010-02-12 14:42:33 -05001895lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001896{ \
1897 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001898 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04001899 "3053 lpfc_" #attr \
1900 " changed from %d (x%x) to %d (x%x)\n", \
1901 vport->cfg_##attr, vport->cfg_##attr, \
1902 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04001903 vport->cfg_##attr = val;\
1904 return 0;\
1905 }\
James Smarte8b62012007-08-02 11:10:09 -04001906 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001907 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001908 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001909 return -EINVAL;\
1910}
1911
James Smarte59058c2008-08-24 21:49:00 -04001912/**
James Smart3621a712009-04-06 18:47:14 -04001913 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001914 *
1915 * Description:
1916 * Macro that given an attr e.g. hba_queue_depth
1917 * expands into a function with the name lpfc_hba_queue_depth_store
1918 *
1919 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1920 * use the lpfc_##attr##_set function to set the value.
1921 * @cdev: class device that is converted into a Scsi_host.
1922 * @buf: contains the attribute value in decimal.
1923 * @count: not used.
1924 *
1925 * Returns:
1926 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1927 * length of buffer upon success.
1928 **/
James Smart3de2a652007-08-02 11:09:59 -04001929#define lpfc_vport_param_store(attr) \
1930static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001931lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1932 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001933{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001934 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001935 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001936 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001937 if (!isdigit(buf[0]))\
1938 return -EINVAL;\
1939 if (sscanf(buf, "%i", &val) != 1)\
1940 return -EINVAL;\
1941 if (lpfc_##attr##_set(vport, val) == 0) \
1942 return strlen(buf);\
1943 else \
1944 return -EINVAL;\
1945}
1946
1947
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001948#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001949static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001950module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001951MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001952lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001953
1954#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001955static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001956module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001957MODULE_PARM_DESC(lpfc_##name, desc);\
1958lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001959lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001960static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001961
1962#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001963static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001964module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001965MODULE_PARM_DESC(lpfc_##name, desc);\
1966lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001967lpfc_param_init(name, defval, minval, maxval)\
1968lpfc_param_set(name, defval, minval, maxval)\
1969lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001970static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1971 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001972
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001973#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001974static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001975module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001976MODULE_PARM_DESC(lpfc_##name, desc);\
1977lpfc_param_hex_show(name)\
1978lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001979static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001980
1981#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001982static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001983module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001984MODULE_PARM_DESC(lpfc_##name, desc);\
1985lpfc_param_hex_show(name)\
1986lpfc_param_init(name, defval, minval, maxval)\
1987lpfc_param_set(name, defval, minval, maxval)\
1988lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001989static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1990 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001991
James Smart3de2a652007-08-02 11:09:59 -04001992#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001993static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001994module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001995MODULE_PARM_DESC(lpfc_##name, desc);\
1996lpfc_vport_param_init(name, defval, minval, maxval)
1997
1998#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001999static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002000module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002001MODULE_PARM_DESC(lpfc_##name, desc);\
2002lpfc_vport_param_show(name)\
2003lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01002004static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04002005
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002006#define LPFC_VPORT_ULL_ATTR_R(name, defval, minval, maxval, desc) \
2007static uint64_t lpfc_##name = defval;\
2008module_param(lpfc_##name, ullong, S_IRUGO);\
2009MODULE_PARM_DESC(lpfc_##name, desc);\
2010lpfc_vport_param_show(name)\
2011lpfc_vport_param_init(name, defval, minval, maxval)\
2012static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
2013
James Smart3de2a652007-08-02 11:09:59 -04002014#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002015static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002016module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002017MODULE_PARM_DESC(lpfc_##name, desc);\
2018lpfc_vport_param_show(name)\
2019lpfc_vport_param_init(name, defval, minval, maxval)\
2020lpfc_vport_param_set(name, defval, minval, maxval)\
2021lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002022static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2023 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002024
2025#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002026static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002027module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002028MODULE_PARM_DESC(lpfc_##name, desc);\
2029lpfc_vport_param_hex_show(name)\
2030lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01002031static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04002032
2033#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05002034static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05002035module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04002036MODULE_PARM_DESC(lpfc_##name, desc);\
2037lpfc_vport_param_hex_show(name)\
2038lpfc_vport_param_init(name, defval, minval, maxval)\
2039lpfc_vport_param_set(name, defval, minval, maxval)\
2040lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002041static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2042 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002043
James Smart81301a92008-12-04 22:39:46 -05002044static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2045static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2046static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2047static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002048static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2049static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2050static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2051static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2052static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2053static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2054static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2055static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002056static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2057 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002058static DEVICE_ATTR(option_rom_version, S_IRUGO,
2059 lpfc_option_rom_version_show, NULL);
2060static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2061 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002062static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002063static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2064static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002065static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002066static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2067 lpfc_board_mode_show, lpfc_board_mode_store);
2068static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2069static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2070static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2071static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2072static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2073static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2074static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2075static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2076static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002077static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2078static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002079static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002080static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2081 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002082static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002083static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2084 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002085
James Smarta12e07b2006-12-02 13:35:30 -05002086static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002087#define WWN_SZ 8
2088/**
2089 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2090 * @buf: WWN string.
2091 * @cnt: Length of string.
2092 * @wwn: Array to receive converted wwn value.
2093 *
2094 * Returns:
2095 * -EINVAL if the buffer does not contain a valid wwn
2096 * 0 success
2097 **/
2098static size_t
2099lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2100{
2101 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002102
James Smart1ba981f2014-02-20 09:56:45 -05002103 /* Count may include a LF at end of string */
2104 if (buf[cnt-1] == '\n')
2105 cnt--;
2106
2107 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2108 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2109 return -EINVAL;
2110
2111 memset(wwn, 0, WWN_SZ);
2112
2113 /* Validate and store the new name */
2114 for (i = 0, j = 0; i < 16; i++) {
2115 if ((*buf >= 'a') && (*buf <= 'f'))
2116 j = ((j << 4) | ((*buf++ - 'a') + 10));
2117 else if ((*buf >= 'A') && (*buf <= 'F'))
2118 j = ((j << 4) | ((*buf++ - 'A') + 10));
2119 else if ((*buf >= '0') && (*buf <= '9'))
2120 j = ((j << 4) | (*buf++ - '0'));
2121 else
2122 return -EINVAL;
2123 if (i % 2) {
2124 wwn[i/2] = j & 0xff;
2125 j = 0;
2126 }
2127 }
2128 return 0;
2129}
James Smarte59058c2008-08-24 21:49:00 -04002130/**
James Smart3621a712009-04-06 18:47:14 -04002131 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002132 * @dev: class device that is converted into a Scsi_host.
2133 * @attr: device attribute, not used.
2134 * @buf: containing the string lpfc_soft_wwn_key.
2135 * @count: must be size of lpfc_soft_wwn_key.
2136 *
2137 * Returns:
2138 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2139 * length of buf indicates success
2140 **/
James Smartc3f28af2006-08-18 17:47:18 -04002141static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002142lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2143 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002144{
Tony Jonesee959b02008-02-22 00:13:36 +01002145 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002146 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2147 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002148 unsigned int cnt = count;
2149
2150 /*
2151 * We're doing a simple sanity check for soft_wwpn setting.
2152 * We require that the user write a specific key to enable
2153 * the soft_wwpn attribute to be settable. Once the attribute
2154 * is written, the enable key resets. If further updates are
2155 * desired, the key must be written again to re-enable the
2156 * attribute.
2157 *
2158 * The "key" is not secret - it is a hardcoded string shown
2159 * here. The intent is to protect against the random user or
2160 * application that is just writing attributes.
2161 */
2162
2163 /* count may include a LF at end of string */
2164 if (buf[cnt-1] == '\n')
2165 cnt--;
2166
James Smarta12e07b2006-12-02 13:35:30 -05002167 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2168 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002169 return -EINVAL;
2170
James Smarta12e07b2006-12-02 13:35:30 -05002171 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002172 return count;
2173}
Tony Jonesee959b02008-02-22 00:13:36 +01002174static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2175 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002176
James Smarte59058c2008-08-24 21:49:00 -04002177/**
James Smart3621a712009-04-06 18:47:14 -04002178 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002179 * @dev: class device that is converted into a Scsi_host.
2180 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002181 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002182 *
2183 * Returns: size of formatted string.
2184 **/
James Smartc3f28af2006-08-18 17:47:18 -04002185static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002186lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2187 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002188{
Tony Jonesee959b02008-02-22 00:13:36 +01002189 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002190 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2191 struct lpfc_hba *phba = vport->phba;
2192
Randy Dunlapafc071e2006-10-23 21:47:13 -07002193 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2194 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002195}
2196
James Smarte59058c2008-08-24 21:49:00 -04002197/**
James Smart3621a712009-04-06 18:47:14 -04002198 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002199 * @dev class device that is converted into a Scsi_host.
2200 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002201 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002202 * @count: number of wwpn bytes in buf
2203 *
2204 * Returns:
2205 * -EACCES hba reset not enabled, adapter over temp
2206 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2207 * -EIO error taking adapter offline or online
2208 * value of count on success
2209 **/
James Smartc3f28af2006-08-18 17:47:18 -04002210static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002211lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2212 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002213{
Tony Jonesee959b02008-02-22 00:13:36 +01002214 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002215 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2216 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002217 struct completion online_compl;
James Smart1ba981f2014-02-20 09:56:45 -05002218 int stat1 = 0, stat2 = 0;
2219 unsigned int cnt = count;
2220 u8 wwpn[WWN_SZ];
James Smartfedd3b72011-02-16 12:39:24 -05002221 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002222
James Smart13815c82008-01-11 01:52:48 -05002223 if (!phba->cfg_enable_hba_reset)
2224 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002225 spin_lock_irq(&phba->hbalock);
2226 if (phba->over_temp_state == HBA_OVER_TEMP) {
2227 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002228 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002229 }
2230 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002231 /* count may include a LF at end of string */
2232 if (buf[cnt-1] == '\n')
2233 cnt--;
2234
James Smart1ba981f2014-02-20 09:56:45 -05002235 if (!phba->soft_wwn_enable)
James Smartc3f28af2006-08-18 17:47:18 -04002236 return -EINVAL;
2237
James Smart1ba981f2014-02-20 09:56:45 -05002238 /* lock setting wwpn, wwnn down */
James Smarta12e07b2006-12-02 13:35:30 -05002239 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002240
James Smart1ba981f2014-02-20 09:56:45 -05002241 rc = lpfc_wwn_set(buf, cnt, wwpn);
2242 if (!rc) {
2243 /* not able to set wwpn, unlock it */
2244 phba->soft_wwn_enable = 1;
2245 return rc;
James Smartc3f28af2006-08-18 17:47:18 -04002246 }
James Smart1ba981f2014-02-20 09:56:45 -05002247
James Smartc3f28af2006-08-18 17:47:18 -04002248 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002249 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002250 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002251 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002252
2253 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2254 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2255
James Smart46fa3112007-04-25 09:51:45 -04002256 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002257 if (stat1)
2258 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002259 "0463 lpfc_soft_wwpn attribute set failed to "
2260 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002261 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002262 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2263 LPFC_EVT_ONLINE);
2264 if (rc == 0)
2265 return -ENOMEM;
2266
James Smartc3f28af2006-08-18 17:47:18 -04002267 wait_for_completion(&online_compl);
2268 if (stat2)
2269 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002270 "0464 lpfc_soft_wwpn attribute set failed to "
2271 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002272 return (stat1 || stat2) ? -EIO : count;
2273}
James Smart1ba981f2014-02-20 09:56:45 -05002274static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002275 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002276
James Smarte59058c2008-08-24 21:49:00 -04002277/**
James Smart3621a712009-04-06 18:47:14 -04002278 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002279 * @dev: class device that is converted into a Scsi_host.
2280 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002281 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002282 *
2283 * Returns: size of formatted string.
2284 **/
James Smarta12e07b2006-12-02 13:35:30 -05002285static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002286lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2287 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002288{
Tony Jonesee959b02008-02-22 00:13:36 +01002289 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002290 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002291 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2292 (unsigned long long)phba->cfg_soft_wwnn);
2293}
2294
James Smarte59058c2008-08-24 21:49:00 -04002295/**
James Smart3621a712009-04-06 18:47:14 -04002296 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002297 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002298 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002299 * @count: number of wwnn bytes in buf.
2300 *
2301 * Returns:
2302 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2303 * value of count on success
2304 **/
James Smarta12e07b2006-12-02 13:35:30 -05002305static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002306lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2307 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002308{
Tony Jonesee959b02008-02-22 00:13:36 +01002309 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002310 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart1ba981f2014-02-20 09:56:45 -05002311 unsigned int cnt = count;
2312 u8 wwnn[WWN_SZ];
2313 int rc;
James Smarta12e07b2006-12-02 13:35:30 -05002314
2315 /* count may include a LF at end of string */
2316 if (buf[cnt-1] == '\n')
2317 cnt--;
2318
James Smart1ba981f2014-02-20 09:56:45 -05002319 if (!phba->soft_wwn_enable)
James Smarta12e07b2006-12-02 13:35:30 -05002320 return -EINVAL;
2321
James Smart1ba981f2014-02-20 09:56:45 -05002322 rc = lpfc_wwn_set(buf, cnt, wwnn);
2323 if (!rc) {
2324 /* Allow wwnn to be set many times, as long as the enable
2325 * is set. However, once the wwpn is set, everything locks.
2326 */
2327 return rc;
James Smarta12e07b2006-12-02 13:35:30 -05002328 }
James Smart1ba981f2014-02-20 09:56:45 -05002329
James Smarta12e07b2006-12-02 13:35:30 -05002330 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2331
2332 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2333 "lpfc%d: soft_wwnn set. Value will take effect upon "
2334 "setting of the soft_wwpn\n", phba->brd_no);
2335
2336 return count;
2337}
James Smart1ba981f2014-02-20 09:56:45 -05002338static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
Tony Jonesee959b02008-02-22 00:13:36 +01002339 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002340
James Smart1ba981f2014-02-20 09:56:45 -05002341/**
2342 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2343 * Optimized Access Storage (OAS) operations.
2344 * @dev: class device that is converted into a Scsi_host.
2345 * @attr: device attribute, not used.
2346 * @buf: buffer for passing information.
2347 *
2348 * Returns:
2349 * value of count
2350 **/
2351static ssize_t
2352lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2353 char *buf)
2354{
2355 struct Scsi_Host *shost = class_to_shost(dev);
2356 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2357
2358 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2359 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2360}
2361
2362/**
2363 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2364 * Optimized Access Storage (OAS) operations.
2365 * @dev: class device that is converted into a Scsi_host.
2366 * @attr: device attribute, not used.
2367 * @buf: buffer for passing information.
2368 * @count: Size of the data buffer.
2369 *
2370 * Returns:
2371 * -EINVAL count is invalid, invalid wwpn byte invalid
2372 * -EPERM oas is not supported by hba
2373 * value of count on success
2374 **/
2375static ssize_t
2376lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2377 const char *buf, size_t count)
2378{
2379 struct Scsi_Host *shost = class_to_shost(dev);
2380 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2381 unsigned int cnt = count;
2382 uint8_t wwpn[WWN_SZ];
2383 int rc;
2384
James Smartf38fa0b2014-04-04 13:52:21 -04002385 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002386 return -EPERM;
2387
2388 /* count may include a LF at end of string */
2389 if (buf[cnt-1] == '\n')
2390 cnt--;
2391
2392 rc = lpfc_wwn_set(buf, cnt, wwpn);
2393 if (rc)
2394 return rc;
2395
2396 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2397 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2398 if (wwn_to_u64(wwpn) == 0)
2399 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2400 else
2401 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2402 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2403 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2404 return count;
2405}
2406static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2407 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2408
2409/**
2410 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2411 * for Optimized Access Storage (OAS) operations.
2412 * @dev: class device that is converted into a Scsi_host.
2413 * @attr: device attribute, not used.
2414 * @buf: buffer for passing information.
2415 *
2416 * Returns:
2417 * value of count on success
2418 **/
2419static ssize_t
2420lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2421 char *buf)
2422{
2423 struct Scsi_Host *shost = class_to_shost(dev);
2424 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2425
2426 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2427 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2428}
2429
2430/**
2431 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2432 * for Optimized Access Storage (OAS) operations.
2433 * @dev: class device that is converted into a Scsi_host.
2434 * @attr: device attribute, not used.
2435 * @buf: buffer for passing information.
2436 * @count: Size of the data buffer.
2437 *
2438 * Returns:
2439 * -EINVAL count is invalid, invalid wwpn byte invalid
2440 * -EPERM oas is not supported by hba
2441 * value of count on success
2442 **/
2443static ssize_t
2444lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2445 const char *buf, size_t count)
2446{
2447 struct Scsi_Host *shost = class_to_shost(dev);
2448 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2449 unsigned int cnt = count;
2450 uint8_t wwpn[WWN_SZ];
2451 int rc;
2452
James Smartf38fa0b2014-04-04 13:52:21 -04002453 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002454 return -EPERM;
2455
2456 /* count may include a LF at end of string */
2457 if (buf[cnt-1] == '\n')
2458 cnt--;
2459
2460 rc = lpfc_wwn_set(buf, cnt, wwpn);
2461 if (rc)
2462 return rc;
2463
2464 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2465 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2466 if (wwn_to_u64(wwpn) == 0)
2467 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2468 else
2469 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2470 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2471 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2472 return count;
2473}
2474static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2475 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2476
2477/**
2478 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2479 * of whether luns will be enabled or disabled
2480 * for Optimized Access Storage (OAS) operations.
2481 * @dev: class device that is converted into a Scsi_host.
2482 * @attr: device attribute, not used.
2483 * @buf: buffer for passing information.
2484 *
2485 * Returns:
2486 * size of formatted string.
2487 **/
2488static ssize_t
2489lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2490 char *buf)
2491{
2492 struct Scsi_Host *shost = class_to_shost(dev);
2493 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2494
2495 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2496}
2497
2498/**
2499 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2500 * of whether luns will be enabled or disabled
2501 * for Optimized Access Storage (OAS) operations.
2502 * @dev: class device that is converted into a Scsi_host.
2503 * @attr: device attribute, not used.
2504 * @buf: buffer for passing information.
2505 * @count: Size of the data buffer.
2506 *
2507 * Returns:
2508 * -EINVAL count is invalid, invalid wwpn byte invalid
2509 * -EPERM oas is not supported by hba
2510 * value of count on success
2511 **/
2512static ssize_t
2513lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2514 const char *buf, size_t count)
2515{
2516 struct Scsi_Host *shost = class_to_shost(dev);
2517 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2518 int val = 0;
2519
James Smartf38fa0b2014-04-04 13:52:21 -04002520 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002521 return -EPERM;
2522
2523 if (!isdigit(buf[0]))
2524 return -EINVAL;
2525
2526 if (sscanf(buf, "%i", &val) != 1)
2527 return -EINVAL;
2528
2529 if ((val != 0) && (val != 1))
2530 return -EINVAL;
2531
2532 phba->cfg_oas_lun_state = val;
2533
2534 return strlen(buf);
2535}
2536static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2537 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2538
2539/**
2540 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2541 * Storage (OAS) lun returned by the
2542 * lpfc_oas_lun_show function.
2543 * @dev: class device that is converted into a Scsi_host.
2544 * @attr: device attribute, not used.
2545 * @buf: buffer for passing information.
2546 *
2547 * Returns:
2548 * size of formatted string.
2549 **/
2550static ssize_t
2551lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2552 char *buf)
2553{
2554 struct Scsi_Host *shost = class_to_shost(dev);
2555 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2556
2557 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2558 return -EFAULT;
2559
2560 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2561}
2562static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2563 lpfc_oas_lun_status_show, NULL);
2564
2565
2566/**
2567 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2568 * (OAS) operations.
2569 * @phba: lpfc_hba pointer.
2570 * @ndlp: pointer to fcp target node.
2571 * @lun: the fc lun for setting oas state.
2572 * @oas_state: the oas state to be set to the lun.
2573 *
2574 * Returns:
2575 * SUCCESS : 0
2576 * -EPERM OAS is not enabled or not supported by this port.
2577 *
2578 */
2579static size_t
2580lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2581 uint8_t tgt_wwpn[], uint64_t lun, uint32_t oas_state)
2582{
2583
2584 int rc = 0;
2585
James Smartf38fa0b2014-04-04 13:52:21 -04002586 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002587 return -EPERM;
2588
2589 if (oas_state) {
2590 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2591 (struct lpfc_name *)tgt_wwpn, lun))
2592 rc = -ENOMEM;
2593 } else {
2594 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2595 (struct lpfc_name *)tgt_wwpn, lun);
2596 }
2597 return rc;
2598
2599}
2600
2601/**
2602 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2603 * Access Storage (OAS) operations.
2604 * @phba: lpfc_hba pointer.
2605 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2606 * @tgt_wwpn: wwpn of the target associated with the returned lun
2607 * @lun_status: status of the lun returned lun
2608 *
2609 * Returns the first or next lun enabled for OAS operations for the vport/target
2610 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2611 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2612 *
2613 * Return:
2614 * lun that is OAS enabled for the vport/target
2615 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2616 */
2617static uint64_t
2618lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2619 uint8_t tgt_wwpn[], uint32_t *lun_status)
2620{
2621 uint64_t found_lun;
2622
2623 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2624 return NOT_OAS_ENABLED_LUN;
2625 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2626 phba->sli4_hba.oas_next_vpt_wwpn,
2627 (struct lpfc_name *)
2628 phba->sli4_hba.oas_next_tgt_wwpn,
2629 &phba->sli4_hba.oas_next_lun,
2630 (struct lpfc_name *)vpt_wwpn,
2631 (struct lpfc_name *)tgt_wwpn,
2632 &found_lun, lun_status))
2633 return found_lun;
2634 else
2635 return NOT_OAS_ENABLED_LUN;
2636}
2637
2638/**
2639 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2640 * @phba: lpfc_hba pointer.
2641 * @vpt_wwpn: vport wwpn by reference.
2642 * @tgt_wwpn: target wwpn by reference.
2643 * @lun: the fc lun for setting oas state.
2644 * @oas_state: the oas state to be set to the oas_lun.
2645 *
2646 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2647 * a lun for OAS operations.
2648 *
2649 * Return:
2650 * SUCCESS: 0
2651 * -ENOMEM: failed to enable an lun for OAS operations
2652 * -EPERM: OAS is not enabled
2653 */
2654static ssize_t
2655lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2656 uint8_t tgt_wwpn[], uint64_t lun,
2657 uint32_t oas_state)
2658{
2659
2660 int rc;
2661
2662 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2663 oas_state);
2664 return rc;
2665}
2666
2667/**
2668 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2669 * @dev: class device that is converted into a Scsi_host.
2670 * @attr: device attribute, not used.
2671 * @buf: buffer for passing information.
2672 *
2673 * This routine returns a lun enabled for OAS each time the function
2674 * is called.
2675 *
2676 * Returns:
2677 * SUCCESS: size of formatted string.
2678 * -EFAULT: target or vport wwpn was not set properly.
2679 * -EPERM: oas is not enabled.
2680 **/
2681static ssize_t
2682lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2683 char *buf)
2684{
2685 struct Scsi_Host *shost = class_to_shost(dev);
2686 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2687
2688 uint64_t oas_lun;
2689 int len = 0;
2690
James Smartf38fa0b2014-04-04 13:52:21 -04002691 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002692 return -EPERM;
2693
2694 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2695 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2696 return -EFAULT;
2697
2698 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2699 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2700 return -EFAULT;
2701
2702 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2703 phba->cfg_oas_tgt_wwpn,
2704 &phba->cfg_oas_lun_status);
2705 if (oas_lun != NOT_OAS_ENABLED_LUN)
2706 phba->cfg_oas_flags |= OAS_LUN_VALID;
2707
2708 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2709
2710 return len;
2711}
2712
2713/**
2714 * lpfc_oas_lun_store - Sets the OAS state for lun
2715 * @dev: class device that is converted into a Scsi_host.
2716 * @attr: device attribute, not used.
2717 * @buf: buffer for passing information.
2718 *
2719 * This function sets the OAS state for lun. Before this function is called,
2720 * the vport wwpn, target wwpn, and oas state need to be set.
2721 *
2722 * Returns:
2723 * SUCCESS: size of formatted string.
2724 * -EFAULT: target or vport wwpn was not set properly.
2725 * -EPERM: oas is not enabled.
2726 * size of formatted string.
2727 **/
2728static ssize_t
2729lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2730 const char *buf, size_t count)
2731{
2732 struct Scsi_Host *shost = class_to_shost(dev);
2733 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2734 uint64_t scsi_lun;
2735 ssize_t rc;
2736
James Smartf38fa0b2014-04-04 13:52:21 -04002737 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002738 return -EPERM;
2739
2740 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2741 return -EFAULT;
2742
2743 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2744 return -EFAULT;
2745
2746 if (!isdigit(buf[0]))
2747 return -EINVAL;
2748
2749 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2750 return -EINVAL;
2751
2752 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2753 "3372 Try to set vport 0x%llx target 0x%llx lun:%lld "
2754 "with oas set to %d\n",
2755 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2756 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
2757 phba->cfg_oas_lun_state);
2758
2759 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
2760 phba->cfg_oas_tgt_wwpn, scsi_lun,
2761 phba->cfg_oas_lun_state);
2762
2763 if (rc)
2764 return rc;
2765
2766 return count;
2767}
2768static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2769 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002770
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002771static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002772module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002773MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2774 " 0 - none,"
2775 " 1 - poll with interrupts enabled"
2776 " 3 - poll and disable FCP ring interrupts");
2777
Tony Jonesee959b02008-02-22 00:13:36 +01002778static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2779 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002780
James Smart92d7f7b2007-06-17 19:56:38 -05002781int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002782module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002783MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2784 " 0 - auto (SLI-3 if supported),"
2785 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2786 " 3 - select SLI-3");
2787
James Smart15672312010-04-06 14:49:03 -04002788int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002789module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002790MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2791lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002792lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002793static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002794
James Smart7d791df2011-07-22 18:37:52 -04002795LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2796 "FCF Fast failover=1 Priority failover=2");
2797
James Smartc14e9952013-03-01 16:38:01 -05002798int lpfc_enable_rrq = 2;
James Smartab56dc22011-02-16 12:39:57 -05002799module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002800MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2801lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002802/*
2803# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2804# 0x0 = disabled, XRI/OXID use not tracked.
2805# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2806# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2807*/
2808lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002809static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2810
dea31012005-04-17 16:05:31 -05002811/*
James Smart84d1b002010-02-12 14:42:33 -05002812# lpfc_suppress_link_up: Bring link up at initialization
2813# 0x0 = bring link up (issue MBX_INIT_LINK)
2814# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2815# 0x2 = never bring up link
2816# Default value is 0.
2817*/
James Smarte40a02c2010-02-26 14:13:54 -05002818LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2819 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2820 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002821/*
2822# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2823# 1 - (1024)
2824# 2 - (2048)
2825# 3 - (3072)
2826# 4 - (4096)
2827# 5 - (5120)
2828*/
2829static ssize_t
2830lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2831{
2832 struct Scsi_Host *shost = class_to_shost(dev);
2833 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2834
2835 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2836}
2837
2838static DEVICE_ATTR(iocb_hw, S_IRUGO,
2839 lpfc_iocb_hw_show, NULL);
2840static ssize_t
2841lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, 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].txq_max);
2848}
2849
2850static DEVICE_ATTR(txq_hw, S_IRUGO,
2851 lpfc_txq_hw_show, NULL);
2852static ssize_t
2853lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2854 char *buf)
2855{
2856 struct Scsi_Host *shost = class_to_shost(dev);
2857 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2858
2859 return snprintf(buf, PAGE_SIZE, "%d\n",
2860 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2861}
2862
2863static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2864 lpfc_txcmplq_hw_show, NULL);
2865
2866int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002867module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002868MODULE_PARM_DESC(lpfc_iocb_cnt,
2869 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2870lpfc_param_show(iocb_cnt);
2871lpfc_param_init(iocb_cnt, 2, 1, 5);
2872static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2873 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002874
2875/*
James Smartc01f3202006-08-18 17:47:08 -04002876# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2877# until the timer expires. Value range is [0,255]. Default value is 30.
2878*/
2879static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2880static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2881module_param(lpfc_nodev_tmo, int, 0);
2882MODULE_PARM_DESC(lpfc_nodev_tmo,
2883 "Seconds driver will hold I/O waiting "
2884 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002885
2886/**
James Smart3621a712009-04-06 18:47:14 -04002887 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002888 * @dev: class converted to a Scsi_host structure.
2889 * @attr: device attribute, not used.
2890 * @buf: on return contains the dev loss timeout in decimal.
2891 *
2892 * Returns: size of formatted string.
2893 **/
James Smartc01f3202006-08-18 17:47:08 -04002894static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002895lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2896 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002897{
Tony Jonesee959b02008-02-22 00:13:36 +01002898 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002900
James Smart3de2a652007-08-02 11:09:59 -04002901 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002902}
2903
James Smarte59058c2008-08-24 21:49:00 -04002904/**
James Smart3621a712009-04-06 18:47:14 -04002905 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002906 * @vport: lpfc vport structure pointer.
2907 * @val: contains the nodev timeout value.
2908 *
2909 * Description:
2910 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2911 * a kernel error message is printed and zero is returned.
2912 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2913 * Otherwise nodev tmo is set to the default value.
2914 *
2915 * Returns:
2916 * zero if already set or if val is in range
2917 * -EINVAL val out of range
2918 **/
James Smartc01f3202006-08-18 17:47:08 -04002919static int
James Smart3de2a652007-08-02 11:09:59 -04002920lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002921{
James Smart3de2a652007-08-02 11:09:59 -04002922 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2923 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2924 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002925 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002926 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002927 "parameter because devloss_tmo is "
2928 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002929 return 0;
2930 }
2931
2932 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002933 vport->cfg_nodev_tmo = val;
2934 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002935 return 0;
2936 }
James Smarte8b62012007-08-02 11:10:09 -04002937 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2938 "0400 lpfc_nodev_tmo attribute cannot be set to"
2939 " %d, allowed range is [%d, %d]\n",
2940 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002941 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002942 return -EINVAL;
2943}
2944
James Smarte59058c2008-08-24 21:49:00 -04002945/**
James Smart3621a712009-04-06 18:47:14 -04002946 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002947 * @vport: lpfc vport structure pointer.
2948 *
2949 * Description:
2950 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2951 **/
James Smart7054a602007-04-25 09:52:34 -04002952static void
James Smart3de2a652007-08-02 11:09:59 -04002953lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002954{
James Smart858c9f62007-06-17 19:56:39 -05002955 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002956 struct lpfc_nodelist *ndlp;
2957
James Smart51ef4c22007-08-02 11:10:31 -04002958 shost = lpfc_shost_from_vport(vport);
2959 spin_lock_irq(shost->host_lock);
2960 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002961 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002962 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2963 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002964}
2965
James Smarte59058c2008-08-24 21:49:00 -04002966/**
James Smart3621a712009-04-06 18:47:14 -04002967 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002968 * @vport: lpfc vport structure pointer.
2969 * @val: contains the tmo value.
2970 *
2971 * Description:
2972 * If the devloss tmo is already set or the vport dev loss tmo has changed
2973 * then a kernel error message is printed and zero is returned.
2974 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2975 * Otherwise nodev tmo is set to the default value.
2976 *
2977 * Returns:
2978 * zero if already set or if val is in range
2979 * -EINVAL val out of range
2980 **/
James Smartc01f3202006-08-18 17:47:08 -04002981static int
James Smart3de2a652007-08-02 11:09:59 -04002982lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002983{
James Smart3de2a652007-08-02 11:09:59 -04002984 if (vport->dev_loss_tmo_changed ||
2985 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002986 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2987 "0401 Ignoring change to nodev_tmo "
2988 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002989 return 0;
2990 }
James Smartc01f3202006-08-18 17:47:08 -04002991 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002992 vport->cfg_nodev_tmo = val;
2993 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002994 /*
2995 * For compat: set the fc_host dev loss so new rports
2996 * will get the value.
2997 */
2998 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002999 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003000 return 0;
3001 }
James Smarte8b62012007-08-02 11:10:09 -04003002 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3003 "0403 lpfc_nodev_tmo attribute cannot be set to"
3004 "%d, allowed range is [%d, %d]\n",
3005 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003006 return -EINVAL;
3007}
3008
James Smart3de2a652007-08-02 11:09:59 -04003009lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003010
Tony Jonesee959b02008-02-22 00:13:36 +01003011static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3012 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003013
3014/*
3015# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3016# disappear until the timer expires. Value range is [0,255]. Default
3017# value is 30.
3018*/
James Smartab56dc22011-02-16 12:39:57 -05003019module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003020MODULE_PARM_DESC(lpfc_devloss_tmo,
3021 "Seconds driver will hold I/O waiting "
3022 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003023lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3024 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3025lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003026
3027/**
James Smart3621a712009-04-06 18:47:14 -04003028 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003029 * @vport: lpfc vport structure pointer.
3030 * @val: contains the tmo value.
3031 *
3032 * Description:
3033 * If val is in a valid range then set the vport nodev tmo,
3034 * devloss tmo, also set the vport dev loss tmo changed flag.
3035 * Else a kernel error message is printed.
3036 *
3037 * Returns:
3038 * zero if val is in range
3039 * -EINVAL val out of range
3040 **/
James Smartc01f3202006-08-18 17:47:08 -04003041static int
James Smart3de2a652007-08-02 11:09:59 -04003042lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003043{
3044 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003045 vport->cfg_nodev_tmo = val;
3046 vport->cfg_devloss_tmo = val;
3047 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003048 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003049 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003050 return 0;
3051 }
3052
James Smarte8b62012007-08-02 11:10:09 -04003053 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3054 "0404 lpfc_devloss_tmo attribute cannot be set to"
3055 " %d, allowed range is [%d, %d]\n",
3056 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003057 return -EINVAL;
3058}
3059
James Smart3de2a652007-08-02 11:09:59 -04003060lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003061static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3062 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003063
3064/*
dea31012005-04-17 16:05:31 -05003065# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3066# deluged with LOTS of information.
3067# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003068# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003069*/
James Smartf4b4c682009-05-22 14:53:12 -04003070LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003071 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003072
3073/*
James Smart7ee5d432007-10-27 13:37:17 -04003074# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3075# objects that have been registered with the nameserver after login.
3076*/
James Smartcf971242012-03-01 22:37:32 -05003077LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003078 "Deregister nameserver objects before LOGO");
3079
3080/*
dea31012005-04-17 16:05:31 -05003081# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003082# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3083# If this parameter value is greater than 1/8th the maximum number of exchanges
3084# supported by the HBA port, then the lun queue depth will be reduced to
3085# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003086*/
James Smart572709e2013-07-15 18:32:43 -04003087LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003088 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003089
3090/*
James Smart7dc517d2010-07-14 15:32:10 -04003091# tgt_queue_depth: This parameter is used to limit the number of outstanding
3092# commands per target port. Value range is [10,65535]. Default value is 65535.
3093*/
3094LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003095 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003096
3097/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003098# hba_queue_depth: This parameter is used to limit the number of outstanding
3099# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3100# value is greater than the maximum number of exchanges supported by the HBA,
3101# then maximum number of exchanges supported by the HBA is used to determine
3102# the hba_queue_depth.
3103*/
3104LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3105 "Max number of FCP commands we can queue to a lpfc HBA");
3106
3107/*
James Smart92d7f7b2007-06-17 19:56:38 -05003108# peer_port_login: This parameter allows/prevents logins
3109# between peer ports hosted on the same physical port.
3110# When this parameter is set 0 peer ports of same physical port
3111# are not allowed to login to each other.
3112# When this parameter is set 1 peer ports of same physical port
3113# are allowed to login to each other.
3114# Default value of this parameter is 0.
3115*/
James Smart3de2a652007-08-02 11:09:59 -04003116LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3117 "Allow peer ports on the same physical port to login to each "
3118 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003119
3120/*
James Smart3de2a652007-08-02 11:09:59 -04003121# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003122# between Virtual Ports and remote initiators.
3123# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3124# other initiators and will attempt to PLOGI all remote ports.
3125# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3126# remote ports and will not attempt to PLOGI to other initiators.
3127# This parameter does not restrict to the physical port.
3128# This parameter does not restrict logins to Fabric resident remote ports.
3129# Default value of this parameter is 1.
3130*/
James Smart3de2a652007-08-02 11:09:59 -04003131static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003132module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003133MODULE_PARM_DESC(lpfc_restrict_login,
3134 "Restrict virtual ports login to remote initiators.");
3135lpfc_vport_param_show(restrict_login);
3136
James Smarte59058c2008-08-24 21:49:00 -04003137/**
James Smart3621a712009-04-06 18:47:14 -04003138 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003139 * @vport: lpfc vport structure pointer.
3140 * @val: contains the restrict login value.
3141 *
3142 * Description:
3143 * If val is not in a valid range then log a kernel error message and set
3144 * the vport restrict login to one.
3145 * If the port type is physical clear the restrict login flag and return.
3146 * Else set the restrict login flag to val.
3147 *
3148 * Returns:
3149 * zero if val is in range
3150 * -EINVAL val out of range
3151 **/
James Smart3de2a652007-08-02 11:09:59 -04003152static int
3153lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3154{
3155 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003156 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003157 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003158 "be set to %d, allowed range is [0, 1]\n",
3159 val);
James Smart3de2a652007-08-02 11:09:59 -04003160 vport->cfg_restrict_login = 1;
3161 return -EINVAL;
3162 }
3163 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3164 vport->cfg_restrict_login = 0;
3165 return 0;
3166 }
3167 vport->cfg_restrict_login = val;
3168 return 0;
3169}
3170
James Smarte59058c2008-08-24 21:49:00 -04003171/**
James Smart3621a712009-04-06 18:47:14 -04003172 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003173 * @vport: lpfc vport structure pointer.
3174 * @val: contains the restrict login value.
3175 *
3176 * Description:
3177 * If val is not in a valid range then log a kernel error message and set
3178 * the vport restrict login to one.
3179 * If the port type is physical and the val is not zero log a kernel
3180 * error message, clear the restrict login flag and return zero.
3181 * Else set the restrict login flag to val.
3182 *
3183 * Returns:
3184 * zero if val is in range
3185 * -EINVAL val out of range
3186 **/
James Smart3de2a652007-08-02 11:09:59 -04003187static int
3188lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3189{
3190 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003191 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003192 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003193 "be set to %d, allowed range is [0, 1]\n",
3194 val);
James Smart3de2a652007-08-02 11:09:59 -04003195 vport->cfg_restrict_login = 1;
3196 return -EINVAL;
3197 }
3198 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003199 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3200 "0468 lpfc_restrict_login must be 0 for "
3201 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003202 vport->cfg_restrict_login = 0;
3203 return 0;
3204 }
3205 vport->cfg_restrict_login = val;
3206 return 0;
3207}
3208lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003209static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3210 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003211
3212/*
dea31012005-04-17 16:05:31 -05003213# Some disk devices have a "select ID" or "select Target" capability.
3214# From a protocol standpoint "select ID" usually means select the
3215# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3216# annex" which contains a table that maps a "select ID" (a number
3217# between 0 and 7F) to an ALPA. By default, for compatibility with
3218# older drivers, the lpfc driver scans this table from low ALPA to high
3219# ALPA.
3220#
3221# Turning on the scan-down variable (on = 1, off = 0) will
3222# cause the lpfc driver to use an inverted table, effectively
3223# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3224#
3225# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3226# and will not work across a fabric. Also this parameter will take
3227# effect only in the case when ALPA map is not available.)
3228*/
James Smart3de2a652007-08-02 11:09:59 -04003229LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3230 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003231
3232/*
dea31012005-04-17 16:05:31 -05003233# lpfc_topology: link topology for init link
3234# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003235# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003236# 0x02 = attempt point-to-point mode only
3237# 0x04 = attempt loop mode only
3238# 0x06 = attempt point-to-point mode then loop
3239# Set point-to-point mode if you want to run as an N_Port.
3240# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3241# Default value is 0.
3242*/
James Smarte59058c2008-08-24 21:49:00 -04003243
3244/**
James Smart3621a712009-04-06 18:47:14 -04003245 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003246 * @phba: lpfc_hba pointer.
3247 * @val: topology value.
3248 *
3249 * Description:
3250 * If val is in a valid range then set the adapter's topology field and
3251 * issue a lip; if the lip fails reset the topology to the old value.
3252 *
3253 * If the value is not in range log a kernel error message and return an error.
3254 *
3255 * Returns:
3256 * zero if val is in range and lip okay
3257 * non-zero return value from lpfc_issue_lip()
3258 * -EINVAL val out of range
3259 **/
James Smarta257bf92009-04-06 18:48:10 -04003260static ssize_t
3261lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3262 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003263{
James Smarta257bf92009-04-06 18:48:10 -04003264 struct Scsi_Host *shost = class_to_shost(dev);
3265 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3266 struct lpfc_hba *phba = vport->phba;
3267 int val = 0;
3268 int nolip = 0;
3269 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003270 int err;
3271 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003272
3273 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3274 nolip = 1;
3275 val_buf = &buf[strlen("nolip ")];
3276 }
3277
3278 if (!isdigit(val_buf[0]))
3279 return -EINVAL;
3280 if (sscanf(val_buf, "%i", &val) != 1)
3281 return -EINVAL;
3282
James Smart83108bd2008-01-11 01:53:09 -05003283 if (val >= 0 && val <= 6) {
3284 prev_val = phba->cfg_topology;
3285 phba->cfg_topology = val;
James Smartff78d8f2011-12-13 13:21:35 -05003286 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3287 val == 4) {
3288 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3289 "3113 Loop mode not supported at speed %d\n",
3290 phba->cfg_link_speed);
3291 phba->cfg_topology = prev_val;
3292 return -EINVAL;
3293 }
James Smarta257bf92009-04-06 18:48:10 -04003294 if (nolip)
3295 return strlen(buf);
3296
James Smart88a2cfb2011-07-22 18:36:33 -04003297 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3298 "3054 lpfc_topology changed from %d to %d\n",
3299 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003300 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3301 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003302 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003303 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003304 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003305 return -EINVAL;
3306 } else
3307 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003308 }
3309 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3310 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3311 "allowed range is [0, 6]\n",
3312 phba->brd_no, val);
3313 return -EINVAL;
3314}
3315static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05003316module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003317MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
3318lpfc_param_show(topology)
3319lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01003320static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003321 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003322
James Smart21e9a0a2009-05-22 14:53:21 -04003323/**
3324 * lpfc_static_vport_show: Read callback function for
3325 * lpfc_static_vport sysfs file.
3326 * @dev: Pointer to class device object.
3327 * @attr: device attribute structure.
3328 * @buf: Data buffer.
3329 *
3330 * This function is the read call back function for
3331 * lpfc_static_vport sysfs file. The lpfc_static_vport
3332 * sysfs file report the mageability of the vport.
3333 **/
3334static ssize_t
3335lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3336 char *buf)
3337{
3338 struct Scsi_Host *shost = class_to_shost(dev);
3339 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3340 if (vport->vport_flag & STATIC_VPORT)
3341 sprintf(buf, "1\n");
3342 else
3343 sprintf(buf, "0\n");
3344
3345 return strlen(buf);
3346}
3347
3348/*
3349 * Sysfs attribute to control the statistical data collection.
3350 */
3351static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3352 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003353
3354/**
James Smart3621a712009-04-06 18:47:14 -04003355 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003356 * @dev: Pointer to class device.
3357 * @buf: Data buffer.
3358 * @count: Size of the data buffer.
3359 *
3360 * This function get called when an user write to the lpfc_stat_data_ctrl
3361 * sysfs file. This function parse the command written to the sysfs file
3362 * and take appropriate action. These commands are used for controlling
3363 * driver statistical data collection.
3364 * Following are the command this function handles.
3365 *
3366 * setbucket <bucket_type> <base> <step>
3367 * = Set the latency buckets.
3368 * destroybucket = destroy all the buckets.
3369 * start = start data collection
3370 * stop = stop data collection
3371 * reset = reset the collected data
3372 **/
3373static ssize_t
3374lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3375 const char *buf, size_t count)
3376{
3377 struct Scsi_Host *shost = class_to_shost(dev);
3378 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3379 struct lpfc_hba *phba = vport->phba;
3380#define LPFC_MAX_DATA_CTRL_LEN 1024
3381 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3382 unsigned long i;
3383 char *str_ptr, *token;
3384 struct lpfc_vport **vports;
3385 struct Scsi_Host *v_shost;
3386 char *bucket_type_str, *base_str, *step_str;
3387 unsigned long base, step, bucket_type;
3388
3389 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003390 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003391 return -EINVAL;
3392
James Smarteb016562014-09-03 12:58:06 -04003393 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003394 str_ptr = &bucket_data[0];
3395 /* Ignore this token - this is command token */
3396 token = strsep(&str_ptr, "\t ");
3397 if (!token)
3398 return -EINVAL;
3399
3400 bucket_type_str = strsep(&str_ptr, "\t ");
3401 if (!bucket_type_str)
3402 return -EINVAL;
3403
3404 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3405 bucket_type = LPFC_LINEAR_BUCKET;
3406 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3407 bucket_type = LPFC_POWER2_BUCKET;
3408 else
3409 return -EINVAL;
3410
3411 base_str = strsep(&str_ptr, "\t ");
3412 if (!base_str)
3413 return -EINVAL;
3414 base = simple_strtoul(base_str, NULL, 0);
3415
3416 step_str = strsep(&str_ptr, "\t ");
3417 if (!step_str)
3418 return -EINVAL;
3419 step = simple_strtoul(step_str, NULL, 0);
3420 if (!step)
3421 return -EINVAL;
3422
3423 /* Block the data collection for every vport */
3424 vports = lpfc_create_vport_work_array(phba);
3425 if (vports == NULL)
3426 return -ENOMEM;
3427
James Smartf4b4c682009-05-22 14:53:12 -04003428 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003429 v_shost = lpfc_shost_from_vport(vports[i]);
3430 spin_lock_irq(v_shost->host_lock);
3431 /* Block and reset data collection */
3432 vports[i]->stat_data_blocked = 1;
3433 if (vports[i]->stat_data_enabled)
3434 lpfc_vport_reset_stat_data(vports[i]);
3435 spin_unlock_irq(v_shost->host_lock);
3436 }
3437
3438 /* Set the bucket attributes */
3439 phba->bucket_type = bucket_type;
3440 phba->bucket_base = base;
3441 phba->bucket_step = step;
3442
James Smartf4b4c682009-05-22 14:53:12 -04003443 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003444 v_shost = lpfc_shost_from_vport(vports[i]);
3445
3446 /* Unblock data collection */
3447 spin_lock_irq(v_shost->host_lock);
3448 vports[i]->stat_data_blocked = 0;
3449 spin_unlock_irq(v_shost->host_lock);
3450 }
3451 lpfc_destroy_vport_work_array(phba, vports);
3452 return strlen(buf);
3453 }
3454
3455 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3456 vports = lpfc_create_vport_work_array(phba);
3457 if (vports == NULL)
3458 return -ENOMEM;
3459
James Smartf4b4c682009-05-22 14:53:12 -04003460 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003461 v_shost = lpfc_shost_from_vport(vports[i]);
3462 spin_lock_irq(shost->host_lock);
3463 vports[i]->stat_data_blocked = 1;
3464 lpfc_free_bucket(vport);
3465 vport->stat_data_enabled = 0;
3466 vports[i]->stat_data_blocked = 0;
3467 spin_unlock_irq(shost->host_lock);
3468 }
3469 lpfc_destroy_vport_work_array(phba, vports);
3470 phba->bucket_type = LPFC_NO_BUCKET;
3471 phba->bucket_base = 0;
3472 phba->bucket_step = 0;
3473 return strlen(buf);
3474 }
3475
3476 if (!strncmp(buf, "start", strlen("start"))) {
3477 /* If no buckets configured return error */
3478 if (phba->bucket_type == LPFC_NO_BUCKET)
3479 return -EINVAL;
3480 spin_lock_irq(shost->host_lock);
3481 if (vport->stat_data_enabled) {
3482 spin_unlock_irq(shost->host_lock);
3483 return strlen(buf);
3484 }
3485 lpfc_alloc_bucket(vport);
3486 vport->stat_data_enabled = 1;
3487 spin_unlock_irq(shost->host_lock);
3488 return strlen(buf);
3489 }
3490
3491 if (!strncmp(buf, "stop", strlen("stop"))) {
3492 spin_lock_irq(shost->host_lock);
3493 if (vport->stat_data_enabled == 0) {
3494 spin_unlock_irq(shost->host_lock);
3495 return strlen(buf);
3496 }
3497 lpfc_free_bucket(vport);
3498 vport->stat_data_enabled = 0;
3499 spin_unlock_irq(shost->host_lock);
3500 return strlen(buf);
3501 }
3502
3503 if (!strncmp(buf, "reset", strlen("reset"))) {
3504 if ((phba->bucket_type == LPFC_NO_BUCKET)
3505 || !vport->stat_data_enabled)
3506 return strlen(buf);
3507 spin_lock_irq(shost->host_lock);
3508 vport->stat_data_blocked = 1;
3509 lpfc_vport_reset_stat_data(vport);
3510 vport->stat_data_blocked = 0;
3511 spin_unlock_irq(shost->host_lock);
3512 return strlen(buf);
3513 }
3514 return -EINVAL;
3515}
3516
3517
3518/**
James Smart3621a712009-04-06 18:47:14 -04003519 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003520 * @dev: Pointer to class device object.
3521 * @buf: Data buffer.
3522 *
3523 * This function is the read call back function for
3524 * lpfc_stat_data_ctrl sysfs file. This function report the
3525 * current statistical data collection state.
3526 **/
3527static ssize_t
3528lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3529 char *buf)
3530{
3531 struct Scsi_Host *shost = class_to_shost(dev);
3532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3533 struct lpfc_hba *phba = vport->phba;
3534 int index = 0;
3535 int i;
3536 char *bucket_type;
3537 unsigned long bucket_value;
3538
3539 switch (phba->bucket_type) {
3540 case LPFC_LINEAR_BUCKET:
3541 bucket_type = "linear";
3542 break;
3543 case LPFC_POWER2_BUCKET:
3544 bucket_type = "power2";
3545 break;
3546 default:
3547 bucket_type = "No Bucket";
3548 break;
3549 }
3550
3551 sprintf(&buf[index], "Statistical Data enabled :%d, "
3552 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3553 " Bucket step :%d\nLatency Ranges :",
3554 vport->stat_data_enabled, vport->stat_data_blocked,
3555 bucket_type, phba->bucket_base, phba->bucket_step);
3556 index = strlen(buf);
3557 if (phba->bucket_type != LPFC_NO_BUCKET) {
3558 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3559 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3560 bucket_value = phba->bucket_base +
3561 phba->bucket_step * i;
3562 else
3563 bucket_value = phba->bucket_base +
3564 (1 << i) * phba->bucket_step;
3565
3566 if (index + 10 > PAGE_SIZE)
3567 break;
3568 sprintf(&buf[index], "%08ld ", bucket_value);
3569 index = strlen(buf);
3570 }
3571 }
3572 sprintf(&buf[index], "\n");
3573 return strlen(buf);
3574}
3575
3576/*
3577 * Sysfs attribute to control the statistical data collection.
3578 */
3579static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3580 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3581
3582/*
3583 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3584 */
3585
3586/*
3587 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3588 * for each target.
3589 */
3590#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3591#define MAX_STAT_DATA_SIZE_PER_TARGET \
3592 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3593
3594
3595/**
James Smart3621a712009-04-06 18:47:14 -04003596 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003597 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003598 * @kobj: Pointer to the kernel object
3599 * @bin_attr: Attribute object
3600 * @buff: Buffer pointer
3601 * @off: File offset
3602 * @count: Buffer size
3603 *
3604 * This function is the read call back function for lpfc_drvr_stat_data
3605 * sysfs file. This function export the statistical data to user
3606 * applications.
3607 **/
3608static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003609sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3610 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003611 char *buf, loff_t off, size_t count)
3612{
3613 struct device *dev = container_of(kobj, struct device,
3614 kobj);
3615 struct Scsi_Host *shost = class_to_shost(dev);
3616 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3617 struct lpfc_hba *phba = vport->phba;
3618 int i = 0, index = 0;
3619 unsigned long nport_index;
3620 struct lpfc_nodelist *ndlp = NULL;
3621 nport_index = (unsigned long)off /
3622 MAX_STAT_DATA_SIZE_PER_TARGET;
3623
3624 if (!vport->stat_data_enabled || vport->stat_data_blocked
3625 || (phba->bucket_type == LPFC_NO_BUCKET))
3626 return 0;
3627
3628 spin_lock_irq(shost->host_lock);
3629 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3630 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3631 continue;
3632
3633 if (nport_index > 0) {
3634 nport_index--;
3635 continue;
3636 }
3637
3638 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3639 > count)
3640 break;
3641
3642 if (!ndlp->lat_data)
3643 continue;
3644
3645 /* Print the WWN */
3646 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3647 ndlp->nlp_portname.u.wwn[0],
3648 ndlp->nlp_portname.u.wwn[1],
3649 ndlp->nlp_portname.u.wwn[2],
3650 ndlp->nlp_portname.u.wwn[3],
3651 ndlp->nlp_portname.u.wwn[4],
3652 ndlp->nlp_portname.u.wwn[5],
3653 ndlp->nlp_portname.u.wwn[6],
3654 ndlp->nlp_portname.u.wwn[7]);
3655
3656 index = strlen(buf);
3657
3658 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3659 sprintf(&buf[index], "%010u,",
3660 ndlp->lat_data[i].cmd_count);
3661 index = strlen(buf);
3662 }
3663 sprintf(&buf[index], "\n");
3664 index = strlen(buf);
3665 }
3666 spin_unlock_irq(shost->host_lock);
3667 return index;
3668}
3669
3670static struct bin_attribute sysfs_drvr_stat_data_attr = {
3671 .attr = {
3672 .name = "lpfc_drvr_stat_data",
3673 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003674 },
3675 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3676 .read = sysfs_drvr_stat_data_read,
3677 .write = NULL,
3678};
3679
dea31012005-04-17 16:05:31 -05003680/*
3681# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3682# connection.
James Smart76a95d72010-11-20 23:11:48 -05003683# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003684*/
James Smarte59058c2008-08-24 21:49:00 -04003685/**
James Smart3621a712009-04-06 18:47:14 -04003686 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003687 * @phba: lpfc_hba pointer.
3688 * @val: link speed value.
3689 *
3690 * Description:
3691 * If val is in a valid range then set the adapter's link speed field and
3692 * issue a lip; if the lip fails reset the link speed to the old value.
3693 *
3694 * Notes:
3695 * If the value is not in range log a kernel error message and return an error.
3696 *
3697 * Returns:
3698 * zero if val is in range and lip okay.
3699 * non-zero return value from lpfc_issue_lip()
3700 * -EINVAL val out of range
3701 **/
James Smarta257bf92009-04-06 18:48:10 -04003702static ssize_t
3703lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3704 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003705{
James Smarta257bf92009-04-06 18:48:10 -04003706 struct Scsi_Host *shost = class_to_shost(dev);
3707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3708 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003709 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003710 int nolip = 0;
3711 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003712 int err;
3713 uint32_t prev_val;
3714
James Smarta257bf92009-04-06 18:48:10 -04003715 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3716 nolip = 1;
3717 val_buf = &buf[strlen("nolip ")];
3718 }
3719
3720 if (!isdigit(val_buf[0]))
3721 return -EINVAL;
3722 if (sscanf(val_buf, "%i", &val) != 1)
3723 return -EINVAL;
3724
James Smart88a2cfb2011-07-22 18:36:33 -04003725 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3726 "3055 lpfc_link_speed changed from %d to %d %s\n",
3727 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3728
James Smart76a95d72010-11-20 23:11:48 -05003729 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3730 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3731 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3732 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3733 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3734 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3736 "2879 lpfc_link_speed attribute cannot be set "
3737 "to %d. Speed is not supported by this port.\n",
3738 val);
James Smart83108bd2008-01-11 01:53:09 -05003739 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003740 }
James Smartff78d8f2011-12-13 13:21:35 -05003741 if (val == LPFC_USER_LINK_SPEED_16G &&
3742 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3744 "3112 lpfc_link_speed attribute cannot be set "
3745 "to %d. Speed is not supported in loop mode.\n",
3746 val);
3747 return -EINVAL;
3748 }
James Smart76a95d72010-11-20 23:11:48 -05003749 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3750 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003751 prev_val = phba->cfg_link_speed;
3752 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003753 if (nolip)
3754 return strlen(buf);
3755
James Smart83108bd2008-01-11 01:53:09 -05003756 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003757 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003758 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003759 return -EINVAL;
3760 } else
3761 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003762 }
James Smart83108bd2008-01-11 01:53:09 -05003763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003764 "0469 lpfc_link_speed attribute cannot be set to %d, "
3765 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003766 return -EINVAL;
3767}
3768
3769static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003770module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003771MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3772lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003773
3774/**
James Smart3621a712009-04-06 18:47:14 -04003775 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003776 * @phba: lpfc_hba pointer.
3777 * @val: link speed value.
3778 *
3779 * Description:
3780 * If val is in a valid range then set the adapter's link speed field.
3781 *
3782 * Notes:
3783 * If the value is not in range log a kernel error message, clear the link
3784 * speed and return an error.
3785 *
3786 * Returns:
3787 * zero if val saved.
3788 * -EINVAL val out of range
3789 **/
James Smart83108bd2008-01-11 01:53:09 -05003790static int
3791lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3792{
James Smartff78d8f2011-12-13 13:21:35 -05003793 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3794 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3795 "3111 lpfc_link_speed of %d cannot "
3796 "support loop mode, setting topology to default.\n",
3797 val);
3798 phba->cfg_topology = 0;
3799 }
James Smart76a95d72010-11-20 23:11:48 -05003800 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3801 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003802 phba->cfg_link_speed = val;
3803 return 0;
3804 }
3805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003806 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003807 "be set to %d, allowed values are "
3808 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003809 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003810 return -EINVAL;
3811}
3812
Tony Jonesee959b02008-02-22 00:13:36 +01003813static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003814 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003815
3816/*
James Smart0d878412009-10-02 15:16:56 -04003817# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3818# 0 = aer disabled or not supported
3819# 1 = aer supported and enabled (default)
3820# Value range is [0,1]. Default value is 1.
3821*/
3822
3823/**
3824 * lpfc_aer_support_store - Set the adapter for aer support
3825 *
3826 * @dev: class device that is converted into a Scsi_host.
3827 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003828 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003829 * @count: unused variable.
3830 *
3831 * Description:
3832 * If the val is 1 and currently the device's AER capability was not
3833 * enabled, invoke the kernel's enable AER helper routine, trying to
3834 * enable the device's AER capability. If the helper routine enabling
3835 * AER returns success, update the device's cfg_aer_support flag to
3836 * indicate AER is supported by the device; otherwise, if the device
3837 * AER capability is already enabled to support AER, then do nothing.
3838 *
3839 * If the val is 0 and currently the device's AER support was enabled,
3840 * invoke the kernel's disable AER helper routine. After that, update
3841 * the device's cfg_aer_support flag to indicate AER is not supported
3842 * by the device; otherwise, if the device AER capability is already
3843 * disabled from supporting AER, then do nothing.
3844 *
3845 * Returns:
3846 * length of the buf on success if val is in range the intended mode
3847 * is supported.
3848 * -EINVAL if val out of range or intended mode is not supported.
3849 **/
3850static ssize_t
3851lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3852 const char *buf, size_t count)
3853{
3854 struct Scsi_Host *shost = class_to_shost(dev);
3855 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3856 struct lpfc_hba *phba = vport->phba;
3857 int val = 0, rc = -EINVAL;
3858
3859 if (!isdigit(buf[0]))
3860 return -EINVAL;
3861 if (sscanf(buf, "%i", &val) != 1)
3862 return -EINVAL;
3863
3864 switch (val) {
3865 case 0:
3866 if (phba->hba_flag & HBA_AER_ENABLED) {
3867 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3868 if (!rc) {
3869 spin_lock_irq(&phba->hbalock);
3870 phba->hba_flag &= ~HBA_AER_ENABLED;
3871 spin_unlock_irq(&phba->hbalock);
3872 phba->cfg_aer_support = 0;
3873 rc = strlen(buf);
3874 } else
James Smart891478a2009-11-18 15:40:23 -05003875 rc = -EPERM;
3876 } else {
James Smart0d878412009-10-02 15:16:56 -04003877 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003878 rc = strlen(buf);
3879 }
James Smart0d878412009-10-02 15:16:56 -04003880 break;
3881 case 1:
3882 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3883 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3884 if (!rc) {
3885 spin_lock_irq(&phba->hbalock);
3886 phba->hba_flag |= HBA_AER_ENABLED;
3887 spin_unlock_irq(&phba->hbalock);
3888 phba->cfg_aer_support = 1;
3889 rc = strlen(buf);
3890 } else
James Smart891478a2009-11-18 15:40:23 -05003891 rc = -EPERM;
3892 } else {
James Smart0d878412009-10-02 15:16:56 -04003893 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003894 rc = strlen(buf);
3895 }
James Smart0d878412009-10-02 15:16:56 -04003896 break;
3897 default:
3898 rc = -EINVAL;
3899 break;
3900 }
3901 return rc;
3902}
3903
3904static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003905module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003906MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3907lpfc_param_show(aer_support)
3908
3909/**
3910 * lpfc_aer_support_init - Set the initial adapters aer support flag
3911 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003912 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003913 *
3914 * Description:
3915 * If val is in a valid range [0,1], then set the adapter's initial
3916 * cfg_aer_support field. It will be up to the driver's probe_one
3917 * routine to determine whether the device's AER support can be set
3918 * or not.
3919 *
3920 * Notes:
3921 * If the value is not in range log a kernel error message, and
3922 * choose the default value of setting AER support and return.
3923 *
3924 * Returns:
3925 * zero if val saved.
3926 * -EINVAL val out of range
3927 **/
3928static int
3929lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3930{
3931 if (val == 0 || val == 1) {
3932 phba->cfg_aer_support = val;
3933 return 0;
3934 }
3935 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3936 "2712 lpfc_aer_support attribute value %d out "
3937 "of range, allowed values are 0|1, setting it "
3938 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003939 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003940 phba->cfg_aer_support = 1;
3941 return -EINVAL;
3942}
3943
3944static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3945 lpfc_aer_support_show, lpfc_aer_support_store);
3946
3947/**
3948 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3949 * @dev: class device that is converted into a Scsi_host.
3950 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003951 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003952 * @count: unused variable.
3953 *
3954 * Description:
3955 * If the @buf contains 1 and the device currently has the AER support
3956 * enabled, then invokes the kernel AER helper routine
3957 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3958 * error status register.
3959 *
3960 * Notes:
3961 *
3962 * Returns:
3963 * -EINVAL if the buf does not contain the 1 or the device is not currently
3964 * enabled with the AER support.
3965 **/
3966static ssize_t
3967lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3968 const char *buf, size_t count)
3969{
3970 struct Scsi_Host *shost = class_to_shost(dev);
3971 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3972 struct lpfc_hba *phba = vport->phba;
3973 int val, rc = -1;
3974
3975 if (!isdigit(buf[0]))
3976 return -EINVAL;
3977 if (sscanf(buf, "%i", &val) != 1)
3978 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003979 if (val != 1)
3980 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003981
James Smart891478a2009-11-18 15:40:23 -05003982 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003983 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3984
3985 if (rc == 0)
3986 return strlen(buf);
3987 else
James Smart891478a2009-11-18 15:40:23 -05003988 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003989}
3990
3991static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3992 lpfc_aer_cleanup_state);
3993
James Smart912e3ac2011-05-24 11:42:11 -04003994/**
3995 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3996 *
3997 * @dev: class device that is converted into a Scsi_host.
3998 * @attr: device attribute, not used.
3999 * @buf: containing the string the number of vfs to be enabled.
4000 * @count: unused variable.
4001 *
4002 * Description:
4003 * When this api is called either through user sysfs, the driver shall
4004 * try to enable or disable SR-IOV virtual functions according to the
4005 * following:
4006 *
4007 * If zero virtual function has been enabled to the physical function,
4008 * the driver shall invoke the pci enable virtual function api trying
4009 * to enable the virtual functions. If the nr_vfn provided is greater
4010 * than the maximum supported, the maximum virtual function number will
4011 * be used for invoking the api; otherwise, the nr_vfn provided shall
4012 * be used for invoking the api. If the api call returned success, the
4013 * actual number of virtual functions enabled will be set to the driver
4014 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4015 * cfg_sriov_nr_virtfn remains zero.
4016 *
4017 * If none-zero virtual functions have already been enabled to the
4018 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4019 * -EINVAL will be returned and the driver does nothing;
4020 *
4021 * If the nr_vfn provided is zero and none-zero virtual functions have
4022 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4023 * disabling virtual function api shall be invoded to disable all the
4024 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4025 * zero. Otherwise, if zero virtual function has been enabled, do
4026 * nothing.
4027 *
4028 * Returns:
4029 * length of the buf on success if val is in range the intended mode
4030 * is supported.
4031 * -EINVAL if val out of range or intended mode is not supported.
4032 **/
4033static ssize_t
4034lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4035 const char *buf, size_t count)
4036{
4037 struct Scsi_Host *shost = class_to_shost(dev);
4038 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4039 struct lpfc_hba *phba = vport->phba;
4040 struct pci_dev *pdev = phba->pcidev;
4041 int val = 0, rc = -EINVAL;
4042
4043 /* Sanity check on user data */
4044 if (!isdigit(buf[0]))
4045 return -EINVAL;
4046 if (sscanf(buf, "%i", &val) != 1)
4047 return -EINVAL;
4048 if (val < 0)
4049 return -EINVAL;
4050
4051 /* Request disabling virtual functions */
4052 if (val == 0) {
4053 if (phba->cfg_sriov_nr_virtfn > 0) {
4054 pci_disable_sriov(pdev);
4055 phba->cfg_sriov_nr_virtfn = 0;
4056 }
4057 return strlen(buf);
4058 }
4059
4060 /* Request enabling virtual functions */
4061 if (phba->cfg_sriov_nr_virtfn > 0) {
4062 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4063 "3018 There are %d virtual functions "
4064 "enabled on physical function.\n",
4065 phba->cfg_sriov_nr_virtfn);
4066 return -EEXIST;
4067 }
4068
4069 if (val <= LPFC_MAX_VFN_PER_PFN)
4070 phba->cfg_sriov_nr_virtfn = val;
4071 else {
4072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4073 "3019 Enabling %d virtual functions is not "
4074 "allowed.\n", val);
4075 return -EINVAL;
4076 }
4077
4078 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4079 if (rc) {
4080 phba->cfg_sriov_nr_virtfn = 0;
4081 rc = -EPERM;
4082 } else
4083 rc = strlen(buf);
4084
4085 return rc;
4086}
4087
4088static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
4089module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
4090MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
4091lpfc_param_show(sriov_nr_virtfn)
4092
4093/**
4094 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
4095 * @phba: lpfc_hba pointer.
4096 * @val: link speed value.
4097 *
4098 * Description:
4099 * If val is in a valid range [0,255], then set the adapter's initial
4100 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
4101 * number shall be used instead. It will be up to the driver's probe_one
4102 * routine to determine whether the device's SR-IOV is supported or not.
4103 *
4104 * Returns:
4105 * zero if val saved.
4106 * -EINVAL val out of range
4107 **/
4108static int
4109lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
4110{
4111 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
4112 phba->cfg_sriov_nr_virtfn = val;
4113 return 0;
4114 }
4115
4116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4117 "3017 Enabling %d virtual functions is not "
4118 "allowed.\n", val);
4119 return -EINVAL;
4120}
4121static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4122 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4123
James Smart173edbb2012-06-12 13:54:50 -04004124/**
James Smartc71ab862012-10-31 14:44:33 -04004125 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4126 *
4127 * @dev: class device that is converted into a Scsi_host.
4128 * @attr: device attribute, not used.
4129 * @buf: containing the string the number of vfs to be enabled.
4130 * @count: unused variable.
4131 *
4132 * Description:
4133 *
4134 * Returns:
4135 * length of the buf on success if val is in range the intended mode
4136 * is supported.
4137 * -EINVAL if val out of range or intended mode is not supported.
4138 **/
4139static ssize_t
4140lpfc_request_firmware_upgrade_store(struct device *dev,
4141 struct device_attribute *attr,
4142 const char *buf, size_t count)
4143{
4144 struct Scsi_Host *shost = class_to_shost(dev);
4145 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4146 struct lpfc_hba *phba = vport->phba;
4147 int val = 0, rc = -EINVAL;
4148
4149 /* Sanity check on user data */
4150 if (!isdigit(buf[0]))
4151 return -EINVAL;
4152 if (sscanf(buf, "%i", &val) != 1)
4153 return -EINVAL;
4154 if (val != 1)
4155 return -EINVAL;
4156
4157 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4158 if (rc)
4159 rc = -EPERM;
4160 else
4161 rc = strlen(buf);
4162 return rc;
4163}
4164
4165static int lpfc_req_fw_upgrade;
4166module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4167MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4168lpfc_param_show(request_firmware_upgrade)
4169
4170/**
4171 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4172 * @phba: lpfc_hba pointer.
4173 * @val: 0 or 1.
4174 *
4175 * Description:
4176 * Set the initial Linux generic firmware upgrade enable or disable flag.
4177 *
4178 * Returns:
4179 * zero if val saved.
4180 * -EINVAL val out of range
4181 **/
4182static int
4183lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4184{
4185 if (val >= 0 && val <= 1) {
4186 phba->cfg_request_firmware_upgrade = val;
4187 return 0;
4188 }
4189 return -EINVAL;
4190}
4191static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4192 lpfc_request_firmware_upgrade_show,
4193 lpfc_request_firmware_upgrade_store);
4194
4195/**
James Smart173edbb2012-06-12 13:54:50 -04004196 * lpfc_fcp_imax_store
4197 *
4198 * @dev: class device that is converted into a Scsi_host.
4199 * @attr: device attribute, not used.
4200 * @buf: string with the number of fast-path FCP interrupts per second.
4201 * @count: unused variable.
4202 *
4203 * Description:
4204 * If val is in a valid range [636,651042], then set the adapter's
4205 * maximum number of fast-path FCP interrupts per second.
4206 *
4207 * Returns:
4208 * length of the buf on success if val is in range the intended mode
4209 * is supported.
4210 * -EINVAL if val out of range or intended mode is not supported.
4211 **/
4212static ssize_t
4213lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4214 const char *buf, size_t count)
4215{
4216 struct Scsi_Host *shost = class_to_shost(dev);
4217 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4218 struct lpfc_hba *phba = vport->phba;
4219 int val = 0, i;
4220
James Smartbf8dae82012-08-03 12:36:24 -04004221 /* fcp_imax is only valid for SLI4 */
4222 if (phba->sli_rev != LPFC_SLI_REV4)
4223 return -EINVAL;
4224
James Smart173edbb2012-06-12 13:54:50 -04004225 /* Sanity check on user data */
4226 if (!isdigit(buf[0]))
4227 return -EINVAL;
4228 if (sscanf(buf, "%i", &val) != 1)
4229 return -EINVAL;
4230
James Smartbf8dae82012-08-03 12:36:24 -04004231 /*
4232 * Value range for the HBA is [5000,5000000]
4233 * The value for each EQ depends on how many EQs are configured.
4234 */
4235 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04004236 return -EINVAL;
4237
4238 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04004239 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04004240 lpfc_modify_fcp_eq_delay(phba, i);
4241
4242 return strlen(buf);
4243}
4244
4245/*
4246# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004247# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004248#
James Smartbf8dae82012-08-03 12:36:24 -04004249# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004250*/
James Smartbf8dae82012-08-03 12:36:24 -04004251static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004252module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4253MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004254 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004255lpfc_param_show(fcp_imax)
4256
4257/**
4258 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4259 * @phba: lpfc_hba pointer.
4260 * @val: link speed value.
4261 *
4262 * Description:
4263 * If val is in a valid range [636,651042], then initialize the adapter's
4264 * maximum number of fast-path FCP interrupts per second.
4265 *
4266 * Returns:
4267 * zero if val saved.
4268 * -EINVAL val out of range
4269 **/
4270static int
4271lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4272{
James Smartbf8dae82012-08-03 12:36:24 -04004273 if (phba->sli_rev != LPFC_SLI_REV4) {
4274 phba->cfg_fcp_imax = 0;
4275 return 0;
4276 }
4277
4278 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04004279 phba->cfg_fcp_imax = val;
4280 return 0;
4281 }
4282
4283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4284 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04004285 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004286
4287 return 0;
4288}
4289
4290static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4291 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4292
James Smart7bb03bb2013-04-17 20:19:16 -04004293/**
4294 * lpfc_state_show - Display current driver CPU affinity
4295 * @dev: class converted to a Scsi_host structure.
4296 * @attr: device attribute, not used.
4297 * @buf: on return contains text describing the state of the link.
4298 *
4299 * Returns: size of formatted string.
4300 **/
4301static ssize_t
4302lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4303 char *buf)
4304{
4305 struct Scsi_Host *shost = class_to_shost(dev);
4306 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4307 struct lpfc_hba *phba = vport->phba;
4308 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004309 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004310
4311 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4312 (phba->intr_type != MSIX))
4313 return len;
4314
4315 switch (phba->cfg_fcp_cpu_map) {
4316 case 0:
4317 len += snprintf(buf + len, PAGE_SIZE-len,
4318 "fcp_cpu_map: No mapping (%d)\n",
4319 phba->cfg_fcp_cpu_map);
4320 return len;
4321 case 1:
4322 len += snprintf(buf + len, PAGE_SIZE-len,
4323 "fcp_cpu_map: HBA centric mapping (%d): "
4324 "%d online CPUs\n",
4325 phba->cfg_fcp_cpu_map,
4326 phba->sli4_hba.num_online_cpu);
4327 break;
4328 case 2:
4329 len += snprintf(buf + len, PAGE_SIZE-len,
4330 "fcp_cpu_map: Driver centric mapping (%d): "
4331 "%d online CPUs\n",
4332 phba->cfg_fcp_cpu_map,
4333 phba->sli4_hba.num_online_cpu);
4334 break;
4335 }
4336
James Smart76fd07a2014-02-20 09:57:18 -05004337 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4338 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4339
4340 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004341 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4342 len += snprintf(buf + len, PAGE_SIZE-len,
4343 "CPU %02d io_chan %02d "
4344 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004345 phba->sli4_hba.curr_disp_cpu,
4346 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004347 cpup->core_id);
4348 else
4349 len += snprintf(buf + len, PAGE_SIZE-len,
4350 "CPU %02d io_chan %02d "
4351 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004352 phba->sli4_hba.curr_disp_cpu,
4353 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004354 cpup->core_id, cpup->irq);
4355
James Smart76fd07a2014-02-20 09:57:18 -05004356 phba->sli4_hba.curr_disp_cpu++;
4357
4358 /* display max number of CPUs keeping some margin */
4359 if (phba->sli4_hba.curr_disp_cpu <
4360 phba->sli4_hba.num_present_cpu &&
4361 (len >= (PAGE_SIZE - 64))) {
4362 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4363 break;
4364 }
James Smart7bb03bb2013-04-17 20:19:16 -04004365 }
James Smart76fd07a2014-02-20 09:57:18 -05004366
4367 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4368 phba->sli4_hba.curr_disp_cpu = 0;
4369
James Smart7bb03bb2013-04-17 20:19:16 -04004370 return len;
4371}
4372
4373/**
4374 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4375 * @dev: class device that is converted into a Scsi_host.
4376 * @attr: device attribute, not used.
4377 * @buf: one or more lpfc_polling_flags values.
4378 * @count: not used.
4379 *
4380 * Returns:
4381 * -EINVAL - Not implemented yet.
4382 **/
4383static ssize_t
4384lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4385 const char *buf, size_t count)
4386{
4387 int status = -EINVAL;
4388 return status;
4389}
4390
4391/*
4392# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4393# for the HBA.
4394#
4395# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4396# 0 - Do not affinitze IRQ vectors
4397# 1 - Affintize HBA vectors with respect to each HBA
4398# (start with CPU0 for each HBA)
4399# 2 - Affintize HBA vectors with respect to the entire driver
4400# (round robin thru all CPUs across all HBAs)
4401*/
4402static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4403module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4404MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4405 "Defines how to map CPUs to IRQ vectors per HBA");
4406
4407/**
4408 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4409 * @phba: lpfc_hba pointer.
4410 * @val: link speed value.
4411 *
4412 * Description:
4413 * If val is in a valid range [0-2], then affinitze the adapter's
4414 * MSIX vectors.
4415 *
4416 * Returns:
4417 * zero if val saved.
4418 * -EINVAL val out of range
4419 **/
4420static int
4421lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4422{
4423 if (phba->sli_rev != LPFC_SLI_REV4) {
4424 phba->cfg_fcp_cpu_map = 0;
4425 return 0;
4426 }
4427
4428 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4429 phba->cfg_fcp_cpu_map = val;
4430 return 0;
4431 }
4432
4433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4434 "3326 fcp_cpu_map: %d out of range, using default\n",
4435 val);
4436 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4437
4438 return 0;
4439}
4440
4441static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4442 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4443
James Smart0d878412009-10-02 15:16:56 -04004444/*
dea31012005-04-17 16:05:31 -05004445# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4446# Value range is [2,3]. Default value is 3.
4447*/
James Smart3de2a652007-08-02 11:09:59 -04004448LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4449 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004450
4451/*
4452# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4453# is [0,1]. Default value is 0.
4454*/
James Smart3de2a652007-08-02 11:09:59 -04004455LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4456 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004457
4458/*
James Smart3cb01c52013-07-15 18:35:04 -04004459# lpfc_first_burst_size: First burst size to use on the NPorts
4460# that support first burst.
4461# Value range is [0,65536]. Default value is 0.
4462*/
4463LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4464 "First burst size for Targets that support first burst");
4465
4466/*
James Smart977b5a02008-09-07 11:52:04 -04004467# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4468# depth. Default value is 0. When the value of this parameter is zero the
4469# SCSI command completion time is not used for controlling I/O queue depth. When
4470# the parameter is set to a non-zero value, the I/O queue depth is controlled
4471# to limit the I/O completion time to the parameter value.
4472# The value is set in milliseconds.
4473*/
4474static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05004475module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04004476MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
4477 "Use command completion time to control queue depth");
4478lpfc_vport_param_show(max_scsicmpl_time);
4479lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
4480static int
4481lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4482{
4483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4484 struct lpfc_nodelist *ndlp, *next_ndlp;
4485
4486 if (val == vport->cfg_max_scsicmpl_time)
4487 return 0;
4488 if ((val < 0) || (val > 60000))
4489 return -EINVAL;
4490 vport->cfg_max_scsicmpl_time = val;
4491
4492 spin_lock_irq(shost->host_lock);
4493 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4494 if (!NLP_CHK_NODE_ACT(ndlp))
4495 continue;
4496 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4497 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004498 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004499 }
4500 spin_unlock_irq(shost->host_lock);
4501 return 0;
4502}
4503lpfc_vport_param_store(max_scsicmpl_time);
4504static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4505 lpfc_max_scsicmpl_time_show,
4506 lpfc_max_scsicmpl_time_store);
4507
4508/*
dea31012005-04-17 16:05:31 -05004509# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4510# range is [0,1]. Default value is 0.
4511*/
4512LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4513
4514/*
James Smart49aa1432012-08-03 12:36:42 -04004515# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4516# range is [0,1]. Default value is 0.
4517# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4518# For [1], FCP commands are issued to a Work Queue associated with the
4519# current CPU.
James Smartec2087a2013-09-06 12:20:36 -04004520# It would be set to 1 by the driver if it's able to set up cpu affinity
4521# for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4522# roundrobin scheduling of FCP I/Os through WQs will be used.
James Smart49aa1432012-08-03 12:36:42 -04004523*/
James Smartec2087a2013-09-06 12:20:36 -04004524LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
James Smart49aa1432012-08-03 12:36:42 -04004525 "issuing commands [0] - Round Robin, [1] - Current CPU");
4526
4527/*
James Smarta6571c62012-10-31 14:44:42 -04004528# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4529# range is [0,1]. Default value is 0.
4530# For [0], bus reset issues target reset to ALL devices
4531# For [1], bus reset issues target reset to non-FCP2 devices
4532*/
4533LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4534 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4535
4536
4537/*
dea31012005-04-17 16:05:31 -05004538# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4539# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004540# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004541# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4542# cr_delay is set to 0.
4543*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004544LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004545 "interrupt response is generated");
4546
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004547LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004548 "interrupt response is generated");
4549
4550/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004551# lpfc_multi_ring_support: Determines how many rings to spread available
4552# cmd/rsp IOCB entries across.
4553# Value range is [1,2]. Default value is 1.
4554*/
4555LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4556 "SLI rings to spread IOCB entries across");
4557
4558/*
James Smarta4bc3372006-12-02 13:34:16 -05004559# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4560# identifies what rctl value to configure the additional ring for.
4561# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4562*/
James Smart6a9c52c2009-10-02 15:16:51 -04004563LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004564 255, "Identifies RCTL for additional ring configuration");
4565
4566/*
4567# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4568# identifies what type value to configure the additional ring for.
4569# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4570*/
James Smart6a9c52c2009-10-02 15:16:51 -04004571LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004572 255, "Identifies TYPE for additional ring configuration");
4573
4574/*
dea31012005-04-17 16:05:31 -05004575# lpfc_fdmi_on: controls FDMI support.
James Smart76b2c342015-04-07 15:07:19 -04004576# Set NOT Set
4577# bit 0 = FDMI support no FDMI support
4578# LPFC_FDMI_SUPPORT just turns basic support on/off
4579# bit 1 = Register delay no register delay (60 seconds)
4580# LPFC_FDMI_REG_DELAY 60 sec registration delay after FDMI login
4581# bit 2 = All attributes Use a attribute subset
4582# LPFC_FDMI_ALL_ATTRIB applies to both port and HBA attributes
4583# Port attrutes subset: 1 thru 6 OR all: 1 thru 0xd 0x101 0x102 0x103
4584# HBA attributes subset: 1 thru 0xb OR all: 1 thru 0xc
4585# Value range [0,7]. Default value is 0.
dea31012005-04-17 16:05:31 -05004586*/
James Smart76b2c342015-04-07 15:07:19 -04004587LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 7, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004588
4589/*
4590# Specifies the maximum number of ELS cmds we can have outstanding (for
4591# discovery). Value range is [1,64]. Default value = 32.
4592*/
James Smart3de2a652007-08-02 11:09:59 -04004593LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004594 "during discovery");
4595
4596/*
James Smartc4a7c922013-05-31 17:04:59 -04004597# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4598# will be scanned by the SCSI midlayer when sequential scanning is
4599# used; and is also the highest LUN ID allowed when the SCSI midlayer
4600# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4601# LUN ID limit, but the SCSI midlayer requires this field for the uses
4602# above. The lpfc driver limits the default value to 255 for two reasons.
4603# As it bounds the sequential scan loop, scanning for thousands of luns
4604# on a target can take minutes of wall clock time. Additionally,
4605# there are FC targets, such as JBODs, that only recognize 8-bits of
4606# LUN ID. When they receive a value greater than 8 bits, they chop off
4607# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4608# and so on all as LUN ID 0. This causes the linux kernel, which sees
4609# valid responses at each of the LUN IDs, to believe there are multiple
4610# devices present, when in fact, there is only 1.
4611# A customer that is aware of their target behaviors, and the results as
4612# indicated above, is welcome to increase the lpfc_max_luns value.
4613# As mentioned, this value is not used by the lpfc driver, only the
4614# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004615# Value range is [0,65535]. Default value is 255.
4616# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004617*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004618LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004619
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004620/*
4621# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4622# Value range is [1,255], default value is 10.
4623*/
4624LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4625 "Milliseconds driver will wait between polling FCP ring");
4626
James Smart4ff43242006-12-02 13:34:56 -05004627/*
James Smart0c411222013-09-06 12:22:46 -04004628# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4629# to complete in seconds. Value range is [5,180], default value is 60.
4630*/
4631LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4632 "Maximum time to wait for task management commands to complete");
4633/*
James Smart4ff43242006-12-02 13:34:56 -05004634# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4635# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004636# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004637# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004638# 2 = MSI-X enabled (default)
4639# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004640*/
George Kadianakis8605c462010-01-17 21:19:31 +02004641LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004642 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004643
James Smart13815c82008-01-11 01:52:48 -05004644/*
James Smart67d12732012-08-03 12:36:13 -04004645# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4646#
4647# Value range is [1,7]. Default value is 4.
4648*/
4649LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4650 LPFC_FCP_IO_CHAN_MAX,
4651 "Set the number of FCP I/O channels");
4652
4653/*
James Smart13815c82008-01-11 01:52:48 -05004654# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4655# 0 = HBA resets disabled
4656# 1 = HBA resets enabled (default)
4657# Value range is [0,1]. Default value is 1.
4658*/
4659LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004660
James Smart13815c82008-01-11 01:52:48 -05004661/*
James Smarteb7a3392010-11-20 23:12:02 -05004662# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004663# 0 = HBA Heartbeat disabled
4664# 1 = HBA Heartbeat enabled (default)
4665# Value range is [0,1]. Default value is 1.
4666*/
James Smarteb7a3392010-11-20 23:12:02 -05004667LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004668
James Smart83108bd2008-01-11 01:53:09 -05004669/*
James Smart1ba981f2014-02-20 09:56:45 -05004670# lpfc_EnableXLane: Enable Express Lane Feature
4671# 0x0 Express Lane Feature disabled
4672# 0x1 Express Lane Feature enabled
4673# Value range is [0,1]. Default value is 0.
4674*/
4675LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4676
4677/*
4678# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4679# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4680# Value range is [0x0,0x7f]. Default value is 0
4681*/
James Smart28d7f3d2014-05-21 08:05:28 -04004682LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004683
4684/*
James Smart81301a92008-12-04 22:39:46 -05004685# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4686# 0 = BlockGuard disabled (default)
4687# 1 = BlockGuard enabled
4688# Value range is [0,1]. Default value is 0.
4689*/
4690LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4691
James Smart6fb120a2009-05-22 14:52:59 -04004692/*
James Smartba20c852012-08-03 12:36:52 -04004693# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4694# 0 = disabled (default)
4695# 1 = enabled
4696# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004697#
4698# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004699*/
4700unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4701
James Smartba20c852012-08-03 12:36:52 -04004702/*
James Smart81301a92008-12-04 22:39:46 -05004703# lpfc_prot_mask: i
4704# - Bit mask of host protection capabilities used to register with the
4705# SCSI mid-layer
4706# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4707# - Allows you to ultimately specify which profiles to use
4708# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004709# - SHOST_DIF_TYPE1_PROTECTION 1
4710# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4711# - SHOST_DIX_TYPE0_PROTECTION 8
4712# HBA supports DIX Type 0: Host to HBA protection only
4713# - SHOST_DIX_TYPE1_PROTECTION 16
4714# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004715#
4716*/
James Smart7c56b9f2011-07-22 18:36:25 -04004717unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4718 SHOST_DIX_TYPE0_PROTECTION |
4719 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004720
James Smartab56dc22011-02-16 12:39:57 -05004721module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004722MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4723
4724/*
4725# lpfc_prot_guard: i
4726# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004727# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004728# - Allows you to ultimately specify which profiles to use
4729# - Default will result in registering capabilities for all guard types
4730#
4731*/
4732unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004733module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004734MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4735
James Smart92494142011-02-16 12:39:44 -05004736/*
4737 * Delay initial NPort discovery when Clean Address bit is cleared in
4738 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4739 * This parameter can have value 0 or 1.
4740 * When this parameter is set to 0, no delay is added to the initial
4741 * discovery.
4742 * When this parameter is set to non-zero value, initial Nport discovery is
4743 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4744 * accept and FCID/Fabric name/Fabric portname is changed.
4745 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4746 * when Clean Address bit is cleared in FLOGI/FDISC
4747 * accept and FCID/Fabric name/Fabric portname is changed.
4748 * Default value is 0.
4749 */
4750int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05004751module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05004752MODULE_PARM_DESC(lpfc_delay_discovery,
4753 "Delay NPort discovery when Clean Address bit is cleared. "
4754 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05004755
4756/*
James Smart3621a712009-04-06 18:47:14 -04004757 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004758 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004759 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4760 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004761 * Because of the additional overhead involved in setting up T10-DIF,
4762 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4763 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004764 */
4765LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4766 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4767
James Smart96f70772013-04-17 20:16:15 -04004768/*
4769 * This parameter will be depricated, the driver cannot limit the
4770 * protection data s/g list.
4771 */
4772LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4773 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4774 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004775
Tony Jonesee959b02008-02-22 00:13:36 +01004776struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004777 &dev_attr_bg_info,
4778 &dev_attr_bg_guard_err,
4779 &dev_attr_bg_apptag_err,
4780 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004781 &dev_attr_info,
4782 &dev_attr_serialnum,
4783 &dev_attr_modeldesc,
4784 &dev_attr_modelname,
4785 &dev_attr_programtype,
4786 &dev_attr_portnum,
4787 &dev_attr_fwrev,
4788 &dev_attr_hdw,
4789 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004790 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004791 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004792 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004793 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004794 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004795 &dev_attr_lpfc_temp_sensor,
4796 &dev_attr_lpfc_log_verbose,
4797 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004798 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004799 &dev_attr_lpfc_hba_queue_depth,
4800 &dev_attr_lpfc_peer_port_login,
4801 &dev_attr_lpfc_nodev_tmo,
4802 &dev_attr_lpfc_devloss_tmo,
4803 &dev_attr_lpfc_fcp_class,
4804 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004805 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004806 &dev_attr_lpfc_ack0,
4807 &dev_attr_lpfc_topology,
4808 &dev_attr_lpfc_scan_down,
4809 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004810 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004811 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004812 &dev_attr_lpfc_cr_delay,
4813 &dev_attr_lpfc_cr_count,
4814 &dev_attr_lpfc_multi_ring_support,
4815 &dev_attr_lpfc_multi_ring_rctl,
4816 &dev_attr_lpfc_multi_ring_type,
4817 &dev_attr_lpfc_fdmi_on,
4818 &dev_attr_lpfc_max_luns,
4819 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004820 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004821 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004822 &dev_attr_nport_evt_cnt,
4823 &dev_attr_board_mode,
4824 &dev_attr_max_vpi,
4825 &dev_attr_used_vpi,
4826 &dev_attr_max_rpi,
4827 &dev_attr_used_rpi,
4828 &dev_attr_max_xri,
4829 &dev_attr_used_xri,
4830 &dev_attr_npiv_info,
4831 &dev_attr_issue_reset,
4832 &dev_attr_lpfc_poll,
4833 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04004834 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01004835 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004836 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004837 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04004838 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004839 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004840 &dev_attr_lpfc_soft_wwnn,
4841 &dev_attr_lpfc_soft_wwpn,
4842 &dev_attr_lpfc_soft_wwn_enable,
4843 &dev_attr_lpfc_enable_hba_reset,
4844 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05004845 &dev_attr_lpfc_EnableXLane,
4846 &dev_attr_lpfc_XLanePriority,
4847 &dev_attr_lpfc_xlane_lun,
4848 &dev_attr_lpfc_xlane_tgt,
4849 &dev_attr_lpfc_xlane_vpt,
4850 &dev_attr_lpfc_xlane_lun_state,
4851 &dev_attr_lpfc_xlane_lun_status,
Tony Jonesee959b02008-02-22 00:13:36 +01004852 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004853 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004854 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004855 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004856 &dev_attr_lpfc_aer_support,
4857 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004858 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004859 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004860 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004861 &dev_attr_lpfc_iocb_cnt,
4862 &dev_attr_iocb_hw,
4863 &dev_attr_txq_hw,
4864 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004865 &dev_attr_lpfc_fips_level,
4866 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004867 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004868 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004869 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05004870 &dev_attr_lpfc_xlane_supported,
dea31012005-04-17 16:05:31 -05004871 NULL,
4872};
4873
Tony Jonesee959b02008-02-22 00:13:36 +01004874struct device_attribute *lpfc_vport_attrs[] = {
4875 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004876 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004877 &dev_attr_num_discovered_ports,
4878 &dev_attr_lpfc_drvr_version,
4879 &dev_attr_lpfc_log_verbose,
4880 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004881 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004882 &dev_attr_lpfc_nodev_tmo,
4883 &dev_attr_lpfc_devloss_tmo,
4884 &dev_attr_lpfc_hba_queue_depth,
4885 &dev_attr_lpfc_peer_port_login,
4886 &dev_attr_lpfc_restrict_login,
4887 &dev_attr_lpfc_fcp_class,
4888 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004889 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004890 &dev_attr_lpfc_fdmi_on,
4891 &dev_attr_lpfc_max_luns,
4892 &dev_attr_nport_evt_cnt,
4893 &dev_attr_npiv_info,
4894 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004895 &dev_attr_lpfc_max_scsicmpl_time,
4896 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004897 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004898 &dev_attr_lpfc_fips_level,
4899 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004900 NULL,
4901};
4902
James Smarte59058c2008-08-24 21:49:00 -04004903/**
James Smart3621a712009-04-06 18:47:14 -04004904 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004905 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004906 * @kobj: kernel kobject that contains the kernel class device.
4907 * @bin_attr: kernel attributes passed to us.
4908 * @buf: contains the data to be written to the adapter IOREG space.
4909 * @off: offset into buffer to beginning of data.
4910 * @count: bytes to transfer.
4911 *
4912 * Description:
4913 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4914 * Uses the adapter io control registers to send buf contents to the adapter.
4915 *
4916 * Returns:
4917 * -ERANGE off and count combo out of range
4918 * -EINVAL off, count or buff address invalid
4919 * -EPERM adapter is offline
4920 * value of count, buf contents written
4921 **/
dea31012005-04-17 16:05:31 -05004922static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004923sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4924 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004925 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004926{
4927 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004928 struct device *dev = container_of(kobj, struct device, kobj);
4929 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004930 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4931 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004932
James Smartf1126682009-06-10 17:22:44 -04004933 if (phba->sli_rev >= LPFC_SLI_REV4)
4934 return -EPERM;
4935
dea31012005-04-17 16:05:31 -05004936 if ((off + count) > FF_REG_AREA_SIZE)
4937 return -ERANGE;
4938
James Smartf7a919b2011-08-21 21:49:16 -04004939 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4940 return 0;
dea31012005-04-17 16:05:31 -05004941
4942 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4943 return -EINVAL;
4944
James Smartf7a919b2011-08-21 21:49:16 -04004945 /* This is to protect HBA registers from accidental writes. */
4946 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4947 return -EINVAL;
4948
4949 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004950 return -EPERM;
dea31012005-04-17 16:05:31 -05004951
James Smart2e0fef82007-06-17 19:56:36 -05004952 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004953 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4954 buf_off += sizeof(uint32_t))
4955 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004956 phba->ctrl_regs_memmap_p + off + buf_off);
4957
James Smart2e0fef82007-06-17 19:56:36 -05004958 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004959
4960 return count;
4961}
4962
James Smarte59058c2008-08-24 21:49:00 -04004963/**
James Smart3621a712009-04-06 18:47:14 -04004964 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004965 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004966 * @kobj: kernel kobject that contains the kernel class device.
4967 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004968 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004969 * @off: offset into buffer to beginning of data.
4970 * @count: bytes to transfer.
4971 *
4972 * Description:
4973 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4974 * Uses the adapter io control registers to read data into buf.
4975 *
4976 * Returns:
4977 * -ERANGE off and count combo out of range
4978 * -EINVAL off, count or buff address invalid
4979 * value of count, buf contents read
4980 **/
dea31012005-04-17 16:05:31 -05004981static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004982sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4983 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004984 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004985{
4986 size_t buf_off;
4987 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004988 struct device *dev = container_of(kobj, struct device, kobj);
4989 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004990 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4991 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004992
James Smartf1126682009-06-10 17:22:44 -04004993 if (phba->sli_rev >= LPFC_SLI_REV4)
4994 return -EPERM;
4995
dea31012005-04-17 16:05:31 -05004996 if (off > FF_REG_AREA_SIZE)
4997 return -ERANGE;
4998
4999 if ((off + count) > FF_REG_AREA_SIZE)
5000 count = FF_REG_AREA_SIZE - off;
5001
5002 if (count == 0) return 0;
5003
5004 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5005 return -EINVAL;
5006
James Smart2e0fef82007-06-17 19:56:36 -05005007 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005008
5009 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5010 tmp_ptr = (uint32_t *)(buf + buf_off);
5011 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5012 }
5013
James Smart2e0fef82007-06-17 19:56:36 -05005014 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005015
5016 return count;
5017}
5018
5019static struct bin_attribute sysfs_ctlreg_attr = {
5020 .attr = {
5021 .name = "ctlreg",
5022 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005023 },
5024 .size = 256,
5025 .read = sysfs_ctlreg_read,
5026 .write = sysfs_ctlreg_write,
5027};
5028
James Smarte59058c2008-08-24 21:49:00 -04005029/**
James Smart3621a712009-04-06 18:47:14 -04005030 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005031 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005032 * @kobj: kernel kobject that contains the kernel class device.
5033 * @bin_attr: kernel attributes passed to us.
5034 * @buf: contains the data to be written to sysfs mbox.
5035 * @off: offset into buffer to beginning of data.
5036 * @count: bytes to transfer.
5037 *
5038 * Description:
James Smart026abb82011-12-13 13:20:45 -05005039 * Deprecated function. All mailbox access from user space is performed via the
5040 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005041 *
5042 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005043 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005044 **/
dea31012005-04-17 16:05:31 -05005045static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005046sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5047 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005048 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005049{
James Smart026abb82011-12-13 13:20:45 -05005050 return -EPERM;
dea31012005-04-17 16:05:31 -05005051}
5052
James Smarte59058c2008-08-24 21:49:00 -04005053/**
James Smart3621a712009-04-06 18:47:14 -04005054 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005055 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005056 * @kobj: kernel kobject that contains the kernel class device.
5057 * @bin_attr: kernel attributes passed to us.
5058 * @buf: contains the data to be read from sysfs mbox.
5059 * @off: offset into buffer to beginning of data.
5060 * @count: bytes to transfer.
5061 *
5062 * Description:
James Smart026abb82011-12-13 13:20:45 -05005063 * Deprecated function. All mailbox access from user space is performed via the
5064 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005065 *
5066 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005067 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005068 **/
dea31012005-04-17 16:05:31 -05005069static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005070sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5071 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005072 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005073{
James Smart026abb82011-12-13 13:20:45 -05005074 return -EPERM;
dea31012005-04-17 16:05:31 -05005075}
5076
5077static struct bin_attribute sysfs_mbox_attr = {
5078 .attr = {
5079 .name = "mbox",
5080 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005081 },
James Smartc0c11512011-05-24 11:41:34 -04005082 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005083 .read = sysfs_mbox_read,
5084 .write = sysfs_mbox_write,
5085};
5086
James Smarte59058c2008-08-24 21:49:00 -04005087/**
James Smart3621a712009-04-06 18:47:14 -04005088 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005089 * @vport: address of lpfc vport structure.
5090 *
5091 * Return codes:
5092 * zero on success
5093 * error return code from sysfs_create_bin_file()
5094 **/
dea31012005-04-17 16:05:31 -05005095int
James Smart2e0fef82007-06-17 19:56:36 -05005096lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005097{
James Smart2e0fef82007-06-17 19:56:36 -05005098 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005099 int error;
5100
Tony Jonesee959b02008-02-22 00:13:36 +01005101 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005102 &sysfs_drvr_stat_data_attr);
5103
5104 /* Virtual ports do not need ctrl_reg and mbox */
5105 if (error || vport->port_type == LPFC_NPIV_PORT)
5106 goto out;
5107
5108 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005109 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005110 if (error)
James Smarteada2722008-12-04 22:39:13 -05005111 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005112
Tony Jonesee959b02008-02-22 00:13:36 +01005113 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005114 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005115 if (error)
5116 goto out_remove_ctlreg_attr;
5117
5118 return 0;
5119out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005120 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005121out_remove_stat_attr:
5122 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5123 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005124out:
5125 return error;
5126}
5127
James Smarte59058c2008-08-24 21:49:00 -04005128/**
James Smart3621a712009-04-06 18:47:14 -04005129 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005130 * @vport: address of lpfc vport structure.
5131 **/
dea31012005-04-17 16:05:31 -05005132void
James Smart2e0fef82007-06-17 19:56:36 -05005133lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005134{
James Smart2e0fef82007-06-17 19:56:36 -05005135 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005136 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5137 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005138 /* Virtual ports do not need ctrl_reg and mbox */
5139 if (vport->port_type == LPFC_NPIV_PORT)
5140 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005141 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5142 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005143}
5144
5145
5146/*
5147 * Dynamic FC Host Attributes Support
5148 */
5149
James Smarte59058c2008-08-24 21:49:00 -04005150/**
James Smart3621a712009-04-06 18:47:14 -04005151 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005152 * @shost: kernel scsi host pointer.
5153 **/
dea31012005-04-17 16:05:31 -05005154static void
5155lpfc_get_host_port_id(struct Scsi_Host *shost)
5156{
James Smart2e0fef82007-06-17 19:56:36 -05005157 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5158
dea31012005-04-17 16:05:31 -05005159 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005160 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005161}
5162
James Smarte59058c2008-08-24 21:49:00 -04005163/**
James Smart3621a712009-04-06 18:47:14 -04005164 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005165 * @shost: kernel scsi host pointer.
5166 **/
dea31012005-04-17 16:05:31 -05005167static void
5168lpfc_get_host_port_type(struct Scsi_Host *shost)
5169{
James Smart2e0fef82007-06-17 19:56:36 -05005170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5171 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005172
5173 spin_lock_irq(shost->host_lock);
5174
James Smart92d7f7b2007-06-17 19:56:38 -05005175 if (vport->port_type == LPFC_NPIV_PORT) {
5176 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5177 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005178 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005179 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005180 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5181 else
5182 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5183 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005184 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005185 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5186 else
5187 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5188 }
5189 } else
5190 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5191
5192 spin_unlock_irq(shost->host_lock);
5193}
5194
James Smarte59058c2008-08-24 21:49:00 -04005195/**
James Smart3621a712009-04-06 18:47:14 -04005196 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005197 * @shost: kernel scsi host pointer.
5198 **/
dea31012005-04-17 16:05:31 -05005199static void
5200lpfc_get_host_port_state(struct Scsi_Host *shost)
5201{
James Smart2e0fef82007-06-17 19:56:36 -05005202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5203 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005204
5205 spin_lock_irq(shost->host_lock);
5206
James Smart2e0fef82007-06-17 19:56:36 -05005207 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005208 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5209 else {
James Smart2e0fef82007-06-17 19:56:36 -05005210 switch (phba->link_state) {
5211 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005212 case LPFC_LINK_DOWN:
5213 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5214 break;
5215 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005216 case LPFC_CLEAR_LA:
5217 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005218 /* Links up, reports port state accordingly */
5219 if (vport->port_state < LPFC_VPORT_READY)
5220 fc_host_port_state(shost) =
5221 FC_PORTSTATE_BYPASSED;
5222 else
5223 fc_host_port_state(shost) =
5224 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005225 break;
5226 case LPFC_HBA_ERROR:
5227 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5228 break;
5229 default:
5230 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5231 break;
5232 }
5233 }
5234
5235 spin_unlock_irq(shost->host_lock);
5236}
5237
James Smarte59058c2008-08-24 21:49:00 -04005238/**
James Smart3621a712009-04-06 18:47:14 -04005239 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005240 * @shost: kernel scsi host pointer.
5241 **/
dea31012005-04-17 16:05:31 -05005242static void
5243lpfc_get_host_speed(struct Scsi_Host *shost)
5244{
James Smart2e0fef82007-06-17 19:56:36 -05005245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5246 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005247
5248 spin_lock_irq(shost->host_lock);
5249
James Smart2e0fef82007-06-17 19:56:36 -05005250 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05005251 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005252 case LPFC_LINK_SPEED_1GHZ:
5253 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005254 break;
James Smart76a95d72010-11-20 23:11:48 -05005255 case LPFC_LINK_SPEED_2GHZ:
5256 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005257 break;
James Smart76a95d72010-11-20 23:11:48 -05005258 case LPFC_LINK_SPEED_4GHZ:
5259 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005260 break;
James Smart76a95d72010-11-20 23:11:48 -05005261 case LPFC_LINK_SPEED_8GHZ:
5262 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005263 break;
James Smart76a95d72010-11-20 23:11:48 -05005264 case LPFC_LINK_SPEED_10GHZ:
5265 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005266 break;
James Smart76a95d72010-11-20 23:11:48 -05005267 case LPFC_LINK_SPEED_16GHZ:
5268 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5269 break;
5270 default:
5271 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005272 break;
5273 }
James Smart09372822008-01-11 01:52:54 -05005274 } else
5275 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005276
5277 spin_unlock_irq(shost->host_lock);
5278}
5279
James Smarte59058c2008-08-24 21:49:00 -04005280/**
James Smart3621a712009-04-06 18:47:14 -04005281 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005282 * @shost: kernel scsi host pointer.
5283 **/
dea31012005-04-17 16:05:31 -05005284static void
5285lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5286{
James Smart2e0fef82007-06-17 19:56:36 -05005287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5288 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005289 u64 node_name;
dea31012005-04-17 16:05:31 -05005290
5291 spin_lock_irq(shost->host_lock);
5292
James Smart73d91e52011-10-10 21:32:10 -04005293 if ((vport->port_state > LPFC_FLOGI) &&
5294 ((vport->fc_flag & FC_FABRIC) ||
5295 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5296 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005297 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005298 else
5299 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005300 node_name = 0;
dea31012005-04-17 16:05:31 -05005301
5302 spin_unlock_irq(shost->host_lock);
5303
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005304 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005305}
5306
James Smarte59058c2008-08-24 21:49:00 -04005307/**
James Smart3621a712009-04-06 18:47:14 -04005308 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005309 * @shost: kernel scsi host pointer.
5310 *
5311 * Notes:
5312 * NULL on error for link down, no mbox pool, sli2 active,
5313 * management not allowed, memory allocation error, or mbox error.
5314 *
5315 * Returns:
5316 * NULL for error
5317 * address of the adapter host statistics
5318 **/
dea31012005-04-17 16:05:31 -05005319static struct fc_host_statistics *
5320lpfc_get_stats(struct Scsi_Host *shost)
5321{
James Smart2e0fef82007-06-17 19:56:36 -05005322 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5323 struct lpfc_hba *phba = vport->phba;
5324 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005325 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005326 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005327 LPFC_MBOXQ_t *pmboxq;
5328 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005329 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005330 int rc = 0;
dea31012005-04-17 16:05:31 -05005331
James Smart92d7f7b2007-06-17 19:56:38 -05005332 /*
5333 * prevent udev from issuing mailbox commands until the port is
5334 * configured.
5335 */
James Smart2e0fef82007-06-17 19:56:36 -05005336 if (phba->link_state < LPFC_LINK_DOWN ||
5337 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005338 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005339 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005340
5341 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005342 return NULL;
5343
dea31012005-04-17 16:05:31 -05005344 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5345 if (!pmboxq)
5346 return NULL;
5347 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5348
James Smart04c68492009-05-22 14:52:52 -04005349 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005350 pmb->mbxCommand = MBX_READ_STATUS;
5351 pmb->mbxOwner = OWN_HOST;
5352 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005353 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005354
James Smart75baf692010-06-08 18:31:21 -04005355 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005356 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005357 else
dea31012005-04-17 16:05:31 -05005358 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5359
5360 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005361 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005362 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005363 return NULL;
5364 }
5365
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005366 memset(hs, 0, sizeof (struct fc_host_statistics));
5367
dea31012005-04-17 16:05:31 -05005368 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005369 /*
5370 * The MBX_READ_STATUS returns tx_k_bytes which has to
5371 * converted to words
5372 */
5373 hs->tx_words = (uint64_t)
5374 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5375 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005376 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005377 hs->rx_words = (uint64_t)
5378 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5379 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005380
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005381 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005382 pmb->mbxCommand = MBX_READ_LNK_STAT;
5383 pmb->mbxOwner = OWN_HOST;
5384 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005385 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005386
James Smart75baf692010-06-08 18:31:21 -04005387 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005388 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005389 else
dea31012005-04-17 16:05:31 -05005390 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5391
5392 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005393 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005394 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005395 return NULL;
5396 }
5397
5398 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5399 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5400 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5401 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5402 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5403 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5404 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5405
James Smart64ba8812006-08-02 15:24:34 -04005406 hs->link_failure_count -= lso->link_failure_count;
5407 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5408 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5409 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5410 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5411 hs->invalid_crc_count -= lso->invalid_crc_count;
5412 hs->error_frames -= lso->error_frames;
5413
James Smart76a95d72010-11-20 23:11:48 -05005414 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005415 hs->lip_count = -1;
5416 hs->nos_count = (phba->link_events >> 1);
5417 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005418 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005419 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005420 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005421 hs->nos_count = -1;
5422 } else {
5423 hs->lip_count = -1;
5424 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005425 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005426 }
5427
5428 hs->dumped_frames = -1;
5429
James Smart64ba8812006-08-02 15:24:34 -04005430 seconds = get_seconds();
5431 if (seconds < psli->stats_start)
5432 hs->seconds_since_last_reset = seconds +
5433 ((unsigned long)-1 - psli->stats_start);
5434 else
5435 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005436
James Smart1dcb58e2007-04-25 09:51:30 -04005437 mempool_free(pmboxq, phba->mbox_mem_pool);
5438
dea31012005-04-17 16:05:31 -05005439 return hs;
5440}
5441
James Smarte59058c2008-08-24 21:49:00 -04005442/**
James Smart3621a712009-04-06 18:47:14 -04005443 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005444 * @shost: kernel scsi host pointer.
5445 **/
James Smart64ba8812006-08-02 15:24:34 -04005446static void
5447lpfc_reset_stats(struct Scsi_Host *shost)
5448{
James Smart2e0fef82007-06-17 19:56:36 -05005449 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5450 struct lpfc_hba *phba = vport->phba;
5451 struct lpfc_sli *psli = &phba->sli;
5452 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005453 LPFC_MBOXQ_t *pmboxq;
5454 MAILBOX_t *pmb;
5455 int rc = 0;
5456
James Smart2e0fef82007-06-17 19:56:36 -05005457 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005458 return;
5459
James Smart64ba8812006-08-02 15:24:34 -04005460 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5461 if (!pmboxq)
5462 return;
5463 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5464
James Smart04c68492009-05-22 14:52:52 -04005465 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005466 pmb->mbxCommand = MBX_READ_STATUS;
5467 pmb->mbxOwner = OWN_HOST;
5468 pmb->un.varWords[0] = 0x1; /* reset request */
5469 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005470 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005471
James Smart2e0fef82007-06-17 19:56:36 -05005472 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005473 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005474 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5475 else
5476 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5477
5478 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005479 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005480 mempool_free(pmboxq, phba->mbox_mem_pool);
5481 return;
5482 }
5483
5484 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5485 pmb->mbxCommand = MBX_READ_LNK_STAT;
5486 pmb->mbxOwner = OWN_HOST;
5487 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005488 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005489
James Smart2e0fef82007-06-17 19:56:36 -05005490 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005491 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005492 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5493 else
5494 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5495
5496 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005497 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005498 mempool_free( pmboxq, phba->mbox_mem_pool);
5499 return;
5500 }
5501
5502 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5503 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5504 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5505 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5506 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5507 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5508 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005509 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005510 lso->link_events = (phba->link_events >> 1);
5511 else
5512 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005513
5514 psli->stats_start = get_seconds();
5515
James Smart1dcb58e2007-04-25 09:51:30 -04005516 mempool_free(pmboxq, phba->mbox_mem_pool);
5517
James Smart64ba8812006-08-02 15:24:34 -04005518 return;
5519}
dea31012005-04-17 16:05:31 -05005520
5521/*
5522 * The LPFC driver treats linkdown handling as target loss events so there
5523 * are no sysfs handlers for link_down_tmo.
5524 */
James Smart685f0bf2007-04-25 09:53:08 -04005525
James Smarte59058c2008-08-24 21:49:00 -04005526/**
James Smart3621a712009-04-06 18:47:14 -04005527 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005528 * @starget: kernel scsi target pointer.
5529 *
5530 * Returns:
5531 * address of the node list if found
5532 * NULL target not found
5533 **/
James Smart685f0bf2007-04-25 09:53:08 -04005534static struct lpfc_nodelist *
5535lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005536{
James Smart2e0fef82007-06-17 19:56:36 -05005537 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005539 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005540
5541 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005542 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005543 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005544 if (NLP_CHK_NODE_ACT(ndlp) &&
5545 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005546 starget->id == ndlp->nlp_sid) {
5547 spin_unlock_irq(shost->host_lock);
5548 return ndlp;
dea31012005-04-17 16:05:31 -05005549 }
5550 }
5551 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005552 return NULL;
5553}
dea31012005-04-17 16:05:31 -05005554
James Smarte59058c2008-08-24 21:49:00 -04005555/**
James Smart3621a712009-04-06 18:47:14 -04005556 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005557 * @starget: kernel scsi target pointer.
5558 **/
James Smart685f0bf2007-04-25 09:53:08 -04005559static void
5560lpfc_get_starget_port_id(struct scsi_target *starget)
5561{
5562 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5563
5564 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005565}
5566
James Smarte59058c2008-08-24 21:49:00 -04005567/**
James Smart3621a712009-04-06 18:47:14 -04005568 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005569 * @starget: kernel scsi target pointer.
5570 *
5571 * Description: Set the target node name to the ndlp node name wwn or zero.
5572 **/
dea31012005-04-17 16:05:31 -05005573static void
5574lpfc_get_starget_node_name(struct scsi_target *starget)
5575{
James Smart685f0bf2007-04-25 09:53:08 -04005576 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005577
James Smart685f0bf2007-04-25 09:53:08 -04005578 fc_starget_node_name(starget) =
5579 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005580}
5581
James Smarte59058c2008-08-24 21:49:00 -04005582/**
James Smart3621a712009-04-06 18:47:14 -04005583 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005584 * @starget: kernel scsi target pointer.
5585 *
5586 * Description: set the target port name to the ndlp port name wwn or zero.
5587 **/
dea31012005-04-17 16:05:31 -05005588static void
5589lpfc_get_starget_port_name(struct scsi_target *starget)
5590{
James Smart685f0bf2007-04-25 09:53:08 -04005591 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005592
James Smart685f0bf2007-04-25 09:53:08 -04005593 fc_starget_port_name(starget) =
5594 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005595}
5596
James Smarte59058c2008-08-24 21:49:00 -04005597/**
James Smart3621a712009-04-06 18:47:14 -04005598 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005599 * @rport: fc rport address.
5600 * @timeout: new value for dev loss tmo.
5601 *
5602 * Description:
5603 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5604 * dev_loss_tmo to one.
5605 **/
dea31012005-04-17 16:05:31 -05005606static void
dea31012005-04-17 16:05:31 -05005607lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5608{
dea31012005-04-17 16:05:31 -05005609 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005610 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005611 else
James Smartc01f3202006-08-18 17:47:08 -04005612 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005613}
5614
James Smarte59058c2008-08-24 21:49:00 -04005615/**
James Smart3621a712009-04-06 18:47:14 -04005616 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005617 *
5618 * Description:
5619 * Macro that uses field to generate a function with the name lpfc_show_rport_
5620 *
5621 * lpfc_show_rport_##field: returns the bytes formatted in buf
5622 * @cdev: class converted to an fc_rport.
5623 * @buf: on return contains the target_field or zero.
5624 *
5625 * Returns: size of formatted string.
5626 **/
dea31012005-04-17 16:05:31 -05005627#define lpfc_rport_show_function(field, format_string, sz, cast) \
5628static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005629lpfc_show_rport_##field (struct device *dev, \
5630 struct device_attribute *attr, \
5631 char *buf) \
dea31012005-04-17 16:05:31 -05005632{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005633 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005634 struct lpfc_rport_data *rdata = rport->hostdata; \
5635 return snprintf(buf, sz, format_string, \
5636 (rdata->target) ? cast rdata->target->field : 0); \
5637}
5638
5639#define lpfc_rport_rd_attr(field, format_string, sz) \
5640 lpfc_rport_show_function(field, format_string, sz, ) \
5641static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5642
James Smarteada2722008-12-04 22:39:13 -05005643/**
James Smart3621a712009-04-06 18:47:14 -04005644 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005645 * @fc_vport: The fc_vport who's symbolic name has been changed.
5646 *
5647 * Description:
5648 * This function is called by the transport after the @fc_vport's symbolic name
5649 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005650 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005651 **/
5652static void
5653lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5654{
5655 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5656
5657 if (vport->port_state == LPFC_VPORT_READY)
5658 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5659}
dea31012005-04-17 16:05:31 -05005660
James Smartf4b4c682009-05-22 14:53:12 -04005661/**
5662 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5663 * @phba: Pointer to lpfc_hba struct.
5664 *
5665 * This function is called by the lpfc_get_cfgparam() routine to set the
5666 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005667 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005668 * before hba port or vport created.
5669 **/
5670static void
5671lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5672{
5673 phba->cfg_log_verbose = verbose;
5674}
5675
dea31012005-04-17 16:05:31 -05005676struct fc_function_template lpfc_transport_functions = {
5677 /* fixed attributes the driver supports */
5678 .show_host_node_name = 1,
5679 .show_host_port_name = 1,
5680 .show_host_supported_classes = 1,
5681 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005682 .show_host_supported_speeds = 1,
5683 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005684 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005685
5686 /* dynamic attributes the driver supports */
5687 .get_host_port_id = lpfc_get_host_port_id,
5688 .show_host_port_id = 1,
5689
5690 .get_host_port_type = lpfc_get_host_port_type,
5691 .show_host_port_type = 1,
5692
5693 .get_host_port_state = lpfc_get_host_port_state,
5694 .show_host_port_state = 1,
5695
5696 /* active_fc4s is shown but doesn't change (thus no get function) */
5697 .show_host_active_fc4s = 1,
5698
5699 .get_host_speed = lpfc_get_host_speed,
5700 .show_host_speed = 1,
5701
5702 .get_host_fabric_name = lpfc_get_host_fabric_name,
5703 .show_host_fabric_name = 1,
5704
5705 /*
5706 * The LPFC driver treats linkdown handling as target loss events
5707 * so there are no sysfs handlers for link_down_tmo.
5708 */
5709
5710 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005711 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005712
5713 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5714 .show_rport_maxframe_size = 1,
5715 .show_rport_supported_classes = 1,
5716
dea31012005-04-17 16:05:31 -05005717 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5718 .show_rport_dev_loss_tmo = 1,
5719
5720 .get_starget_port_id = lpfc_get_starget_port_id,
5721 .show_starget_port_id = 1,
5722
5723 .get_starget_node_name = lpfc_get_starget_node_name,
5724 .show_starget_node_name = 1,
5725
5726 .get_starget_port_name = lpfc_get_starget_port_name,
5727 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005728
5729 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005730 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5731 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005732
James Smart92d7f7b2007-06-17 19:56:38 -05005733 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005734
5735 .vport_disable = lpfc_vport_disable,
5736
5737 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005738
5739 .bsg_request = lpfc_bsg_request,
5740 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005741};
5742
James Smart98c9ea52007-10-27 13:37:33 -04005743struct fc_function_template lpfc_vport_transport_functions = {
5744 /* fixed attributes the driver supports */
5745 .show_host_node_name = 1,
5746 .show_host_port_name = 1,
5747 .show_host_supported_classes = 1,
5748 .show_host_supported_fc4s = 1,
5749 .show_host_supported_speeds = 1,
5750 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005751 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005752
5753 /* dynamic attributes the driver supports */
5754 .get_host_port_id = lpfc_get_host_port_id,
5755 .show_host_port_id = 1,
5756
5757 .get_host_port_type = lpfc_get_host_port_type,
5758 .show_host_port_type = 1,
5759
5760 .get_host_port_state = lpfc_get_host_port_state,
5761 .show_host_port_state = 1,
5762
5763 /* active_fc4s is shown but doesn't change (thus no get function) */
5764 .show_host_active_fc4s = 1,
5765
5766 .get_host_speed = lpfc_get_host_speed,
5767 .show_host_speed = 1,
5768
5769 .get_host_fabric_name = lpfc_get_host_fabric_name,
5770 .show_host_fabric_name = 1,
5771
5772 /*
5773 * The LPFC driver treats linkdown handling as target loss events
5774 * so there are no sysfs handlers for link_down_tmo.
5775 */
5776
5777 .get_fc_host_stats = lpfc_get_stats,
5778 .reset_fc_host_stats = lpfc_reset_stats,
5779
5780 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5781 .show_rport_maxframe_size = 1,
5782 .show_rport_supported_classes = 1,
5783
5784 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5785 .show_rport_dev_loss_tmo = 1,
5786
5787 .get_starget_port_id = lpfc_get_starget_port_id,
5788 .show_starget_port_id = 1,
5789
5790 .get_starget_node_name = lpfc_get_starget_node_name,
5791 .show_starget_node_name = 1,
5792
5793 .get_starget_port_name = lpfc_get_starget_port_name,
5794 .show_starget_port_name = 1,
5795
5796 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5797 .terminate_rport_io = lpfc_terminate_rport_io,
5798
5799 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005800
5801 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005802};
5803
James Smarte59058c2008-08-24 21:49:00 -04005804/**
James Smart3621a712009-04-06 18:47:14 -04005805 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005806 * @phba: lpfc_hba pointer.
5807 **/
dea31012005-04-17 16:05:31 -05005808void
5809lpfc_get_cfgparam(struct lpfc_hba *phba)
5810{
James Smart49aa1432012-08-03 12:36:42 -04005811 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005812 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005813 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5814 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005815 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005816 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5817 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005818 lpfc_ack0_init(phba, lpfc_ack0);
5819 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005820 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005821 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04005822 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005823 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005824 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005825 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005826 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005827 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005828 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart67d12732012-08-03 12:36:13 -04005829 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005830 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5831 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart1ba981f2014-02-20 09:56:45 -05005832 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5833 if (phba->sli_rev != LPFC_SLI_REV4)
5834 phba->cfg_EnableXLane = 0;
5835 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5836 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5837 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5838 phba->cfg_oas_lun_state = 0;
5839 phba->cfg_oas_lun_status = 0;
5840 phba->cfg_oas_flags = 0;
James Smart81301a92008-12-04 22:39:46 -05005841 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005842 if (phba->sli_rev == LPFC_SLI_REV4)
5843 phba->cfg_poll = 0;
5844 else
James Smart1ba981f2014-02-20 09:56:45 -05005845 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005846 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005847 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005848 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005849 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005850 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005851 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005852 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005853 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005854 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005855 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005856 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005857 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005858 return;
5859}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005860
James Smarte59058c2008-08-24 21:49:00 -04005861/**
James Smart3621a712009-04-06 18:47:14 -04005862 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005863 * @vport: lpfc_vport pointer.
5864 **/
James Smart3de2a652007-08-02 11:09:59 -04005865void
5866lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5867{
James Smarte8b62012007-08-02 11:10:09 -04005868 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005869 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005870 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005871 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5872 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5873 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5874 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5875 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5876 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04005877 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04005878 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005879 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5880 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5881 lpfc_max_luns_init(vport, lpfc_max_luns);
5882 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005883 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005884 return;
5885}