blob: 745ba85a899350afb7a4483b23b1485b0dfff8ec [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 Smartc4a7c922013-05-31 17:04:59 -04004 * Copyright (C) 2004-2013 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040026#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040027#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070029#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050030
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_tcq.h>
35#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040036#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050037
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_hw.h"
40#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040041#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040042#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_disc.h"
44#include "lpfc_scsi.h"
45#include "lpfc.h"
46#include "lpfc_logmsg.h"
47#include "lpfc_version.h"
48#include "lpfc_compat.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050051
James Smartc01f3202006-08-18 17:47:08 -040052#define LPFC_DEF_DEVLOSS_TMO 30
53#define LPFC_MIN_DEVLOSS_TMO 1
54#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050055
James Smartf7a919b2011-08-21 21:49:16 -040056/*
57 * Write key size should be multiple of 4. If write key is changed
58 * make sure that library write key is also changed.
59 */
60#define LPFC_REG_WRITE_KEY_SIZE 4
61#define LPFC_REG_WRITE_KEY "EMLX"
62
James Smarte59058c2008-08-24 21:49:00 -040063/**
James Smart3621a712009-04-06 18:47:14 -040064 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040065 * @incr: integer to convert.
66 * @hdw: ascii string holding converted integer plus a string terminator.
67 *
68 * Description:
69 * JEDEC Joint Electron Device Engineering Council.
70 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71 * character string. The string is then terminated with a NULL in byte 9.
72 * Hex 0-9 becomes ascii '0' to '9'.
73 * Hex a-f becomes ascii '=' to 'B' capital B.
74 *
75 * Notes:
76 * Coded for 32 bit integers only.
77 **/
dea31012005-04-17 16:05:31 -050078static void
79lpfc_jedec_to_ascii(int incr, char hdw[])
80{
81 int i, j;
82 for (i = 0; i < 8; i++) {
83 j = (incr & 0xf);
84 if (j <= 9)
85 hdw[7 - i] = 0x30 + j;
86 else
87 hdw[7 - i] = 0x61 + j - 10;
88 incr = (incr >> 4);
89 }
90 hdw[8] = 0;
91 return;
92}
93
James Smarte59058c2008-08-24 21:49:00 -040094/**
James Smart3621a712009-04-06 18:47:14 -040095 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040096 * @dev: class unused variable.
97 * @attr: device attribute, not used.
98 * @buf: on return contains the module description text.
99 *
100 * Returns: size of formatted string.
101 **/
dea31012005-04-17 16:05:31 -0500102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100103lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
dea31012005-04-17 16:05:31 -0500105{
106 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
107}
108
James Smart45ed1192009-10-02 15:17:02 -0400109/**
110 * lpfc_enable_fip_show - Return the fip mode of the HBA
111 * @dev: class unused variable.
112 * @attr: device attribute, not used.
113 * @buf: on return contains the module description text.
114 *
115 * Returns: size of formatted string.
116 **/
117static ssize_t
118lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119 char *buf)
120{
121 struct Scsi_Host *shost = class_to_shost(dev);
122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
124
125 if (phba->hba_flag & HBA_FIP_SUPPORT)
126 return snprintf(buf, PAGE_SIZE, "1\n");
127 else
128 return snprintf(buf, PAGE_SIZE, "0\n");
129}
130
James Smart81301a92008-12-04 22:39:46 -0500131static ssize_t
132lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133 char *buf)
134{
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
138
139 if (phba->cfg_enable_bg)
140 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142 else
143 return snprintf(buf, PAGE_SIZE,
144 "BlockGuard Not Supported\n");
145 else
146 return snprintf(buf, PAGE_SIZE,
147 "BlockGuard Disabled\n");
148}
149
150static ssize_t
151lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152 char *buf)
153{
154 struct Scsi_Host *shost = class_to_shost(dev);
155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156 struct lpfc_hba *phba = vport->phba;
157
James Smart87b5c322008-12-16 10:34:09 -0500158 return snprintf(buf, PAGE_SIZE, "%llu\n",
159 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500160}
161
162static ssize_t
163lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164 char *buf)
165{
166 struct Scsi_Host *shost = class_to_shost(dev);
167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 struct lpfc_hba *phba = vport->phba;
169
James Smart87b5c322008-12-16 10:34:09 -0500170 return snprintf(buf, PAGE_SIZE, "%llu\n",
171 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500172}
173
174static ssize_t
175lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176 char *buf)
177{
178 struct Scsi_Host *shost = class_to_shost(dev);
179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 struct lpfc_hba *phba = vport->phba;
181
James Smart87b5c322008-12-16 10:34:09 -0500182 return snprintf(buf, PAGE_SIZE, "%llu\n",
183 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500184}
185
James Smarte59058c2008-08-24 21:49:00 -0400186/**
James Smart3621a712009-04-06 18:47:14 -0400187 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400188 * @dev: class converted to a Scsi_host structure.
189 * @attr: device attribute, not used.
190 * @buf: on return contains the formatted text from lpfc_info().
191 *
192 * Returns: size of formatted string.
193 **/
dea31012005-04-17 16:05:31 -0500194static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100195lpfc_info_show(struct device *dev, struct device_attribute *attr,
196 char *buf)
dea31012005-04-17 16:05:31 -0500197{
Tony Jonesee959b02008-02-22 00:13:36 +0100198 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500199
dea31012005-04-17 16:05:31 -0500200 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
201}
202
James Smarte59058c2008-08-24 21:49:00 -0400203/**
James Smart3621a712009-04-06 18:47:14 -0400204 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400205 * @dev: class converted to a Scsi_host structure.
206 * @attr: device attribute, not used.
207 * @buf: on return contains the formatted text serial number.
208 *
209 * Returns: size of formatted string.
210 **/
dea31012005-04-17 16:05:31 -0500211static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100212lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213 char *buf)
dea31012005-04-17 16:05:31 -0500214{
Tony Jonesee959b02008-02-22 00:13:36 +0100215 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217 struct lpfc_hba *phba = vport->phba;
218
dea31012005-04-17 16:05:31 -0500219 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
220}
221
James Smarte59058c2008-08-24 21:49:00 -0400222/**
James Smart3621a712009-04-06 18:47:14 -0400223 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400224 * @dev: class converted to a Scsi_host structure.
225 * @attr: device attribute, not used.
226 * @buf: on return contains the formatted support level.
227 *
228 * Description:
229 * Returns a number indicating the temperature sensor level currently
230 * supported, zero or one in ascii.
231 *
232 * Returns: size of formatted string.
233 **/
dea31012005-04-17 16:05:31 -0500234static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100235lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400237{
Tony Jonesee959b02008-02-22 00:13:36 +0100238 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 struct lpfc_hba *phba = vport->phba;
241 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
242}
243
James Smarte59058c2008-08-24 21:49:00 -0400244/**
James Smart3621a712009-04-06 18:47:14 -0400245 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400246 * @dev: class converted to a Scsi_host structure.
247 * @attr: device attribute, not used.
248 * @buf: on return contains the scsi vpd model description.
249 *
250 * Returns: size of formatted string.
251 **/
James Smart57127f12007-10-27 13:37:05 -0400252static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100253lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254 char *buf)
dea31012005-04-17 16:05:31 -0500255{
Tony Jonesee959b02008-02-22 00:13:36 +0100256 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258 struct lpfc_hba *phba = vport->phba;
259
dea31012005-04-17 16:05:31 -0500260 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
261}
262
James Smarte59058c2008-08-24 21:49:00 -0400263/**
James Smart3621a712009-04-06 18:47:14 -0400264 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400265 * @dev: class converted to a Scsi_host structure.
266 * @attr: device attribute, not used.
267 * @buf: on return contains the scsi vpd model name.
268 *
269 * Returns: size of formatted string.
270 **/
dea31012005-04-17 16:05:31 -0500271static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100272lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273 char *buf)
dea31012005-04-17 16:05:31 -0500274{
Tony Jonesee959b02008-02-22 00:13:36 +0100275 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277 struct lpfc_hba *phba = vport->phba;
278
dea31012005-04-17 16:05:31 -0500279 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
280}
281
James Smarte59058c2008-08-24 21:49:00 -0400282/**
James Smart3621a712009-04-06 18:47:14 -0400283 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400284 * @dev: class converted to a Scsi_host structure.
285 * @attr: device attribute, not used.
286 * @buf: on return contains the scsi vpd program type.
287 *
288 * Returns: size of formatted string.
289 **/
dea31012005-04-17 16:05:31 -0500290static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100291lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292 char *buf)
dea31012005-04-17 16:05:31 -0500293{
Tony Jonesee959b02008-02-22 00:13:36 +0100294 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500295 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296 struct lpfc_hba *phba = vport->phba;
297
dea31012005-04-17 16:05:31 -0500298 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
299}
300
James Smarte59058c2008-08-24 21:49:00 -0400301/**
James Smart3621a712009-04-06 18:47:14 -0400302 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400303 * @dev: class converted to a Scsi_host structure.
304 * @attr: device attribute, not used.
305 * @buf: on return contains the Menlo Maintenance sli flag.
306 *
307 * Returns: size of formatted string.
308 **/
309static ssize_t
310lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311{
312 struct Scsi_Host *shost = class_to_shost(dev);
313 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314 struct lpfc_hba *phba = vport->phba;
315
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
318}
319
320/**
James Smart3621a712009-04-06 18:47:14 -0400321 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400322 * @dev: class converted to a Scsi_host structure.
323 * @attr: device attribute, not used.
324 * @buf: on return contains scsi vpd program type.
325 *
326 * Returns: size of formatted string.
327 **/
dea31012005-04-17 16:05:31 -0500328static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100329lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330 char *buf)
dea31012005-04-17 16:05:31 -0500331{
Tony Jonesee959b02008-02-22 00:13:36 +0100332 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500333 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334 struct lpfc_hba *phba = vport->phba;
335
dea31012005-04-17 16:05:31 -0500336 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
337}
338
James Smarte59058c2008-08-24 21:49:00 -0400339/**
James Smart3621a712009-04-06 18:47:14 -0400340 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400341 * @dev: class converted to a Scsi_host structure.
342 * @attr: device attribute, not used.
343 * @buf: on return contains the scsi vpd program type.
344 *
345 * Returns: size of formatted string.
346 **/
dea31012005-04-17 16:05:31 -0500347static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100348lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349 char *buf)
dea31012005-04-17 16:05:31 -0500350{
Tony Jonesee959b02008-02-22 00:13:36 +0100351 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500354 uint32_t if_type;
355 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500356 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500357 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500358
dea31012005-04-17 16:05:31 -0500359 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500360 if_type = phba->sli4_hba.pc_sli4_params.if_type;
361 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
362
363 if (phba->sli_rev < LPFC_SLI_REV4)
364 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
365 fwrev, phba->sli_rev);
366 else
367 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
368 fwrev, phba->sli_rev, if_type, sli_family);
369
370 return len;
dea31012005-04-17 16:05:31 -0500371}
372
James Smarte59058c2008-08-24 21:49:00 -0400373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the scsi vpd program type.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500383{
384 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500388 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500389
dea31012005-04-17 16:05:31 -0500390 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
391 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
392}
James Smarte59058c2008-08-24 21:49:00 -0400393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains the ROM and FCode ascii strings.
399 *
400 * Returns: size of formatted string.
401 **/
dea31012005-04-17 16:05:31 -0500402static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100403lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
404 char *buf)
dea31012005-04-17 16:05:31 -0500405{
Tony Jonesee959b02008-02-22 00:13:36 +0100406 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
409
dea31012005-04-17 16:05:31 -0500410 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
411}
James Smarte59058c2008-08-24 21:49:00 -0400412
413/**
James Smart3621a712009-04-06 18:47:14 -0400414 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400415 * @dev: class converted to a Scsi_host structure.
416 * @attr: device attribute, not used.
417 * @buf: on return contains text describing the state of the link.
418 *
419 * Notes:
420 * The switch statement has no default so zero will be returned.
421 *
422 * Returns: size of formatted string.
423 **/
dea31012005-04-17 16:05:31 -0500424static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100425lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
426 char *buf)
dea31012005-04-17 16:05:31 -0500427{
Tony Jonesee959b02008-02-22 00:13:36 +0100428 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
430 struct lpfc_hba *phba = vport->phba;
431 int len = 0;
432
433 switch (phba->link_state) {
434 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500435 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500436 case LPFC_INIT_START:
437 case LPFC_INIT_MBX_CMDS:
438 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500439 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400440 if (phba->hba_flag & LINK_DISABLED)
441 len += snprintf(buf + len, PAGE_SIZE-len,
442 "Link Down - User disabled\n");
443 else
444 len += snprintf(buf + len, PAGE_SIZE-len,
445 "Link Down\n");
dea31012005-04-17 16:05:31 -0500446 break;
447 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500448 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500449 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400450 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500451
452 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500453 case LPFC_LOCAL_CFG_LINK:
454 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500455 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500456 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500457 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500458 case LPFC_FLOGI:
459 case LPFC_FABRIC_CFG_LINK:
460 case LPFC_NS_REG:
461 case LPFC_NS_QRY:
462 case LPFC_BUILD_DISC_LIST:
463 case LPFC_DISC_AUTH:
464 len += snprintf(buf + len, PAGE_SIZE - len,
465 "Discovery\n");
466 break;
467 case LPFC_VPORT_READY:
468 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
469 break;
470
James Smart92d7f7b2007-06-17 19:56:38 -0500471 case LPFC_VPORT_FAILED:
472 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
473 break;
474
475 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500476 len += snprintf(buf + len, PAGE_SIZE - len,
477 "Unknown\n");
478 break;
479 }
James Smart84774a42008-08-24 21:50:06 -0400480 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
481 len += snprintf(buf + len, PAGE_SIZE-len,
482 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500483 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500484 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500485 len += snprintf(buf + len, PAGE_SIZE-len,
486 " Public Loop\n");
487 else
488 len += snprintf(buf + len, PAGE_SIZE-len,
489 " Private Loop\n");
490 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500491 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500492 len += snprintf(buf + len, PAGE_SIZE-len,
493 " Fabric\n");
494 else
495 len += snprintf(buf + len, PAGE_SIZE-len,
496 " Point-2-Point\n");
497 }
498 }
James Smart2e0fef82007-06-17 19:56:36 -0500499
dea31012005-04-17 16:05:31 -0500500 return len;
501}
502
James Smarte59058c2008-08-24 21:49:00 -0400503/**
James Smart026abb82011-12-13 13:20:45 -0500504 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
505 * @dev: class unused variable.
506 * @attr: device attribute, not used.
507 * @buf: on return contains the module description text.
508 *
509 * Returns: size of formatted string.
510 **/
511static ssize_t
512lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
513 char *buf)
514{
515 struct Scsi_Host *shost = class_to_shost(dev);
516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
518
519 if (phba->sli_rev < LPFC_SLI_REV4)
520 return snprintf(buf, PAGE_SIZE, "fc\n");
521
522 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
523 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
524 return snprintf(buf, PAGE_SIZE, "fcoe\n");
525 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
526 return snprintf(buf, PAGE_SIZE, "fc\n");
527 }
528 return snprintf(buf, PAGE_SIZE, "unknown\n");
529}
530
531/**
James Smart84d1b002010-02-12 14:42:33 -0500532 * lpfc_link_state_store - Transition the link_state on an HBA port
533 * @dev: class device that is converted into a Scsi_host.
534 * @attr: device attribute, not used.
535 * @buf: one or more lpfc_polling_flags values.
536 * @count: not used.
537 *
538 * Returns:
539 * -EINVAL if the buffer is not "up" or "down"
540 * return from link state change function if non-zero
541 * length of the buf on success
542 **/
543static ssize_t
544lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
545 const char *buf, size_t count)
546{
547 struct Scsi_Host *shost = class_to_shost(dev);
548 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
549 struct lpfc_hba *phba = vport->phba;
550
551 int status = -EINVAL;
552
553 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
554 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400555 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500556 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
557 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400558 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500559
560 if (status == 0)
561 return strlen(buf);
562 else
563 return status;
564}
565
566/**
James Smart3621a712009-04-06 18:47:14 -0400567 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400568 * @dev: class device that is converted into a Scsi_host.
569 * @attr: device attribute, not used.
570 * @buf: on return contains the sum of fc mapped and unmapped.
571 *
572 * Description:
573 * Returns the ascii text number of the sum of the fc mapped and unmapped
574 * vport counts.
575 *
576 * Returns: size of formatted string.
577 **/
dea31012005-04-17 16:05:31 -0500578static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100579lpfc_num_discovered_ports_show(struct device *dev,
580 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500581{
Tony Jonesee959b02008-02-22 00:13:36 +0100582 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584
585 return snprintf(buf, PAGE_SIZE, "%d\n",
586 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500587}
588
James Smarte59058c2008-08-24 21:49:00 -0400589/**
James Smart3621a712009-04-06 18:47:14 -0400590 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400591 * @shost: Scsi_Host pointer.
592 *
593 * Description:
594 * Bring the link down gracefully then re-init the link. The firmware will
595 * re-init the fiber channel interface as required. Does not issue a LIP.
596 *
597 * Returns:
598 * -EPERM port offline or management commands are being blocked
599 * -ENOMEM cannot allocate memory for the mailbox command
600 * -EIO error sending the mailbox command
601 * zero for success
602 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700603static int
James Smart2e0fef82007-06-17 19:56:36 -0500604lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500605{
James Smart2e0fef82007-06-17 19:56:36 -0500606 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
607 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500608 LPFC_MBOXQ_t *pmboxq;
609 int mbxstatus = MBXERR_ERROR;
610
James Smart2e0fef82007-06-17 19:56:36 -0500611 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500612 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500613 return -EPERM;
614
615 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
616
617 if (!pmboxq)
618 return -ENOMEM;
619
620 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400621 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
622 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400623
James Smart33ccf8d2006-08-17 11:57:58 -0400624 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500625
James Smart04c68492009-05-22 14:52:52 -0400626 if ((mbxstatus == MBX_SUCCESS) &&
627 (pmboxq->u.mb.mbxStatus == 0 ||
628 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400629 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
630 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
631 phba->cfg_link_speed);
632 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
633 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400634 if ((mbxstatus == MBX_SUCCESS) &&
635 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
636 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
637 "2859 SLI authentication is required "
638 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400639 }
640
James Smart5b8bd0c2007-04-25 09:52:49 -0400641 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500642 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400643 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500644
645 if (mbxstatus == MBXERR_ERROR)
646 return -EIO;
647
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700648 return 0;
dea31012005-04-17 16:05:31 -0500649}
650
James Smarte59058c2008-08-24 21:49:00 -0400651/**
James Smart3621a712009-04-06 18:47:14 -0400652 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400653 * @phba: lpfc_hba pointer.
654 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
655 *
656 * Notes:
657 * Assumes any error from lpfc_do_offline() will be negative.
658 * Can wait up to 5 seconds for the port ring buffers count
659 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400660 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400661 *
662 * Returns:
663 * -EIO error posting the event
664 * zero for success
665 **/
James Smart40496f02006-07-06 15:50:22 -0400666static int
James Smart46fa3112007-04-25 09:51:45 -0400667lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
668{
669 struct completion online_compl;
670 struct lpfc_sli_ring *pring;
671 struct lpfc_sli *psli;
672 int status = 0;
673 int cnt = 0;
674 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500675 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400676
677 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500678 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400679 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500680 if (rc == 0)
681 return -ENOMEM;
682
James Smart46fa3112007-04-25 09:51:45 -0400683 wait_for_completion(&online_compl);
684
685 if (status != 0)
686 return -EIO;
687
688 psli = &phba->sli;
689
James Smart09372822008-01-11 01:52:54 -0500690 /* Wait a little for things to settle down, but not
691 * long enough for dev loss timeout to expire.
692 */
James Smart46fa3112007-04-25 09:51:45 -0400693 for (i = 0; i < psli->num_rings; i++) {
694 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500695 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400696 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500697 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400698 lpfc_printf_log(phba,
699 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400700 "0466 Outstanding IO when "
701 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400702 break;
703 }
704 }
705 }
706
707 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500708 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
709 if (rc == 0)
710 return -ENOMEM;
711
James Smart46fa3112007-04-25 09:51:45 -0400712 wait_for_completion(&online_compl);
713
714 if (status != 0)
715 return -EIO;
716
717 return 0;
718}
719
James Smarte59058c2008-08-24 21:49:00 -0400720/**
James Smart3621a712009-04-06 18:47:14 -0400721 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400722 * @phba: lpfc_hba pointer.
723 *
724 * Description:
725 * If the port is configured to allow a reset then the hba is brought
726 * offline then online.
727 *
728 * Notes:
729 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500730 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400731 *
732 * Returns:
733 * lpfc_do_offline() return code if not zero
734 * -EIO reset not configured or error posting the event
735 * zero for success
736 **/
James Smart7f860592011-03-11 16:05:52 -0500737int
James Smart40496f02006-07-06 15:50:22 -0400738lpfc_selective_reset(struct lpfc_hba *phba)
739{
740 struct completion online_compl;
741 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500742 int rc;
James Smart40496f02006-07-06 15:50:22 -0400743
James Smart71157c92013-07-15 18:34:36 -0400744 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400745 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500746
James Smart71157c92013-07-15 18:34:36 -0400747 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
748 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400749
James Smart71157c92013-07-15 18:34:36 -0400750 if (status != 0)
751 return status;
752 }
James Smart40496f02006-07-06 15:50:22 -0400753
754 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500755 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400756 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500757 if (rc == 0)
758 return -ENOMEM;
759
James Smart40496f02006-07-06 15:50:22 -0400760 wait_for_completion(&online_compl);
761
762 if (status != 0)
763 return -EIO;
764
765 return 0;
766}
767
James Smarte59058c2008-08-24 21:49:00 -0400768/**
James Smart3621a712009-04-06 18:47:14 -0400769 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400770 * @dev: class device that is converted into a Scsi_host.
771 * @attr: device attribute, not used.
772 * @buf: containing the string "selective".
773 * @count: unused variable.
774 *
775 * Description:
776 * If the buf contains the string "selective" then lpfc_selective_reset()
777 * is called to perform the reset.
778 *
779 * Notes:
780 * Assumes any error from lpfc_selective_reset() will be negative.
781 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200782 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400783 *
784 * Returns:
785 * -EINVAL if the buffer does not contain the string "selective"
786 * length of buf if lpfc-selective_reset() if the call succeeds
787 * return value of lpfc_selective_reset() if the call fails
788**/
James Smart40496f02006-07-06 15:50:22 -0400789static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100790lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
791 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400792{
Tony Jonesee959b02008-02-22 00:13:36 +0100793 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500794 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
795 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400796 int status = -EINVAL;
797
James Smart73d91e52011-10-10 21:32:10 -0400798 if (!phba->cfg_enable_hba_reset)
799 return -EACCES;
800
James Smart40496f02006-07-06 15:50:22 -0400801 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500802 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400803
804 if (status == 0)
805 return strlen(buf);
806 else
807 return status;
808}
809
James Smarte59058c2008-08-24 21:49:00 -0400810/**
James Smart88a2cfb2011-07-22 18:36:33 -0400811 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
812 * @phba: lpfc_hba pointer.
813 *
814 * Description:
815 * SLI4 interface type-2 device to wait on the sliport status register for
816 * the readyness after performing a firmware reset.
817 *
818 * Returns:
James Smart026abb82011-12-13 13:20:45 -0500819 * zero for success, -EPERM when port does not have privilage to perform the
820 * reset, -EIO when port timeout from recovering from the reset.
821 *
822 * Note:
823 * As the caller will interpret the return code by value, be careful in making
824 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400825 **/
James Smart73d91e52011-10-10 21:32:10 -0400826int
James Smart88a2cfb2011-07-22 18:36:33 -0400827lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
828{
James Smartf7a919b2011-08-21 21:49:16 -0400829 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400830 int i;
831
James Smartf7a919b2011-08-21 21:49:16 -0400832 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400833 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
834 &portstat_reg.word0);
835
James Smartf7a919b2011-08-21 21:49:16 -0400836 /* verify if privilaged for the request operation */
837 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
838 !bf_get(lpfc_sliport_status_err, &portstat_reg))
839 return -EPERM;
840
James Smart88a2cfb2011-07-22 18:36:33 -0400841 /* wait for the SLI port firmware ready after firmware reset */
842 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
843 msleep(10);
844 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
845 &portstat_reg.word0);
846 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
847 continue;
848 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
849 continue;
850 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
851 continue;
852 break;
853 }
854
855 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
856 return 0;
857 else
858 return -EIO;
859}
860
861/**
James Smart52d52442011-05-24 11:42:45 -0400862 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400863 * @phba: lpfc_hba pointer.
864 *
865 * Description:
James Smart52d52442011-05-24 11:42:45 -0400866 * Request SLI4 interface type-2 device to perform a physical register set
867 * access.
James Smartc0c11512011-05-24 11:41:34 -0400868 *
869 * Returns:
870 * zero for success
871 **/
872static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400873lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400874{
875 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400876 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500877 uint32_t before_fc_flag;
878 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400879 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500880 int status = 0, rc = 0;
881 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400882
883 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400884 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400885
James Smart52d52442011-05-24 11:42:45 -0400886 if ((phba->sli_rev < LPFC_SLI_REV4) ||
887 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
888 LPFC_SLI_INTF_IF_TYPE_2))
889 return -EPERM;
890
James Smart026abb82011-12-13 13:20:45 -0500891 /* Keep state if we need to restore back */
892 before_fc_flag = phba->pport->fc_flag;
893 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
894
James Smartb76f2dc2011-07-22 18:37:42 -0400895 /* Disable SR-IOV virtual functions if enabled */
896 if (phba->cfg_sriov_nr_virtfn) {
897 pci_disable_sriov(pdev);
898 phba->cfg_sriov_nr_virtfn = 0;
899 }
James Smart229adb02013-04-17 20:16:51 -0400900
James Smartc0c11512011-05-24 11:41:34 -0400901 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
902
903 if (status != 0)
904 return status;
905
906 /* wait for the device to be quiesced before firmware reset */
907 msleep(100);
908
909 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
910 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400911
912 if (opcode == LPFC_FW_DUMP)
913 reg_val |= LPFC_FW_DUMP_REQUEST;
914 else if (opcode == LPFC_FW_RESET)
915 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
916 else if (opcode == LPFC_DV_RESET)
917 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
918
James Smartc0c11512011-05-24 11:41:34 -0400919 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
920 LPFC_CTL_PDEV_CTL_OFFSET);
921 /* flush */
922 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
923
924 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400925 rc = lpfc_sli4_pdev_status_reg_wait(phba);
926
James Smart026abb82011-12-13 13:20:45 -0500927 if (rc == -EPERM) {
James Smart6b5151f2012-01-18 16:24:06 -0500928 /* no privilage for reset */
929 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
930 "3150 No privilage to perform the requested "
931 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500932 } else if (rc == -EIO) {
933 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500934 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
935 "3153 Fail to perform the requested "
936 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400937 return rc;
James Smart026abb82011-12-13 13:20:45 -0500938 }
939
940 /* keep the original port state */
941 if (before_fc_flag & FC_OFFLINE_MODE)
942 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400943
944 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500945 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
946 LPFC_EVT_ONLINE);
947 if (!job_posted)
948 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400949
950 wait_for_completion(&online_compl);
951
James Smart026abb82011-12-13 13:20:45 -0500952out:
953 /* in any case, restore the virtual functions enabled as before */
954 if (sriov_nr_virtfn) {
955 sriov_err =
956 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
957 if (!sriov_err)
958 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
959 }
James Smartc0c11512011-05-24 11:41:34 -0400960
James Smart026abb82011-12-13 13:20:45 -0500961 /* return proper error code */
962 if (!rc) {
963 if (!job_posted)
964 rc = -ENOMEM;
965 else if (status)
966 rc = -EIO;
967 }
968 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400969}
970
971/**
James Smart3621a712009-04-06 18:47:14 -0400972 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400973 * @dev: class device that is converted into a Scsi_host.
974 * @attr: device attribute, not used.
975 * @buf: on return contains the ascii number of nport events.
976 *
977 * Returns: size of formatted string.
978 **/
dea31012005-04-17 16:05:31 -0500979static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100980lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
981 char *buf)
dea31012005-04-17 16:05:31 -0500982{
Tony Jonesee959b02008-02-22 00:13:36 +0100983 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
985 struct lpfc_hba *phba = vport->phba;
986
dea31012005-04-17 16:05:31 -0500987 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
988}
989
James Smarte59058c2008-08-24 21:49:00 -0400990/**
James Smart3621a712009-04-06 18:47:14 -0400991 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400992 * @dev: class device that is converted into a Scsi_host.
993 * @attr: device attribute, not used.
994 * @buf: on return contains the state of the adapter.
995 *
996 * Returns: size of formatted string.
997 **/
dea31012005-04-17 16:05:31 -0500998static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100999lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1000 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001001{
Tony Jonesee959b02008-02-22 00:13:36 +01001002 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001003 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1004 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001005 char * state;
1006
James Smart2e0fef82007-06-17 19:56:36 -05001007 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001008 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001009 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001010 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001011 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001012 state = "offline";
1013 else
1014 state = "online";
1015
1016 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1017}
1018
James Smarte59058c2008-08-24 21:49:00 -04001019/**
James Smart3621a712009-04-06 18:47:14 -04001020 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001021 * @dev: class device that is converted into a Scsi_host.
1022 * @attr: device attribute, not used.
1023 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1024 * @count: unused variable.
1025 *
1026 * Returns:
1027 * -EACCES if enable hba reset not enabled
1028 * -EINVAL if the buffer does not contain a valid string (see above)
1029 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1030 * buf length greater than zero indicates success
1031 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001032static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001033lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1034 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001035{
Tony Jonesee959b02008-02-22 00:13:36 +01001036 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001037 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1038 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001039 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001040 char *board_mode_str = NULL;
1041 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001042 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001043
James Smart026abb82011-12-13 13:20:45 -05001044 if (!phba->cfg_enable_hba_reset) {
1045 status = -EACCES;
1046 goto board_mode_out;
1047 }
James Smart88a2cfb2011-07-22 18:36:33 -04001048
1049 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001050 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001051
Jamie Wellnitz41415862006-02-28 19:25:27 -05001052 init_completion(&online_compl);
1053
James Smart46fa3112007-04-25 09:51:45 -04001054 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001055 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001056 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001057 if (rc == 0) {
1058 status = -ENOMEM;
1059 goto board_mode_out;
1060 }
James Smart46fa3112007-04-25 09:51:45 -04001061 wait_for_completion(&online_compl);
1062 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1063 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001064 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001065 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001066 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001067 else
1068 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001069 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001070 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001071 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001072 else
1073 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001074 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001075 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1076 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1077 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1078 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1079 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001080 else
James Smart026abb82011-12-13 13:20:45 -05001081 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001082
James Smart026abb82011-12-13 13:20:45 -05001083board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001084 if (!status)
1085 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001086 else {
1087 board_mode_str = strchr(buf, '\n');
1088 if (board_mode_str)
1089 *board_mode_str = '\0';
1090 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1091 "3097 Failed \"%s\", status(%d), "
1092 "fc_flag(x%x)\n",
1093 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001094 return status;
James Smart026abb82011-12-13 13:20:45 -05001095 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001096}
1097
James Smarte59058c2008-08-24 21:49:00 -04001098/**
James Smart3621a712009-04-06 18:47:14 -04001099 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001100 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001101 * @mxri: max xri count.
1102 * @axri: available xri count.
1103 * @mrpi: max rpi count.
1104 * @arpi: available rpi count.
1105 * @mvpi: max vpi count.
1106 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001107 *
1108 * Description:
1109 * If an integer pointer for an count is not null then the value for the
1110 * count is returned.
1111 *
1112 * Returns:
1113 * zero on error
1114 * one for success
1115 **/
James Smart311464e2007-08-02 11:10:37 -04001116static int
James Smart858c9f62007-06-17 19:56:39 -05001117lpfc_get_hba_info(struct lpfc_hba *phba,
1118 uint32_t *mxri, uint32_t *axri,
1119 uint32_t *mrpi, uint32_t *arpi,
1120 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001121{
James Smart04c68492009-05-22 14:52:52 -04001122 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001123 LPFC_MBOXQ_t *pmboxq;
1124 MAILBOX_t *pmb;
1125 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001126 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001127
1128 /*
1129 * prevent udev from issuing mailbox commands until the port is
1130 * configured.
1131 */
1132 if (phba->link_state < LPFC_LINK_DOWN ||
1133 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001134 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001135 return 0;
1136
1137 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1138 return 0;
1139
1140 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1141 if (!pmboxq)
1142 return 0;
1143 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1144
James Smart04c68492009-05-22 14:52:52 -04001145 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001146 pmb->mbxCommand = MBX_READ_CONFIG;
1147 pmb->mbxOwner = OWN_HOST;
1148 pmboxq->context1 = NULL;
1149
James Smart75baf692010-06-08 18:31:21 -04001150 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001151 rc = MBX_NOT_FINISHED;
1152 else
1153 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1154
1155 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001156 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001157 mempool_free(pmboxq, phba->mbox_mem_pool);
1158 return 0;
1159 }
1160
James Smartda0436e2009-05-22 14:51:39 -04001161 if (phba->sli_rev == LPFC_SLI_REV4) {
1162 rd_config = &pmboxq->u.mqe.un.rd_config;
1163 if (mrpi)
1164 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1165 if (arpi)
1166 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1167 phba->sli4_hba.max_cfg_param.rpi_used;
1168 if (mxri)
1169 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1170 if (axri)
1171 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1172 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001173
1174 /* Account for differences with SLI-3. Get vpi count from
1175 * mailbox data and subtract one for max vpi value.
1176 */
1177 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1178 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1179
James Smartda0436e2009-05-22 14:51:39 -04001180 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001181 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001182 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001183 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001184 } else {
1185 if (mrpi)
1186 *mrpi = pmb->un.varRdConfig.max_rpi;
1187 if (arpi)
1188 *arpi = pmb->un.varRdConfig.avail_rpi;
1189 if (mxri)
1190 *mxri = pmb->un.varRdConfig.max_xri;
1191 if (axri)
1192 *axri = pmb->un.varRdConfig.avail_xri;
1193 if (mvpi)
1194 *mvpi = pmb->un.varRdConfig.max_vpi;
1195 if (avpi)
1196 *avpi = pmb->un.varRdConfig.avail_vpi;
1197 }
James Smart92d7f7b2007-06-17 19:56:38 -05001198
1199 mempool_free(pmboxq, phba->mbox_mem_pool);
1200 return 1;
1201}
1202
James Smarte59058c2008-08-24 21:49:00 -04001203/**
James Smart3621a712009-04-06 18:47:14 -04001204 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001205 * @dev: class device that is converted into a Scsi_host.
1206 * @attr: device attribute, not used.
1207 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1208 *
1209 * Description:
1210 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1211 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1212 * to "Unknown" and the buffer length is returned, therefore the caller
1213 * must check for "Unknown" in the buffer to detect a failure.
1214 *
1215 * Returns: size of formatted string.
1216 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001217static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001218lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1219 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001220{
Tony Jonesee959b02008-02-22 00:13:36 +01001221 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1223 struct lpfc_hba *phba = vport->phba;
1224 uint32_t cnt;
1225
James Smart858c9f62007-06-17 19:56:39 -05001226 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001227 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1228 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1229}
1230
James Smarte59058c2008-08-24 21:49:00 -04001231/**
James Smart3621a712009-04-06 18:47:14 -04001232 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001233 * @dev: class device that is converted into a Scsi_host.
1234 * @attr: device attribute, not used.
1235 * @buf: containing the used rpi count in decimal or "Unknown".
1236 *
1237 * Description:
1238 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1239 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1240 * to "Unknown" and the buffer length is returned, therefore the caller
1241 * must check for "Unknown" in the buffer to detect a failure.
1242 *
1243 * Returns: size of formatted string.
1244 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001245static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001246lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1247 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001248{
Tony Jonesee959b02008-02-22 00:13:36 +01001249 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001250 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1251 struct lpfc_hba *phba = vport->phba;
1252 uint32_t cnt, acnt;
1253
James Smart858c9f62007-06-17 19:56:39 -05001254 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001255 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1256 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1257}
1258
James Smarte59058c2008-08-24 21:49:00 -04001259/**
James Smart3621a712009-04-06 18:47:14 -04001260 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001261 * @dev: class device that is converted into a Scsi_host.
1262 * @attr: device attribute, not used.
1263 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1264 *
1265 * Description:
1266 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1267 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1268 * to "Unknown" and the buffer length is returned, therefore the caller
1269 * must check for "Unknown" in the buffer to detect a failure.
1270 *
1271 * Returns: size of formatted string.
1272 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001273static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001274lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1275 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001276{
Tony Jonesee959b02008-02-22 00:13:36 +01001277 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001278 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1279 struct lpfc_hba *phba = vport->phba;
1280 uint32_t cnt;
1281
James Smart858c9f62007-06-17 19:56:39 -05001282 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001283 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1284 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1285}
1286
James Smarte59058c2008-08-24 21:49:00 -04001287/**
James Smart3621a712009-04-06 18:47:14 -04001288 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001289 * @dev: class device that is converted into a Scsi_host.
1290 * @attr: device attribute, not used.
1291 * @buf: on return contains the used xri count in decimal or "Unknown".
1292 *
1293 * Description:
1294 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1295 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1296 * to "Unknown" and the buffer length is returned, therefore the caller
1297 * must check for "Unknown" in the buffer to detect a failure.
1298 *
1299 * Returns: size of formatted string.
1300 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001301static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001302lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1303 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001304{
Tony Jonesee959b02008-02-22 00:13:36 +01001305 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1307 struct lpfc_hba *phba = vport->phba;
1308 uint32_t cnt, acnt;
1309
James Smart858c9f62007-06-17 19:56:39 -05001310 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1311 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1312 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1313}
1314
James Smarte59058c2008-08-24 21:49:00 -04001315/**
James Smart3621a712009-04-06 18:47:14 -04001316 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001317 * @dev: class device that is converted into a Scsi_host.
1318 * @attr: device attribute, not used.
1319 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1320 *
1321 * Description:
1322 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1323 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1324 * to "Unknown" and the buffer length is returned, therefore the caller
1325 * must check for "Unknown" in the buffer to detect a failure.
1326 *
1327 * Returns: size of formatted string.
1328 **/
James Smart858c9f62007-06-17 19:56:39 -05001329static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001330lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1331 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001332{
Tony Jonesee959b02008-02-22 00:13:36 +01001333 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1335 struct lpfc_hba *phba = vport->phba;
1336 uint32_t cnt;
1337
1338 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1339 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1340 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1341}
1342
James Smarte59058c2008-08-24 21:49:00 -04001343/**
James Smart3621a712009-04-06 18:47:14 -04001344 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001345 * @dev: class device that is converted into a Scsi_host.
1346 * @attr: device attribute, not used.
1347 * @buf: on return contains the used vpi count in decimal or "Unknown".
1348 *
1349 * Description:
1350 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1351 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1352 * to "Unknown" and the buffer length is returned, therefore the caller
1353 * must check for "Unknown" in the buffer to detect a failure.
1354 *
1355 * Returns: size of formatted string.
1356 **/
James Smart858c9f62007-06-17 19:56:39 -05001357static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001358lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1359 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001360{
Tony Jonesee959b02008-02-22 00:13:36 +01001361 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001362 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1363 struct lpfc_hba *phba = vport->phba;
1364 uint32_t cnt, acnt;
1365
1366 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001367 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1368 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1369}
1370
James Smarte59058c2008-08-24 21:49:00 -04001371/**
James Smart3621a712009-04-06 18:47:14 -04001372 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001373 * @dev: class device that is converted into a Scsi_host.
1374 * @attr: device attribute, not used.
1375 * @buf: text that must be interpreted to determine if npiv is supported.
1376 *
1377 * Description:
1378 * Buffer will contain text indicating npiv is not suppoerted on the port,
1379 * the port is an NPIV physical port, or it is an npiv virtual port with
1380 * the id of the vport.
1381 *
1382 * Returns: size of formatted string.
1383 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001384static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001385lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1386 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001387{
Tony Jonesee959b02008-02-22 00:13:36 +01001388 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1390 struct lpfc_hba *phba = vport->phba;
1391
1392 if (!(phba->max_vpi))
1393 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1394 if (vport->port_type == LPFC_PHYSICAL_PORT)
1395 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1396 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1397}
1398
James Smarte59058c2008-08-24 21:49:00 -04001399/**
James Smart3621a712009-04-06 18:47:14 -04001400 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001401 * @dev: class device that is converted into a Scsi_host.
1402 * @attr: device attribute, not used.
1403 * @buf: on return contains the cfg_poll in hex.
1404 *
1405 * Notes:
1406 * cfg_poll should be a lpfc_polling_flags type.
1407 *
1408 * Returns: size of formatted string.
1409 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001410static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001411lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1412 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001413{
Tony Jonesee959b02008-02-22 00:13:36 +01001414 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1416 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001417
1418 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1419}
1420
James Smarte59058c2008-08-24 21:49:00 -04001421/**
James Smart3621a712009-04-06 18:47:14 -04001422 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001423 * @dev: class device that is converted into a Scsi_host.
1424 * @attr: device attribute, not used.
1425 * @buf: one or more lpfc_polling_flags values.
1426 * @count: not used.
1427 *
1428 * Notes:
1429 * buf contents converted to integer and checked for a valid value.
1430 *
1431 * Returns:
1432 * -EINVAL if the buffer connot be converted or is out of range
1433 * length of the buf on success
1434 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001435static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001436lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1437 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001438{
Tony Jonesee959b02008-02-22 00:13:36 +01001439 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001440 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1441 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001442 uint32_t creg_val;
1443 uint32_t old_val;
1444 int val=0;
1445
1446 if (!isdigit(buf[0]))
1447 return -EINVAL;
1448
1449 if (sscanf(buf, "%i", &val) != 1)
1450 return -EINVAL;
1451
1452 if ((val & 0x3) != val)
1453 return -EINVAL;
1454
James Smart45ed1192009-10-02 15:17:02 -04001455 if (phba->sli_rev == LPFC_SLI_REV4)
1456 val = 0;
1457
James Smart88a2cfb2011-07-22 18:36:33 -04001458 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1459 "3051 lpfc_poll changed from %d to %d\n",
1460 phba->cfg_poll, val);
1461
James Smart2e0fef82007-06-17 19:56:36 -05001462 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001463
1464 old_val = phba->cfg_poll;
1465
1466 if (val & ENABLE_FCP_RING_POLLING) {
1467 if ((val & DISABLE_FCP_RING_INT) &&
1468 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001469 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1470 spin_unlock_irq(&phba->hbalock);
1471 return -EINVAL;
1472 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001473 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1474 writel(creg_val, phba->HCregaddr);
1475 readl(phba->HCregaddr); /* flush */
1476
1477 lpfc_poll_start_timer(phba);
1478 }
1479 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001480 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001481 return -EINVAL;
1482 }
1483
1484 if (!(val & DISABLE_FCP_RING_INT) &&
1485 (old_val & DISABLE_FCP_RING_INT))
1486 {
James Smart2e0fef82007-06-17 19:56:36 -05001487 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001488 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001489 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001490 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1491 spin_unlock_irq(&phba->hbalock);
1492 return -EINVAL;
1493 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001494 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1495 writel(creg_val, phba->HCregaddr);
1496 readl(phba->HCregaddr); /* flush */
1497 }
1498
1499 phba->cfg_poll = val;
1500
James Smart2e0fef82007-06-17 19:56:36 -05001501 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001502
1503 return strlen(buf);
1504}
dea31012005-04-17 16:05:31 -05001505
James Smarte59058c2008-08-24 21:49:00 -04001506/**
James Smartbc739052010-08-04 16:11:18 -04001507 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1508 * @dev: class unused variable.
1509 * @attr: device attribute, not used.
1510 * @buf: on return contains the module description text.
1511 *
1512 * Returns: size of formatted string.
1513 **/
1514static ssize_t
1515lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1516 char *buf)
1517{
1518 struct Scsi_Host *shost = class_to_shost(dev);
1519 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1520 struct lpfc_hba *phba = vport->phba;
1521
1522 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1523}
1524
1525/**
1526 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1527 * @dev: class unused variable.
1528 * @attr: device attribute, not used.
1529 * @buf: on return contains the module description text.
1530 *
1531 * Returns: size of formatted string.
1532 **/
1533static ssize_t
1534lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1535 char *buf)
1536{
1537 struct Scsi_Host *shost = class_to_shost(dev);
1538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1539 struct lpfc_hba *phba = vport->phba;
1540
1541 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1542}
1543
1544/**
James Smartab56dc22011-02-16 12:39:57 -05001545 * lpfc_dss_show - Return the current state of dss and the configured state
1546 * @dev: class converted to a Scsi_host structure.
1547 * @attr: device attribute, not used.
1548 * @buf: on return contains the formatted text.
1549 *
1550 * Returns: size of formatted string.
1551 **/
1552static ssize_t
1553lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1554 char *buf)
1555{
1556 struct Scsi_Host *shost = class_to_shost(dev);
1557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1558 struct lpfc_hba *phba = vport->phba;
1559
1560 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1561 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1562 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1563 "" : "Not ");
1564}
1565
1566/**
James Smart912e3ac2011-05-24 11:42:11 -04001567 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1568 * @dev: class converted to a Scsi_host structure.
1569 * @attr: device attribute, not used.
1570 * @buf: on return contains the formatted support level.
1571 *
1572 * Description:
1573 * Returns the maximum number of virtual functions a physical function can
1574 * support, 0 will be returned if called on virtual function.
1575 *
1576 * Returns: size of formatted string.
1577 **/
1578static ssize_t
1579lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1580 struct device_attribute *attr,
1581 char *buf)
1582{
1583 struct Scsi_Host *shost = class_to_shost(dev);
1584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1585 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001586 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001587
James Smart0a96e972011-07-22 18:37:28 -04001588 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1589 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001590}
1591
1592/**
James Smart3621a712009-04-06 18:47:14 -04001593 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001594 *
1595 * Description:
1596 * Macro that given an attr e.g. hba_queue_depth expands
1597 * into a function with the name lpfc_hba_queue_depth_show.
1598 *
1599 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1600 * @dev: class device that is converted into a Scsi_host.
1601 * @attr: device attribute, not used.
1602 * @buf: on return contains the attribute value in decimal.
1603 *
1604 * Returns: size of formatted string.
1605 **/
dea31012005-04-17 16:05:31 -05001606#define lpfc_param_show(attr) \
1607static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001608lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1609 char *buf) \
dea31012005-04-17 16:05:31 -05001610{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001611 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001612 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1613 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001614 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001615 val = phba->cfg_##attr;\
1616 return snprintf(buf, PAGE_SIZE, "%d\n",\
1617 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001618}
1619
James Smarte59058c2008-08-24 21:49:00 -04001620/**
James Smart3621a712009-04-06 18:47:14 -04001621 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001622 *
1623 * Description:
1624 * Macro that given an attr e.g. hba_queue_depth expands
1625 * into a function with the name lpfc_hba_queue_depth_show
1626 *
1627 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1628 * @dev: class device that is converted into a Scsi_host.
1629 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001630 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001631 *
1632 * Returns: size of formatted string.
1633 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001634#define lpfc_param_hex_show(attr) \
1635static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001636lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1637 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001638{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001639 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001640 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1641 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001642 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001643 val = phba->cfg_##attr;\
1644 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1645 phba->cfg_##attr);\
1646}
1647
James Smarte59058c2008-08-24 21:49:00 -04001648/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001649 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001650 *
1651 * Description:
1652 * Macro that given an attr e.g. hba_queue_depth expands
1653 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1654 * takes a default argument, a minimum and maximum argument.
1655 *
1656 * lpfc_##attr##_init: Initializes an attribute.
1657 * @phba: pointer the the adapter structure.
1658 * @val: integer attribute value.
1659 *
1660 * Validates the min and max values then sets the adapter config field
1661 * accordingly, or uses the default if out of range and prints an error message.
1662 *
1663 * Returns:
1664 * zero on success
1665 * -EINVAL if default used
1666 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001667#define lpfc_param_init(attr, default, minval, maxval) \
1668static int \
James Smart84d1b002010-02-12 14:42:33 -05001669lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001670{ \
1671 if (val >= minval && val <= maxval) {\
1672 phba->cfg_##attr = val;\
1673 return 0;\
1674 }\
1675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001676 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1677 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001678 phba->cfg_##attr = default;\
1679 return -EINVAL;\
1680}
1681
James Smarte59058c2008-08-24 21:49:00 -04001682/**
James Smart3621a712009-04-06 18:47:14 -04001683 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001684 *
1685 * Description:
1686 * Macro that given an attr e.g. hba_queue_depth expands
1687 * into a function with the name lpfc_hba_queue_depth_set
1688 *
1689 * lpfc_##attr##_set: Sets an attribute value.
1690 * @phba: pointer the the adapter structure.
1691 * @val: integer attribute value.
1692 *
1693 * Description:
1694 * Validates the min and max values then sets the
1695 * adapter config field if in the valid range. prints error message
1696 * and does not set the parameter if invalid.
1697 *
1698 * Returns:
1699 * zero on success
1700 * -EINVAL if val is invalid
1701 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001702#define lpfc_param_set(attr, default, minval, maxval) \
1703static int \
James Smart84d1b002010-02-12 14:42:33 -05001704lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001705{ \
1706 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1708 "3052 lpfc_" #attr " changed from %d to %d\n", \
1709 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001710 phba->cfg_##attr = val;\
1711 return 0;\
1712 }\
1713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001714 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1715 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001716 return -EINVAL;\
1717}
1718
James Smarte59058c2008-08-24 21:49:00 -04001719/**
James Smart3621a712009-04-06 18:47:14 -04001720 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001721 *
1722 * Description:
1723 * Macro that given an attr e.g. hba_queue_depth expands
1724 * into a function with the name lpfc_hba_queue_depth_store.
1725 *
1726 * lpfc_##attr##_store: Set an sttribute value.
1727 * @dev: class device that is converted into a Scsi_host.
1728 * @attr: device attribute, not used.
1729 * @buf: contains the attribute value in ascii.
1730 * @count: not used.
1731 *
1732 * Description:
1733 * Convert the ascii text number to an integer, then
1734 * use the lpfc_##attr##_set function to set the value.
1735 *
1736 * Returns:
1737 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1738 * length of buffer upon success.
1739 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001740#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001741static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001742lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1743 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001744{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001745 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1747 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001748 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001749 if (!isdigit(buf[0]))\
1750 return -EINVAL;\
1751 if (sscanf(buf, "%i", &val) != 1)\
1752 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001753 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001754 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001755 else \
1756 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001757}
1758
James Smarte59058c2008-08-24 21:49:00 -04001759/**
James Smart3621a712009-04-06 18:47:14 -04001760 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001761 *
1762 * Description:
1763 * Macro that given an attr e.g. hba_queue_depth expands
1764 * into a function with the name lpfc_hba_queue_depth_show
1765 *
1766 * lpfc_##attr##_show: prints the attribute value in decimal.
1767 * @dev: class device that is converted into a Scsi_host.
1768 * @attr: device attribute, not used.
1769 * @buf: on return contains the attribute value in decimal.
1770 *
1771 * Returns: length of formatted string.
1772 **/
James Smart3de2a652007-08-02 11:09:59 -04001773#define lpfc_vport_param_show(attr) \
1774static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001775lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1776 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001777{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001778 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001779 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001780 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001781 val = vport->cfg_##attr;\
1782 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1783}
1784
James Smarte59058c2008-08-24 21:49:00 -04001785/**
James Smart3621a712009-04-06 18:47:14 -04001786 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001787 *
1788 * Description:
1789 * Macro that given an attr e.g.
1790 * hba_queue_depth expands into a function with the name
1791 * lpfc_hba_queue_depth_show
1792 *
James Smart3621a712009-04-06 18:47:14 -04001793 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001794 * @dev: class device that is converted into a Scsi_host.
1795 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001796 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001797 *
1798 * Returns: length of formatted string.
1799 **/
James Smart3de2a652007-08-02 11:09:59 -04001800#define lpfc_vport_param_hex_show(attr) \
1801static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001802lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1803 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001804{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001805 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001806 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001807 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001808 val = vport->cfg_##attr;\
1809 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1810}
1811
James Smarte59058c2008-08-24 21:49:00 -04001812/**
James Smart3621a712009-04-06 18:47:14 -04001813 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001814 *
1815 * Description:
1816 * Macro that given an attr e.g. hba_queue_depth expands
1817 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1818 * takes a default argument, a minimum and maximum argument.
1819 *
1820 * lpfc_##attr##_init: validates the min and max values then sets the
1821 * adapter config field accordingly, or uses the default if out of range
1822 * and prints an error message.
1823 * @phba: pointer the the adapter structure.
1824 * @val: integer attribute value.
1825 *
1826 * Returns:
1827 * zero on success
1828 * -EINVAL if default used
1829 **/
James Smart3de2a652007-08-02 11:09:59 -04001830#define lpfc_vport_param_init(attr, default, minval, maxval) \
1831static int \
James Smart84d1b002010-02-12 14:42:33 -05001832lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001833{ \
1834 if (val >= minval && val <= maxval) {\
1835 vport->cfg_##attr = val;\
1836 return 0;\
1837 }\
James Smarte8b62012007-08-02 11:10:09 -04001838 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001839 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001840 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001841 vport->cfg_##attr = default;\
1842 return -EINVAL;\
1843}
1844
James Smarte59058c2008-08-24 21:49:00 -04001845/**
James Smart3621a712009-04-06 18:47:14 -04001846 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001847 *
1848 * Description:
1849 * Macro that given an attr e.g. hba_queue_depth expands
1850 * into a function with the name lpfc_hba_queue_depth_set
1851 *
1852 * lpfc_##attr##_set: validates the min and max values then sets the
1853 * adapter config field if in the valid range. prints error message
1854 * and does not set the parameter if invalid.
1855 * @phba: pointer the the adapter structure.
1856 * @val: integer attribute value.
1857 *
1858 * Returns:
1859 * zero on success
1860 * -EINVAL if val is invalid
1861 **/
James Smart3de2a652007-08-02 11:09:59 -04001862#define lpfc_vport_param_set(attr, default, minval, maxval) \
1863static int \
James Smart84d1b002010-02-12 14:42:33 -05001864lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001865{ \
1866 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001867 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1868 "3053 lpfc_" #attr " changed from %d to %d\n", \
1869 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001870 vport->cfg_##attr = val;\
1871 return 0;\
1872 }\
James Smarte8b62012007-08-02 11:10:09 -04001873 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001874 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001875 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001876 return -EINVAL;\
1877}
1878
James Smarte59058c2008-08-24 21:49:00 -04001879/**
James Smart3621a712009-04-06 18:47:14 -04001880 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001881 *
1882 * Description:
1883 * Macro that given an attr e.g. hba_queue_depth
1884 * expands into a function with the name lpfc_hba_queue_depth_store
1885 *
1886 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1887 * use the lpfc_##attr##_set function to set the value.
1888 * @cdev: class device that is converted into a Scsi_host.
1889 * @buf: contains the attribute value in decimal.
1890 * @count: not used.
1891 *
1892 * Returns:
1893 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1894 * length of buffer upon success.
1895 **/
James Smart3de2a652007-08-02 11:09:59 -04001896#define lpfc_vport_param_store(attr) \
1897static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001898lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1899 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001900{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001901 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001902 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001903 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001904 if (!isdigit(buf[0]))\
1905 return -EINVAL;\
1906 if (sscanf(buf, "%i", &val) != 1)\
1907 return -EINVAL;\
1908 if (lpfc_##attr##_set(vport, val) == 0) \
1909 return strlen(buf);\
1910 else \
1911 return -EINVAL;\
1912}
1913
1914
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001915#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001916static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001917module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001918MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001919lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001920
1921#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001922static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001923module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001924MODULE_PARM_DESC(lpfc_##name, desc);\
1925lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001926lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001927static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001928
1929#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001930static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001931module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001932MODULE_PARM_DESC(lpfc_##name, desc);\
1933lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001934lpfc_param_init(name, defval, minval, maxval)\
1935lpfc_param_set(name, defval, minval, maxval)\
1936lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001937static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1938 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001939
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001940#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001941static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001942module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001943MODULE_PARM_DESC(lpfc_##name, desc);\
1944lpfc_param_hex_show(name)\
1945lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001946static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001947
1948#define LPFC_ATTR_HEX_RW(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);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001951MODULE_PARM_DESC(lpfc_##name, desc);\
1952lpfc_param_hex_show(name)\
1953lpfc_param_init(name, defval, minval, maxval)\
1954lpfc_param_set(name, defval, minval, maxval)\
1955lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001956static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1957 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001958
James Smart3de2a652007-08-02 11:09:59 -04001959#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001960static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001961module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001962MODULE_PARM_DESC(lpfc_##name, desc);\
1963lpfc_vport_param_init(name, defval, minval, maxval)
1964
1965#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001966static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001967module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001968MODULE_PARM_DESC(lpfc_##name, desc);\
1969lpfc_vport_param_show(name)\
1970lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001971static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001972
1973#define LPFC_VPORT_ATTR_RW(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 Smart3de2a652007-08-02 11:09:59 -04001976MODULE_PARM_DESC(lpfc_##name, desc);\
1977lpfc_vport_param_show(name)\
1978lpfc_vport_param_init(name, defval, minval, maxval)\
1979lpfc_vport_param_set(name, defval, minval, maxval)\
1980lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001981static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1982 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001983
1984#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001985static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001986module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001987MODULE_PARM_DESC(lpfc_##name, desc);\
1988lpfc_vport_param_hex_show(name)\
1989lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001990static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001991
1992#define LPFC_VPORT_ATTR_HEX_RW(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_hex_show(name)\
1997lpfc_vport_param_init(name, defval, minval, maxval)\
1998lpfc_vport_param_set(name, defval, minval, maxval)\
1999lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002000static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2001 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002002
James Smart81301a92008-12-04 22:39:46 -05002003static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2004static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2005static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2006static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002007static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2008static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2009static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2010static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2011static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2012static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2013static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2014static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002015static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2016 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002017static DEVICE_ATTR(option_rom_version, S_IRUGO,
2018 lpfc_option_rom_version_show, NULL);
2019static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2020 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002021static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002022static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2023static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002024static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002025static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2026 lpfc_board_mode_show, lpfc_board_mode_store);
2027static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2028static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2029static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2030static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2031static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2032static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2033static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2034static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2035static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002036static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2037static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002038static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002039static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2040 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002041static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002042
James Smarta12e07b2006-12-02 13:35:30 -05002043static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04002044
James Smarte59058c2008-08-24 21:49:00 -04002045/**
James Smart3621a712009-04-06 18:47:14 -04002046 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002047 * @dev: class device that is converted into a Scsi_host.
2048 * @attr: device attribute, not used.
2049 * @buf: containing the string lpfc_soft_wwn_key.
2050 * @count: must be size of lpfc_soft_wwn_key.
2051 *
2052 * Returns:
2053 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2054 * length of buf indicates success
2055 **/
James Smartc3f28af2006-08-18 17:47:18 -04002056static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002057lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2058 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002059{
Tony Jonesee959b02008-02-22 00:13:36 +01002060 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002061 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2062 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002063 unsigned int cnt = count;
2064
2065 /*
2066 * We're doing a simple sanity check for soft_wwpn setting.
2067 * We require that the user write a specific key to enable
2068 * the soft_wwpn attribute to be settable. Once the attribute
2069 * is written, the enable key resets. If further updates are
2070 * desired, the key must be written again to re-enable the
2071 * attribute.
2072 *
2073 * The "key" is not secret - it is a hardcoded string shown
2074 * here. The intent is to protect against the random user or
2075 * application that is just writing attributes.
2076 */
2077
2078 /* count may include a LF at end of string */
2079 if (buf[cnt-1] == '\n')
2080 cnt--;
2081
James Smarta12e07b2006-12-02 13:35:30 -05002082 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2083 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002084 return -EINVAL;
2085
James Smarta12e07b2006-12-02 13:35:30 -05002086 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002087 return count;
2088}
Tony Jonesee959b02008-02-22 00:13:36 +01002089static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2090 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002091
James Smarte59058c2008-08-24 21:49:00 -04002092/**
James Smart3621a712009-04-06 18:47:14 -04002093 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002094 * @dev: class device that is converted into a Scsi_host.
2095 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002096 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002097 *
2098 * Returns: size of formatted string.
2099 **/
James Smartc3f28af2006-08-18 17:47:18 -04002100static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002101lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2102 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002103{
Tony Jonesee959b02008-02-22 00:13:36 +01002104 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002105 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2106 struct lpfc_hba *phba = vport->phba;
2107
Randy Dunlapafc071e2006-10-23 21:47:13 -07002108 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2109 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002110}
2111
James Smarte59058c2008-08-24 21:49:00 -04002112/**
James Smart3621a712009-04-06 18:47:14 -04002113 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002114 * @dev class device that is converted into a Scsi_host.
2115 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002116 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002117 * @count: number of wwpn bytes in buf
2118 *
2119 * Returns:
2120 * -EACCES hba reset not enabled, adapter over temp
2121 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2122 * -EIO error taking adapter offline or online
2123 * value of count on success
2124 **/
James Smartc3f28af2006-08-18 17:47:18 -04002125static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002126lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2127 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002128{
Tony Jonesee959b02008-02-22 00:13:36 +01002129 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2131 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002132 struct completion online_compl;
2133 int stat1=0, stat2=0;
2134 unsigned int i, j, cnt=count;
2135 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002136 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002137
James Smart13815c82008-01-11 01:52:48 -05002138 if (!phba->cfg_enable_hba_reset)
2139 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002140 spin_lock_irq(&phba->hbalock);
2141 if (phba->over_temp_state == HBA_OVER_TEMP) {
2142 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002143 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002144 }
2145 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002146 /* count may include a LF at end of string */
2147 if (buf[cnt-1] == '\n')
2148 cnt--;
2149
James Smarta12e07b2006-12-02 13:35:30 -05002150 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002151 ((cnt == 17) && (*buf++ != 'x')) ||
2152 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2153 return -EINVAL;
2154
James Smarta12e07b2006-12-02 13:35:30 -05002155 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002156
2157 memset(wwpn, 0, sizeof(wwpn));
2158
2159 /* Validate and store the new name */
2160 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002161 int value;
2162
2163 value = hex_to_bin(*buf++);
2164 if (value >= 0)
2165 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002166 else
2167 return -EINVAL;
2168 if (i % 2) {
2169 wwpn[i/2] = j & 0xff;
2170 j = 0;
2171 }
2172 }
2173 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002174 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002175 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002176 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002177
2178 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2179 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2180
James Smart46fa3112007-04-25 09:51:45 -04002181 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002182 if (stat1)
2183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002184 "0463 lpfc_soft_wwpn attribute set failed to "
2185 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002186 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002187 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2188 LPFC_EVT_ONLINE);
2189 if (rc == 0)
2190 return -ENOMEM;
2191
James Smartc3f28af2006-08-18 17:47:18 -04002192 wait_for_completion(&online_compl);
2193 if (stat2)
2194 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002195 "0464 lpfc_soft_wwpn attribute set failed to "
2196 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002197 return (stat1 || stat2) ? -EIO : count;
2198}
Tony Jonesee959b02008-02-22 00:13:36 +01002199static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2200 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002201
James Smarte59058c2008-08-24 21:49:00 -04002202/**
James Smart3621a712009-04-06 18:47:14 -04002203 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002204 * @dev: class device that is converted into a Scsi_host.
2205 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002206 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002207 *
2208 * Returns: size of formatted string.
2209 **/
James Smarta12e07b2006-12-02 13:35:30 -05002210static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002211lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2212 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002213{
Tony Jonesee959b02008-02-22 00:13:36 +01002214 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002215 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002216 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2217 (unsigned long long)phba->cfg_soft_wwnn);
2218}
2219
James Smarte59058c2008-08-24 21:49:00 -04002220/**
James Smart3621a712009-04-06 18:47:14 -04002221 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002222 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002223 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002224 * @count: number of wwnn bytes in buf.
2225 *
2226 * Returns:
2227 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2228 * value of count on success
2229 **/
James Smarta12e07b2006-12-02 13:35:30 -05002230static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002231lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2232 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002233{
Tony Jonesee959b02008-02-22 00:13:36 +01002234 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002235 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002236 unsigned int i, j, cnt=count;
2237 u8 wwnn[8];
2238
2239 /* count may include a LF at end of string */
2240 if (buf[cnt-1] == '\n')
2241 cnt--;
2242
2243 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2244 ((cnt == 17) && (*buf++ != 'x')) ||
2245 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2246 return -EINVAL;
2247
2248 /*
2249 * Allow wwnn to be set many times, as long as the enable is set.
2250 * However, once the wwpn is set, everything locks.
2251 */
2252
2253 memset(wwnn, 0, sizeof(wwnn));
2254
2255 /* Validate and store the new name */
2256 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002257 int value;
2258
2259 value = hex_to_bin(*buf++);
2260 if (value >= 0)
2261 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002262 else
2263 return -EINVAL;
2264 if (i % 2) {
2265 wwnn[i/2] = j & 0xff;
2266 j = 0;
2267 }
2268 }
2269 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2270
2271 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2272 "lpfc%d: soft_wwnn set. Value will take effect upon "
2273 "setting of the soft_wwpn\n", phba->brd_no);
2274
2275 return count;
2276}
Tony Jonesee959b02008-02-22 00:13:36 +01002277static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2278 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002279
James Smartc3f28af2006-08-18 17:47:18 -04002280
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002281static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002282module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002283MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2284 " 0 - none,"
2285 " 1 - poll with interrupts enabled"
2286 " 3 - poll and disable FCP ring interrupts");
2287
Tony Jonesee959b02008-02-22 00:13:36 +01002288static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2289 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002290
James Smart92d7f7b2007-06-17 19:56:38 -05002291int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002292module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002293MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2294 " 0 - auto (SLI-3 if supported),"
2295 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2296 " 3 - select SLI-3");
2297
James Smart15672312010-04-06 14:49:03 -04002298int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002299module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002300MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2301lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002302lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002303static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002304
James Smart7d791df2011-07-22 18:37:52 -04002305LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2306 "FCF Fast failover=1 Priority failover=2");
2307
James Smartc14e9952013-03-01 16:38:01 -05002308int lpfc_enable_rrq = 2;
James Smartab56dc22011-02-16 12:39:57 -05002309module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002310MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2311lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002312/*
2313# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2314# 0x0 = disabled, XRI/OXID use not tracked.
2315# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2316# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2317*/
2318lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002319static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2320
dea31012005-04-17 16:05:31 -05002321/*
James Smart84d1b002010-02-12 14:42:33 -05002322# lpfc_suppress_link_up: Bring link up at initialization
2323# 0x0 = bring link up (issue MBX_INIT_LINK)
2324# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2325# 0x2 = never bring up link
2326# Default value is 0.
2327*/
James Smarte40a02c2010-02-26 14:13:54 -05002328LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2329 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2330 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002331/*
2332# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2333# 1 - (1024)
2334# 2 - (2048)
2335# 3 - (3072)
2336# 4 - (4096)
2337# 5 - (5120)
2338*/
2339static ssize_t
2340lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2341{
2342 struct Scsi_Host *shost = class_to_shost(dev);
2343 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2344
2345 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2346}
2347
2348static DEVICE_ATTR(iocb_hw, S_IRUGO,
2349 lpfc_iocb_hw_show, NULL);
2350static ssize_t
2351lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2352{
2353 struct Scsi_Host *shost = class_to_shost(dev);
2354 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2355
2356 return snprintf(buf, PAGE_SIZE, "%d\n",
2357 phba->sli.ring[LPFC_ELS_RING].txq_max);
2358}
2359
2360static DEVICE_ATTR(txq_hw, S_IRUGO,
2361 lpfc_txq_hw_show, NULL);
2362static ssize_t
2363lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2364 char *buf)
2365{
2366 struct Scsi_Host *shost = class_to_shost(dev);
2367 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2368
2369 return snprintf(buf, PAGE_SIZE, "%d\n",
2370 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2371}
2372
2373static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2374 lpfc_txcmplq_hw_show, NULL);
2375
2376int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002377module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002378MODULE_PARM_DESC(lpfc_iocb_cnt,
2379 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2380lpfc_param_show(iocb_cnt);
2381lpfc_param_init(iocb_cnt, 2, 1, 5);
2382static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2383 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002384
2385/*
James Smartc01f3202006-08-18 17:47:08 -04002386# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2387# until the timer expires. Value range is [0,255]. Default value is 30.
2388*/
2389static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2390static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2391module_param(lpfc_nodev_tmo, int, 0);
2392MODULE_PARM_DESC(lpfc_nodev_tmo,
2393 "Seconds driver will hold I/O waiting "
2394 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002395
2396/**
James Smart3621a712009-04-06 18:47:14 -04002397 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002398 * @dev: class converted to a Scsi_host structure.
2399 * @attr: device attribute, not used.
2400 * @buf: on return contains the dev loss timeout in decimal.
2401 *
2402 * Returns: size of formatted string.
2403 **/
James Smartc01f3202006-08-18 17:47:08 -04002404static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002405lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2406 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002407{
Tony Jonesee959b02008-02-22 00:13:36 +01002408 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002409 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002410
James Smart3de2a652007-08-02 11:09:59 -04002411 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002412}
2413
James Smarte59058c2008-08-24 21:49:00 -04002414/**
James Smart3621a712009-04-06 18:47:14 -04002415 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002416 * @vport: lpfc vport structure pointer.
2417 * @val: contains the nodev timeout value.
2418 *
2419 * Description:
2420 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2421 * a kernel error message is printed and zero is returned.
2422 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2423 * Otherwise nodev tmo is set to the default value.
2424 *
2425 * Returns:
2426 * zero if already set or if val is in range
2427 * -EINVAL val out of range
2428 **/
James Smartc01f3202006-08-18 17:47:08 -04002429static int
James Smart3de2a652007-08-02 11:09:59 -04002430lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002431{
James Smart3de2a652007-08-02 11:09:59 -04002432 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2433 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2434 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002435 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002436 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002437 "parameter because devloss_tmo is "
2438 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002439 return 0;
2440 }
2441
2442 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002443 vport->cfg_nodev_tmo = val;
2444 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002445 return 0;
2446 }
James Smarte8b62012007-08-02 11:10:09 -04002447 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2448 "0400 lpfc_nodev_tmo attribute cannot be set to"
2449 " %d, allowed range is [%d, %d]\n",
2450 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002451 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002452 return -EINVAL;
2453}
2454
James Smarte59058c2008-08-24 21:49:00 -04002455/**
James Smart3621a712009-04-06 18:47:14 -04002456 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002457 * @vport: lpfc vport structure pointer.
2458 *
2459 * Description:
2460 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2461 **/
James Smart7054a602007-04-25 09:52:34 -04002462static void
James Smart3de2a652007-08-02 11:09:59 -04002463lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002464{
James Smart858c9f62007-06-17 19:56:39 -05002465 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002466 struct lpfc_nodelist *ndlp;
2467
James Smart51ef4c22007-08-02 11:10:31 -04002468 shost = lpfc_shost_from_vport(vport);
2469 spin_lock_irq(shost->host_lock);
2470 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002471 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002472 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2473 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002474}
2475
James Smarte59058c2008-08-24 21:49:00 -04002476/**
James Smart3621a712009-04-06 18:47:14 -04002477 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002478 * @vport: lpfc vport structure pointer.
2479 * @val: contains the tmo value.
2480 *
2481 * Description:
2482 * If the devloss tmo is already set or the vport dev loss tmo has changed
2483 * then a kernel error message is printed and zero is returned.
2484 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2485 * Otherwise nodev tmo is set to the default value.
2486 *
2487 * Returns:
2488 * zero if already set or if val is in range
2489 * -EINVAL val out of range
2490 **/
James Smartc01f3202006-08-18 17:47:08 -04002491static int
James Smart3de2a652007-08-02 11:09:59 -04002492lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002493{
James Smart3de2a652007-08-02 11:09:59 -04002494 if (vport->dev_loss_tmo_changed ||
2495 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002496 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2497 "0401 Ignoring change to nodev_tmo "
2498 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002499 return 0;
2500 }
James Smartc01f3202006-08-18 17:47:08 -04002501 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002502 vport->cfg_nodev_tmo = val;
2503 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002504 /*
2505 * For compat: set the fc_host dev loss so new rports
2506 * will get the value.
2507 */
2508 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002509 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002510 return 0;
2511 }
James Smarte8b62012007-08-02 11:10:09 -04002512 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2513 "0403 lpfc_nodev_tmo attribute cannot be set to"
2514 "%d, allowed range is [%d, %d]\n",
2515 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002516 return -EINVAL;
2517}
2518
James Smart3de2a652007-08-02 11:09:59 -04002519lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002520
Tony Jonesee959b02008-02-22 00:13:36 +01002521static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2522 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002523
2524/*
2525# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2526# disappear until the timer expires. Value range is [0,255]. Default
2527# value is 30.
2528*/
James Smartab56dc22011-02-16 12:39:57 -05002529module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002530MODULE_PARM_DESC(lpfc_devloss_tmo,
2531 "Seconds driver will hold I/O waiting "
2532 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002533lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2534 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2535lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002536
2537/**
James Smart3621a712009-04-06 18:47:14 -04002538 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002539 * @vport: lpfc vport structure pointer.
2540 * @val: contains the tmo value.
2541 *
2542 * Description:
2543 * If val is in a valid range then set the vport nodev tmo,
2544 * devloss tmo, also set the vport dev loss tmo changed flag.
2545 * Else a kernel error message is printed.
2546 *
2547 * Returns:
2548 * zero if val is in range
2549 * -EINVAL val out of range
2550 **/
James Smartc01f3202006-08-18 17:47:08 -04002551static int
James Smart3de2a652007-08-02 11:09:59 -04002552lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002553{
2554 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002555 vport->cfg_nodev_tmo = val;
2556 vport->cfg_devloss_tmo = val;
2557 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002558 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002559 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002560 return 0;
2561 }
2562
James Smarte8b62012007-08-02 11:10:09 -04002563 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2564 "0404 lpfc_devloss_tmo attribute cannot be set to"
2565 " %d, allowed range is [%d, %d]\n",
2566 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002567 return -EINVAL;
2568}
2569
James Smart3de2a652007-08-02 11:09:59 -04002570lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002571static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2572 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002573
2574/*
dea31012005-04-17 16:05:31 -05002575# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2576# deluged with LOTS of information.
2577# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002578# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002579*/
James Smartf4b4c682009-05-22 14:53:12 -04002580LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002581 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002582
2583/*
James Smart7ee5d432007-10-27 13:37:17 -04002584# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2585# objects that have been registered with the nameserver after login.
2586*/
James Smartcf971242012-03-01 22:37:32 -05002587LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04002588 "Deregister nameserver objects before LOGO");
2589
2590/*
dea31012005-04-17 16:05:31 -05002591# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04002592# commands per FCP LUN. Value range is [1,512]. Default value is 30.
2593# If this parameter value is greater than 1/8th the maximum number of exchanges
2594# supported by the HBA port, then the lun queue depth will be reduced to
2595# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05002596*/
James Smart572709e2013-07-15 18:32:43 -04002597LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04002598 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002599
2600/*
James Smart7dc517d2010-07-14 15:32:10 -04002601# tgt_queue_depth: This parameter is used to limit the number of outstanding
2602# commands per target port. Value range is [10,65535]. Default value is 65535.
2603*/
2604LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04002605 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04002606
2607/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002608# hba_queue_depth: This parameter is used to limit the number of outstanding
2609# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2610# value is greater than the maximum number of exchanges supported by the HBA,
2611# then maximum number of exchanges supported by the HBA is used to determine
2612# the hba_queue_depth.
2613*/
2614LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2615 "Max number of FCP commands we can queue to a lpfc HBA");
2616
2617/*
James Smart92d7f7b2007-06-17 19:56:38 -05002618# peer_port_login: This parameter allows/prevents logins
2619# between peer ports hosted on the same physical port.
2620# When this parameter is set 0 peer ports of same physical port
2621# are not allowed to login to each other.
2622# When this parameter is set 1 peer ports of same physical port
2623# are allowed to login to each other.
2624# Default value of this parameter is 0.
2625*/
James Smart3de2a652007-08-02 11:09:59 -04002626LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2627 "Allow peer ports on the same physical port to login to each "
2628 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002629
2630/*
James Smart3de2a652007-08-02 11:09:59 -04002631# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002632# between Virtual Ports and remote initiators.
2633# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2634# other initiators and will attempt to PLOGI all remote ports.
2635# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2636# remote ports and will not attempt to PLOGI to other initiators.
2637# This parameter does not restrict to the physical port.
2638# This parameter does not restrict logins to Fabric resident remote ports.
2639# Default value of this parameter is 1.
2640*/
James Smart3de2a652007-08-02 11:09:59 -04002641static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002642module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002643MODULE_PARM_DESC(lpfc_restrict_login,
2644 "Restrict virtual ports login to remote initiators.");
2645lpfc_vport_param_show(restrict_login);
2646
James Smarte59058c2008-08-24 21:49:00 -04002647/**
James Smart3621a712009-04-06 18:47:14 -04002648 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002649 * @vport: lpfc vport structure pointer.
2650 * @val: contains the restrict login value.
2651 *
2652 * Description:
2653 * If val is not in a valid range then log a kernel error message and set
2654 * the vport restrict login to one.
2655 * If the port type is physical clear the restrict login flag and return.
2656 * Else set the restrict login flag to val.
2657 *
2658 * Returns:
2659 * zero if val is in range
2660 * -EINVAL val out of range
2661 **/
James Smart3de2a652007-08-02 11:09:59 -04002662static int
2663lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2664{
2665 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002666 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002667 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002668 "be set to %d, allowed range is [0, 1]\n",
2669 val);
James Smart3de2a652007-08-02 11:09:59 -04002670 vport->cfg_restrict_login = 1;
2671 return -EINVAL;
2672 }
2673 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2674 vport->cfg_restrict_login = 0;
2675 return 0;
2676 }
2677 vport->cfg_restrict_login = val;
2678 return 0;
2679}
2680
James Smarte59058c2008-08-24 21:49:00 -04002681/**
James Smart3621a712009-04-06 18:47:14 -04002682 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002683 * @vport: lpfc vport structure pointer.
2684 * @val: contains the restrict login value.
2685 *
2686 * Description:
2687 * If val is not in a valid range then log a kernel error message and set
2688 * the vport restrict login to one.
2689 * If the port type is physical and the val is not zero log a kernel
2690 * error message, clear the restrict login flag and return zero.
2691 * Else set the restrict login flag to val.
2692 *
2693 * Returns:
2694 * zero if val is in range
2695 * -EINVAL val out of range
2696 **/
James Smart3de2a652007-08-02 11:09:59 -04002697static int
2698lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2699{
2700 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002701 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002702 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002703 "be set to %d, allowed range is [0, 1]\n",
2704 val);
James Smart3de2a652007-08-02 11:09:59 -04002705 vport->cfg_restrict_login = 1;
2706 return -EINVAL;
2707 }
2708 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002709 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2710 "0468 lpfc_restrict_login must be 0 for "
2711 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002712 vport->cfg_restrict_login = 0;
2713 return 0;
2714 }
2715 vport->cfg_restrict_login = val;
2716 return 0;
2717}
2718lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002719static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2720 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002721
2722/*
dea31012005-04-17 16:05:31 -05002723# Some disk devices have a "select ID" or "select Target" capability.
2724# From a protocol standpoint "select ID" usually means select the
2725# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2726# annex" which contains a table that maps a "select ID" (a number
2727# between 0 and 7F) to an ALPA. By default, for compatibility with
2728# older drivers, the lpfc driver scans this table from low ALPA to high
2729# ALPA.
2730#
2731# Turning on the scan-down variable (on = 1, off = 0) will
2732# cause the lpfc driver to use an inverted table, effectively
2733# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2734#
2735# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2736# and will not work across a fabric. Also this parameter will take
2737# effect only in the case when ALPA map is not available.)
2738*/
James Smart3de2a652007-08-02 11:09:59 -04002739LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2740 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002741
2742/*
dea31012005-04-17 16:05:31 -05002743# lpfc_topology: link topology for init link
2744# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002745# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002746# 0x02 = attempt point-to-point mode only
2747# 0x04 = attempt loop mode only
2748# 0x06 = attempt point-to-point mode then loop
2749# Set point-to-point mode if you want to run as an N_Port.
2750# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2751# Default value is 0.
2752*/
James Smarte59058c2008-08-24 21:49:00 -04002753
2754/**
James Smart3621a712009-04-06 18:47:14 -04002755 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002756 * @phba: lpfc_hba pointer.
2757 * @val: topology value.
2758 *
2759 * Description:
2760 * If val is in a valid range then set the adapter's topology field and
2761 * issue a lip; if the lip fails reset the topology to the old value.
2762 *
2763 * If the value is not in range log a kernel error message and return an error.
2764 *
2765 * Returns:
2766 * zero if val is in range and lip okay
2767 * non-zero return value from lpfc_issue_lip()
2768 * -EINVAL val out of range
2769 **/
James Smarta257bf92009-04-06 18:48:10 -04002770static ssize_t
2771lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2772 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002773{
James Smarta257bf92009-04-06 18:48:10 -04002774 struct Scsi_Host *shost = class_to_shost(dev);
2775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2776 struct lpfc_hba *phba = vport->phba;
2777 int val = 0;
2778 int nolip = 0;
2779 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002780 int err;
2781 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002782
2783 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2784 nolip = 1;
2785 val_buf = &buf[strlen("nolip ")];
2786 }
2787
2788 if (!isdigit(val_buf[0]))
2789 return -EINVAL;
2790 if (sscanf(val_buf, "%i", &val) != 1)
2791 return -EINVAL;
2792
James Smart83108bd2008-01-11 01:53:09 -05002793 if (val >= 0 && val <= 6) {
2794 prev_val = phba->cfg_topology;
2795 phba->cfg_topology = val;
James Smartff78d8f2011-12-13 13:21:35 -05002796 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
2797 val == 4) {
2798 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2799 "3113 Loop mode not supported at speed %d\n",
2800 phba->cfg_link_speed);
2801 phba->cfg_topology = prev_val;
2802 return -EINVAL;
2803 }
James Smarta257bf92009-04-06 18:48:10 -04002804 if (nolip)
2805 return strlen(buf);
2806
James Smart88a2cfb2011-07-22 18:36:33 -04002807 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2808 "3054 lpfc_topology changed from %d to %d\n",
2809 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04002810 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
2811 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05002812 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002813 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002814 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002815 return -EINVAL;
2816 } else
2817 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002818 }
2819 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2820 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2821 "allowed range is [0, 6]\n",
2822 phba->brd_no, val);
2823 return -EINVAL;
2824}
2825static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002826module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002827MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2828lpfc_param_show(topology)
2829lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002830static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002831 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002832
James Smart21e9a0a2009-05-22 14:53:21 -04002833/**
2834 * lpfc_static_vport_show: Read callback function for
2835 * lpfc_static_vport sysfs file.
2836 * @dev: Pointer to class device object.
2837 * @attr: device attribute structure.
2838 * @buf: Data buffer.
2839 *
2840 * This function is the read call back function for
2841 * lpfc_static_vport sysfs file. The lpfc_static_vport
2842 * sysfs file report the mageability of the vport.
2843 **/
2844static ssize_t
2845lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2846 char *buf)
2847{
2848 struct Scsi_Host *shost = class_to_shost(dev);
2849 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2850 if (vport->vport_flag & STATIC_VPORT)
2851 sprintf(buf, "1\n");
2852 else
2853 sprintf(buf, "0\n");
2854
2855 return strlen(buf);
2856}
2857
2858/*
2859 * Sysfs attribute to control the statistical data collection.
2860 */
2861static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2862 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002863
2864/**
James Smart3621a712009-04-06 18:47:14 -04002865 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002866 * @dev: Pointer to class device.
2867 * @buf: Data buffer.
2868 * @count: Size of the data buffer.
2869 *
2870 * This function get called when an user write to the lpfc_stat_data_ctrl
2871 * sysfs file. This function parse the command written to the sysfs file
2872 * and take appropriate action. These commands are used for controlling
2873 * driver statistical data collection.
2874 * Following are the command this function handles.
2875 *
2876 * setbucket <bucket_type> <base> <step>
2877 * = Set the latency buckets.
2878 * destroybucket = destroy all the buckets.
2879 * start = start data collection
2880 * stop = stop data collection
2881 * reset = reset the collected data
2882 **/
2883static ssize_t
2884lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2885 const char *buf, size_t count)
2886{
2887 struct Scsi_Host *shost = class_to_shost(dev);
2888 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2889 struct lpfc_hba *phba = vport->phba;
2890#define LPFC_MAX_DATA_CTRL_LEN 1024
2891 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2892 unsigned long i;
2893 char *str_ptr, *token;
2894 struct lpfc_vport **vports;
2895 struct Scsi_Host *v_shost;
2896 char *bucket_type_str, *base_str, *step_str;
2897 unsigned long base, step, bucket_type;
2898
2899 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002900 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002901 return -EINVAL;
2902
2903 strcpy(bucket_data, buf);
2904 str_ptr = &bucket_data[0];
2905 /* Ignore this token - this is command token */
2906 token = strsep(&str_ptr, "\t ");
2907 if (!token)
2908 return -EINVAL;
2909
2910 bucket_type_str = strsep(&str_ptr, "\t ");
2911 if (!bucket_type_str)
2912 return -EINVAL;
2913
2914 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2915 bucket_type = LPFC_LINEAR_BUCKET;
2916 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2917 bucket_type = LPFC_POWER2_BUCKET;
2918 else
2919 return -EINVAL;
2920
2921 base_str = strsep(&str_ptr, "\t ");
2922 if (!base_str)
2923 return -EINVAL;
2924 base = simple_strtoul(base_str, NULL, 0);
2925
2926 step_str = strsep(&str_ptr, "\t ");
2927 if (!step_str)
2928 return -EINVAL;
2929 step = simple_strtoul(step_str, NULL, 0);
2930 if (!step)
2931 return -EINVAL;
2932
2933 /* Block the data collection for every vport */
2934 vports = lpfc_create_vport_work_array(phba);
2935 if (vports == NULL)
2936 return -ENOMEM;
2937
James Smartf4b4c682009-05-22 14:53:12 -04002938 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002939 v_shost = lpfc_shost_from_vport(vports[i]);
2940 spin_lock_irq(v_shost->host_lock);
2941 /* Block and reset data collection */
2942 vports[i]->stat_data_blocked = 1;
2943 if (vports[i]->stat_data_enabled)
2944 lpfc_vport_reset_stat_data(vports[i]);
2945 spin_unlock_irq(v_shost->host_lock);
2946 }
2947
2948 /* Set the bucket attributes */
2949 phba->bucket_type = bucket_type;
2950 phba->bucket_base = base;
2951 phba->bucket_step = step;
2952
James Smartf4b4c682009-05-22 14:53:12 -04002953 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002954 v_shost = lpfc_shost_from_vport(vports[i]);
2955
2956 /* Unblock data collection */
2957 spin_lock_irq(v_shost->host_lock);
2958 vports[i]->stat_data_blocked = 0;
2959 spin_unlock_irq(v_shost->host_lock);
2960 }
2961 lpfc_destroy_vport_work_array(phba, vports);
2962 return strlen(buf);
2963 }
2964
2965 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2966 vports = lpfc_create_vport_work_array(phba);
2967 if (vports == NULL)
2968 return -ENOMEM;
2969
James Smartf4b4c682009-05-22 14:53:12 -04002970 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002971 v_shost = lpfc_shost_from_vport(vports[i]);
2972 spin_lock_irq(shost->host_lock);
2973 vports[i]->stat_data_blocked = 1;
2974 lpfc_free_bucket(vport);
2975 vport->stat_data_enabled = 0;
2976 vports[i]->stat_data_blocked = 0;
2977 spin_unlock_irq(shost->host_lock);
2978 }
2979 lpfc_destroy_vport_work_array(phba, vports);
2980 phba->bucket_type = LPFC_NO_BUCKET;
2981 phba->bucket_base = 0;
2982 phba->bucket_step = 0;
2983 return strlen(buf);
2984 }
2985
2986 if (!strncmp(buf, "start", strlen("start"))) {
2987 /* If no buckets configured return error */
2988 if (phba->bucket_type == LPFC_NO_BUCKET)
2989 return -EINVAL;
2990 spin_lock_irq(shost->host_lock);
2991 if (vport->stat_data_enabled) {
2992 spin_unlock_irq(shost->host_lock);
2993 return strlen(buf);
2994 }
2995 lpfc_alloc_bucket(vport);
2996 vport->stat_data_enabled = 1;
2997 spin_unlock_irq(shost->host_lock);
2998 return strlen(buf);
2999 }
3000
3001 if (!strncmp(buf, "stop", strlen("stop"))) {
3002 spin_lock_irq(shost->host_lock);
3003 if (vport->stat_data_enabled == 0) {
3004 spin_unlock_irq(shost->host_lock);
3005 return strlen(buf);
3006 }
3007 lpfc_free_bucket(vport);
3008 vport->stat_data_enabled = 0;
3009 spin_unlock_irq(shost->host_lock);
3010 return strlen(buf);
3011 }
3012
3013 if (!strncmp(buf, "reset", strlen("reset"))) {
3014 if ((phba->bucket_type == LPFC_NO_BUCKET)
3015 || !vport->stat_data_enabled)
3016 return strlen(buf);
3017 spin_lock_irq(shost->host_lock);
3018 vport->stat_data_blocked = 1;
3019 lpfc_vport_reset_stat_data(vport);
3020 vport->stat_data_blocked = 0;
3021 spin_unlock_irq(shost->host_lock);
3022 return strlen(buf);
3023 }
3024 return -EINVAL;
3025}
3026
3027
3028/**
James Smart3621a712009-04-06 18:47:14 -04003029 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003030 * @dev: Pointer to class device object.
3031 * @buf: Data buffer.
3032 *
3033 * This function is the read call back function for
3034 * lpfc_stat_data_ctrl sysfs file. This function report the
3035 * current statistical data collection state.
3036 **/
3037static ssize_t
3038lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3039 char *buf)
3040{
3041 struct Scsi_Host *shost = class_to_shost(dev);
3042 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3043 struct lpfc_hba *phba = vport->phba;
3044 int index = 0;
3045 int i;
3046 char *bucket_type;
3047 unsigned long bucket_value;
3048
3049 switch (phba->bucket_type) {
3050 case LPFC_LINEAR_BUCKET:
3051 bucket_type = "linear";
3052 break;
3053 case LPFC_POWER2_BUCKET:
3054 bucket_type = "power2";
3055 break;
3056 default:
3057 bucket_type = "No Bucket";
3058 break;
3059 }
3060
3061 sprintf(&buf[index], "Statistical Data enabled :%d, "
3062 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3063 " Bucket step :%d\nLatency Ranges :",
3064 vport->stat_data_enabled, vport->stat_data_blocked,
3065 bucket_type, phba->bucket_base, phba->bucket_step);
3066 index = strlen(buf);
3067 if (phba->bucket_type != LPFC_NO_BUCKET) {
3068 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3069 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3070 bucket_value = phba->bucket_base +
3071 phba->bucket_step * i;
3072 else
3073 bucket_value = phba->bucket_base +
3074 (1 << i) * phba->bucket_step;
3075
3076 if (index + 10 > PAGE_SIZE)
3077 break;
3078 sprintf(&buf[index], "%08ld ", bucket_value);
3079 index = strlen(buf);
3080 }
3081 }
3082 sprintf(&buf[index], "\n");
3083 return strlen(buf);
3084}
3085
3086/*
3087 * Sysfs attribute to control the statistical data collection.
3088 */
3089static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3090 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3091
3092/*
3093 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3094 */
3095
3096/*
3097 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3098 * for each target.
3099 */
3100#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3101#define MAX_STAT_DATA_SIZE_PER_TARGET \
3102 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3103
3104
3105/**
James Smart3621a712009-04-06 18:47:14 -04003106 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003107 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003108 * @kobj: Pointer to the kernel object
3109 * @bin_attr: Attribute object
3110 * @buff: Buffer pointer
3111 * @off: File offset
3112 * @count: Buffer size
3113 *
3114 * This function is the read call back function for lpfc_drvr_stat_data
3115 * sysfs file. This function export the statistical data to user
3116 * applications.
3117 **/
3118static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003119sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3120 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003121 char *buf, loff_t off, size_t count)
3122{
3123 struct device *dev = container_of(kobj, struct device,
3124 kobj);
3125 struct Scsi_Host *shost = class_to_shost(dev);
3126 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3127 struct lpfc_hba *phba = vport->phba;
3128 int i = 0, index = 0;
3129 unsigned long nport_index;
3130 struct lpfc_nodelist *ndlp = NULL;
3131 nport_index = (unsigned long)off /
3132 MAX_STAT_DATA_SIZE_PER_TARGET;
3133
3134 if (!vport->stat_data_enabled || vport->stat_data_blocked
3135 || (phba->bucket_type == LPFC_NO_BUCKET))
3136 return 0;
3137
3138 spin_lock_irq(shost->host_lock);
3139 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3140 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3141 continue;
3142
3143 if (nport_index > 0) {
3144 nport_index--;
3145 continue;
3146 }
3147
3148 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3149 > count)
3150 break;
3151
3152 if (!ndlp->lat_data)
3153 continue;
3154
3155 /* Print the WWN */
3156 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3157 ndlp->nlp_portname.u.wwn[0],
3158 ndlp->nlp_portname.u.wwn[1],
3159 ndlp->nlp_portname.u.wwn[2],
3160 ndlp->nlp_portname.u.wwn[3],
3161 ndlp->nlp_portname.u.wwn[4],
3162 ndlp->nlp_portname.u.wwn[5],
3163 ndlp->nlp_portname.u.wwn[6],
3164 ndlp->nlp_portname.u.wwn[7]);
3165
3166 index = strlen(buf);
3167
3168 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3169 sprintf(&buf[index], "%010u,",
3170 ndlp->lat_data[i].cmd_count);
3171 index = strlen(buf);
3172 }
3173 sprintf(&buf[index], "\n");
3174 index = strlen(buf);
3175 }
3176 spin_unlock_irq(shost->host_lock);
3177 return index;
3178}
3179
3180static struct bin_attribute sysfs_drvr_stat_data_attr = {
3181 .attr = {
3182 .name = "lpfc_drvr_stat_data",
3183 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003184 },
3185 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3186 .read = sysfs_drvr_stat_data_read,
3187 .write = NULL,
3188};
3189
dea31012005-04-17 16:05:31 -05003190/*
3191# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3192# connection.
James Smart76a95d72010-11-20 23:11:48 -05003193# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003194*/
James Smarte59058c2008-08-24 21:49:00 -04003195/**
James Smart3621a712009-04-06 18:47:14 -04003196 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003197 * @phba: lpfc_hba pointer.
3198 * @val: link speed value.
3199 *
3200 * Description:
3201 * If val is in a valid range then set the adapter's link speed field and
3202 * issue a lip; if the lip fails reset the link speed to the old value.
3203 *
3204 * Notes:
3205 * If the value is not in range log a kernel error message and return an error.
3206 *
3207 * Returns:
3208 * zero if val is in range and lip okay.
3209 * non-zero return value from lpfc_issue_lip()
3210 * -EINVAL val out of range
3211 **/
James Smarta257bf92009-04-06 18:48:10 -04003212static ssize_t
3213lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3214 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003215{
James Smarta257bf92009-04-06 18:48:10 -04003216 struct Scsi_Host *shost = class_to_shost(dev);
3217 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3218 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003219 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003220 int nolip = 0;
3221 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003222 int err;
3223 uint32_t prev_val;
3224
James Smarta257bf92009-04-06 18:48:10 -04003225 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3226 nolip = 1;
3227 val_buf = &buf[strlen("nolip ")];
3228 }
3229
3230 if (!isdigit(val_buf[0]))
3231 return -EINVAL;
3232 if (sscanf(val_buf, "%i", &val) != 1)
3233 return -EINVAL;
3234
James Smart88a2cfb2011-07-22 18:36:33 -04003235 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3236 "3055 lpfc_link_speed changed from %d to %d %s\n",
3237 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3238
James Smart76a95d72010-11-20 23:11:48 -05003239 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3240 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3241 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3242 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3243 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3244 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3245 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3246 "2879 lpfc_link_speed attribute cannot be set "
3247 "to %d. Speed is not supported by this port.\n",
3248 val);
James Smart83108bd2008-01-11 01:53:09 -05003249 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003250 }
James Smartff78d8f2011-12-13 13:21:35 -05003251 if (val == LPFC_USER_LINK_SPEED_16G &&
3252 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3254 "3112 lpfc_link_speed attribute cannot be set "
3255 "to %d. Speed is not supported in loop mode.\n",
3256 val);
3257 return -EINVAL;
3258 }
James Smart76a95d72010-11-20 23:11:48 -05003259 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3260 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003261 prev_val = phba->cfg_link_speed;
3262 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003263 if (nolip)
3264 return strlen(buf);
3265
James Smart83108bd2008-01-11 01:53:09 -05003266 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003267 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003268 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003269 return -EINVAL;
3270 } else
3271 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003272 }
James Smart83108bd2008-01-11 01:53:09 -05003273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003274 "0469 lpfc_link_speed attribute cannot be set to %d, "
3275 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003276 return -EINVAL;
3277}
3278
3279static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003280module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003281MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3282lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003283
3284/**
James Smart3621a712009-04-06 18:47:14 -04003285 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003286 * @phba: lpfc_hba pointer.
3287 * @val: link speed value.
3288 *
3289 * Description:
3290 * If val is in a valid range then set the adapter's link speed field.
3291 *
3292 * Notes:
3293 * If the value is not in range log a kernel error message, clear the link
3294 * speed and return an error.
3295 *
3296 * Returns:
3297 * zero if val saved.
3298 * -EINVAL val out of range
3299 **/
James Smart83108bd2008-01-11 01:53:09 -05003300static int
3301lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3302{
James Smartff78d8f2011-12-13 13:21:35 -05003303 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3305 "3111 lpfc_link_speed of %d cannot "
3306 "support loop mode, setting topology to default.\n",
3307 val);
3308 phba->cfg_topology = 0;
3309 }
James Smart76a95d72010-11-20 23:11:48 -05003310 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3311 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003312 phba->cfg_link_speed = val;
3313 return 0;
3314 }
3315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003316 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003317 "be set to %d, allowed values are "
3318 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003319 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003320 return -EINVAL;
3321}
3322
Tony Jonesee959b02008-02-22 00:13:36 +01003323static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003324 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003325
3326/*
James Smart0d878412009-10-02 15:16:56 -04003327# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3328# 0 = aer disabled or not supported
3329# 1 = aer supported and enabled (default)
3330# Value range is [0,1]. Default value is 1.
3331*/
3332
3333/**
3334 * lpfc_aer_support_store - Set the adapter for aer support
3335 *
3336 * @dev: class device that is converted into a Scsi_host.
3337 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003338 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003339 * @count: unused variable.
3340 *
3341 * Description:
3342 * If the val is 1 and currently the device's AER capability was not
3343 * enabled, invoke the kernel's enable AER helper routine, trying to
3344 * enable the device's AER capability. If the helper routine enabling
3345 * AER returns success, update the device's cfg_aer_support flag to
3346 * indicate AER is supported by the device; otherwise, if the device
3347 * AER capability is already enabled to support AER, then do nothing.
3348 *
3349 * If the val is 0 and currently the device's AER support was enabled,
3350 * invoke the kernel's disable AER helper routine. After that, update
3351 * the device's cfg_aer_support flag to indicate AER is not supported
3352 * by the device; otherwise, if the device AER capability is already
3353 * disabled from supporting AER, then do nothing.
3354 *
3355 * Returns:
3356 * length of the buf on success if val is in range the intended mode
3357 * is supported.
3358 * -EINVAL if val out of range or intended mode is not supported.
3359 **/
3360static ssize_t
3361lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3362 const char *buf, size_t count)
3363{
3364 struct Scsi_Host *shost = class_to_shost(dev);
3365 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3366 struct lpfc_hba *phba = vport->phba;
3367 int val = 0, rc = -EINVAL;
3368
3369 if (!isdigit(buf[0]))
3370 return -EINVAL;
3371 if (sscanf(buf, "%i", &val) != 1)
3372 return -EINVAL;
3373
3374 switch (val) {
3375 case 0:
3376 if (phba->hba_flag & HBA_AER_ENABLED) {
3377 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3378 if (!rc) {
3379 spin_lock_irq(&phba->hbalock);
3380 phba->hba_flag &= ~HBA_AER_ENABLED;
3381 spin_unlock_irq(&phba->hbalock);
3382 phba->cfg_aer_support = 0;
3383 rc = strlen(buf);
3384 } else
James Smart891478a2009-11-18 15:40:23 -05003385 rc = -EPERM;
3386 } else {
James Smart0d878412009-10-02 15:16:56 -04003387 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003388 rc = strlen(buf);
3389 }
James Smart0d878412009-10-02 15:16:56 -04003390 break;
3391 case 1:
3392 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3393 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3394 if (!rc) {
3395 spin_lock_irq(&phba->hbalock);
3396 phba->hba_flag |= HBA_AER_ENABLED;
3397 spin_unlock_irq(&phba->hbalock);
3398 phba->cfg_aer_support = 1;
3399 rc = strlen(buf);
3400 } else
James Smart891478a2009-11-18 15:40:23 -05003401 rc = -EPERM;
3402 } else {
James Smart0d878412009-10-02 15:16:56 -04003403 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003404 rc = strlen(buf);
3405 }
James Smart0d878412009-10-02 15:16:56 -04003406 break;
3407 default:
3408 rc = -EINVAL;
3409 break;
3410 }
3411 return rc;
3412}
3413
3414static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003415module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003416MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3417lpfc_param_show(aer_support)
3418
3419/**
3420 * lpfc_aer_support_init - Set the initial adapters aer support flag
3421 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003422 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003423 *
3424 * Description:
3425 * If val is in a valid range [0,1], then set the adapter's initial
3426 * cfg_aer_support field. It will be up to the driver's probe_one
3427 * routine to determine whether the device's AER support can be set
3428 * or not.
3429 *
3430 * Notes:
3431 * If the value is not in range log a kernel error message, and
3432 * choose the default value of setting AER support and return.
3433 *
3434 * Returns:
3435 * zero if val saved.
3436 * -EINVAL val out of range
3437 **/
3438static int
3439lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3440{
3441 if (val == 0 || val == 1) {
3442 phba->cfg_aer_support = val;
3443 return 0;
3444 }
3445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3446 "2712 lpfc_aer_support attribute value %d out "
3447 "of range, allowed values are 0|1, setting it "
3448 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003449 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003450 phba->cfg_aer_support = 1;
3451 return -EINVAL;
3452}
3453
3454static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3455 lpfc_aer_support_show, lpfc_aer_support_store);
3456
3457/**
3458 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3459 * @dev: class device that is converted into a Scsi_host.
3460 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003461 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003462 * @count: unused variable.
3463 *
3464 * Description:
3465 * If the @buf contains 1 and the device currently has the AER support
3466 * enabled, then invokes the kernel AER helper routine
3467 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3468 * error status register.
3469 *
3470 * Notes:
3471 *
3472 * Returns:
3473 * -EINVAL if the buf does not contain the 1 or the device is not currently
3474 * enabled with the AER support.
3475 **/
3476static ssize_t
3477lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3478 const char *buf, size_t count)
3479{
3480 struct Scsi_Host *shost = class_to_shost(dev);
3481 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3482 struct lpfc_hba *phba = vport->phba;
3483 int val, rc = -1;
3484
3485 if (!isdigit(buf[0]))
3486 return -EINVAL;
3487 if (sscanf(buf, "%i", &val) != 1)
3488 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003489 if (val != 1)
3490 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003491
James Smart891478a2009-11-18 15:40:23 -05003492 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003493 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3494
3495 if (rc == 0)
3496 return strlen(buf);
3497 else
James Smart891478a2009-11-18 15:40:23 -05003498 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003499}
3500
3501static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3502 lpfc_aer_cleanup_state);
3503
James Smart912e3ac2011-05-24 11:42:11 -04003504/**
3505 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3506 *
3507 * @dev: class device that is converted into a Scsi_host.
3508 * @attr: device attribute, not used.
3509 * @buf: containing the string the number of vfs to be enabled.
3510 * @count: unused variable.
3511 *
3512 * Description:
3513 * When this api is called either through user sysfs, the driver shall
3514 * try to enable or disable SR-IOV virtual functions according to the
3515 * following:
3516 *
3517 * If zero virtual function has been enabled to the physical function,
3518 * the driver shall invoke the pci enable virtual function api trying
3519 * to enable the virtual functions. If the nr_vfn provided is greater
3520 * than the maximum supported, the maximum virtual function number will
3521 * be used for invoking the api; otherwise, the nr_vfn provided shall
3522 * be used for invoking the api. If the api call returned success, the
3523 * actual number of virtual functions enabled will be set to the driver
3524 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3525 * cfg_sriov_nr_virtfn remains zero.
3526 *
3527 * If none-zero virtual functions have already been enabled to the
3528 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3529 * -EINVAL will be returned and the driver does nothing;
3530 *
3531 * If the nr_vfn provided is zero and none-zero virtual functions have
3532 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3533 * disabling virtual function api shall be invoded to disable all the
3534 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3535 * zero. Otherwise, if zero virtual function has been enabled, do
3536 * nothing.
3537 *
3538 * Returns:
3539 * length of the buf on success if val is in range the intended mode
3540 * is supported.
3541 * -EINVAL if val out of range or intended mode is not supported.
3542 **/
3543static ssize_t
3544lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3545 const char *buf, size_t count)
3546{
3547 struct Scsi_Host *shost = class_to_shost(dev);
3548 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3549 struct lpfc_hba *phba = vport->phba;
3550 struct pci_dev *pdev = phba->pcidev;
3551 int val = 0, rc = -EINVAL;
3552
3553 /* Sanity check on user data */
3554 if (!isdigit(buf[0]))
3555 return -EINVAL;
3556 if (sscanf(buf, "%i", &val) != 1)
3557 return -EINVAL;
3558 if (val < 0)
3559 return -EINVAL;
3560
3561 /* Request disabling virtual functions */
3562 if (val == 0) {
3563 if (phba->cfg_sriov_nr_virtfn > 0) {
3564 pci_disable_sriov(pdev);
3565 phba->cfg_sriov_nr_virtfn = 0;
3566 }
3567 return strlen(buf);
3568 }
3569
3570 /* Request enabling virtual functions */
3571 if (phba->cfg_sriov_nr_virtfn > 0) {
3572 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3573 "3018 There are %d virtual functions "
3574 "enabled on physical function.\n",
3575 phba->cfg_sriov_nr_virtfn);
3576 return -EEXIST;
3577 }
3578
3579 if (val <= LPFC_MAX_VFN_PER_PFN)
3580 phba->cfg_sriov_nr_virtfn = val;
3581 else {
3582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3583 "3019 Enabling %d virtual functions is not "
3584 "allowed.\n", val);
3585 return -EINVAL;
3586 }
3587
3588 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3589 if (rc) {
3590 phba->cfg_sriov_nr_virtfn = 0;
3591 rc = -EPERM;
3592 } else
3593 rc = strlen(buf);
3594
3595 return rc;
3596}
3597
3598static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3599module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3600MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3601lpfc_param_show(sriov_nr_virtfn)
3602
3603/**
3604 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3605 * @phba: lpfc_hba pointer.
3606 * @val: link speed value.
3607 *
3608 * Description:
3609 * If val is in a valid range [0,255], then set the adapter's initial
3610 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3611 * number shall be used instead. It will be up to the driver's probe_one
3612 * routine to determine whether the device's SR-IOV is supported or not.
3613 *
3614 * Returns:
3615 * zero if val saved.
3616 * -EINVAL val out of range
3617 **/
3618static int
3619lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3620{
3621 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3622 phba->cfg_sriov_nr_virtfn = val;
3623 return 0;
3624 }
3625
3626 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3627 "3017 Enabling %d virtual functions is not "
3628 "allowed.\n", val);
3629 return -EINVAL;
3630}
3631static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3632 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3633
James Smart173edbb2012-06-12 13:54:50 -04003634/**
James Smartc71ab862012-10-31 14:44:33 -04003635 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
3636 *
3637 * @dev: class device that is converted into a Scsi_host.
3638 * @attr: device attribute, not used.
3639 * @buf: containing the string the number of vfs to be enabled.
3640 * @count: unused variable.
3641 *
3642 * Description:
3643 *
3644 * Returns:
3645 * length of the buf on success if val is in range the intended mode
3646 * is supported.
3647 * -EINVAL if val out of range or intended mode is not supported.
3648 **/
3649static ssize_t
3650lpfc_request_firmware_upgrade_store(struct device *dev,
3651 struct device_attribute *attr,
3652 const char *buf, size_t count)
3653{
3654 struct Scsi_Host *shost = class_to_shost(dev);
3655 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3656 struct lpfc_hba *phba = vport->phba;
3657 int val = 0, rc = -EINVAL;
3658
3659 /* Sanity check on user data */
3660 if (!isdigit(buf[0]))
3661 return -EINVAL;
3662 if (sscanf(buf, "%i", &val) != 1)
3663 return -EINVAL;
3664 if (val != 1)
3665 return -EINVAL;
3666
3667 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
3668 if (rc)
3669 rc = -EPERM;
3670 else
3671 rc = strlen(buf);
3672 return rc;
3673}
3674
3675static int lpfc_req_fw_upgrade;
3676module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
3677MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
3678lpfc_param_show(request_firmware_upgrade)
3679
3680/**
3681 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
3682 * @phba: lpfc_hba pointer.
3683 * @val: 0 or 1.
3684 *
3685 * Description:
3686 * Set the initial Linux generic firmware upgrade enable or disable flag.
3687 *
3688 * Returns:
3689 * zero if val saved.
3690 * -EINVAL val out of range
3691 **/
3692static int
3693lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
3694{
3695 if (val >= 0 && val <= 1) {
3696 phba->cfg_request_firmware_upgrade = val;
3697 return 0;
3698 }
3699 return -EINVAL;
3700}
3701static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
3702 lpfc_request_firmware_upgrade_show,
3703 lpfc_request_firmware_upgrade_store);
3704
3705/**
James Smart173edbb2012-06-12 13:54:50 -04003706 * lpfc_fcp_imax_store
3707 *
3708 * @dev: class device that is converted into a Scsi_host.
3709 * @attr: device attribute, not used.
3710 * @buf: string with the number of fast-path FCP interrupts per second.
3711 * @count: unused variable.
3712 *
3713 * Description:
3714 * If val is in a valid range [636,651042], then set the adapter's
3715 * maximum number of fast-path FCP interrupts per second.
3716 *
3717 * Returns:
3718 * length of the buf on success if val is in range the intended mode
3719 * is supported.
3720 * -EINVAL if val out of range or intended mode is not supported.
3721 **/
3722static ssize_t
3723lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
3724 const char *buf, size_t count)
3725{
3726 struct Scsi_Host *shost = class_to_shost(dev);
3727 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3728 struct lpfc_hba *phba = vport->phba;
3729 int val = 0, i;
3730
James Smartbf8dae82012-08-03 12:36:24 -04003731 /* fcp_imax is only valid for SLI4 */
3732 if (phba->sli_rev != LPFC_SLI_REV4)
3733 return -EINVAL;
3734
James Smart173edbb2012-06-12 13:54:50 -04003735 /* Sanity check on user data */
3736 if (!isdigit(buf[0]))
3737 return -EINVAL;
3738 if (sscanf(buf, "%i", &val) != 1)
3739 return -EINVAL;
3740
James Smartbf8dae82012-08-03 12:36:24 -04003741 /*
3742 * Value range for the HBA is [5000,5000000]
3743 * The value for each EQ depends on how many EQs are configured.
3744 */
3745 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04003746 return -EINVAL;
3747
3748 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04003749 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04003750 lpfc_modify_fcp_eq_delay(phba, i);
3751
3752 return strlen(buf);
3753}
3754
3755/*
3756# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04003757# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04003758#
James Smartbf8dae82012-08-03 12:36:24 -04003759# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04003760*/
James Smartbf8dae82012-08-03 12:36:24 -04003761static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003762module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
3763MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04003764 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04003765lpfc_param_show(fcp_imax)
3766
3767/**
3768 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
3769 * @phba: lpfc_hba pointer.
3770 * @val: link speed value.
3771 *
3772 * Description:
3773 * If val is in a valid range [636,651042], then initialize the adapter's
3774 * maximum number of fast-path FCP interrupts per second.
3775 *
3776 * Returns:
3777 * zero if val saved.
3778 * -EINVAL val out of range
3779 **/
3780static int
3781lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
3782{
James Smartbf8dae82012-08-03 12:36:24 -04003783 if (phba->sli_rev != LPFC_SLI_REV4) {
3784 phba->cfg_fcp_imax = 0;
3785 return 0;
3786 }
3787
3788 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04003789 phba->cfg_fcp_imax = val;
3790 return 0;
3791 }
3792
3793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3794 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04003795 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003796
3797 return 0;
3798}
3799
3800static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
3801 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
3802
James Smart7bb03bb2013-04-17 20:19:16 -04003803/**
3804 * lpfc_state_show - Display current driver CPU affinity
3805 * @dev: class converted to a Scsi_host structure.
3806 * @attr: device attribute, not used.
3807 * @buf: on return contains text describing the state of the link.
3808 *
3809 * Returns: size of formatted string.
3810 **/
3811static ssize_t
3812lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
3813 char *buf)
3814{
3815 struct Scsi_Host *shost = class_to_shost(dev);
3816 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3817 struct lpfc_hba *phba = vport->phba;
3818 struct lpfc_vector_map_info *cpup;
3819 int idx, len = 0;
3820
3821 if ((phba->sli_rev != LPFC_SLI_REV4) ||
3822 (phba->intr_type != MSIX))
3823 return len;
3824
3825 switch (phba->cfg_fcp_cpu_map) {
3826 case 0:
3827 len += snprintf(buf + len, PAGE_SIZE-len,
3828 "fcp_cpu_map: No mapping (%d)\n",
3829 phba->cfg_fcp_cpu_map);
3830 return len;
3831 case 1:
3832 len += snprintf(buf + len, PAGE_SIZE-len,
3833 "fcp_cpu_map: HBA centric mapping (%d): "
3834 "%d online CPUs\n",
3835 phba->cfg_fcp_cpu_map,
3836 phba->sli4_hba.num_online_cpu);
3837 break;
3838 case 2:
3839 len += snprintf(buf + len, PAGE_SIZE-len,
3840 "fcp_cpu_map: Driver centric mapping (%d): "
3841 "%d online CPUs\n",
3842 phba->cfg_fcp_cpu_map,
3843 phba->sli4_hba.num_online_cpu);
3844 break;
3845 }
3846
3847 cpup = phba->sli4_hba.cpu_map;
3848 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
3849 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
3850 len += snprintf(buf + len, PAGE_SIZE-len,
3851 "CPU %02d io_chan %02d "
3852 "physid %d coreid %d\n",
3853 idx, cpup->channel_id, cpup->phys_id,
3854 cpup->core_id);
3855 else
3856 len += snprintf(buf + len, PAGE_SIZE-len,
3857 "CPU %02d io_chan %02d "
3858 "physid %d coreid %d IRQ %d\n",
3859 idx, cpup->channel_id, cpup->phys_id,
3860 cpup->core_id, cpup->irq);
3861
3862 cpup++;
3863 }
3864 return len;
3865}
3866
3867/**
3868 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
3869 * @dev: class device that is converted into a Scsi_host.
3870 * @attr: device attribute, not used.
3871 * @buf: one or more lpfc_polling_flags values.
3872 * @count: not used.
3873 *
3874 * Returns:
3875 * -EINVAL - Not implemented yet.
3876 **/
3877static ssize_t
3878lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
3879 const char *buf, size_t count)
3880{
3881 int status = -EINVAL;
3882 return status;
3883}
3884
3885/*
3886# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
3887# for the HBA.
3888#
3889# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
3890# 0 - Do not affinitze IRQ vectors
3891# 1 - Affintize HBA vectors with respect to each HBA
3892# (start with CPU0 for each HBA)
3893# 2 - Affintize HBA vectors with respect to the entire driver
3894# (round robin thru all CPUs across all HBAs)
3895*/
3896static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
3897module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
3898MODULE_PARM_DESC(lpfc_fcp_cpu_map,
3899 "Defines how to map CPUs to IRQ vectors per HBA");
3900
3901/**
3902 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
3903 * @phba: lpfc_hba pointer.
3904 * @val: link speed value.
3905 *
3906 * Description:
3907 * If val is in a valid range [0-2], then affinitze the adapter's
3908 * MSIX vectors.
3909 *
3910 * Returns:
3911 * zero if val saved.
3912 * -EINVAL val out of range
3913 **/
3914static int
3915lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
3916{
3917 if (phba->sli_rev != LPFC_SLI_REV4) {
3918 phba->cfg_fcp_cpu_map = 0;
3919 return 0;
3920 }
3921
3922 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
3923 phba->cfg_fcp_cpu_map = val;
3924 return 0;
3925 }
3926
3927 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3928 "3326 fcp_cpu_map: %d out of range, using default\n",
3929 val);
3930 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
3931
3932 return 0;
3933}
3934
3935static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
3936 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
3937
James Smart0d878412009-10-02 15:16:56 -04003938/*
dea31012005-04-17 16:05:31 -05003939# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3940# Value range is [2,3]. Default value is 3.
3941*/
James Smart3de2a652007-08-02 11:09:59 -04003942LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3943 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003944
3945/*
3946# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3947# is [0,1]. Default value is 0.
3948*/
James Smart3de2a652007-08-02 11:09:59 -04003949LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3950 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003951
3952/*
James Smart977b5a02008-09-07 11:52:04 -04003953# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3954# depth. Default value is 0. When the value of this parameter is zero the
3955# SCSI command completion time is not used for controlling I/O queue depth. When
3956# the parameter is set to a non-zero value, the I/O queue depth is controlled
3957# to limit the I/O completion time to the parameter value.
3958# The value is set in milliseconds.
3959*/
3960static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003961module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003962MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3963 "Use command completion time to control queue depth");
3964lpfc_vport_param_show(max_scsicmpl_time);
3965lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3966static int
3967lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3968{
3969 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3970 struct lpfc_nodelist *ndlp, *next_ndlp;
3971
3972 if (val == vport->cfg_max_scsicmpl_time)
3973 return 0;
3974 if ((val < 0) || (val > 60000))
3975 return -EINVAL;
3976 vport->cfg_max_scsicmpl_time = val;
3977
3978 spin_lock_irq(shost->host_lock);
3979 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3980 if (!NLP_CHK_NODE_ACT(ndlp))
3981 continue;
3982 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3983 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003984 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003985 }
3986 spin_unlock_irq(shost->host_lock);
3987 return 0;
3988}
3989lpfc_vport_param_store(max_scsicmpl_time);
3990static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3991 lpfc_max_scsicmpl_time_show,
3992 lpfc_max_scsicmpl_time_store);
3993
3994/*
dea31012005-04-17 16:05:31 -05003995# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3996# range is [0,1]. Default value is 0.
3997*/
3998LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3999
4000/*
James Smart49aa1432012-08-03 12:36:42 -04004001# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4002# range is [0,1]. Default value is 0.
4003# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4004# For [1], FCP commands are issued to a Work Queue associated with the
4005# current CPU.
4006*/
4007LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algrithmn for "
4008 "issuing commands [0] - Round Robin, [1] - Current CPU");
4009
4010/*
James Smarta6571c62012-10-31 14:44:42 -04004011# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4012# range is [0,1]. Default value is 0.
4013# For [0], bus reset issues target reset to ALL devices
4014# For [1], bus reset issues target reset to non-FCP2 devices
4015*/
4016LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4017 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4018
4019
4020/*
dea31012005-04-17 16:05:31 -05004021# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4022# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004023# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004024# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4025# cr_delay is set to 0.
4026*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004027LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004028 "interrupt response is generated");
4029
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004030LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004031 "interrupt response is generated");
4032
4033/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004034# lpfc_multi_ring_support: Determines how many rings to spread available
4035# cmd/rsp IOCB entries across.
4036# Value range is [1,2]. Default value is 1.
4037*/
4038LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4039 "SLI rings to spread IOCB entries across");
4040
4041/*
James Smarta4bc3372006-12-02 13:34:16 -05004042# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4043# identifies what rctl value to configure the additional ring for.
4044# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4045*/
James Smart6a9c52c2009-10-02 15:16:51 -04004046LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004047 255, "Identifies RCTL for additional ring configuration");
4048
4049/*
4050# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4051# identifies what type value to configure the additional ring for.
4052# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4053*/
James Smart6a9c52c2009-10-02 15:16:51 -04004054LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004055 255, "Identifies TYPE for additional ring configuration");
4056
4057/*
dea31012005-04-17 16:05:31 -05004058# lpfc_fdmi_on: controls FDMI support.
4059# 0 = no FDMI support
4060# 1 = support FDMI without attribute of hostname
4061# 2 = support FDMI with attribute of hostname
4062# Value range [0,2]. Default value is 0.
4063*/
James Smart3de2a652007-08-02 11:09:59 -04004064LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004065
4066/*
4067# Specifies the maximum number of ELS cmds we can have outstanding (for
4068# discovery). Value range is [1,64]. Default value = 32.
4069*/
James Smart3de2a652007-08-02 11:09:59 -04004070LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004071 "during discovery");
4072
4073/*
James Smartc4a7c922013-05-31 17:04:59 -04004074# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4075# will be scanned by the SCSI midlayer when sequential scanning is
4076# used; and is also the highest LUN ID allowed when the SCSI midlayer
4077# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4078# LUN ID limit, but the SCSI midlayer requires this field for the uses
4079# above. The lpfc driver limits the default value to 255 for two reasons.
4080# As it bounds the sequential scan loop, scanning for thousands of luns
4081# on a target can take minutes of wall clock time. Additionally,
4082# there are FC targets, such as JBODs, that only recognize 8-bits of
4083# LUN ID. When they receive a value greater than 8 bits, they chop off
4084# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4085# and so on all as LUN ID 0. This causes the linux kernel, which sees
4086# valid responses at each of the LUN IDs, to believe there are multiple
4087# devices present, when in fact, there is only 1.
4088# A customer that is aware of their target behaviors, and the results as
4089# indicated above, is welcome to increase the lpfc_max_luns value.
4090# As mentioned, this value is not used by the lpfc driver, only the
4091# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004092# Value range is [0,65535]. Default value is 255.
4093# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004094*/
James Smartc4a7c922013-05-31 17:04:59 -04004095LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004096
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004097/*
4098# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4099# Value range is [1,255], default value is 10.
4100*/
4101LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4102 "Milliseconds driver will wait between polling FCP ring");
4103
James Smart4ff43242006-12-02 13:34:56 -05004104/*
4105# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4106# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004107# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004108# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004109# 2 = MSI-X enabled (default)
4110# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004111*/
George Kadianakis8605c462010-01-17 21:19:31 +02004112LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004113 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004114
James Smart13815c82008-01-11 01:52:48 -05004115/*
James Smartda0436e2009-05-22 14:51:39 -04004116# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
James Smart67d12732012-08-03 12:36:13 -04004117# This parameter is ignored and will eventually be depricated
James Smartda0436e2009-05-22 14:51:39 -04004118#
James Smart67d12732012-08-03 12:36:13 -04004119# Value range is [1,7]. Default value is 4.
James Smartda0436e2009-05-22 14:51:39 -04004120*/
James Smart67d12732012-08-03 12:36:13 -04004121LPFC_ATTR_R(fcp_wq_count, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4122 LPFC_FCP_IO_CHAN_MAX,
James Smartda0436e2009-05-22 14:51:39 -04004123 "Set the number of fast-path FCP work queues, if possible");
4124
4125/*
James Smart67d12732012-08-03 12:36:13 -04004126# lpfc_fcp_eq_count: Set the number of FCP EQ/CQ/WQ IO channels
James Smartda0436e2009-05-22 14:51:39 -04004127#
James Smart67d12732012-08-03 12:36:13 -04004128# Value range is [1,7]. Default value is 4.
James Smartda0436e2009-05-22 14:51:39 -04004129*/
James Smart67d12732012-08-03 12:36:13 -04004130LPFC_ATTR_R(fcp_eq_count, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4131 LPFC_FCP_IO_CHAN_MAX,
James Smartda0436e2009-05-22 14:51:39 -04004132 "Set the number of fast-path FCP event queues, if possible");
4133
4134/*
James Smart67d12732012-08-03 12:36:13 -04004135# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4136#
4137# Value range is [1,7]. Default value is 4.
4138*/
4139LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4140 LPFC_FCP_IO_CHAN_MAX,
4141 "Set the number of FCP I/O channels");
4142
4143/*
James Smart13815c82008-01-11 01:52:48 -05004144# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4145# 0 = HBA resets disabled
4146# 1 = HBA resets enabled (default)
4147# Value range is [0,1]. Default value is 1.
4148*/
4149LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004150
James Smart13815c82008-01-11 01:52:48 -05004151/*
James Smarteb7a3392010-11-20 23:12:02 -05004152# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004153# 0 = HBA Heartbeat disabled
4154# 1 = HBA Heartbeat enabled (default)
4155# Value range is [0,1]. Default value is 1.
4156*/
James Smarteb7a3392010-11-20 23:12:02 -05004157LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004158
James Smart83108bd2008-01-11 01:53:09 -05004159/*
James Smart81301a92008-12-04 22:39:46 -05004160# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4161# 0 = BlockGuard disabled (default)
4162# 1 = BlockGuard enabled
4163# Value range is [0,1]. Default value is 0.
4164*/
4165LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4166
James Smart6fb120a2009-05-22 14:52:59 -04004167/*
James Smartba20c852012-08-03 12:36:52 -04004168# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4169# 0 = disabled (default)
4170# 1 = enabled
4171# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004172#
4173# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004174*/
4175unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4176
James Smartba20c852012-08-03 12:36:52 -04004177/*
James Smart81301a92008-12-04 22:39:46 -05004178# lpfc_prot_mask: i
4179# - Bit mask of host protection capabilities used to register with the
4180# SCSI mid-layer
4181# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4182# - Allows you to ultimately specify which profiles to use
4183# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004184# - SHOST_DIF_TYPE1_PROTECTION 1
4185# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4186# - SHOST_DIX_TYPE0_PROTECTION 8
4187# HBA supports DIX Type 0: Host to HBA protection only
4188# - SHOST_DIX_TYPE1_PROTECTION 16
4189# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004190#
4191*/
James Smart7c56b9f2011-07-22 18:36:25 -04004192unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4193 SHOST_DIX_TYPE0_PROTECTION |
4194 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004195
James Smartab56dc22011-02-16 12:39:57 -05004196module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004197MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4198
4199/*
4200# lpfc_prot_guard: i
4201# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004202# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004203# - Allows you to ultimately specify which profiles to use
4204# - Default will result in registering capabilities for all guard types
4205#
4206*/
4207unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004208module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004209MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4210
James Smart92494142011-02-16 12:39:44 -05004211/*
4212 * Delay initial NPort discovery when Clean Address bit is cleared in
4213 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4214 * This parameter can have value 0 or 1.
4215 * When this parameter is set to 0, no delay is added to the initial
4216 * discovery.
4217 * When this parameter is set to non-zero value, initial Nport discovery is
4218 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4219 * accept and FCID/Fabric name/Fabric portname is changed.
4220 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4221 * when Clean Address bit is cleared in FLOGI/FDISC
4222 * accept and FCID/Fabric name/Fabric portname is changed.
4223 * Default value is 0.
4224 */
4225int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05004226module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05004227MODULE_PARM_DESC(lpfc_delay_discovery,
4228 "Delay NPort discovery when Clean Address bit is cleared. "
4229 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05004230
4231/*
James Smart3621a712009-04-06 18:47:14 -04004232 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004233 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004234 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4235 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004236 * Because of the additional overhead involved in setting up T10-DIF,
4237 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4238 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004239 */
4240LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4241 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4242
James Smart96f70772013-04-17 20:16:15 -04004243/*
4244 * This parameter will be depricated, the driver cannot limit the
4245 * protection data s/g list.
4246 */
4247LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4248 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4249 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004250
Tony Jonesee959b02008-02-22 00:13:36 +01004251struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004252 &dev_attr_bg_info,
4253 &dev_attr_bg_guard_err,
4254 &dev_attr_bg_apptag_err,
4255 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004256 &dev_attr_info,
4257 &dev_attr_serialnum,
4258 &dev_attr_modeldesc,
4259 &dev_attr_modelname,
4260 &dev_attr_programtype,
4261 &dev_attr_portnum,
4262 &dev_attr_fwrev,
4263 &dev_attr_hdw,
4264 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004265 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004266 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004267 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004268 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004269 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004270 &dev_attr_lpfc_temp_sensor,
4271 &dev_attr_lpfc_log_verbose,
4272 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004273 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004274 &dev_attr_lpfc_hba_queue_depth,
4275 &dev_attr_lpfc_peer_port_login,
4276 &dev_attr_lpfc_nodev_tmo,
4277 &dev_attr_lpfc_devloss_tmo,
4278 &dev_attr_lpfc_fcp_class,
4279 &dev_attr_lpfc_use_adisc,
4280 &dev_attr_lpfc_ack0,
4281 &dev_attr_lpfc_topology,
4282 &dev_attr_lpfc_scan_down,
4283 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004284 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004285 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004286 &dev_attr_lpfc_cr_delay,
4287 &dev_attr_lpfc_cr_count,
4288 &dev_attr_lpfc_multi_ring_support,
4289 &dev_attr_lpfc_multi_ring_rctl,
4290 &dev_attr_lpfc_multi_ring_type,
4291 &dev_attr_lpfc_fdmi_on,
4292 &dev_attr_lpfc_max_luns,
4293 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004294 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004295 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004296 &dev_attr_nport_evt_cnt,
4297 &dev_attr_board_mode,
4298 &dev_attr_max_vpi,
4299 &dev_attr_used_vpi,
4300 &dev_attr_max_rpi,
4301 &dev_attr_used_rpi,
4302 &dev_attr_max_xri,
4303 &dev_attr_used_xri,
4304 &dev_attr_npiv_info,
4305 &dev_attr_issue_reset,
4306 &dev_attr_lpfc_poll,
4307 &dev_attr_lpfc_poll_tmo,
4308 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004309 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004310 &dev_attr_lpfc_fcp_cpu_map,
James Smartda0436e2009-05-22 14:51:39 -04004311 &dev_attr_lpfc_fcp_wq_count,
4312 &dev_attr_lpfc_fcp_eq_count,
James Smart67d12732012-08-03 12:36:13 -04004313 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004314 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004315 &dev_attr_lpfc_soft_wwnn,
4316 &dev_attr_lpfc_soft_wwpn,
4317 &dev_attr_lpfc_soft_wwn_enable,
4318 &dev_attr_lpfc_enable_hba_reset,
4319 &dev_attr_lpfc_enable_hba_heartbeat,
4320 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004321 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004322 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004323 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004324 &dev_attr_lpfc_aer_support,
4325 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004326 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004327 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004328 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004329 &dev_attr_lpfc_iocb_cnt,
4330 &dev_attr_iocb_hw,
4331 &dev_attr_txq_hw,
4332 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004333 &dev_attr_lpfc_fips_level,
4334 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004335 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004336 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004337 &dev_attr_protocol,
dea31012005-04-17 16:05:31 -05004338 NULL,
4339};
4340
Tony Jonesee959b02008-02-22 00:13:36 +01004341struct device_attribute *lpfc_vport_attrs[] = {
4342 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004343 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004344 &dev_attr_num_discovered_ports,
4345 &dev_attr_lpfc_drvr_version,
4346 &dev_attr_lpfc_log_verbose,
4347 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004348 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004349 &dev_attr_lpfc_nodev_tmo,
4350 &dev_attr_lpfc_devloss_tmo,
4351 &dev_attr_lpfc_hba_queue_depth,
4352 &dev_attr_lpfc_peer_port_login,
4353 &dev_attr_lpfc_restrict_login,
4354 &dev_attr_lpfc_fcp_class,
4355 &dev_attr_lpfc_use_adisc,
4356 &dev_attr_lpfc_fdmi_on,
4357 &dev_attr_lpfc_max_luns,
4358 &dev_attr_nport_evt_cnt,
4359 &dev_attr_npiv_info,
4360 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004361 &dev_attr_lpfc_max_scsicmpl_time,
4362 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004363 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004364 &dev_attr_lpfc_fips_level,
4365 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004366 NULL,
4367};
4368
James Smarte59058c2008-08-24 21:49:00 -04004369/**
James Smart3621a712009-04-06 18:47:14 -04004370 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004371 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004372 * @kobj: kernel kobject that contains the kernel class device.
4373 * @bin_attr: kernel attributes passed to us.
4374 * @buf: contains the data to be written to the adapter IOREG space.
4375 * @off: offset into buffer to beginning of data.
4376 * @count: bytes to transfer.
4377 *
4378 * Description:
4379 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4380 * Uses the adapter io control registers to send buf contents to the adapter.
4381 *
4382 * Returns:
4383 * -ERANGE off and count combo out of range
4384 * -EINVAL off, count or buff address invalid
4385 * -EPERM adapter is offline
4386 * value of count, buf contents written
4387 **/
dea31012005-04-17 16:05:31 -05004388static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004389sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4390 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004391 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004392{
4393 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004394 struct device *dev = container_of(kobj, struct device, kobj);
4395 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004396 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4397 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004398
James Smartf1126682009-06-10 17:22:44 -04004399 if (phba->sli_rev >= LPFC_SLI_REV4)
4400 return -EPERM;
4401
dea31012005-04-17 16:05:31 -05004402 if ((off + count) > FF_REG_AREA_SIZE)
4403 return -ERANGE;
4404
James Smartf7a919b2011-08-21 21:49:16 -04004405 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4406 return 0;
dea31012005-04-17 16:05:31 -05004407
4408 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4409 return -EINVAL;
4410
James Smartf7a919b2011-08-21 21:49:16 -04004411 /* This is to protect HBA registers from accidental writes. */
4412 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4413 return -EINVAL;
4414
4415 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004416 return -EPERM;
dea31012005-04-17 16:05:31 -05004417
James Smart2e0fef82007-06-17 19:56:36 -05004418 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004419 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4420 buf_off += sizeof(uint32_t))
4421 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004422 phba->ctrl_regs_memmap_p + off + buf_off);
4423
James Smart2e0fef82007-06-17 19:56:36 -05004424 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004425
4426 return count;
4427}
4428
James Smarte59058c2008-08-24 21:49:00 -04004429/**
James Smart3621a712009-04-06 18:47:14 -04004430 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004431 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004432 * @kobj: kernel kobject that contains the kernel class device.
4433 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004434 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004435 * @off: offset into buffer to beginning of data.
4436 * @count: bytes to transfer.
4437 *
4438 * Description:
4439 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4440 * Uses the adapter io control registers to read data into buf.
4441 *
4442 * Returns:
4443 * -ERANGE off and count combo out of range
4444 * -EINVAL off, count or buff address invalid
4445 * value of count, buf contents read
4446 **/
dea31012005-04-17 16:05:31 -05004447static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004448sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4449 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004450 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004451{
4452 size_t buf_off;
4453 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004454 struct device *dev = container_of(kobj, struct device, kobj);
4455 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4457 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004458
James Smartf1126682009-06-10 17:22:44 -04004459 if (phba->sli_rev >= LPFC_SLI_REV4)
4460 return -EPERM;
4461
dea31012005-04-17 16:05:31 -05004462 if (off > FF_REG_AREA_SIZE)
4463 return -ERANGE;
4464
4465 if ((off + count) > FF_REG_AREA_SIZE)
4466 count = FF_REG_AREA_SIZE - off;
4467
4468 if (count == 0) return 0;
4469
4470 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4471 return -EINVAL;
4472
James Smart2e0fef82007-06-17 19:56:36 -05004473 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004474
4475 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4476 tmp_ptr = (uint32_t *)(buf + buf_off);
4477 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4478 }
4479
James Smart2e0fef82007-06-17 19:56:36 -05004480 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004481
4482 return count;
4483}
4484
4485static struct bin_attribute sysfs_ctlreg_attr = {
4486 .attr = {
4487 .name = "ctlreg",
4488 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004489 },
4490 .size = 256,
4491 .read = sysfs_ctlreg_read,
4492 .write = sysfs_ctlreg_write,
4493};
4494
James Smarte59058c2008-08-24 21:49:00 -04004495/**
James Smart3621a712009-04-06 18:47:14 -04004496 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004497 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004498 * @kobj: kernel kobject that contains the kernel class device.
4499 * @bin_attr: kernel attributes passed to us.
4500 * @buf: contains the data to be written to sysfs mbox.
4501 * @off: offset into buffer to beginning of data.
4502 * @count: bytes to transfer.
4503 *
4504 * Description:
James Smart026abb82011-12-13 13:20:45 -05004505 * Deprecated function. All mailbox access from user space is performed via the
4506 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004507 *
4508 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004509 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004510 **/
dea31012005-04-17 16:05:31 -05004511static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004512sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4513 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004514 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004515{
James Smart026abb82011-12-13 13:20:45 -05004516 return -EPERM;
dea31012005-04-17 16:05:31 -05004517}
4518
James Smarte59058c2008-08-24 21:49:00 -04004519/**
James Smart3621a712009-04-06 18:47:14 -04004520 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004521 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004522 * @kobj: kernel kobject that contains the kernel class device.
4523 * @bin_attr: kernel attributes passed to us.
4524 * @buf: contains the data to be read from sysfs mbox.
4525 * @off: offset into buffer to beginning of data.
4526 * @count: bytes to transfer.
4527 *
4528 * Description:
James Smart026abb82011-12-13 13:20:45 -05004529 * Deprecated function. All mailbox access from user space is performed via the
4530 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004531 *
4532 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004533 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004534 **/
dea31012005-04-17 16:05:31 -05004535static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004536sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4537 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004538 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004539{
James Smart026abb82011-12-13 13:20:45 -05004540 return -EPERM;
dea31012005-04-17 16:05:31 -05004541}
4542
4543static struct bin_attribute sysfs_mbox_attr = {
4544 .attr = {
4545 .name = "mbox",
4546 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004547 },
James Smartc0c11512011-05-24 11:41:34 -04004548 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004549 .read = sysfs_mbox_read,
4550 .write = sysfs_mbox_write,
4551};
4552
James Smarte59058c2008-08-24 21:49:00 -04004553/**
James Smart3621a712009-04-06 18:47:14 -04004554 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004555 * @vport: address of lpfc vport structure.
4556 *
4557 * Return codes:
4558 * zero on success
4559 * error return code from sysfs_create_bin_file()
4560 **/
dea31012005-04-17 16:05:31 -05004561int
James Smart2e0fef82007-06-17 19:56:36 -05004562lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004563{
James Smart2e0fef82007-06-17 19:56:36 -05004564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004565 int error;
4566
Tony Jonesee959b02008-02-22 00:13:36 +01004567 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004568 &sysfs_drvr_stat_data_attr);
4569
4570 /* Virtual ports do not need ctrl_reg and mbox */
4571 if (error || vport->port_type == LPFC_NPIV_PORT)
4572 goto out;
4573
4574 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004575 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004576 if (error)
James Smarteada2722008-12-04 22:39:13 -05004577 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004578
Tony Jonesee959b02008-02-22 00:13:36 +01004579 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004580 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004581 if (error)
4582 goto out_remove_ctlreg_attr;
4583
4584 return 0;
4585out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004586 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004587out_remove_stat_attr:
4588 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4589 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004590out:
4591 return error;
4592}
4593
James Smarte59058c2008-08-24 21:49:00 -04004594/**
James Smart3621a712009-04-06 18:47:14 -04004595 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004596 * @vport: address of lpfc vport structure.
4597 **/
dea31012005-04-17 16:05:31 -05004598void
James Smart2e0fef82007-06-17 19:56:36 -05004599lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004600{
James Smart2e0fef82007-06-17 19:56:36 -05004601 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004602 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4603 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004604 /* Virtual ports do not need ctrl_reg and mbox */
4605 if (vport->port_type == LPFC_NPIV_PORT)
4606 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004607 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4608 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004609}
4610
4611
4612/*
4613 * Dynamic FC Host Attributes Support
4614 */
4615
James Smarte59058c2008-08-24 21:49:00 -04004616/**
James Smart3621a712009-04-06 18:47:14 -04004617 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004618 * @shost: kernel scsi host pointer.
4619 **/
dea31012005-04-17 16:05:31 -05004620static void
4621lpfc_get_host_port_id(struct Scsi_Host *shost)
4622{
James Smart2e0fef82007-06-17 19:56:36 -05004623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4624
dea31012005-04-17 16:05:31 -05004625 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004626 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004627}
4628
James Smarte59058c2008-08-24 21:49:00 -04004629/**
James Smart3621a712009-04-06 18:47:14 -04004630 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004631 * @shost: kernel scsi host pointer.
4632 **/
dea31012005-04-17 16:05:31 -05004633static void
4634lpfc_get_host_port_type(struct Scsi_Host *shost)
4635{
James Smart2e0fef82007-06-17 19:56:36 -05004636 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4637 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004638
4639 spin_lock_irq(shost->host_lock);
4640
James Smart92d7f7b2007-06-17 19:56:38 -05004641 if (vport->port_type == LPFC_NPIV_PORT) {
4642 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4643 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004644 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004645 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004646 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4647 else
4648 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4649 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004650 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004651 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4652 else
4653 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4654 }
4655 } else
4656 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4657
4658 spin_unlock_irq(shost->host_lock);
4659}
4660
James Smarte59058c2008-08-24 21:49:00 -04004661/**
James Smart3621a712009-04-06 18:47:14 -04004662 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004663 * @shost: kernel scsi host pointer.
4664 **/
dea31012005-04-17 16:05:31 -05004665static void
4666lpfc_get_host_port_state(struct Scsi_Host *shost)
4667{
James Smart2e0fef82007-06-17 19:56:36 -05004668 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4669 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004670
4671 spin_lock_irq(shost->host_lock);
4672
James Smart2e0fef82007-06-17 19:56:36 -05004673 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004674 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4675 else {
James Smart2e0fef82007-06-17 19:56:36 -05004676 switch (phba->link_state) {
4677 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004678 case LPFC_LINK_DOWN:
4679 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4680 break;
4681 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004682 case LPFC_CLEAR_LA:
4683 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05004684 /* Links up, reports port state accordingly */
4685 if (vport->port_state < LPFC_VPORT_READY)
4686 fc_host_port_state(shost) =
4687 FC_PORTSTATE_BYPASSED;
4688 else
4689 fc_host_port_state(shost) =
4690 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05004691 break;
4692 case LPFC_HBA_ERROR:
4693 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4694 break;
4695 default:
4696 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4697 break;
4698 }
4699 }
4700
4701 spin_unlock_irq(shost->host_lock);
4702}
4703
James Smarte59058c2008-08-24 21:49:00 -04004704/**
James Smart3621a712009-04-06 18:47:14 -04004705 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004706 * @shost: kernel scsi host pointer.
4707 **/
dea31012005-04-17 16:05:31 -05004708static void
4709lpfc_get_host_speed(struct Scsi_Host *shost)
4710{
James Smart2e0fef82007-06-17 19:56:36 -05004711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4712 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004713
4714 spin_lock_irq(shost->host_lock);
4715
James Smart2e0fef82007-06-17 19:56:36 -05004716 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004717 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004718 case LPFC_LINK_SPEED_1GHZ:
4719 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004720 break;
James Smart76a95d72010-11-20 23:11:48 -05004721 case LPFC_LINK_SPEED_2GHZ:
4722 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004723 break;
James Smart76a95d72010-11-20 23:11:48 -05004724 case LPFC_LINK_SPEED_4GHZ:
4725 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004726 break;
James Smart76a95d72010-11-20 23:11:48 -05004727 case LPFC_LINK_SPEED_8GHZ:
4728 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004729 break;
James Smart76a95d72010-11-20 23:11:48 -05004730 case LPFC_LINK_SPEED_10GHZ:
4731 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004732 break;
James Smart76a95d72010-11-20 23:11:48 -05004733 case LPFC_LINK_SPEED_16GHZ:
4734 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4735 break;
4736 default:
4737 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004738 break;
4739 }
James Smart09372822008-01-11 01:52:54 -05004740 } else
4741 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004742
4743 spin_unlock_irq(shost->host_lock);
4744}
4745
James Smarte59058c2008-08-24 21:49:00 -04004746/**
James Smart3621a712009-04-06 18:47:14 -04004747 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004748 * @shost: kernel scsi host pointer.
4749 **/
dea31012005-04-17 16:05:31 -05004750static void
4751lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4752{
James Smart2e0fef82007-06-17 19:56:36 -05004753 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4754 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004755 u64 node_name;
dea31012005-04-17 16:05:31 -05004756
4757 spin_lock_irq(shost->host_lock);
4758
James Smart73d91e52011-10-10 21:32:10 -04004759 if ((vport->port_state > LPFC_FLOGI) &&
4760 ((vport->fc_flag & FC_FABRIC) ||
4761 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4762 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004763 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004764 else
4765 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004766 node_name = 0;
dea31012005-04-17 16:05:31 -05004767
4768 spin_unlock_irq(shost->host_lock);
4769
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004770 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004771}
4772
James Smarte59058c2008-08-24 21:49:00 -04004773/**
James Smart3621a712009-04-06 18:47:14 -04004774 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004775 * @shost: kernel scsi host pointer.
4776 *
4777 * Notes:
4778 * NULL on error for link down, no mbox pool, sli2 active,
4779 * management not allowed, memory allocation error, or mbox error.
4780 *
4781 * Returns:
4782 * NULL for error
4783 * address of the adapter host statistics
4784 **/
dea31012005-04-17 16:05:31 -05004785static struct fc_host_statistics *
4786lpfc_get_stats(struct Scsi_Host *shost)
4787{
James Smart2e0fef82007-06-17 19:56:36 -05004788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4789 struct lpfc_hba *phba = vport->phba;
4790 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004791 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004792 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004793 LPFC_MBOXQ_t *pmboxq;
4794 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004795 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004796 int rc = 0;
dea31012005-04-17 16:05:31 -05004797
James Smart92d7f7b2007-06-17 19:56:38 -05004798 /*
4799 * prevent udev from issuing mailbox commands until the port is
4800 * configured.
4801 */
James Smart2e0fef82007-06-17 19:56:36 -05004802 if (phba->link_state < LPFC_LINK_DOWN ||
4803 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004804 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004805 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004806
4807 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004808 return NULL;
4809
dea31012005-04-17 16:05:31 -05004810 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4811 if (!pmboxq)
4812 return NULL;
4813 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4814
James Smart04c68492009-05-22 14:52:52 -04004815 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004816 pmb->mbxCommand = MBX_READ_STATUS;
4817 pmb->mbxOwner = OWN_HOST;
4818 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004819 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004820
James Smart75baf692010-06-08 18:31:21 -04004821 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004822 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004823 else
dea31012005-04-17 16:05:31 -05004824 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4825
4826 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004827 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004828 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004829 return NULL;
4830 }
4831
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004832 memset(hs, 0, sizeof (struct fc_host_statistics));
4833
dea31012005-04-17 16:05:31 -05004834 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004835 /*
4836 * The MBX_READ_STATUS returns tx_k_bytes which has to
4837 * converted to words
4838 */
4839 hs->tx_words = (uint64_t)
4840 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4841 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004842 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004843 hs->rx_words = (uint64_t)
4844 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4845 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004846
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004847 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004848 pmb->mbxCommand = MBX_READ_LNK_STAT;
4849 pmb->mbxOwner = OWN_HOST;
4850 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004851 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004852
James Smart75baf692010-06-08 18:31:21 -04004853 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004854 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004855 else
dea31012005-04-17 16:05:31 -05004856 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4857
4858 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004859 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004860 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004861 return NULL;
4862 }
4863
4864 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4865 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4866 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4867 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4868 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4869 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4870 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4871
James Smart64ba8812006-08-02 15:24:34 -04004872 hs->link_failure_count -= lso->link_failure_count;
4873 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4874 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4875 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4876 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4877 hs->invalid_crc_count -= lso->invalid_crc_count;
4878 hs->error_frames -= lso->error_frames;
4879
James Smart76a95d72010-11-20 23:11:48 -05004880 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004881 hs->lip_count = -1;
4882 hs->nos_count = (phba->link_events >> 1);
4883 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004884 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004885 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004886 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004887 hs->nos_count = -1;
4888 } else {
4889 hs->lip_count = -1;
4890 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004891 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004892 }
4893
4894 hs->dumped_frames = -1;
4895
James Smart64ba8812006-08-02 15:24:34 -04004896 seconds = get_seconds();
4897 if (seconds < psli->stats_start)
4898 hs->seconds_since_last_reset = seconds +
4899 ((unsigned long)-1 - psli->stats_start);
4900 else
4901 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004902
James Smart1dcb58e2007-04-25 09:51:30 -04004903 mempool_free(pmboxq, phba->mbox_mem_pool);
4904
dea31012005-04-17 16:05:31 -05004905 return hs;
4906}
4907
James Smarte59058c2008-08-24 21:49:00 -04004908/**
James Smart3621a712009-04-06 18:47:14 -04004909 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004910 * @shost: kernel scsi host pointer.
4911 **/
James Smart64ba8812006-08-02 15:24:34 -04004912static void
4913lpfc_reset_stats(struct Scsi_Host *shost)
4914{
James Smart2e0fef82007-06-17 19:56:36 -05004915 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4916 struct lpfc_hba *phba = vport->phba;
4917 struct lpfc_sli *psli = &phba->sli;
4918 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004919 LPFC_MBOXQ_t *pmboxq;
4920 MAILBOX_t *pmb;
4921 int rc = 0;
4922
James Smart2e0fef82007-06-17 19:56:36 -05004923 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004924 return;
4925
James Smart64ba8812006-08-02 15:24:34 -04004926 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4927 if (!pmboxq)
4928 return;
4929 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4930
James Smart04c68492009-05-22 14:52:52 -04004931 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004932 pmb->mbxCommand = MBX_READ_STATUS;
4933 pmb->mbxOwner = OWN_HOST;
4934 pmb->un.varWords[0] = 0x1; /* reset request */
4935 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004936 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004937
James Smart2e0fef82007-06-17 19:56:36 -05004938 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004939 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004940 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4941 else
4942 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4943
4944 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004945 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004946 mempool_free(pmboxq, phba->mbox_mem_pool);
4947 return;
4948 }
4949
4950 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4951 pmb->mbxCommand = MBX_READ_LNK_STAT;
4952 pmb->mbxOwner = OWN_HOST;
4953 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004954 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004955
James Smart2e0fef82007-06-17 19:56:36 -05004956 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004957 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004958 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4959 else
4960 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4961
4962 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004963 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004964 mempool_free( pmboxq, phba->mbox_mem_pool);
4965 return;
4966 }
4967
4968 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4969 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4970 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4971 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4972 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4973 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4974 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004975 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004976 lso->link_events = (phba->link_events >> 1);
4977 else
4978 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004979
4980 psli->stats_start = get_seconds();
4981
James Smart1dcb58e2007-04-25 09:51:30 -04004982 mempool_free(pmboxq, phba->mbox_mem_pool);
4983
James Smart64ba8812006-08-02 15:24:34 -04004984 return;
4985}
dea31012005-04-17 16:05:31 -05004986
4987/*
4988 * The LPFC driver treats linkdown handling as target loss events so there
4989 * are no sysfs handlers for link_down_tmo.
4990 */
James Smart685f0bf2007-04-25 09:53:08 -04004991
James Smarte59058c2008-08-24 21:49:00 -04004992/**
James Smart3621a712009-04-06 18:47:14 -04004993 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004994 * @starget: kernel scsi target pointer.
4995 *
4996 * Returns:
4997 * address of the node list if found
4998 * NULL target not found
4999 **/
James Smart685f0bf2007-04-25 09:53:08 -04005000static struct lpfc_nodelist *
5001lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005002{
James Smart2e0fef82007-06-17 19:56:36 -05005003 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5004 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005005 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005006
5007 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005008 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005009 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005010 if (NLP_CHK_NODE_ACT(ndlp) &&
5011 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005012 starget->id == ndlp->nlp_sid) {
5013 spin_unlock_irq(shost->host_lock);
5014 return ndlp;
dea31012005-04-17 16:05:31 -05005015 }
5016 }
5017 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005018 return NULL;
5019}
dea31012005-04-17 16:05:31 -05005020
James Smarte59058c2008-08-24 21:49:00 -04005021/**
James Smart3621a712009-04-06 18:47:14 -04005022 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005023 * @starget: kernel scsi target pointer.
5024 **/
James Smart685f0bf2007-04-25 09:53:08 -04005025static void
5026lpfc_get_starget_port_id(struct scsi_target *starget)
5027{
5028 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5029
5030 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005031}
5032
James Smarte59058c2008-08-24 21:49:00 -04005033/**
James Smart3621a712009-04-06 18:47:14 -04005034 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005035 * @starget: kernel scsi target pointer.
5036 *
5037 * Description: Set the target node name to the ndlp node name wwn or zero.
5038 **/
dea31012005-04-17 16:05:31 -05005039static void
5040lpfc_get_starget_node_name(struct scsi_target *starget)
5041{
James Smart685f0bf2007-04-25 09:53:08 -04005042 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005043
James Smart685f0bf2007-04-25 09:53:08 -04005044 fc_starget_node_name(starget) =
5045 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005046}
5047
James Smarte59058c2008-08-24 21:49:00 -04005048/**
James Smart3621a712009-04-06 18:47:14 -04005049 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005050 * @starget: kernel scsi target pointer.
5051 *
5052 * Description: set the target port name to the ndlp port name wwn or zero.
5053 **/
dea31012005-04-17 16:05:31 -05005054static void
5055lpfc_get_starget_port_name(struct scsi_target *starget)
5056{
James Smart685f0bf2007-04-25 09:53:08 -04005057 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005058
James Smart685f0bf2007-04-25 09:53:08 -04005059 fc_starget_port_name(starget) =
5060 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005061}
5062
James Smarte59058c2008-08-24 21:49:00 -04005063/**
James Smart3621a712009-04-06 18:47:14 -04005064 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005065 * @rport: fc rport address.
5066 * @timeout: new value for dev loss tmo.
5067 *
5068 * Description:
5069 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5070 * dev_loss_tmo to one.
5071 **/
dea31012005-04-17 16:05:31 -05005072static void
dea31012005-04-17 16:05:31 -05005073lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5074{
dea31012005-04-17 16:05:31 -05005075 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005076 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005077 else
James Smartc01f3202006-08-18 17:47:08 -04005078 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005079}
5080
James Smarte59058c2008-08-24 21:49:00 -04005081/**
James Smart3621a712009-04-06 18:47:14 -04005082 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005083 *
5084 * Description:
5085 * Macro that uses field to generate a function with the name lpfc_show_rport_
5086 *
5087 * lpfc_show_rport_##field: returns the bytes formatted in buf
5088 * @cdev: class converted to an fc_rport.
5089 * @buf: on return contains the target_field or zero.
5090 *
5091 * Returns: size of formatted string.
5092 **/
dea31012005-04-17 16:05:31 -05005093#define lpfc_rport_show_function(field, format_string, sz, cast) \
5094static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005095lpfc_show_rport_##field (struct device *dev, \
5096 struct device_attribute *attr, \
5097 char *buf) \
dea31012005-04-17 16:05:31 -05005098{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005099 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005100 struct lpfc_rport_data *rdata = rport->hostdata; \
5101 return snprintf(buf, sz, format_string, \
5102 (rdata->target) ? cast rdata->target->field : 0); \
5103}
5104
5105#define lpfc_rport_rd_attr(field, format_string, sz) \
5106 lpfc_rport_show_function(field, format_string, sz, ) \
5107static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5108
James Smarteada2722008-12-04 22:39:13 -05005109/**
James Smart3621a712009-04-06 18:47:14 -04005110 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005111 * @fc_vport: The fc_vport who's symbolic name has been changed.
5112 *
5113 * Description:
5114 * This function is called by the transport after the @fc_vport's symbolic name
5115 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005116 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005117 **/
5118static void
5119lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5120{
5121 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5122
5123 if (vport->port_state == LPFC_VPORT_READY)
5124 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5125}
dea31012005-04-17 16:05:31 -05005126
James Smartf4b4c682009-05-22 14:53:12 -04005127/**
5128 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5129 * @phba: Pointer to lpfc_hba struct.
5130 *
5131 * This function is called by the lpfc_get_cfgparam() routine to set the
5132 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005133 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005134 * before hba port or vport created.
5135 **/
5136static void
5137lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5138{
5139 phba->cfg_log_verbose = verbose;
5140}
5141
dea31012005-04-17 16:05:31 -05005142struct fc_function_template lpfc_transport_functions = {
5143 /* fixed attributes the driver supports */
5144 .show_host_node_name = 1,
5145 .show_host_port_name = 1,
5146 .show_host_supported_classes = 1,
5147 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005148 .show_host_supported_speeds = 1,
5149 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005150 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005151
5152 /* dynamic attributes the driver supports */
5153 .get_host_port_id = lpfc_get_host_port_id,
5154 .show_host_port_id = 1,
5155
5156 .get_host_port_type = lpfc_get_host_port_type,
5157 .show_host_port_type = 1,
5158
5159 .get_host_port_state = lpfc_get_host_port_state,
5160 .show_host_port_state = 1,
5161
5162 /* active_fc4s is shown but doesn't change (thus no get function) */
5163 .show_host_active_fc4s = 1,
5164
5165 .get_host_speed = lpfc_get_host_speed,
5166 .show_host_speed = 1,
5167
5168 .get_host_fabric_name = lpfc_get_host_fabric_name,
5169 .show_host_fabric_name = 1,
5170
5171 /*
5172 * The LPFC driver treats linkdown handling as target loss events
5173 * so there are no sysfs handlers for link_down_tmo.
5174 */
5175
5176 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005177 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005178
5179 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5180 .show_rport_maxframe_size = 1,
5181 .show_rport_supported_classes = 1,
5182
dea31012005-04-17 16:05:31 -05005183 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5184 .show_rport_dev_loss_tmo = 1,
5185
5186 .get_starget_port_id = lpfc_get_starget_port_id,
5187 .show_starget_port_id = 1,
5188
5189 .get_starget_node_name = lpfc_get_starget_node_name,
5190 .show_starget_node_name = 1,
5191
5192 .get_starget_port_name = lpfc_get_starget_port_name,
5193 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005194
5195 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005196 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5197 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005198
James Smart92d7f7b2007-06-17 19:56:38 -05005199 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005200
5201 .vport_disable = lpfc_vport_disable,
5202
5203 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005204
5205 .bsg_request = lpfc_bsg_request,
5206 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005207};
5208
James Smart98c9ea52007-10-27 13:37:33 -04005209struct fc_function_template lpfc_vport_transport_functions = {
5210 /* fixed attributes the driver supports */
5211 .show_host_node_name = 1,
5212 .show_host_port_name = 1,
5213 .show_host_supported_classes = 1,
5214 .show_host_supported_fc4s = 1,
5215 .show_host_supported_speeds = 1,
5216 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005217 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005218
5219 /* dynamic attributes the driver supports */
5220 .get_host_port_id = lpfc_get_host_port_id,
5221 .show_host_port_id = 1,
5222
5223 .get_host_port_type = lpfc_get_host_port_type,
5224 .show_host_port_type = 1,
5225
5226 .get_host_port_state = lpfc_get_host_port_state,
5227 .show_host_port_state = 1,
5228
5229 /* active_fc4s is shown but doesn't change (thus no get function) */
5230 .show_host_active_fc4s = 1,
5231
5232 .get_host_speed = lpfc_get_host_speed,
5233 .show_host_speed = 1,
5234
5235 .get_host_fabric_name = lpfc_get_host_fabric_name,
5236 .show_host_fabric_name = 1,
5237
5238 /*
5239 * The LPFC driver treats linkdown handling as target loss events
5240 * so there are no sysfs handlers for link_down_tmo.
5241 */
5242
5243 .get_fc_host_stats = lpfc_get_stats,
5244 .reset_fc_host_stats = lpfc_reset_stats,
5245
5246 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5247 .show_rport_maxframe_size = 1,
5248 .show_rport_supported_classes = 1,
5249
5250 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5251 .show_rport_dev_loss_tmo = 1,
5252
5253 .get_starget_port_id = lpfc_get_starget_port_id,
5254 .show_starget_port_id = 1,
5255
5256 .get_starget_node_name = lpfc_get_starget_node_name,
5257 .show_starget_node_name = 1,
5258
5259 .get_starget_port_name = lpfc_get_starget_port_name,
5260 .show_starget_port_name = 1,
5261
5262 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5263 .terminate_rport_io = lpfc_terminate_rport_io,
5264
5265 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005266
5267 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005268};
5269
James Smarte59058c2008-08-24 21:49:00 -04005270/**
James Smart3621a712009-04-06 18:47:14 -04005271 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005272 * @phba: lpfc_hba pointer.
5273 **/
dea31012005-04-17 16:05:31 -05005274void
5275lpfc_get_cfgparam(struct lpfc_hba *phba)
5276{
James Smart49aa1432012-08-03 12:36:42 -04005277 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005278 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005279 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5280 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005281 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005282 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5283 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005284 lpfc_ack0_init(phba, lpfc_ack0);
5285 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005286 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005287 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005288 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005289 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005290 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005291 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005292 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005293 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smartda0436e2009-05-22 14:51:39 -04005294 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5295 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart67d12732012-08-03 12:36:13 -04005296 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005297 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5298 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005299 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005300 if (phba->sli_rev == LPFC_SLI_REV4)
5301 phba->cfg_poll = 0;
5302 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005303 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005304 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005305 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005306 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005307 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005308 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005309 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005310 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005311 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005312 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005313 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005314 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005315 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005316 return;
5317}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005318
James Smarte59058c2008-08-24 21:49:00 -04005319/**
James Smart3621a712009-04-06 18:47:14 -04005320 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005321 * @vport: lpfc_vport pointer.
5322 **/
James Smart3de2a652007-08-02 11:09:59 -04005323void
5324lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5325{
James Smarte8b62012007-08-02 11:10:09 -04005326 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005327 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005328 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005329 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5330 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5331 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5332 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5333 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5334 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005335 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005336 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5337 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5338 lpfc_max_luns_init(vport, lpfc_max_luns);
5339 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005340 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005341 return;
5342}