blob: 9937e572efdb7816a0e5e56a9181ab438d512d79 [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
James Smart229adb02013-04-17 20:16:51 -0400677 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
678 return 0;
679
James Smart46fa3112007-04-25 09:51:45 -0400680 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500681 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400682 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500683 if (rc == 0)
684 return -ENOMEM;
685
James Smart46fa3112007-04-25 09:51:45 -0400686 wait_for_completion(&online_compl);
687
688 if (status != 0)
689 return -EIO;
690
691 psli = &phba->sli;
692
James Smart09372822008-01-11 01:52:54 -0500693 /* Wait a little for things to settle down, but not
694 * long enough for dev loss timeout to expire.
695 */
James Smart46fa3112007-04-25 09:51:45 -0400696 for (i = 0; i < psli->num_rings; i++) {
697 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500698 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400699 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500700 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400701 lpfc_printf_log(phba,
702 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400703 "0466 Outstanding IO when "
704 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400705 break;
706 }
707 }
708 }
709
710 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500711 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
712 if (rc == 0)
713 return -ENOMEM;
714
James Smart46fa3112007-04-25 09:51:45 -0400715 wait_for_completion(&online_compl);
716
717 if (status != 0)
718 return -EIO;
719
720 return 0;
721}
722
James Smarte59058c2008-08-24 21:49:00 -0400723/**
James Smart3621a712009-04-06 18:47:14 -0400724 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400725 * @phba: lpfc_hba pointer.
726 *
727 * Description:
728 * If the port is configured to allow a reset then the hba is brought
729 * offline then online.
730 *
731 * Notes:
732 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500733 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400734 *
735 * Returns:
736 * lpfc_do_offline() return code if not zero
737 * -EIO reset not configured or error posting the event
738 * zero for success
739 **/
James Smart7f860592011-03-11 16:05:52 -0500740int
James Smart40496f02006-07-06 15:50:22 -0400741lpfc_selective_reset(struct lpfc_hba *phba)
742{
743 struct completion online_compl;
744 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500745 int rc;
James Smart40496f02006-07-06 15:50:22 -0400746
James Smart229adb02013-04-17 20:16:51 -0400747 if ((!phba->cfg_enable_hba_reset) ||
748 (phba->pport->fc_flag & FC_OFFLINE_MODE))
James Smartf7a919b2011-08-21 21:49:16 -0400749 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500750
James Smart46fa3112007-04-25 09:51:45 -0400751 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400752
753 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400754 return status;
James Smart40496f02006-07-06 15:50:22 -0400755
756 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500757 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400758 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500759 if (rc == 0)
760 return -ENOMEM;
761
James Smart40496f02006-07-06 15:50:22 -0400762 wait_for_completion(&online_compl);
763
764 if (status != 0)
765 return -EIO;
766
767 return 0;
768}
769
James Smarte59058c2008-08-24 21:49:00 -0400770/**
James Smart3621a712009-04-06 18:47:14 -0400771 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400772 * @dev: class device that is converted into a Scsi_host.
773 * @attr: device attribute, not used.
774 * @buf: containing the string "selective".
775 * @count: unused variable.
776 *
777 * Description:
778 * If the buf contains the string "selective" then lpfc_selective_reset()
779 * is called to perform the reset.
780 *
781 * Notes:
782 * Assumes any error from lpfc_selective_reset() will be negative.
783 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200784 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400785 *
786 * Returns:
787 * -EINVAL if the buffer does not contain the string "selective"
788 * length of buf if lpfc-selective_reset() if the call succeeds
789 * return value of lpfc_selective_reset() if the call fails
790**/
James Smart40496f02006-07-06 15:50:22 -0400791static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100792lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
793 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400794{
Tony Jonesee959b02008-02-22 00:13:36 +0100795 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
797 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400798 int status = -EINVAL;
799
James Smart73d91e52011-10-10 21:32:10 -0400800 if (!phba->cfg_enable_hba_reset)
801 return -EACCES;
802
James Smart40496f02006-07-06 15:50:22 -0400803 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500804 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400805
806 if (status == 0)
807 return strlen(buf);
808 else
809 return status;
810}
811
James Smarte59058c2008-08-24 21:49:00 -0400812/**
James Smart88a2cfb2011-07-22 18:36:33 -0400813 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
814 * @phba: lpfc_hba pointer.
815 *
816 * Description:
817 * SLI4 interface type-2 device to wait on the sliport status register for
818 * the readyness after performing a firmware reset.
819 *
820 * Returns:
James Smart026abb82011-12-13 13:20:45 -0500821 * zero for success, -EPERM when port does not have privilage to perform the
822 * reset, -EIO when port timeout from recovering from the reset.
823 *
824 * Note:
825 * As the caller will interpret the return code by value, be careful in making
826 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400827 **/
James Smart73d91e52011-10-10 21:32:10 -0400828int
James Smart88a2cfb2011-07-22 18:36:33 -0400829lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
830{
James Smartf7a919b2011-08-21 21:49:16 -0400831 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400832 int i;
833
James Smartf7a919b2011-08-21 21:49:16 -0400834 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400835 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
836 &portstat_reg.word0);
837
James Smartf7a919b2011-08-21 21:49:16 -0400838 /* verify if privilaged for the request operation */
839 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
840 !bf_get(lpfc_sliport_status_err, &portstat_reg))
841 return -EPERM;
842
James Smart88a2cfb2011-07-22 18:36:33 -0400843 /* wait for the SLI port firmware ready after firmware reset */
844 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
845 msleep(10);
846 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
847 &portstat_reg.word0);
848 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
849 continue;
850 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
851 continue;
852 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
853 continue;
854 break;
855 }
856
857 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
858 return 0;
859 else
860 return -EIO;
861}
862
863/**
James Smart52d52442011-05-24 11:42:45 -0400864 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400865 * @phba: lpfc_hba pointer.
866 *
867 * Description:
James Smart52d52442011-05-24 11:42:45 -0400868 * Request SLI4 interface type-2 device to perform a physical register set
869 * access.
James Smartc0c11512011-05-24 11:41:34 -0400870 *
871 * Returns:
872 * zero for success
873 **/
874static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400875lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400876{
877 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400878 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500879 uint32_t before_fc_flag;
880 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400881 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500882 int status = 0, rc = 0;
883 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400884
885 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400886 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400887
James Smart52d52442011-05-24 11:42:45 -0400888 if ((phba->sli_rev < LPFC_SLI_REV4) ||
889 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
890 LPFC_SLI_INTF_IF_TYPE_2))
891 return -EPERM;
892
James Smart026abb82011-12-13 13:20:45 -0500893 /* Keep state if we need to restore back */
894 before_fc_flag = phba->pport->fc_flag;
895 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
896
James Smartb76f2dc2011-07-22 18:37:42 -0400897 /* Disable SR-IOV virtual functions if enabled */
898 if (phba->cfg_sriov_nr_virtfn) {
899 pci_disable_sriov(pdev);
900 phba->cfg_sriov_nr_virtfn = 0;
901 }
James Smart229adb02013-04-17 20:16:51 -0400902
James Smartc0c11512011-05-24 11:41:34 -0400903 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
904
905 if (status != 0)
906 return status;
907
908 /* wait for the device to be quiesced before firmware reset */
909 msleep(100);
910
911 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
912 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400913
914 if (opcode == LPFC_FW_DUMP)
915 reg_val |= LPFC_FW_DUMP_REQUEST;
916 else if (opcode == LPFC_FW_RESET)
917 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
918 else if (opcode == LPFC_DV_RESET)
919 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
920
James Smartc0c11512011-05-24 11:41:34 -0400921 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
922 LPFC_CTL_PDEV_CTL_OFFSET);
923 /* flush */
924 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
925
926 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400927 rc = lpfc_sli4_pdev_status_reg_wait(phba);
928
James Smart026abb82011-12-13 13:20:45 -0500929 if (rc == -EPERM) {
James Smart6b5151f2012-01-18 16:24:06 -0500930 /* no privilage for reset */
931 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
932 "3150 No privilage to perform the requested "
933 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500934 } else if (rc == -EIO) {
935 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500936 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
937 "3153 Fail to perform the requested "
938 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400939 return rc;
James Smart026abb82011-12-13 13:20:45 -0500940 }
941
942 /* keep the original port state */
943 if (before_fc_flag & FC_OFFLINE_MODE)
944 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400945
946 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500947 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
948 LPFC_EVT_ONLINE);
949 if (!job_posted)
950 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400951
952 wait_for_completion(&online_compl);
953
James Smart026abb82011-12-13 13:20:45 -0500954out:
955 /* in any case, restore the virtual functions enabled as before */
956 if (sriov_nr_virtfn) {
957 sriov_err =
958 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
959 if (!sriov_err)
960 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
961 }
James Smartc0c11512011-05-24 11:41:34 -0400962
James Smart026abb82011-12-13 13:20:45 -0500963 /* return proper error code */
964 if (!rc) {
965 if (!job_posted)
966 rc = -ENOMEM;
967 else if (status)
968 rc = -EIO;
969 }
970 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400971}
972
973/**
James Smart3621a712009-04-06 18:47:14 -0400974 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400975 * @dev: class device that is converted into a Scsi_host.
976 * @attr: device attribute, not used.
977 * @buf: on return contains the ascii number of nport events.
978 *
979 * Returns: size of formatted string.
980 **/
dea31012005-04-17 16:05:31 -0500981static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100982lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
983 char *buf)
dea31012005-04-17 16:05:31 -0500984{
Tony Jonesee959b02008-02-22 00:13:36 +0100985 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500986 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
987 struct lpfc_hba *phba = vport->phba;
988
dea31012005-04-17 16:05:31 -0500989 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
990}
991
James Smarte59058c2008-08-24 21:49:00 -0400992/**
James Smart3621a712009-04-06 18:47:14 -0400993 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400994 * @dev: class device that is converted into a Scsi_host.
995 * @attr: device attribute, not used.
996 * @buf: on return contains the state of the adapter.
997 *
998 * Returns: size of formatted string.
999 **/
dea31012005-04-17 16:05:31 -05001000static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001001lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1002 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001003{
Tony Jonesee959b02008-02-22 00:13:36 +01001004 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1006 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001007 char * state;
1008
James Smart2e0fef82007-06-17 19:56:36 -05001009 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001010 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001011 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001012 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001013 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001014 state = "offline";
1015 else
1016 state = "online";
1017
1018 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1026 * @count: unused variable.
1027 *
1028 * Returns:
1029 * -EACCES if enable hba reset not enabled
1030 * -EINVAL if the buffer does not contain a valid string (see above)
1031 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1032 * buf length greater than zero indicates success
1033 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001034static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001035lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1036 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001037{
Tony Jonesee959b02008-02-22 00:13:36 +01001038 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1040 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001041 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001042 char *board_mode_str = NULL;
1043 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001044 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001045
James Smart026abb82011-12-13 13:20:45 -05001046 if (!phba->cfg_enable_hba_reset) {
1047 status = -EACCES;
1048 goto board_mode_out;
1049 }
James Smart88a2cfb2011-07-22 18:36:33 -04001050
1051 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001052 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001053
Jamie Wellnitz41415862006-02-28 19:25:27 -05001054 init_completion(&online_compl);
1055
James Smart46fa3112007-04-25 09:51:45 -04001056 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001057 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001058 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001059 if (rc == 0) {
1060 status = -ENOMEM;
1061 goto board_mode_out;
1062 }
James Smart46fa3112007-04-25 09:51:45 -04001063 wait_for_completion(&online_compl);
1064 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1065 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001066 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001067 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001068 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001069 else
1070 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001071 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001072 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001073 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001074 else
1075 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001076 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001077 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1078 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1079 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1080 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1081 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001082 else
James Smart026abb82011-12-13 13:20:45 -05001083 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001084
James Smart026abb82011-12-13 13:20:45 -05001085board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001086 if (!status)
1087 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001088 else {
1089 board_mode_str = strchr(buf, '\n');
1090 if (board_mode_str)
1091 *board_mode_str = '\0';
1092 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1093 "3097 Failed \"%s\", status(%d), "
1094 "fc_flag(x%x)\n",
1095 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001096 return status;
James Smart026abb82011-12-13 13:20:45 -05001097 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001098}
1099
James Smarte59058c2008-08-24 21:49:00 -04001100/**
James Smart3621a712009-04-06 18:47:14 -04001101 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001102 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001103 * @mxri: max xri count.
1104 * @axri: available xri count.
1105 * @mrpi: max rpi count.
1106 * @arpi: available rpi count.
1107 * @mvpi: max vpi count.
1108 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001109 *
1110 * Description:
1111 * If an integer pointer for an count is not null then the value for the
1112 * count is returned.
1113 *
1114 * Returns:
1115 * zero on error
1116 * one for success
1117 **/
James Smart311464e2007-08-02 11:10:37 -04001118static int
James Smart858c9f62007-06-17 19:56:39 -05001119lpfc_get_hba_info(struct lpfc_hba *phba,
1120 uint32_t *mxri, uint32_t *axri,
1121 uint32_t *mrpi, uint32_t *arpi,
1122 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001123{
James Smart04c68492009-05-22 14:52:52 -04001124 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001125 LPFC_MBOXQ_t *pmboxq;
1126 MAILBOX_t *pmb;
1127 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001128 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001129
1130 /*
1131 * prevent udev from issuing mailbox commands until the port is
1132 * configured.
1133 */
1134 if (phba->link_state < LPFC_LINK_DOWN ||
1135 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001136 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001137 return 0;
1138
1139 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1140 return 0;
1141
1142 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1143 if (!pmboxq)
1144 return 0;
1145 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1146
James Smart04c68492009-05-22 14:52:52 -04001147 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001148 pmb->mbxCommand = MBX_READ_CONFIG;
1149 pmb->mbxOwner = OWN_HOST;
1150 pmboxq->context1 = NULL;
1151
James Smart75baf692010-06-08 18:31:21 -04001152 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001153 rc = MBX_NOT_FINISHED;
1154 else
1155 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1156
1157 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001158 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001159 mempool_free(pmboxq, phba->mbox_mem_pool);
1160 return 0;
1161 }
1162
James Smartda0436e2009-05-22 14:51:39 -04001163 if (phba->sli_rev == LPFC_SLI_REV4) {
1164 rd_config = &pmboxq->u.mqe.un.rd_config;
1165 if (mrpi)
1166 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1167 if (arpi)
1168 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1169 phba->sli4_hba.max_cfg_param.rpi_used;
1170 if (mxri)
1171 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1172 if (axri)
1173 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1174 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001175
1176 /* Account for differences with SLI-3. Get vpi count from
1177 * mailbox data and subtract one for max vpi value.
1178 */
1179 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1180 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1181
James Smartda0436e2009-05-22 14:51:39 -04001182 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001183 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001184 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001185 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001186 } else {
1187 if (mrpi)
1188 *mrpi = pmb->un.varRdConfig.max_rpi;
1189 if (arpi)
1190 *arpi = pmb->un.varRdConfig.avail_rpi;
1191 if (mxri)
1192 *mxri = pmb->un.varRdConfig.max_xri;
1193 if (axri)
1194 *axri = pmb->un.varRdConfig.avail_xri;
1195 if (mvpi)
1196 *mvpi = pmb->un.varRdConfig.max_vpi;
1197 if (avpi)
1198 *avpi = pmb->un.varRdConfig.avail_vpi;
1199 }
James Smart92d7f7b2007-06-17 19:56:38 -05001200
1201 mempool_free(pmboxq, phba->mbox_mem_pool);
1202 return 1;
1203}
1204
James Smarte59058c2008-08-24 21:49:00 -04001205/**
James Smart3621a712009-04-06 18:47:14 -04001206 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001207 * @dev: class device that is converted into a Scsi_host.
1208 * @attr: device attribute, not used.
1209 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1210 *
1211 * Description:
1212 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1213 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1214 * to "Unknown" and the buffer length is returned, therefore the caller
1215 * must check for "Unknown" in the buffer to detect a failure.
1216 *
1217 * Returns: size of formatted string.
1218 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001219static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001220lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1221 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001222{
Tony Jonesee959b02008-02-22 00:13:36 +01001223 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001224 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1225 struct lpfc_hba *phba = vport->phba;
1226 uint32_t cnt;
1227
James Smart858c9f62007-06-17 19:56:39 -05001228 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001229 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1230 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1231}
1232
James Smarte59058c2008-08-24 21:49:00 -04001233/**
James Smart3621a712009-04-06 18:47:14 -04001234 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001235 * @dev: class device that is converted into a Scsi_host.
1236 * @attr: device attribute, not used.
1237 * @buf: containing the used rpi count in decimal or "Unknown".
1238 *
1239 * Description:
1240 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1241 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1242 * to "Unknown" and the buffer length is returned, therefore the caller
1243 * must check for "Unknown" in the buffer to detect a failure.
1244 *
1245 * Returns: size of formatted string.
1246 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001247static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001248lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1249 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001250{
Tony Jonesee959b02008-02-22 00:13:36 +01001251 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001252 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1253 struct lpfc_hba *phba = vport->phba;
1254 uint32_t cnt, acnt;
1255
James Smart858c9f62007-06-17 19:56:39 -05001256 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001257 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1258 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1259}
1260
James Smarte59058c2008-08-24 21:49:00 -04001261/**
James Smart3621a712009-04-06 18:47:14 -04001262 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001263 * @dev: class device that is converted into a Scsi_host.
1264 * @attr: device attribute, not used.
1265 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1266 *
1267 * Description:
1268 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1269 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1270 * to "Unknown" and the buffer length is returned, therefore the caller
1271 * must check for "Unknown" in the buffer to detect a failure.
1272 *
1273 * Returns: size of formatted string.
1274 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001275static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001276lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1277 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001278{
Tony Jonesee959b02008-02-22 00:13:36 +01001279 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001280 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1281 struct lpfc_hba *phba = vport->phba;
1282 uint32_t cnt;
1283
James Smart858c9f62007-06-17 19:56:39 -05001284 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001285 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1286 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1287}
1288
James Smarte59058c2008-08-24 21:49:00 -04001289/**
James Smart3621a712009-04-06 18:47:14 -04001290 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001291 * @dev: class device that is converted into a Scsi_host.
1292 * @attr: device attribute, not used.
1293 * @buf: on return contains the used xri count in decimal or "Unknown".
1294 *
1295 * Description:
1296 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1297 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1298 * to "Unknown" and the buffer length is returned, therefore the caller
1299 * must check for "Unknown" in the buffer to detect a failure.
1300 *
1301 * Returns: size of formatted string.
1302 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001303static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001304lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1305 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001306{
Tony Jonesee959b02008-02-22 00:13:36 +01001307 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1309 struct lpfc_hba *phba = vport->phba;
1310 uint32_t cnt, acnt;
1311
James Smart858c9f62007-06-17 19:56:39 -05001312 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1313 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1314 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1315}
1316
James Smarte59058c2008-08-24 21:49:00 -04001317/**
James Smart3621a712009-04-06 18:47:14 -04001318 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001319 * @dev: class device that is converted into a Scsi_host.
1320 * @attr: device attribute, not used.
1321 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1322 *
1323 * Description:
1324 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1325 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1326 * to "Unknown" and the buffer length is returned, therefore the caller
1327 * must check for "Unknown" in the buffer to detect a failure.
1328 *
1329 * Returns: size of formatted string.
1330 **/
James Smart858c9f62007-06-17 19:56:39 -05001331static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001332lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1333 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001334{
Tony Jonesee959b02008-02-22 00:13:36 +01001335 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001336 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1337 struct lpfc_hba *phba = vport->phba;
1338 uint32_t cnt;
1339
1340 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1341 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1342 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1343}
1344
James Smarte59058c2008-08-24 21:49:00 -04001345/**
James Smart3621a712009-04-06 18:47:14 -04001346 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001347 * @dev: class device that is converted into a Scsi_host.
1348 * @attr: device attribute, not used.
1349 * @buf: on return contains the used vpi count in decimal or "Unknown".
1350 *
1351 * Description:
1352 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1353 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1354 * to "Unknown" and the buffer length is returned, therefore the caller
1355 * must check for "Unknown" in the buffer to detect a failure.
1356 *
1357 * Returns: size of formatted string.
1358 **/
James Smart858c9f62007-06-17 19:56:39 -05001359static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001360lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1361 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001362{
Tony Jonesee959b02008-02-22 00:13:36 +01001363 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001364 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1365 struct lpfc_hba *phba = vport->phba;
1366 uint32_t cnt, acnt;
1367
1368 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001369 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1370 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1371}
1372
James Smarte59058c2008-08-24 21:49:00 -04001373/**
James Smart3621a712009-04-06 18:47:14 -04001374 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001375 * @dev: class device that is converted into a Scsi_host.
1376 * @attr: device attribute, not used.
1377 * @buf: text that must be interpreted to determine if npiv is supported.
1378 *
1379 * Description:
1380 * Buffer will contain text indicating npiv is not suppoerted on the port,
1381 * the port is an NPIV physical port, or it is an npiv virtual port with
1382 * the id of the vport.
1383 *
1384 * Returns: size of formatted string.
1385 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001386static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001387lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1388 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001389{
Tony Jonesee959b02008-02-22 00:13:36 +01001390 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001391 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1392 struct lpfc_hba *phba = vport->phba;
1393
1394 if (!(phba->max_vpi))
1395 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1396 if (vport->port_type == LPFC_PHYSICAL_PORT)
1397 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1398 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1399}
1400
James Smarte59058c2008-08-24 21:49:00 -04001401/**
James Smart3621a712009-04-06 18:47:14 -04001402 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001403 * @dev: class device that is converted into a Scsi_host.
1404 * @attr: device attribute, not used.
1405 * @buf: on return contains the cfg_poll in hex.
1406 *
1407 * Notes:
1408 * cfg_poll should be a lpfc_polling_flags type.
1409 *
1410 * Returns: size of formatted string.
1411 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001412static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001413lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1414 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001415{
Tony Jonesee959b02008-02-22 00:13:36 +01001416 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001417 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1418 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001419
1420 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1421}
1422
James Smarte59058c2008-08-24 21:49:00 -04001423/**
James Smart3621a712009-04-06 18:47:14 -04001424 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001425 * @dev: class device that is converted into a Scsi_host.
1426 * @attr: device attribute, not used.
1427 * @buf: one or more lpfc_polling_flags values.
1428 * @count: not used.
1429 *
1430 * Notes:
1431 * buf contents converted to integer and checked for a valid value.
1432 *
1433 * Returns:
1434 * -EINVAL if the buffer connot be converted or is out of range
1435 * length of the buf on success
1436 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001437static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001438lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1439 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001440{
Tony Jonesee959b02008-02-22 00:13:36 +01001441 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1443 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001444 uint32_t creg_val;
1445 uint32_t old_val;
1446 int val=0;
1447
1448 if (!isdigit(buf[0]))
1449 return -EINVAL;
1450
1451 if (sscanf(buf, "%i", &val) != 1)
1452 return -EINVAL;
1453
1454 if ((val & 0x3) != val)
1455 return -EINVAL;
1456
James Smart45ed1192009-10-02 15:17:02 -04001457 if (phba->sli_rev == LPFC_SLI_REV4)
1458 val = 0;
1459
James Smart88a2cfb2011-07-22 18:36:33 -04001460 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1461 "3051 lpfc_poll changed from %d to %d\n",
1462 phba->cfg_poll, val);
1463
James Smart2e0fef82007-06-17 19:56:36 -05001464 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001465
1466 old_val = phba->cfg_poll;
1467
1468 if (val & ENABLE_FCP_RING_POLLING) {
1469 if ((val & DISABLE_FCP_RING_INT) &&
1470 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001471 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1472 spin_unlock_irq(&phba->hbalock);
1473 return -EINVAL;
1474 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001475 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1476 writel(creg_val, phba->HCregaddr);
1477 readl(phba->HCregaddr); /* flush */
1478
1479 lpfc_poll_start_timer(phba);
1480 }
1481 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001482 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001483 return -EINVAL;
1484 }
1485
1486 if (!(val & DISABLE_FCP_RING_INT) &&
1487 (old_val & DISABLE_FCP_RING_INT))
1488 {
James Smart2e0fef82007-06-17 19:56:36 -05001489 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001490 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001491 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001492 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1493 spin_unlock_irq(&phba->hbalock);
1494 return -EINVAL;
1495 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001496 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1497 writel(creg_val, phba->HCregaddr);
1498 readl(phba->HCregaddr); /* flush */
1499 }
1500
1501 phba->cfg_poll = val;
1502
James Smart2e0fef82007-06-17 19:56:36 -05001503 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001504
1505 return strlen(buf);
1506}
dea31012005-04-17 16:05:31 -05001507
James Smarte59058c2008-08-24 21:49:00 -04001508/**
James Smartbc739052010-08-04 16:11:18 -04001509 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1510 * @dev: class unused variable.
1511 * @attr: device attribute, not used.
1512 * @buf: on return contains the module description text.
1513 *
1514 * Returns: size of formatted string.
1515 **/
1516static ssize_t
1517lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1518 char *buf)
1519{
1520 struct Scsi_Host *shost = class_to_shost(dev);
1521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1522 struct lpfc_hba *phba = vport->phba;
1523
1524 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1525}
1526
1527/**
1528 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1529 * @dev: class unused variable.
1530 * @attr: device attribute, not used.
1531 * @buf: on return contains the module description text.
1532 *
1533 * Returns: size of formatted string.
1534 **/
1535static ssize_t
1536lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1537 char *buf)
1538{
1539 struct Scsi_Host *shost = class_to_shost(dev);
1540 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1541 struct lpfc_hba *phba = vport->phba;
1542
1543 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1544}
1545
1546/**
James Smartab56dc22011-02-16 12:39:57 -05001547 * lpfc_dss_show - Return the current state of dss and the configured state
1548 * @dev: class converted to a Scsi_host structure.
1549 * @attr: device attribute, not used.
1550 * @buf: on return contains the formatted text.
1551 *
1552 * Returns: size of formatted string.
1553 **/
1554static ssize_t
1555lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1556 char *buf)
1557{
1558 struct Scsi_Host *shost = class_to_shost(dev);
1559 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1560 struct lpfc_hba *phba = vport->phba;
1561
1562 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1563 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1564 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1565 "" : "Not ");
1566}
1567
1568/**
James Smart912e3ac2011-05-24 11:42:11 -04001569 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1570 * @dev: class converted to a Scsi_host structure.
1571 * @attr: device attribute, not used.
1572 * @buf: on return contains the formatted support level.
1573 *
1574 * Description:
1575 * Returns the maximum number of virtual functions a physical function can
1576 * support, 0 will be returned if called on virtual function.
1577 *
1578 * Returns: size of formatted string.
1579 **/
1580static ssize_t
1581lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1582 struct device_attribute *attr,
1583 char *buf)
1584{
1585 struct Scsi_Host *shost = class_to_shost(dev);
1586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1587 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001588 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001589
James Smart0a96e972011-07-22 18:37:28 -04001590 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1591 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001592}
1593
1594/**
James Smart3621a712009-04-06 18:47:14 -04001595 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001596 *
1597 * Description:
1598 * Macro that given an attr e.g. hba_queue_depth expands
1599 * into a function with the name lpfc_hba_queue_depth_show.
1600 *
1601 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1602 * @dev: class device that is converted into a Scsi_host.
1603 * @attr: device attribute, not used.
1604 * @buf: on return contains the attribute value in decimal.
1605 *
1606 * Returns: size of formatted string.
1607 **/
dea31012005-04-17 16:05:31 -05001608#define lpfc_param_show(attr) \
1609static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001610lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1611 char *buf) \
dea31012005-04-17 16:05:31 -05001612{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001613 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001614 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1615 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001616 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001617 val = phba->cfg_##attr;\
1618 return snprintf(buf, PAGE_SIZE, "%d\n",\
1619 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001620}
1621
James Smarte59058c2008-08-24 21:49:00 -04001622/**
James Smart3621a712009-04-06 18:47:14 -04001623 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001624 *
1625 * Description:
1626 * Macro that given an attr e.g. hba_queue_depth expands
1627 * into a function with the name lpfc_hba_queue_depth_show
1628 *
1629 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1630 * @dev: class device that is converted into a Scsi_host.
1631 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001632 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001633 *
1634 * Returns: size of formatted string.
1635 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001636#define lpfc_param_hex_show(attr) \
1637static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001638lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1639 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001640{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001641 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001642 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1643 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001644 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001645 val = phba->cfg_##attr;\
1646 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1647 phba->cfg_##attr);\
1648}
1649
James Smarte59058c2008-08-24 21:49:00 -04001650/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001651 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001652 *
1653 * Description:
1654 * Macro that given an attr e.g. hba_queue_depth expands
1655 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1656 * takes a default argument, a minimum and maximum argument.
1657 *
1658 * lpfc_##attr##_init: Initializes an attribute.
1659 * @phba: pointer the the adapter structure.
1660 * @val: integer attribute value.
1661 *
1662 * Validates the min and max values then sets the adapter config field
1663 * accordingly, or uses the default if out of range and prints an error message.
1664 *
1665 * Returns:
1666 * zero on success
1667 * -EINVAL if default used
1668 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001669#define lpfc_param_init(attr, default, minval, maxval) \
1670static int \
James Smart84d1b002010-02-12 14:42:33 -05001671lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001672{ \
1673 if (val >= minval && val <= maxval) {\
1674 phba->cfg_##attr = val;\
1675 return 0;\
1676 }\
1677 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001678 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1679 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001680 phba->cfg_##attr = default;\
1681 return -EINVAL;\
1682}
1683
James Smarte59058c2008-08-24 21:49:00 -04001684/**
James Smart3621a712009-04-06 18:47:14 -04001685 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001686 *
1687 * Description:
1688 * Macro that given an attr e.g. hba_queue_depth expands
1689 * into a function with the name lpfc_hba_queue_depth_set
1690 *
1691 * lpfc_##attr##_set: Sets an attribute value.
1692 * @phba: pointer the the adapter structure.
1693 * @val: integer attribute value.
1694 *
1695 * Description:
1696 * Validates the min and max values then sets the
1697 * adapter config field if in the valid range. prints error message
1698 * and does not set the parameter if invalid.
1699 *
1700 * Returns:
1701 * zero on success
1702 * -EINVAL if val is invalid
1703 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001704#define lpfc_param_set(attr, default, minval, maxval) \
1705static int \
James Smart84d1b002010-02-12 14:42:33 -05001706lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001707{ \
1708 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1710 "3052 lpfc_" #attr " changed from %d to %d\n", \
1711 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001712 phba->cfg_##attr = val;\
1713 return 0;\
1714 }\
1715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001716 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1717 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001718 return -EINVAL;\
1719}
1720
James Smarte59058c2008-08-24 21:49:00 -04001721/**
James Smart3621a712009-04-06 18:47:14 -04001722 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001723 *
1724 * Description:
1725 * Macro that given an attr e.g. hba_queue_depth expands
1726 * into a function with the name lpfc_hba_queue_depth_store.
1727 *
1728 * lpfc_##attr##_store: Set an sttribute value.
1729 * @dev: class device that is converted into a Scsi_host.
1730 * @attr: device attribute, not used.
1731 * @buf: contains the attribute value in ascii.
1732 * @count: not used.
1733 *
1734 * Description:
1735 * Convert the ascii text number to an integer, then
1736 * use the lpfc_##attr##_set function to set the value.
1737 *
1738 * Returns:
1739 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1740 * length of buffer upon success.
1741 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001742#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001743static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001744lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1745 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001746{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001747 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001748 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1749 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001750 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001751 if (!isdigit(buf[0]))\
1752 return -EINVAL;\
1753 if (sscanf(buf, "%i", &val) != 1)\
1754 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001755 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001756 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001757 else \
1758 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001759}
1760
James Smarte59058c2008-08-24 21:49:00 -04001761/**
James Smart3621a712009-04-06 18:47:14 -04001762 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001763 *
1764 * Description:
1765 * Macro that given an attr e.g. hba_queue_depth expands
1766 * into a function with the name lpfc_hba_queue_depth_show
1767 *
1768 * lpfc_##attr##_show: prints the attribute value in decimal.
1769 * @dev: class device that is converted into a Scsi_host.
1770 * @attr: device attribute, not used.
1771 * @buf: on return contains the attribute value in decimal.
1772 *
1773 * Returns: length of formatted string.
1774 **/
James Smart3de2a652007-08-02 11:09:59 -04001775#define lpfc_vport_param_show(attr) \
1776static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001777lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1778 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001779{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001780 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001781 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001782 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001783 val = vport->cfg_##attr;\
1784 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1785}
1786
James Smarte59058c2008-08-24 21:49:00 -04001787/**
James Smart3621a712009-04-06 18:47:14 -04001788 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001789 *
1790 * Description:
1791 * Macro that given an attr e.g.
1792 * hba_queue_depth expands into a function with the name
1793 * lpfc_hba_queue_depth_show
1794 *
James Smart3621a712009-04-06 18:47:14 -04001795 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001796 * @dev: class device that is converted into a Scsi_host.
1797 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001798 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001799 *
1800 * Returns: length of formatted string.
1801 **/
James Smart3de2a652007-08-02 11:09:59 -04001802#define lpfc_vport_param_hex_show(attr) \
1803static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001804lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1805 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001806{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001807 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001808 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001809 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001810 val = vport->cfg_##attr;\
1811 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1812}
1813
James Smarte59058c2008-08-24 21:49:00 -04001814/**
James Smart3621a712009-04-06 18:47:14 -04001815 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001816 *
1817 * Description:
1818 * Macro that given an attr e.g. hba_queue_depth expands
1819 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1820 * takes a default argument, a minimum and maximum argument.
1821 *
1822 * lpfc_##attr##_init: validates the min and max values then sets the
1823 * adapter config field accordingly, or uses the default if out of range
1824 * and prints an error message.
1825 * @phba: pointer the the adapter structure.
1826 * @val: integer attribute value.
1827 *
1828 * Returns:
1829 * zero on success
1830 * -EINVAL if default used
1831 **/
James Smart3de2a652007-08-02 11:09:59 -04001832#define lpfc_vport_param_init(attr, default, minval, maxval) \
1833static int \
James Smart84d1b002010-02-12 14:42:33 -05001834lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001835{ \
1836 if (val >= minval && val <= maxval) {\
1837 vport->cfg_##attr = val;\
1838 return 0;\
1839 }\
James Smarte8b62012007-08-02 11:10:09 -04001840 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001841 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001842 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001843 vport->cfg_##attr = default;\
1844 return -EINVAL;\
1845}
1846
James Smarte59058c2008-08-24 21:49:00 -04001847/**
James Smart3621a712009-04-06 18:47:14 -04001848 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001849 *
1850 * Description:
1851 * Macro that given an attr e.g. hba_queue_depth expands
1852 * into a function with the name lpfc_hba_queue_depth_set
1853 *
1854 * lpfc_##attr##_set: validates the min and max values then sets the
1855 * adapter config field if in the valid range. prints error message
1856 * and does not set the parameter if invalid.
1857 * @phba: pointer the the adapter structure.
1858 * @val: integer attribute value.
1859 *
1860 * Returns:
1861 * zero on success
1862 * -EINVAL if val is invalid
1863 **/
James Smart3de2a652007-08-02 11:09:59 -04001864#define lpfc_vport_param_set(attr, default, minval, maxval) \
1865static int \
James Smart84d1b002010-02-12 14:42:33 -05001866lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001867{ \
1868 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001869 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1870 "3053 lpfc_" #attr " changed from %d to %d\n", \
1871 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001872 vport->cfg_##attr = val;\
1873 return 0;\
1874 }\
James Smarte8b62012007-08-02 11:10:09 -04001875 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001876 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001877 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001878 return -EINVAL;\
1879}
1880
James Smarte59058c2008-08-24 21:49:00 -04001881/**
James Smart3621a712009-04-06 18:47:14 -04001882 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001883 *
1884 * Description:
1885 * Macro that given an attr e.g. hba_queue_depth
1886 * expands into a function with the name lpfc_hba_queue_depth_store
1887 *
1888 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1889 * use the lpfc_##attr##_set function to set the value.
1890 * @cdev: class device that is converted into a Scsi_host.
1891 * @buf: contains the attribute value in decimal.
1892 * @count: not used.
1893 *
1894 * Returns:
1895 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1896 * length of buffer upon success.
1897 **/
James Smart3de2a652007-08-02 11:09:59 -04001898#define lpfc_vport_param_store(attr) \
1899static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001900lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1901 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001902{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001903 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001904 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001905 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001906 if (!isdigit(buf[0]))\
1907 return -EINVAL;\
1908 if (sscanf(buf, "%i", &val) != 1)\
1909 return -EINVAL;\
1910 if (lpfc_##attr##_set(vport, val) == 0) \
1911 return strlen(buf);\
1912 else \
1913 return -EINVAL;\
1914}
1915
1916
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001917#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001918static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001919module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001920MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001921lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001922
1923#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001924static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001925module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001926MODULE_PARM_DESC(lpfc_##name, desc);\
1927lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001928lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001929static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001930
1931#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001932static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001933module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001934MODULE_PARM_DESC(lpfc_##name, desc);\
1935lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001936lpfc_param_init(name, defval, minval, maxval)\
1937lpfc_param_set(name, defval, minval, maxval)\
1938lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001939static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1940 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001941
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001942#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001943static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001944module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001945MODULE_PARM_DESC(lpfc_##name, desc);\
1946lpfc_param_hex_show(name)\
1947lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001948static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001949
1950#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001951static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001952module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001953MODULE_PARM_DESC(lpfc_##name, desc);\
1954lpfc_param_hex_show(name)\
1955lpfc_param_init(name, defval, minval, maxval)\
1956lpfc_param_set(name, defval, minval, maxval)\
1957lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001958static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1959 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001960
James Smart3de2a652007-08-02 11:09:59 -04001961#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001962static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001963module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001964MODULE_PARM_DESC(lpfc_##name, desc);\
1965lpfc_vport_param_init(name, defval, minval, maxval)
1966
1967#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001968static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001969module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001970MODULE_PARM_DESC(lpfc_##name, desc);\
1971lpfc_vport_param_show(name)\
1972lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001973static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001974
1975#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001976static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001977module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001978MODULE_PARM_DESC(lpfc_##name, desc);\
1979lpfc_vport_param_show(name)\
1980lpfc_vport_param_init(name, defval, minval, maxval)\
1981lpfc_vport_param_set(name, defval, minval, maxval)\
1982lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001983static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1984 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001985
1986#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001987static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001988module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001989MODULE_PARM_DESC(lpfc_##name, desc);\
1990lpfc_vport_param_hex_show(name)\
1991lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001992static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001993
1994#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001995static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001996module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001997MODULE_PARM_DESC(lpfc_##name, desc);\
1998lpfc_vport_param_hex_show(name)\
1999lpfc_vport_param_init(name, defval, minval, maxval)\
2000lpfc_vport_param_set(name, defval, minval, maxval)\
2001lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01002002static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2003 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04002004
James Smart81301a92008-12-04 22:39:46 -05002005static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2006static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2007static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2008static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002009static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2010static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2011static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2012static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2013static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2014static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2015static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2016static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002017static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2018 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002019static DEVICE_ATTR(option_rom_version, S_IRUGO,
2020 lpfc_option_rom_version_show, NULL);
2021static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2022 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002023static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002024static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2025static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002026static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002027static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2028 lpfc_board_mode_show, lpfc_board_mode_store);
2029static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2030static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2031static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2032static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2033static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2034static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2035static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2036static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2037static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002038static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2039static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002040static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002041static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2042 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002043static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002044
James Smarta12e07b2006-12-02 13:35:30 -05002045static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04002046
James Smarte59058c2008-08-24 21:49:00 -04002047/**
James Smart3621a712009-04-06 18:47:14 -04002048 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002049 * @dev: class device that is converted into a Scsi_host.
2050 * @attr: device attribute, not used.
2051 * @buf: containing the string lpfc_soft_wwn_key.
2052 * @count: must be size of lpfc_soft_wwn_key.
2053 *
2054 * Returns:
2055 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2056 * length of buf indicates success
2057 **/
James Smartc3f28af2006-08-18 17:47:18 -04002058static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002059lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2060 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002061{
Tony Jonesee959b02008-02-22 00:13:36 +01002062 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2064 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002065 unsigned int cnt = count;
2066
2067 /*
2068 * We're doing a simple sanity check for soft_wwpn setting.
2069 * We require that the user write a specific key to enable
2070 * the soft_wwpn attribute to be settable. Once the attribute
2071 * is written, the enable key resets. If further updates are
2072 * desired, the key must be written again to re-enable the
2073 * attribute.
2074 *
2075 * The "key" is not secret - it is a hardcoded string shown
2076 * here. The intent is to protect against the random user or
2077 * application that is just writing attributes.
2078 */
2079
2080 /* count may include a LF at end of string */
2081 if (buf[cnt-1] == '\n')
2082 cnt--;
2083
James Smarta12e07b2006-12-02 13:35:30 -05002084 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2085 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002086 return -EINVAL;
2087
James Smarta12e07b2006-12-02 13:35:30 -05002088 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002089 return count;
2090}
Tony Jonesee959b02008-02-22 00:13:36 +01002091static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2092 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002093
James Smarte59058c2008-08-24 21:49:00 -04002094/**
James Smart3621a712009-04-06 18:47:14 -04002095 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002096 * @dev: class device that is converted into a Scsi_host.
2097 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002098 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002099 *
2100 * Returns: size of formatted string.
2101 **/
James Smartc3f28af2006-08-18 17:47:18 -04002102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002103lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2104 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002105{
Tony Jonesee959b02008-02-22 00:13:36 +01002106 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2108 struct lpfc_hba *phba = vport->phba;
2109
Randy Dunlapafc071e2006-10-23 21:47:13 -07002110 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2111 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002112}
2113
James Smarte59058c2008-08-24 21:49:00 -04002114/**
James Smart3621a712009-04-06 18:47:14 -04002115 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002116 * @dev class device that is converted into a Scsi_host.
2117 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002118 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002119 * @count: number of wwpn bytes in buf
2120 *
2121 * Returns:
2122 * -EACCES hba reset not enabled, adapter over temp
2123 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2124 * -EIO error taking adapter offline or online
2125 * value of count on success
2126 **/
James Smartc3f28af2006-08-18 17:47:18 -04002127static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002128lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2129 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002130{
Tony Jonesee959b02008-02-22 00:13:36 +01002131 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2133 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002134 struct completion online_compl;
2135 int stat1=0, stat2=0;
2136 unsigned int i, j, cnt=count;
2137 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002138 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002139
James Smart13815c82008-01-11 01:52:48 -05002140 if (!phba->cfg_enable_hba_reset)
2141 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002142 spin_lock_irq(&phba->hbalock);
2143 if (phba->over_temp_state == HBA_OVER_TEMP) {
2144 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002145 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002146 }
2147 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002148 /* count may include a LF at end of string */
2149 if (buf[cnt-1] == '\n')
2150 cnt--;
2151
James Smarta12e07b2006-12-02 13:35:30 -05002152 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002153 ((cnt == 17) && (*buf++ != 'x')) ||
2154 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2155 return -EINVAL;
2156
James Smarta12e07b2006-12-02 13:35:30 -05002157 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002158
2159 memset(wwpn, 0, sizeof(wwpn));
2160
2161 /* Validate and store the new name */
2162 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002163 int value;
2164
2165 value = hex_to_bin(*buf++);
2166 if (value >= 0)
2167 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002168 else
2169 return -EINVAL;
2170 if (i % 2) {
2171 wwpn[i/2] = j & 0xff;
2172 j = 0;
2173 }
2174 }
2175 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002176 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002177 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002178 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002179
2180 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2181 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2182
James Smart46fa3112007-04-25 09:51:45 -04002183 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002184 if (stat1)
2185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002186 "0463 lpfc_soft_wwpn attribute set failed to "
2187 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002188 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002189 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2190 LPFC_EVT_ONLINE);
2191 if (rc == 0)
2192 return -ENOMEM;
2193
James Smartc3f28af2006-08-18 17:47:18 -04002194 wait_for_completion(&online_compl);
2195 if (stat2)
2196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002197 "0464 lpfc_soft_wwpn attribute set failed to "
2198 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002199 return (stat1 || stat2) ? -EIO : count;
2200}
Tony Jonesee959b02008-02-22 00:13:36 +01002201static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2202 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002203
James Smarte59058c2008-08-24 21:49:00 -04002204/**
James Smart3621a712009-04-06 18:47:14 -04002205 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002206 * @dev: class device that is converted into a Scsi_host.
2207 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002208 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002209 *
2210 * Returns: size of formatted string.
2211 **/
James Smarta12e07b2006-12-02 13:35:30 -05002212static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002213lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2214 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002215{
Tony Jonesee959b02008-02-22 00:13:36 +01002216 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002217 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002218 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2219 (unsigned long long)phba->cfg_soft_wwnn);
2220}
2221
James Smarte59058c2008-08-24 21:49:00 -04002222/**
James Smart3621a712009-04-06 18:47:14 -04002223 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002224 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002225 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002226 * @count: number of wwnn bytes in buf.
2227 *
2228 * Returns:
2229 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2230 * value of count on success
2231 **/
James Smarta12e07b2006-12-02 13:35:30 -05002232static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002233lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2234 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002235{
Tony Jonesee959b02008-02-22 00:13:36 +01002236 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002237 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002238 unsigned int i, j, cnt=count;
2239 u8 wwnn[8];
2240
2241 /* count may include a LF at end of string */
2242 if (buf[cnt-1] == '\n')
2243 cnt--;
2244
2245 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2246 ((cnt == 17) && (*buf++ != 'x')) ||
2247 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2248 return -EINVAL;
2249
2250 /*
2251 * Allow wwnn to be set many times, as long as the enable is set.
2252 * However, once the wwpn is set, everything locks.
2253 */
2254
2255 memset(wwnn, 0, sizeof(wwnn));
2256
2257 /* Validate and store the new name */
2258 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002259 int value;
2260
2261 value = hex_to_bin(*buf++);
2262 if (value >= 0)
2263 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002264 else
2265 return -EINVAL;
2266 if (i % 2) {
2267 wwnn[i/2] = j & 0xff;
2268 j = 0;
2269 }
2270 }
2271 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2272
2273 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2274 "lpfc%d: soft_wwnn set. Value will take effect upon "
2275 "setting of the soft_wwpn\n", phba->brd_no);
2276
2277 return count;
2278}
Tony Jonesee959b02008-02-22 00:13:36 +01002279static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2280 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002281
James Smartc3f28af2006-08-18 17:47:18 -04002282
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002283static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002284module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002285MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2286 " 0 - none,"
2287 " 1 - poll with interrupts enabled"
2288 " 3 - poll and disable FCP ring interrupts");
2289
Tony Jonesee959b02008-02-22 00:13:36 +01002290static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2291 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002292
James Smart92d7f7b2007-06-17 19:56:38 -05002293int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002294module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002295MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2296 " 0 - auto (SLI-3 if supported),"
2297 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2298 " 3 - select SLI-3");
2299
James Smart15672312010-04-06 14:49:03 -04002300int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002301module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002302MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2303lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002304lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002305static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002306
James Smart7d791df2011-07-22 18:37:52 -04002307LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2308 "FCF Fast failover=1 Priority failover=2");
2309
James Smartc14e9952013-03-01 16:38:01 -05002310int lpfc_enable_rrq = 2;
James Smartab56dc22011-02-16 12:39:57 -05002311module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002312MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2313lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002314/*
2315# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2316# 0x0 = disabled, XRI/OXID use not tracked.
2317# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2318# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2319*/
2320lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002321static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2322
dea31012005-04-17 16:05:31 -05002323/*
James Smart84d1b002010-02-12 14:42:33 -05002324# lpfc_suppress_link_up: Bring link up at initialization
2325# 0x0 = bring link up (issue MBX_INIT_LINK)
2326# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2327# 0x2 = never bring up link
2328# Default value is 0.
2329*/
James Smarte40a02c2010-02-26 14:13:54 -05002330LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2331 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2332 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002333/*
2334# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2335# 1 - (1024)
2336# 2 - (2048)
2337# 3 - (3072)
2338# 4 - (4096)
2339# 5 - (5120)
2340*/
2341static ssize_t
2342lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2343{
2344 struct Scsi_Host *shost = class_to_shost(dev);
2345 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2346
2347 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2348}
2349
2350static DEVICE_ATTR(iocb_hw, S_IRUGO,
2351 lpfc_iocb_hw_show, NULL);
2352static ssize_t
2353lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2354{
2355 struct Scsi_Host *shost = class_to_shost(dev);
2356 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2357
2358 return snprintf(buf, PAGE_SIZE, "%d\n",
2359 phba->sli.ring[LPFC_ELS_RING].txq_max);
2360}
2361
2362static DEVICE_ATTR(txq_hw, S_IRUGO,
2363 lpfc_txq_hw_show, NULL);
2364static ssize_t
2365lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2366 char *buf)
2367{
2368 struct Scsi_Host *shost = class_to_shost(dev);
2369 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2370
2371 return snprintf(buf, PAGE_SIZE, "%d\n",
2372 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2373}
2374
2375static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2376 lpfc_txcmplq_hw_show, NULL);
2377
2378int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002379module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002380MODULE_PARM_DESC(lpfc_iocb_cnt,
2381 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2382lpfc_param_show(iocb_cnt);
2383lpfc_param_init(iocb_cnt, 2, 1, 5);
2384static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2385 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002386
2387/*
James Smartc01f3202006-08-18 17:47:08 -04002388# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2389# until the timer expires. Value range is [0,255]. Default value is 30.
2390*/
2391static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2392static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2393module_param(lpfc_nodev_tmo, int, 0);
2394MODULE_PARM_DESC(lpfc_nodev_tmo,
2395 "Seconds driver will hold I/O waiting "
2396 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002397
2398/**
James Smart3621a712009-04-06 18:47:14 -04002399 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002400 * @dev: class converted to a Scsi_host structure.
2401 * @attr: device attribute, not used.
2402 * @buf: on return contains the dev loss timeout in decimal.
2403 *
2404 * Returns: size of formatted string.
2405 **/
James Smartc01f3202006-08-18 17:47:08 -04002406static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002407lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2408 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002409{
Tony Jonesee959b02008-02-22 00:13:36 +01002410 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002412
James Smart3de2a652007-08-02 11:09:59 -04002413 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002414}
2415
James Smarte59058c2008-08-24 21:49:00 -04002416/**
James Smart3621a712009-04-06 18:47:14 -04002417 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002418 * @vport: lpfc vport structure pointer.
2419 * @val: contains the nodev timeout value.
2420 *
2421 * Description:
2422 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2423 * a kernel error message is printed and zero is returned.
2424 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2425 * Otherwise nodev tmo is set to the default value.
2426 *
2427 * Returns:
2428 * zero if already set or if val is in range
2429 * -EINVAL val out of range
2430 **/
James Smartc01f3202006-08-18 17:47:08 -04002431static int
James Smart3de2a652007-08-02 11:09:59 -04002432lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002433{
James Smart3de2a652007-08-02 11:09:59 -04002434 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2435 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2436 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002437 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002438 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002439 "parameter because devloss_tmo is "
2440 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002441 return 0;
2442 }
2443
2444 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002445 vport->cfg_nodev_tmo = val;
2446 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002447 return 0;
2448 }
James Smarte8b62012007-08-02 11:10:09 -04002449 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2450 "0400 lpfc_nodev_tmo attribute cannot be set to"
2451 " %d, allowed range is [%d, %d]\n",
2452 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002453 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002454 return -EINVAL;
2455}
2456
James Smarte59058c2008-08-24 21:49:00 -04002457/**
James Smart3621a712009-04-06 18:47:14 -04002458 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002459 * @vport: lpfc vport structure pointer.
2460 *
2461 * Description:
2462 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2463 **/
James Smart7054a602007-04-25 09:52:34 -04002464static void
James Smart3de2a652007-08-02 11:09:59 -04002465lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002466{
James Smart858c9f62007-06-17 19:56:39 -05002467 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002468 struct lpfc_nodelist *ndlp;
2469
James Smart51ef4c22007-08-02 11:10:31 -04002470 shost = lpfc_shost_from_vport(vport);
2471 spin_lock_irq(shost->host_lock);
2472 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002473 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002474 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2475 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002476}
2477
James Smarte59058c2008-08-24 21:49:00 -04002478/**
James Smart3621a712009-04-06 18:47:14 -04002479 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002480 * @vport: lpfc vport structure pointer.
2481 * @val: contains the tmo value.
2482 *
2483 * Description:
2484 * If the devloss tmo is already set or the vport dev loss tmo has changed
2485 * then a kernel error message is printed and zero is returned.
2486 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2487 * Otherwise nodev tmo is set to the default value.
2488 *
2489 * Returns:
2490 * zero if already set or if val is in range
2491 * -EINVAL val out of range
2492 **/
James Smartc01f3202006-08-18 17:47:08 -04002493static int
James Smart3de2a652007-08-02 11:09:59 -04002494lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002495{
James Smart3de2a652007-08-02 11:09:59 -04002496 if (vport->dev_loss_tmo_changed ||
2497 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002498 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2499 "0401 Ignoring change to nodev_tmo "
2500 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002501 return 0;
2502 }
James Smartc01f3202006-08-18 17:47:08 -04002503 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002504 vport->cfg_nodev_tmo = val;
2505 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002506 /*
2507 * For compat: set the fc_host dev loss so new rports
2508 * will get the value.
2509 */
2510 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002511 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002512 return 0;
2513 }
James Smarte8b62012007-08-02 11:10:09 -04002514 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2515 "0403 lpfc_nodev_tmo attribute cannot be set to"
2516 "%d, allowed range is [%d, %d]\n",
2517 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002518 return -EINVAL;
2519}
2520
James Smart3de2a652007-08-02 11:09:59 -04002521lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002522
Tony Jonesee959b02008-02-22 00:13:36 +01002523static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2524 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002525
2526/*
2527# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2528# disappear until the timer expires. Value range is [0,255]. Default
2529# value is 30.
2530*/
James Smartab56dc22011-02-16 12:39:57 -05002531module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002532MODULE_PARM_DESC(lpfc_devloss_tmo,
2533 "Seconds driver will hold I/O waiting "
2534 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002535lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2536 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2537lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002538
2539/**
James Smart3621a712009-04-06 18:47:14 -04002540 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002541 * @vport: lpfc vport structure pointer.
2542 * @val: contains the tmo value.
2543 *
2544 * Description:
2545 * If val is in a valid range then set the vport nodev tmo,
2546 * devloss tmo, also set the vport dev loss tmo changed flag.
2547 * Else a kernel error message is printed.
2548 *
2549 * Returns:
2550 * zero if val is in range
2551 * -EINVAL val out of range
2552 **/
James Smartc01f3202006-08-18 17:47:08 -04002553static int
James Smart3de2a652007-08-02 11:09:59 -04002554lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002555{
2556 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002557 vport->cfg_nodev_tmo = val;
2558 vport->cfg_devloss_tmo = val;
2559 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002560 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002561 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002562 return 0;
2563 }
2564
James Smarte8b62012007-08-02 11:10:09 -04002565 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2566 "0404 lpfc_devloss_tmo attribute cannot be set to"
2567 " %d, allowed range is [%d, %d]\n",
2568 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002569 return -EINVAL;
2570}
2571
James Smart3de2a652007-08-02 11:09:59 -04002572lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002573static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2574 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002575
2576/*
dea31012005-04-17 16:05:31 -05002577# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2578# deluged with LOTS of information.
2579# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002580# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002581*/
James Smartf4b4c682009-05-22 14:53:12 -04002582LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002583 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002584
2585/*
James Smart7ee5d432007-10-27 13:37:17 -04002586# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2587# objects that have been registered with the nameserver after login.
2588*/
James Smartcf971242012-03-01 22:37:32 -05002589LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04002590 "Deregister nameserver objects before LOGO");
2591
2592/*
dea31012005-04-17 16:05:31 -05002593# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04002594# commands per FCP LUN. Value range is [1,512]. Default value is 30.
2595# If this parameter value is greater than 1/8th the maximum number of exchanges
2596# supported by the HBA port, then the lun queue depth will be reduced to
2597# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05002598*/
James Smart572709e2013-07-15 18:32:43 -04002599LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04002600 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002601
2602/*
James Smart7dc517d2010-07-14 15:32:10 -04002603# tgt_queue_depth: This parameter is used to limit the number of outstanding
2604# commands per target port. Value range is [10,65535]. Default value is 65535.
2605*/
2606LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04002607 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04002608
2609/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002610# hba_queue_depth: This parameter is used to limit the number of outstanding
2611# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2612# value is greater than the maximum number of exchanges supported by the HBA,
2613# then maximum number of exchanges supported by the HBA is used to determine
2614# the hba_queue_depth.
2615*/
2616LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2617 "Max number of FCP commands we can queue to a lpfc HBA");
2618
2619/*
James Smart92d7f7b2007-06-17 19:56:38 -05002620# peer_port_login: This parameter allows/prevents logins
2621# between peer ports hosted on the same physical port.
2622# When this parameter is set 0 peer ports of same physical port
2623# are not allowed to login to each other.
2624# When this parameter is set 1 peer ports of same physical port
2625# are allowed to login to each other.
2626# Default value of this parameter is 0.
2627*/
James Smart3de2a652007-08-02 11:09:59 -04002628LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2629 "Allow peer ports on the same physical port to login to each "
2630 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002631
2632/*
James Smart3de2a652007-08-02 11:09:59 -04002633# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002634# between Virtual Ports and remote initiators.
2635# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2636# other initiators and will attempt to PLOGI all remote ports.
2637# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2638# remote ports and will not attempt to PLOGI to other initiators.
2639# This parameter does not restrict to the physical port.
2640# This parameter does not restrict logins to Fabric resident remote ports.
2641# Default value of this parameter is 1.
2642*/
James Smart3de2a652007-08-02 11:09:59 -04002643static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002644module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002645MODULE_PARM_DESC(lpfc_restrict_login,
2646 "Restrict virtual ports login to remote initiators.");
2647lpfc_vport_param_show(restrict_login);
2648
James Smarte59058c2008-08-24 21:49:00 -04002649/**
James Smart3621a712009-04-06 18:47:14 -04002650 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002651 * @vport: lpfc vport structure pointer.
2652 * @val: contains the restrict login value.
2653 *
2654 * Description:
2655 * If val is not in a valid range then log a kernel error message and set
2656 * the vport restrict login to one.
2657 * If the port type is physical clear the restrict login flag and return.
2658 * Else set the restrict login flag to val.
2659 *
2660 * Returns:
2661 * zero if val is in range
2662 * -EINVAL val out of range
2663 **/
James Smart3de2a652007-08-02 11:09:59 -04002664static int
2665lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2666{
2667 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002668 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002669 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002670 "be set to %d, allowed range is [0, 1]\n",
2671 val);
James Smart3de2a652007-08-02 11:09:59 -04002672 vport->cfg_restrict_login = 1;
2673 return -EINVAL;
2674 }
2675 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2676 vport->cfg_restrict_login = 0;
2677 return 0;
2678 }
2679 vport->cfg_restrict_login = val;
2680 return 0;
2681}
2682
James Smarte59058c2008-08-24 21:49:00 -04002683/**
James Smart3621a712009-04-06 18:47:14 -04002684 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002685 * @vport: lpfc vport structure pointer.
2686 * @val: contains the restrict login value.
2687 *
2688 * Description:
2689 * If val is not in a valid range then log a kernel error message and set
2690 * the vport restrict login to one.
2691 * If the port type is physical and the val is not zero log a kernel
2692 * error message, clear the restrict login flag and return zero.
2693 * Else set the restrict login flag to val.
2694 *
2695 * Returns:
2696 * zero if val is in range
2697 * -EINVAL val out of range
2698 **/
James Smart3de2a652007-08-02 11:09:59 -04002699static int
2700lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2701{
2702 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002703 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002704 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002705 "be set to %d, allowed range is [0, 1]\n",
2706 val);
James Smart3de2a652007-08-02 11:09:59 -04002707 vport->cfg_restrict_login = 1;
2708 return -EINVAL;
2709 }
2710 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002711 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2712 "0468 lpfc_restrict_login must be 0 for "
2713 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002714 vport->cfg_restrict_login = 0;
2715 return 0;
2716 }
2717 vport->cfg_restrict_login = val;
2718 return 0;
2719}
2720lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002721static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2722 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002723
2724/*
dea31012005-04-17 16:05:31 -05002725# Some disk devices have a "select ID" or "select Target" capability.
2726# From a protocol standpoint "select ID" usually means select the
2727# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2728# annex" which contains a table that maps a "select ID" (a number
2729# between 0 and 7F) to an ALPA. By default, for compatibility with
2730# older drivers, the lpfc driver scans this table from low ALPA to high
2731# ALPA.
2732#
2733# Turning on the scan-down variable (on = 1, off = 0) will
2734# cause the lpfc driver to use an inverted table, effectively
2735# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2736#
2737# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2738# and will not work across a fabric. Also this parameter will take
2739# effect only in the case when ALPA map is not available.)
2740*/
James Smart3de2a652007-08-02 11:09:59 -04002741LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2742 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002743
2744/*
dea31012005-04-17 16:05:31 -05002745# lpfc_topology: link topology for init link
2746# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002747# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002748# 0x02 = attempt point-to-point mode only
2749# 0x04 = attempt loop mode only
2750# 0x06 = attempt point-to-point mode then loop
2751# Set point-to-point mode if you want to run as an N_Port.
2752# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2753# Default value is 0.
2754*/
James Smarte59058c2008-08-24 21:49:00 -04002755
2756/**
James Smart3621a712009-04-06 18:47:14 -04002757 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002758 * @phba: lpfc_hba pointer.
2759 * @val: topology value.
2760 *
2761 * Description:
2762 * If val is in a valid range then set the adapter's topology field and
2763 * issue a lip; if the lip fails reset the topology to the old value.
2764 *
2765 * If the value is not in range log a kernel error message and return an error.
2766 *
2767 * Returns:
2768 * zero if val is in range and lip okay
2769 * non-zero return value from lpfc_issue_lip()
2770 * -EINVAL val out of range
2771 **/
James Smarta257bf92009-04-06 18:48:10 -04002772static ssize_t
2773lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2774 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002775{
James Smarta257bf92009-04-06 18:48:10 -04002776 struct Scsi_Host *shost = class_to_shost(dev);
2777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2778 struct lpfc_hba *phba = vport->phba;
2779 int val = 0;
2780 int nolip = 0;
2781 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002782 int err;
2783 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002784
2785 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2786 nolip = 1;
2787 val_buf = &buf[strlen("nolip ")];
2788 }
2789
2790 if (!isdigit(val_buf[0]))
2791 return -EINVAL;
2792 if (sscanf(val_buf, "%i", &val) != 1)
2793 return -EINVAL;
2794
James Smart83108bd2008-01-11 01:53:09 -05002795 if (val >= 0 && val <= 6) {
2796 prev_val = phba->cfg_topology;
2797 phba->cfg_topology = val;
James Smartff78d8f2011-12-13 13:21:35 -05002798 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
2799 val == 4) {
2800 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2801 "3113 Loop mode not supported at speed %d\n",
2802 phba->cfg_link_speed);
2803 phba->cfg_topology = prev_val;
2804 return -EINVAL;
2805 }
James Smarta257bf92009-04-06 18:48:10 -04002806 if (nolip)
2807 return strlen(buf);
2808
James Smart88a2cfb2011-07-22 18:36:33 -04002809 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2810 "3054 lpfc_topology changed from %d to %d\n",
2811 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04002812 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
2813 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05002814 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002815 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002816 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002817 return -EINVAL;
2818 } else
2819 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002820 }
2821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2822 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2823 "allowed range is [0, 6]\n",
2824 phba->brd_no, val);
2825 return -EINVAL;
2826}
2827static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002828module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002829MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2830lpfc_param_show(topology)
2831lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002832static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002833 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002834
James Smart21e9a0a2009-05-22 14:53:21 -04002835/**
2836 * lpfc_static_vport_show: Read callback function for
2837 * lpfc_static_vport sysfs file.
2838 * @dev: Pointer to class device object.
2839 * @attr: device attribute structure.
2840 * @buf: Data buffer.
2841 *
2842 * This function is the read call back function for
2843 * lpfc_static_vport sysfs file. The lpfc_static_vport
2844 * sysfs file report the mageability of the vport.
2845 **/
2846static ssize_t
2847lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2848 char *buf)
2849{
2850 struct Scsi_Host *shost = class_to_shost(dev);
2851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2852 if (vport->vport_flag & STATIC_VPORT)
2853 sprintf(buf, "1\n");
2854 else
2855 sprintf(buf, "0\n");
2856
2857 return strlen(buf);
2858}
2859
2860/*
2861 * Sysfs attribute to control the statistical data collection.
2862 */
2863static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2864 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002865
2866/**
James Smart3621a712009-04-06 18:47:14 -04002867 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002868 * @dev: Pointer to class device.
2869 * @buf: Data buffer.
2870 * @count: Size of the data buffer.
2871 *
2872 * This function get called when an user write to the lpfc_stat_data_ctrl
2873 * sysfs file. This function parse the command written to the sysfs file
2874 * and take appropriate action. These commands are used for controlling
2875 * driver statistical data collection.
2876 * Following are the command this function handles.
2877 *
2878 * setbucket <bucket_type> <base> <step>
2879 * = Set the latency buckets.
2880 * destroybucket = destroy all the buckets.
2881 * start = start data collection
2882 * stop = stop data collection
2883 * reset = reset the collected data
2884 **/
2885static ssize_t
2886lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2887 const char *buf, size_t count)
2888{
2889 struct Scsi_Host *shost = class_to_shost(dev);
2890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2891 struct lpfc_hba *phba = vport->phba;
2892#define LPFC_MAX_DATA_CTRL_LEN 1024
2893 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2894 unsigned long i;
2895 char *str_ptr, *token;
2896 struct lpfc_vport **vports;
2897 struct Scsi_Host *v_shost;
2898 char *bucket_type_str, *base_str, *step_str;
2899 unsigned long base, step, bucket_type;
2900
2901 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002902 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002903 return -EINVAL;
2904
2905 strcpy(bucket_data, buf);
2906 str_ptr = &bucket_data[0];
2907 /* Ignore this token - this is command token */
2908 token = strsep(&str_ptr, "\t ");
2909 if (!token)
2910 return -EINVAL;
2911
2912 bucket_type_str = strsep(&str_ptr, "\t ");
2913 if (!bucket_type_str)
2914 return -EINVAL;
2915
2916 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2917 bucket_type = LPFC_LINEAR_BUCKET;
2918 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2919 bucket_type = LPFC_POWER2_BUCKET;
2920 else
2921 return -EINVAL;
2922
2923 base_str = strsep(&str_ptr, "\t ");
2924 if (!base_str)
2925 return -EINVAL;
2926 base = simple_strtoul(base_str, NULL, 0);
2927
2928 step_str = strsep(&str_ptr, "\t ");
2929 if (!step_str)
2930 return -EINVAL;
2931 step = simple_strtoul(step_str, NULL, 0);
2932 if (!step)
2933 return -EINVAL;
2934
2935 /* Block the data collection for every vport */
2936 vports = lpfc_create_vport_work_array(phba);
2937 if (vports == NULL)
2938 return -ENOMEM;
2939
James Smartf4b4c682009-05-22 14:53:12 -04002940 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002941 v_shost = lpfc_shost_from_vport(vports[i]);
2942 spin_lock_irq(v_shost->host_lock);
2943 /* Block and reset data collection */
2944 vports[i]->stat_data_blocked = 1;
2945 if (vports[i]->stat_data_enabled)
2946 lpfc_vport_reset_stat_data(vports[i]);
2947 spin_unlock_irq(v_shost->host_lock);
2948 }
2949
2950 /* Set the bucket attributes */
2951 phba->bucket_type = bucket_type;
2952 phba->bucket_base = base;
2953 phba->bucket_step = step;
2954
James Smartf4b4c682009-05-22 14:53:12 -04002955 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002956 v_shost = lpfc_shost_from_vport(vports[i]);
2957
2958 /* Unblock data collection */
2959 spin_lock_irq(v_shost->host_lock);
2960 vports[i]->stat_data_blocked = 0;
2961 spin_unlock_irq(v_shost->host_lock);
2962 }
2963 lpfc_destroy_vport_work_array(phba, vports);
2964 return strlen(buf);
2965 }
2966
2967 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2968 vports = lpfc_create_vport_work_array(phba);
2969 if (vports == NULL)
2970 return -ENOMEM;
2971
James Smartf4b4c682009-05-22 14:53:12 -04002972 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002973 v_shost = lpfc_shost_from_vport(vports[i]);
2974 spin_lock_irq(shost->host_lock);
2975 vports[i]->stat_data_blocked = 1;
2976 lpfc_free_bucket(vport);
2977 vport->stat_data_enabled = 0;
2978 vports[i]->stat_data_blocked = 0;
2979 spin_unlock_irq(shost->host_lock);
2980 }
2981 lpfc_destroy_vport_work_array(phba, vports);
2982 phba->bucket_type = LPFC_NO_BUCKET;
2983 phba->bucket_base = 0;
2984 phba->bucket_step = 0;
2985 return strlen(buf);
2986 }
2987
2988 if (!strncmp(buf, "start", strlen("start"))) {
2989 /* If no buckets configured return error */
2990 if (phba->bucket_type == LPFC_NO_BUCKET)
2991 return -EINVAL;
2992 spin_lock_irq(shost->host_lock);
2993 if (vport->stat_data_enabled) {
2994 spin_unlock_irq(shost->host_lock);
2995 return strlen(buf);
2996 }
2997 lpfc_alloc_bucket(vport);
2998 vport->stat_data_enabled = 1;
2999 spin_unlock_irq(shost->host_lock);
3000 return strlen(buf);
3001 }
3002
3003 if (!strncmp(buf, "stop", strlen("stop"))) {
3004 spin_lock_irq(shost->host_lock);
3005 if (vport->stat_data_enabled == 0) {
3006 spin_unlock_irq(shost->host_lock);
3007 return strlen(buf);
3008 }
3009 lpfc_free_bucket(vport);
3010 vport->stat_data_enabled = 0;
3011 spin_unlock_irq(shost->host_lock);
3012 return strlen(buf);
3013 }
3014
3015 if (!strncmp(buf, "reset", strlen("reset"))) {
3016 if ((phba->bucket_type == LPFC_NO_BUCKET)
3017 || !vport->stat_data_enabled)
3018 return strlen(buf);
3019 spin_lock_irq(shost->host_lock);
3020 vport->stat_data_blocked = 1;
3021 lpfc_vport_reset_stat_data(vport);
3022 vport->stat_data_blocked = 0;
3023 spin_unlock_irq(shost->host_lock);
3024 return strlen(buf);
3025 }
3026 return -EINVAL;
3027}
3028
3029
3030/**
James Smart3621a712009-04-06 18:47:14 -04003031 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003032 * @dev: Pointer to class device object.
3033 * @buf: Data buffer.
3034 *
3035 * This function is the read call back function for
3036 * lpfc_stat_data_ctrl sysfs file. This function report the
3037 * current statistical data collection state.
3038 **/
3039static ssize_t
3040lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3041 char *buf)
3042{
3043 struct Scsi_Host *shost = class_to_shost(dev);
3044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3045 struct lpfc_hba *phba = vport->phba;
3046 int index = 0;
3047 int i;
3048 char *bucket_type;
3049 unsigned long bucket_value;
3050
3051 switch (phba->bucket_type) {
3052 case LPFC_LINEAR_BUCKET:
3053 bucket_type = "linear";
3054 break;
3055 case LPFC_POWER2_BUCKET:
3056 bucket_type = "power2";
3057 break;
3058 default:
3059 bucket_type = "No Bucket";
3060 break;
3061 }
3062
3063 sprintf(&buf[index], "Statistical Data enabled :%d, "
3064 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3065 " Bucket step :%d\nLatency Ranges :",
3066 vport->stat_data_enabled, vport->stat_data_blocked,
3067 bucket_type, phba->bucket_base, phba->bucket_step);
3068 index = strlen(buf);
3069 if (phba->bucket_type != LPFC_NO_BUCKET) {
3070 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3071 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3072 bucket_value = phba->bucket_base +
3073 phba->bucket_step * i;
3074 else
3075 bucket_value = phba->bucket_base +
3076 (1 << i) * phba->bucket_step;
3077
3078 if (index + 10 > PAGE_SIZE)
3079 break;
3080 sprintf(&buf[index], "%08ld ", bucket_value);
3081 index = strlen(buf);
3082 }
3083 }
3084 sprintf(&buf[index], "\n");
3085 return strlen(buf);
3086}
3087
3088/*
3089 * Sysfs attribute to control the statistical data collection.
3090 */
3091static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3092 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3093
3094/*
3095 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3096 */
3097
3098/*
3099 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3100 * for each target.
3101 */
3102#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3103#define MAX_STAT_DATA_SIZE_PER_TARGET \
3104 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3105
3106
3107/**
James Smart3621a712009-04-06 18:47:14 -04003108 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003109 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003110 * @kobj: Pointer to the kernel object
3111 * @bin_attr: Attribute object
3112 * @buff: Buffer pointer
3113 * @off: File offset
3114 * @count: Buffer size
3115 *
3116 * This function is the read call back function for lpfc_drvr_stat_data
3117 * sysfs file. This function export the statistical data to user
3118 * applications.
3119 **/
3120static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003121sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3122 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003123 char *buf, loff_t off, size_t count)
3124{
3125 struct device *dev = container_of(kobj, struct device,
3126 kobj);
3127 struct Scsi_Host *shost = class_to_shost(dev);
3128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3129 struct lpfc_hba *phba = vport->phba;
3130 int i = 0, index = 0;
3131 unsigned long nport_index;
3132 struct lpfc_nodelist *ndlp = NULL;
3133 nport_index = (unsigned long)off /
3134 MAX_STAT_DATA_SIZE_PER_TARGET;
3135
3136 if (!vport->stat_data_enabled || vport->stat_data_blocked
3137 || (phba->bucket_type == LPFC_NO_BUCKET))
3138 return 0;
3139
3140 spin_lock_irq(shost->host_lock);
3141 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3142 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3143 continue;
3144
3145 if (nport_index > 0) {
3146 nport_index--;
3147 continue;
3148 }
3149
3150 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3151 > count)
3152 break;
3153
3154 if (!ndlp->lat_data)
3155 continue;
3156
3157 /* Print the WWN */
3158 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3159 ndlp->nlp_portname.u.wwn[0],
3160 ndlp->nlp_portname.u.wwn[1],
3161 ndlp->nlp_portname.u.wwn[2],
3162 ndlp->nlp_portname.u.wwn[3],
3163 ndlp->nlp_portname.u.wwn[4],
3164 ndlp->nlp_portname.u.wwn[5],
3165 ndlp->nlp_portname.u.wwn[6],
3166 ndlp->nlp_portname.u.wwn[7]);
3167
3168 index = strlen(buf);
3169
3170 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3171 sprintf(&buf[index], "%010u,",
3172 ndlp->lat_data[i].cmd_count);
3173 index = strlen(buf);
3174 }
3175 sprintf(&buf[index], "\n");
3176 index = strlen(buf);
3177 }
3178 spin_unlock_irq(shost->host_lock);
3179 return index;
3180}
3181
3182static struct bin_attribute sysfs_drvr_stat_data_attr = {
3183 .attr = {
3184 .name = "lpfc_drvr_stat_data",
3185 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003186 },
3187 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3188 .read = sysfs_drvr_stat_data_read,
3189 .write = NULL,
3190};
3191
dea31012005-04-17 16:05:31 -05003192/*
3193# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3194# connection.
James Smart76a95d72010-11-20 23:11:48 -05003195# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003196*/
James Smarte59058c2008-08-24 21:49:00 -04003197/**
James Smart3621a712009-04-06 18:47:14 -04003198 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003199 * @phba: lpfc_hba pointer.
3200 * @val: link speed value.
3201 *
3202 * Description:
3203 * If val is in a valid range then set the adapter's link speed field and
3204 * issue a lip; if the lip fails reset the link speed to the old value.
3205 *
3206 * Notes:
3207 * If the value is not in range log a kernel error message and return an error.
3208 *
3209 * Returns:
3210 * zero if val is in range and lip okay.
3211 * non-zero return value from lpfc_issue_lip()
3212 * -EINVAL val out of range
3213 **/
James Smarta257bf92009-04-06 18:48:10 -04003214static ssize_t
3215lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3216 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003217{
James Smarta257bf92009-04-06 18:48:10 -04003218 struct Scsi_Host *shost = class_to_shost(dev);
3219 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3220 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003221 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003222 int nolip = 0;
3223 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003224 int err;
3225 uint32_t prev_val;
3226
James Smarta257bf92009-04-06 18:48:10 -04003227 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3228 nolip = 1;
3229 val_buf = &buf[strlen("nolip ")];
3230 }
3231
3232 if (!isdigit(val_buf[0]))
3233 return -EINVAL;
3234 if (sscanf(val_buf, "%i", &val) != 1)
3235 return -EINVAL;
3236
James Smart88a2cfb2011-07-22 18:36:33 -04003237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3238 "3055 lpfc_link_speed changed from %d to %d %s\n",
3239 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3240
James Smart76a95d72010-11-20 23:11:48 -05003241 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3242 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3243 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3244 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3245 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3246 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3247 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3248 "2879 lpfc_link_speed attribute cannot be set "
3249 "to %d. Speed is not supported by this port.\n",
3250 val);
James Smart83108bd2008-01-11 01:53:09 -05003251 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003252 }
James Smartff78d8f2011-12-13 13:21:35 -05003253 if (val == LPFC_USER_LINK_SPEED_16G &&
3254 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3255 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3256 "3112 lpfc_link_speed attribute cannot be set "
3257 "to %d. Speed is not supported in loop mode.\n",
3258 val);
3259 return -EINVAL;
3260 }
James Smart76a95d72010-11-20 23:11:48 -05003261 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3262 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003263 prev_val = phba->cfg_link_speed;
3264 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003265 if (nolip)
3266 return strlen(buf);
3267
James Smart83108bd2008-01-11 01:53:09 -05003268 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003269 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003270 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003271 return -EINVAL;
3272 } else
3273 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003274 }
James Smart83108bd2008-01-11 01:53:09 -05003275 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003276 "0469 lpfc_link_speed attribute cannot be set to %d, "
3277 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003278 return -EINVAL;
3279}
3280
3281static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003282module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003283MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3284lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003285
3286/**
James Smart3621a712009-04-06 18:47:14 -04003287 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003288 * @phba: lpfc_hba pointer.
3289 * @val: link speed value.
3290 *
3291 * Description:
3292 * If val is in a valid range then set the adapter's link speed field.
3293 *
3294 * Notes:
3295 * If the value is not in range log a kernel error message, clear the link
3296 * speed and return an error.
3297 *
3298 * Returns:
3299 * zero if val saved.
3300 * -EINVAL val out of range
3301 **/
James Smart83108bd2008-01-11 01:53:09 -05003302static int
3303lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3304{
James Smartff78d8f2011-12-13 13:21:35 -05003305 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3307 "3111 lpfc_link_speed of %d cannot "
3308 "support loop mode, setting topology to default.\n",
3309 val);
3310 phba->cfg_topology = 0;
3311 }
James Smart76a95d72010-11-20 23:11:48 -05003312 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3313 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003314 phba->cfg_link_speed = val;
3315 return 0;
3316 }
3317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003318 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003319 "be set to %d, allowed values are "
3320 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003321 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003322 return -EINVAL;
3323}
3324
Tony Jonesee959b02008-02-22 00:13:36 +01003325static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003326 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003327
3328/*
James Smart0d878412009-10-02 15:16:56 -04003329# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3330# 0 = aer disabled or not supported
3331# 1 = aer supported and enabled (default)
3332# Value range is [0,1]. Default value is 1.
3333*/
3334
3335/**
3336 * lpfc_aer_support_store - Set the adapter for aer support
3337 *
3338 * @dev: class device that is converted into a Scsi_host.
3339 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003340 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003341 * @count: unused variable.
3342 *
3343 * Description:
3344 * If the val is 1 and currently the device's AER capability was not
3345 * enabled, invoke the kernel's enable AER helper routine, trying to
3346 * enable the device's AER capability. If the helper routine enabling
3347 * AER returns success, update the device's cfg_aer_support flag to
3348 * indicate AER is supported by the device; otherwise, if the device
3349 * AER capability is already enabled to support AER, then do nothing.
3350 *
3351 * If the val is 0 and currently the device's AER support was enabled,
3352 * invoke the kernel's disable AER helper routine. After that, update
3353 * the device's cfg_aer_support flag to indicate AER is not supported
3354 * by the device; otherwise, if the device AER capability is already
3355 * disabled from supporting AER, then do nothing.
3356 *
3357 * Returns:
3358 * length of the buf on success if val is in range the intended mode
3359 * is supported.
3360 * -EINVAL if val out of range or intended mode is not supported.
3361 **/
3362static ssize_t
3363lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3364 const char *buf, size_t count)
3365{
3366 struct Scsi_Host *shost = class_to_shost(dev);
3367 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3368 struct lpfc_hba *phba = vport->phba;
3369 int val = 0, rc = -EINVAL;
3370
3371 if (!isdigit(buf[0]))
3372 return -EINVAL;
3373 if (sscanf(buf, "%i", &val) != 1)
3374 return -EINVAL;
3375
3376 switch (val) {
3377 case 0:
3378 if (phba->hba_flag & HBA_AER_ENABLED) {
3379 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3380 if (!rc) {
3381 spin_lock_irq(&phba->hbalock);
3382 phba->hba_flag &= ~HBA_AER_ENABLED;
3383 spin_unlock_irq(&phba->hbalock);
3384 phba->cfg_aer_support = 0;
3385 rc = strlen(buf);
3386 } else
James Smart891478a2009-11-18 15:40:23 -05003387 rc = -EPERM;
3388 } else {
James Smart0d878412009-10-02 15:16:56 -04003389 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003390 rc = strlen(buf);
3391 }
James Smart0d878412009-10-02 15:16:56 -04003392 break;
3393 case 1:
3394 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3395 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3396 if (!rc) {
3397 spin_lock_irq(&phba->hbalock);
3398 phba->hba_flag |= HBA_AER_ENABLED;
3399 spin_unlock_irq(&phba->hbalock);
3400 phba->cfg_aer_support = 1;
3401 rc = strlen(buf);
3402 } else
James Smart891478a2009-11-18 15:40:23 -05003403 rc = -EPERM;
3404 } else {
James Smart0d878412009-10-02 15:16:56 -04003405 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003406 rc = strlen(buf);
3407 }
James Smart0d878412009-10-02 15:16:56 -04003408 break;
3409 default:
3410 rc = -EINVAL;
3411 break;
3412 }
3413 return rc;
3414}
3415
3416static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003417module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003418MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3419lpfc_param_show(aer_support)
3420
3421/**
3422 * lpfc_aer_support_init - Set the initial adapters aer support flag
3423 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003424 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003425 *
3426 * Description:
3427 * If val is in a valid range [0,1], then set the adapter's initial
3428 * cfg_aer_support field. It will be up to the driver's probe_one
3429 * routine to determine whether the device's AER support can be set
3430 * or not.
3431 *
3432 * Notes:
3433 * If the value is not in range log a kernel error message, and
3434 * choose the default value of setting AER support and return.
3435 *
3436 * Returns:
3437 * zero if val saved.
3438 * -EINVAL val out of range
3439 **/
3440static int
3441lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3442{
3443 if (val == 0 || val == 1) {
3444 phba->cfg_aer_support = val;
3445 return 0;
3446 }
3447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3448 "2712 lpfc_aer_support attribute value %d out "
3449 "of range, allowed values are 0|1, setting it "
3450 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003451 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003452 phba->cfg_aer_support = 1;
3453 return -EINVAL;
3454}
3455
3456static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3457 lpfc_aer_support_show, lpfc_aer_support_store);
3458
3459/**
3460 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3461 * @dev: class device that is converted into a Scsi_host.
3462 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003463 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003464 * @count: unused variable.
3465 *
3466 * Description:
3467 * If the @buf contains 1 and the device currently has the AER support
3468 * enabled, then invokes the kernel AER helper routine
3469 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3470 * error status register.
3471 *
3472 * Notes:
3473 *
3474 * Returns:
3475 * -EINVAL if the buf does not contain the 1 or the device is not currently
3476 * enabled with the AER support.
3477 **/
3478static ssize_t
3479lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3480 const char *buf, size_t count)
3481{
3482 struct Scsi_Host *shost = class_to_shost(dev);
3483 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3484 struct lpfc_hba *phba = vport->phba;
3485 int val, rc = -1;
3486
3487 if (!isdigit(buf[0]))
3488 return -EINVAL;
3489 if (sscanf(buf, "%i", &val) != 1)
3490 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003491 if (val != 1)
3492 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003493
James Smart891478a2009-11-18 15:40:23 -05003494 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003495 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3496
3497 if (rc == 0)
3498 return strlen(buf);
3499 else
James Smart891478a2009-11-18 15:40:23 -05003500 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003501}
3502
3503static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3504 lpfc_aer_cleanup_state);
3505
James Smart912e3ac2011-05-24 11:42:11 -04003506/**
3507 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3508 *
3509 * @dev: class device that is converted into a Scsi_host.
3510 * @attr: device attribute, not used.
3511 * @buf: containing the string the number of vfs to be enabled.
3512 * @count: unused variable.
3513 *
3514 * Description:
3515 * When this api is called either through user sysfs, the driver shall
3516 * try to enable or disable SR-IOV virtual functions according to the
3517 * following:
3518 *
3519 * If zero virtual function has been enabled to the physical function,
3520 * the driver shall invoke the pci enable virtual function api trying
3521 * to enable the virtual functions. If the nr_vfn provided is greater
3522 * than the maximum supported, the maximum virtual function number will
3523 * be used for invoking the api; otherwise, the nr_vfn provided shall
3524 * be used for invoking the api. If the api call returned success, the
3525 * actual number of virtual functions enabled will be set to the driver
3526 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3527 * cfg_sriov_nr_virtfn remains zero.
3528 *
3529 * If none-zero virtual functions have already been enabled to the
3530 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3531 * -EINVAL will be returned and the driver does nothing;
3532 *
3533 * If the nr_vfn provided is zero and none-zero virtual functions have
3534 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3535 * disabling virtual function api shall be invoded to disable all the
3536 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3537 * zero. Otherwise, if zero virtual function has been enabled, do
3538 * nothing.
3539 *
3540 * Returns:
3541 * length of the buf on success if val is in range the intended mode
3542 * is supported.
3543 * -EINVAL if val out of range or intended mode is not supported.
3544 **/
3545static ssize_t
3546lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3547 const char *buf, size_t count)
3548{
3549 struct Scsi_Host *shost = class_to_shost(dev);
3550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3551 struct lpfc_hba *phba = vport->phba;
3552 struct pci_dev *pdev = phba->pcidev;
3553 int val = 0, rc = -EINVAL;
3554
3555 /* Sanity check on user data */
3556 if (!isdigit(buf[0]))
3557 return -EINVAL;
3558 if (sscanf(buf, "%i", &val) != 1)
3559 return -EINVAL;
3560 if (val < 0)
3561 return -EINVAL;
3562
3563 /* Request disabling virtual functions */
3564 if (val == 0) {
3565 if (phba->cfg_sriov_nr_virtfn > 0) {
3566 pci_disable_sriov(pdev);
3567 phba->cfg_sriov_nr_virtfn = 0;
3568 }
3569 return strlen(buf);
3570 }
3571
3572 /* Request enabling virtual functions */
3573 if (phba->cfg_sriov_nr_virtfn > 0) {
3574 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3575 "3018 There are %d virtual functions "
3576 "enabled on physical function.\n",
3577 phba->cfg_sriov_nr_virtfn);
3578 return -EEXIST;
3579 }
3580
3581 if (val <= LPFC_MAX_VFN_PER_PFN)
3582 phba->cfg_sriov_nr_virtfn = val;
3583 else {
3584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3585 "3019 Enabling %d virtual functions is not "
3586 "allowed.\n", val);
3587 return -EINVAL;
3588 }
3589
3590 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3591 if (rc) {
3592 phba->cfg_sriov_nr_virtfn = 0;
3593 rc = -EPERM;
3594 } else
3595 rc = strlen(buf);
3596
3597 return rc;
3598}
3599
3600static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3601module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3602MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3603lpfc_param_show(sriov_nr_virtfn)
3604
3605/**
3606 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3607 * @phba: lpfc_hba pointer.
3608 * @val: link speed value.
3609 *
3610 * Description:
3611 * If val is in a valid range [0,255], then set the adapter's initial
3612 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3613 * number shall be used instead. It will be up to the driver's probe_one
3614 * routine to determine whether the device's SR-IOV is supported or not.
3615 *
3616 * Returns:
3617 * zero if val saved.
3618 * -EINVAL val out of range
3619 **/
3620static int
3621lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3622{
3623 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3624 phba->cfg_sriov_nr_virtfn = val;
3625 return 0;
3626 }
3627
3628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3629 "3017 Enabling %d virtual functions is not "
3630 "allowed.\n", val);
3631 return -EINVAL;
3632}
3633static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3634 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3635
James Smart173edbb2012-06-12 13:54:50 -04003636/**
James Smartc71ab862012-10-31 14:44:33 -04003637 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
3638 *
3639 * @dev: class device that is converted into a Scsi_host.
3640 * @attr: device attribute, not used.
3641 * @buf: containing the string the number of vfs to be enabled.
3642 * @count: unused variable.
3643 *
3644 * Description:
3645 *
3646 * Returns:
3647 * length of the buf on success if val is in range the intended mode
3648 * is supported.
3649 * -EINVAL if val out of range or intended mode is not supported.
3650 **/
3651static ssize_t
3652lpfc_request_firmware_upgrade_store(struct device *dev,
3653 struct device_attribute *attr,
3654 const char *buf, size_t count)
3655{
3656 struct Scsi_Host *shost = class_to_shost(dev);
3657 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3658 struct lpfc_hba *phba = vport->phba;
3659 int val = 0, rc = -EINVAL;
3660
3661 /* Sanity check on user data */
3662 if (!isdigit(buf[0]))
3663 return -EINVAL;
3664 if (sscanf(buf, "%i", &val) != 1)
3665 return -EINVAL;
3666 if (val != 1)
3667 return -EINVAL;
3668
3669 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
3670 if (rc)
3671 rc = -EPERM;
3672 else
3673 rc = strlen(buf);
3674 return rc;
3675}
3676
3677static int lpfc_req_fw_upgrade;
3678module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
3679MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
3680lpfc_param_show(request_firmware_upgrade)
3681
3682/**
3683 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
3684 * @phba: lpfc_hba pointer.
3685 * @val: 0 or 1.
3686 *
3687 * Description:
3688 * Set the initial Linux generic firmware upgrade enable or disable flag.
3689 *
3690 * Returns:
3691 * zero if val saved.
3692 * -EINVAL val out of range
3693 **/
3694static int
3695lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
3696{
3697 if (val >= 0 && val <= 1) {
3698 phba->cfg_request_firmware_upgrade = val;
3699 return 0;
3700 }
3701 return -EINVAL;
3702}
3703static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
3704 lpfc_request_firmware_upgrade_show,
3705 lpfc_request_firmware_upgrade_store);
3706
3707/**
James Smart173edbb2012-06-12 13:54:50 -04003708 * lpfc_fcp_imax_store
3709 *
3710 * @dev: class device that is converted into a Scsi_host.
3711 * @attr: device attribute, not used.
3712 * @buf: string with the number of fast-path FCP interrupts per second.
3713 * @count: unused variable.
3714 *
3715 * Description:
3716 * If val is in a valid range [636,651042], then set the adapter's
3717 * maximum number of fast-path FCP interrupts per second.
3718 *
3719 * Returns:
3720 * length of the buf on success if val is in range the intended mode
3721 * is supported.
3722 * -EINVAL if val out of range or intended mode is not supported.
3723 **/
3724static ssize_t
3725lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
3726 const char *buf, size_t count)
3727{
3728 struct Scsi_Host *shost = class_to_shost(dev);
3729 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3730 struct lpfc_hba *phba = vport->phba;
3731 int val = 0, i;
3732
James Smartbf8dae82012-08-03 12:36:24 -04003733 /* fcp_imax is only valid for SLI4 */
3734 if (phba->sli_rev != LPFC_SLI_REV4)
3735 return -EINVAL;
3736
James Smart173edbb2012-06-12 13:54:50 -04003737 /* Sanity check on user data */
3738 if (!isdigit(buf[0]))
3739 return -EINVAL;
3740 if (sscanf(buf, "%i", &val) != 1)
3741 return -EINVAL;
3742
James Smartbf8dae82012-08-03 12:36:24 -04003743 /*
3744 * Value range for the HBA is [5000,5000000]
3745 * The value for each EQ depends on how many EQs are configured.
3746 */
3747 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04003748 return -EINVAL;
3749
3750 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04003751 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04003752 lpfc_modify_fcp_eq_delay(phba, i);
3753
3754 return strlen(buf);
3755}
3756
3757/*
3758# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04003759# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04003760#
James Smartbf8dae82012-08-03 12:36:24 -04003761# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04003762*/
James Smartbf8dae82012-08-03 12:36:24 -04003763static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003764module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
3765MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04003766 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04003767lpfc_param_show(fcp_imax)
3768
3769/**
3770 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
3771 * @phba: lpfc_hba pointer.
3772 * @val: link speed value.
3773 *
3774 * Description:
3775 * If val is in a valid range [636,651042], then initialize the adapter's
3776 * maximum number of fast-path FCP interrupts per second.
3777 *
3778 * Returns:
3779 * zero if val saved.
3780 * -EINVAL val out of range
3781 **/
3782static int
3783lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
3784{
James Smartbf8dae82012-08-03 12:36:24 -04003785 if (phba->sli_rev != LPFC_SLI_REV4) {
3786 phba->cfg_fcp_imax = 0;
3787 return 0;
3788 }
3789
3790 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04003791 phba->cfg_fcp_imax = val;
3792 return 0;
3793 }
3794
3795 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3796 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04003797 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003798
3799 return 0;
3800}
3801
3802static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
3803 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
3804
James Smart7bb03bb2013-04-17 20:19:16 -04003805/**
3806 * lpfc_state_show - Display current driver CPU affinity
3807 * @dev: class converted to a Scsi_host structure.
3808 * @attr: device attribute, not used.
3809 * @buf: on return contains text describing the state of the link.
3810 *
3811 * Returns: size of formatted string.
3812 **/
3813static ssize_t
3814lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
3815 char *buf)
3816{
3817 struct Scsi_Host *shost = class_to_shost(dev);
3818 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3819 struct lpfc_hba *phba = vport->phba;
3820 struct lpfc_vector_map_info *cpup;
3821 int idx, len = 0;
3822
3823 if ((phba->sli_rev != LPFC_SLI_REV4) ||
3824 (phba->intr_type != MSIX))
3825 return len;
3826
3827 switch (phba->cfg_fcp_cpu_map) {
3828 case 0:
3829 len += snprintf(buf + len, PAGE_SIZE-len,
3830 "fcp_cpu_map: No mapping (%d)\n",
3831 phba->cfg_fcp_cpu_map);
3832 return len;
3833 case 1:
3834 len += snprintf(buf + len, PAGE_SIZE-len,
3835 "fcp_cpu_map: HBA centric mapping (%d): "
3836 "%d online CPUs\n",
3837 phba->cfg_fcp_cpu_map,
3838 phba->sli4_hba.num_online_cpu);
3839 break;
3840 case 2:
3841 len += snprintf(buf + len, PAGE_SIZE-len,
3842 "fcp_cpu_map: Driver centric mapping (%d): "
3843 "%d online CPUs\n",
3844 phba->cfg_fcp_cpu_map,
3845 phba->sli4_hba.num_online_cpu);
3846 break;
3847 }
3848
3849 cpup = phba->sli4_hba.cpu_map;
3850 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
3851 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
3852 len += snprintf(buf + len, PAGE_SIZE-len,
3853 "CPU %02d io_chan %02d "
3854 "physid %d coreid %d\n",
3855 idx, cpup->channel_id, cpup->phys_id,
3856 cpup->core_id);
3857 else
3858 len += snprintf(buf + len, PAGE_SIZE-len,
3859 "CPU %02d io_chan %02d "
3860 "physid %d coreid %d IRQ %d\n",
3861 idx, cpup->channel_id, cpup->phys_id,
3862 cpup->core_id, cpup->irq);
3863
3864 cpup++;
3865 }
3866 return len;
3867}
3868
3869/**
3870 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
3871 * @dev: class device that is converted into a Scsi_host.
3872 * @attr: device attribute, not used.
3873 * @buf: one or more lpfc_polling_flags values.
3874 * @count: not used.
3875 *
3876 * Returns:
3877 * -EINVAL - Not implemented yet.
3878 **/
3879static ssize_t
3880lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
3881 const char *buf, size_t count)
3882{
3883 int status = -EINVAL;
3884 return status;
3885}
3886
3887/*
3888# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
3889# for the HBA.
3890#
3891# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
3892# 0 - Do not affinitze IRQ vectors
3893# 1 - Affintize HBA vectors with respect to each HBA
3894# (start with CPU0 for each HBA)
3895# 2 - Affintize HBA vectors with respect to the entire driver
3896# (round robin thru all CPUs across all HBAs)
3897*/
3898static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
3899module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
3900MODULE_PARM_DESC(lpfc_fcp_cpu_map,
3901 "Defines how to map CPUs to IRQ vectors per HBA");
3902
3903/**
3904 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
3905 * @phba: lpfc_hba pointer.
3906 * @val: link speed value.
3907 *
3908 * Description:
3909 * If val is in a valid range [0-2], then affinitze the adapter's
3910 * MSIX vectors.
3911 *
3912 * Returns:
3913 * zero if val saved.
3914 * -EINVAL val out of range
3915 **/
3916static int
3917lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
3918{
3919 if (phba->sli_rev != LPFC_SLI_REV4) {
3920 phba->cfg_fcp_cpu_map = 0;
3921 return 0;
3922 }
3923
3924 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
3925 phba->cfg_fcp_cpu_map = val;
3926 return 0;
3927 }
3928
3929 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3930 "3326 fcp_cpu_map: %d out of range, using default\n",
3931 val);
3932 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
3933
3934 return 0;
3935}
3936
3937static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
3938 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
3939
James Smart0d878412009-10-02 15:16:56 -04003940/*
dea31012005-04-17 16:05:31 -05003941# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3942# Value range is [2,3]. Default value is 3.
3943*/
James Smart3de2a652007-08-02 11:09:59 -04003944LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3945 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003946
3947/*
3948# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3949# is [0,1]. Default value is 0.
3950*/
James Smart3de2a652007-08-02 11:09:59 -04003951LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3952 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003953
3954/*
James Smart977b5a02008-09-07 11:52:04 -04003955# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3956# depth. Default value is 0. When the value of this parameter is zero the
3957# SCSI command completion time is not used for controlling I/O queue depth. When
3958# the parameter is set to a non-zero value, the I/O queue depth is controlled
3959# to limit the I/O completion time to the parameter value.
3960# The value is set in milliseconds.
3961*/
3962static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003963module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003964MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3965 "Use command completion time to control queue depth");
3966lpfc_vport_param_show(max_scsicmpl_time);
3967lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3968static int
3969lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3970{
3971 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3972 struct lpfc_nodelist *ndlp, *next_ndlp;
3973
3974 if (val == vport->cfg_max_scsicmpl_time)
3975 return 0;
3976 if ((val < 0) || (val > 60000))
3977 return -EINVAL;
3978 vport->cfg_max_scsicmpl_time = val;
3979
3980 spin_lock_irq(shost->host_lock);
3981 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3982 if (!NLP_CHK_NODE_ACT(ndlp))
3983 continue;
3984 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3985 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003986 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003987 }
3988 spin_unlock_irq(shost->host_lock);
3989 return 0;
3990}
3991lpfc_vport_param_store(max_scsicmpl_time);
3992static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3993 lpfc_max_scsicmpl_time_show,
3994 lpfc_max_scsicmpl_time_store);
3995
3996/*
dea31012005-04-17 16:05:31 -05003997# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3998# range is [0,1]. Default value is 0.
3999*/
4000LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4001
4002/*
James Smart49aa1432012-08-03 12:36:42 -04004003# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4004# range is [0,1]. Default value is 0.
4005# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4006# For [1], FCP commands are issued to a Work Queue associated with the
4007# current CPU.
4008*/
4009LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algrithmn for "
4010 "issuing commands [0] - Round Robin, [1] - Current CPU");
4011
4012/*
James Smarta6571c62012-10-31 14:44:42 -04004013# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4014# range is [0,1]. Default value is 0.
4015# For [0], bus reset issues target reset to ALL devices
4016# For [1], bus reset issues target reset to non-FCP2 devices
4017*/
4018LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4019 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4020
4021
4022/*
dea31012005-04-17 16:05:31 -05004023# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4024# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004025# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004026# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4027# cr_delay is set to 0.
4028*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004029LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004030 "interrupt response is generated");
4031
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004032LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004033 "interrupt response is generated");
4034
4035/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004036# lpfc_multi_ring_support: Determines how many rings to spread available
4037# cmd/rsp IOCB entries across.
4038# Value range is [1,2]. Default value is 1.
4039*/
4040LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4041 "SLI rings to spread IOCB entries across");
4042
4043/*
James Smarta4bc3372006-12-02 13:34:16 -05004044# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4045# identifies what rctl value to configure the additional ring for.
4046# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4047*/
James Smart6a9c52c2009-10-02 15:16:51 -04004048LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004049 255, "Identifies RCTL for additional ring configuration");
4050
4051/*
4052# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4053# identifies what type value to configure the additional ring for.
4054# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4055*/
James Smart6a9c52c2009-10-02 15:16:51 -04004056LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004057 255, "Identifies TYPE for additional ring configuration");
4058
4059/*
dea31012005-04-17 16:05:31 -05004060# lpfc_fdmi_on: controls FDMI support.
4061# 0 = no FDMI support
4062# 1 = support FDMI without attribute of hostname
4063# 2 = support FDMI with attribute of hostname
4064# Value range [0,2]. Default value is 0.
4065*/
James Smart3de2a652007-08-02 11:09:59 -04004066LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004067
4068/*
4069# Specifies the maximum number of ELS cmds we can have outstanding (for
4070# discovery). Value range is [1,64]. Default value = 32.
4071*/
James Smart3de2a652007-08-02 11:09:59 -04004072LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004073 "during discovery");
4074
4075/*
James Smartc4a7c922013-05-31 17:04:59 -04004076# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4077# will be scanned by the SCSI midlayer when sequential scanning is
4078# used; and is also the highest LUN ID allowed when the SCSI midlayer
4079# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4080# LUN ID limit, but the SCSI midlayer requires this field for the uses
4081# above. The lpfc driver limits the default value to 255 for two reasons.
4082# As it bounds the sequential scan loop, scanning for thousands of luns
4083# on a target can take minutes of wall clock time. Additionally,
4084# there are FC targets, such as JBODs, that only recognize 8-bits of
4085# LUN ID. When they receive a value greater than 8 bits, they chop off
4086# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4087# and so on all as LUN ID 0. This causes the linux kernel, which sees
4088# valid responses at each of the LUN IDs, to believe there are multiple
4089# devices present, when in fact, there is only 1.
4090# A customer that is aware of their target behaviors, and the results as
4091# indicated above, is welcome to increase the lpfc_max_luns value.
4092# As mentioned, this value is not used by the lpfc driver, only the
4093# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004094# Value range is [0,65535]. Default value is 255.
4095# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004096*/
James Smartc4a7c922013-05-31 17:04:59 -04004097LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004098
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004099/*
4100# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4101# Value range is [1,255], default value is 10.
4102*/
4103LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4104 "Milliseconds driver will wait between polling FCP ring");
4105
James Smart4ff43242006-12-02 13:34:56 -05004106/*
4107# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4108# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004109# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004110# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004111# 2 = MSI-X enabled (default)
4112# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004113*/
George Kadianakis8605c462010-01-17 21:19:31 +02004114LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004115 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004116
James Smart13815c82008-01-11 01:52:48 -05004117/*
James Smartda0436e2009-05-22 14:51:39 -04004118# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
James Smart67d12732012-08-03 12:36:13 -04004119# This parameter is ignored and will eventually be depricated
James Smartda0436e2009-05-22 14:51:39 -04004120#
James Smart67d12732012-08-03 12:36:13 -04004121# Value range is [1,7]. Default value is 4.
James Smartda0436e2009-05-22 14:51:39 -04004122*/
James Smart67d12732012-08-03 12:36:13 -04004123LPFC_ATTR_R(fcp_wq_count, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4124 LPFC_FCP_IO_CHAN_MAX,
James Smartda0436e2009-05-22 14:51:39 -04004125 "Set the number of fast-path FCP work queues, if possible");
4126
4127/*
James Smart67d12732012-08-03 12:36:13 -04004128# lpfc_fcp_eq_count: Set the number of FCP EQ/CQ/WQ IO channels
James Smartda0436e2009-05-22 14:51:39 -04004129#
James Smart67d12732012-08-03 12:36:13 -04004130# Value range is [1,7]. Default value is 4.
James Smartda0436e2009-05-22 14:51:39 -04004131*/
James Smart67d12732012-08-03 12:36:13 -04004132LPFC_ATTR_R(fcp_eq_count, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4133 LPFC_FCP_IO_CHAN_MAX,
James Smartda0436e2009-05-22 14:51:39 -04004134 "Set the number of fast-path FCP event queues, if possible");
4135
4136/*
James Smart67d12732012-08-03 12:36:13 -04004137# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4138#
4139# Value range is [1,7]. Default value is 4.
4140*/
4141LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4142 LPFC_FCP_IO_CHAN_MAX,
4143 "Set the number of FCP I/O channels");
4144
4145/*
James Smart13815c82008-01-11 01:52:48 -05004146# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4147# 0 = HBA resets disabled
4148# 1 = HBA resets enabled (default)
4149# Value range is [0,1]. Default value is 1.
4150*/
4151LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004152
James Smart13815c82008-01-11 01:52:48 -05004153/*
James Smarteb7a3392010-11-20 23:12:02 -05004154# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004155# 0 = HBA Heartbeat disabled
4156# 1 = HBA Heartbeat enabled (default)
4157# Value range is [0,1]. Default value is 1.
4158*/
James Smarteb7a3392010-11-20 23:12:02 -05004159LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004160
James Smart83108bd2008-01-11 01:53:09 -05004161/*
James Smart81301a92008-12-04 22:39:46 -05004162# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4163# 0 = BlockGuard disabled (default)
4164# 1 = BlockGuard enabled
4165# Value range is [0,1]. Default value is 0.
4166*/
4167LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4168
James Smart6fb120a2009-05-22 14:52:59 -04004169/*
James Smartba20c852012-08-03 12:36:52 -04004170# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4171# 0 = disabled (default)
4172# 1 = enabled
4173# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004174#
4175# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004176*/
4177unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4178
James Smartba20c852012-08-03 12:36:52 -04004179/*
James Smart81301a92008-12-04 22:39:46 -05004180# lpfc_prot_mask: i
4181# - Bit mask of host protection capabilities used to register with the
4182# SCSI mid-layer
4183# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4184# - Allows you to ultimately specify which profiles to use
4185# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004186# - SHOST_DIF_TYPE1_PROTECTION 1
4187# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4188# - SHOST_DIX_TYPE0_PROTECTION 8
4189# HBA supports DIX Type 0: Host to HBA protection only
4190# - SHOST_DIX_TYPE1_PROTECTION 16
4191# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004192#
4193*/
James Smart7c56b9f2011-07-22 18:36:25 -04004194unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4195 SHOST_DIX_TYPE0_PROTECTION |
4196 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004197
James Smartab56dc22011-02-16 12:39:57 -05004198module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004199MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4200
4201/*
4202# lpfc_prot_guard: i
4203# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004204# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004205# - Allows you to ultimately specify which profiles to use
4206# - Default will result in registering capabilities for all guard types
4207#
4208*/
4209unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004210module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004211MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4212
James Smart92494142011-02-16 12:39:44 -05004213/*
4214 * Delay initial NPort discovery when Clean Address bit is cleared in
4215 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4216 * This parameter can have value 0 or 1.
4217 * When this parameter is set to 0, no delay is added to the initial
4218 * discovery.
4219 * When this parameter is set to non-zero value, initial Nport discovery is
4220 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4221 * accept and FCID/Fabric name/Fabric portname is changed.
4222 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4223 * when Clean Address bit is cleared in FLOGI/FDISC
4224 * accept and FCID/Fabric name/Fabric portname is changed.
4225 * Default value is 0.
4226 */
4227int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05004228module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05004229MODULE_PARM_DESC(lpfc_delay_discovery,
4230 "Delay NPort discovery when Clean Address bit is cleared. "
4231 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05004232
4233/*
James Smart3621a712009-04-06 18:47:14 -04004234 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004235 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004236 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4237 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004238 * Because of the additional overhead involved in setting up T10-DIF,
4239 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4240 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004241 */
4242LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4243 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4244
James Smart96f70772013-04-17 20:16:15 -04004245/*
4246 * This parameter will be depricated, the driver cannot limit the
4247 * protection data s/g list.
4248 */
4249LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4250 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4251 "Max Protection Scatter Gather Segment Count");
James Smart81301a92008-12-04 22:39:46 -05004252
Tony Jonesee959b02008-02-22 00:13:36 +01004253struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004254 &dev_attr_bg_info,
4255 &dev_attr_bg_guard_err,
4256 &dev_attr_bg_apptag_err,
4257 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004258 &dev_attr_info,
4259 &dev_attr_serialnum,
4260 &dev_attr_modeldesc,
4261 &dev_attr_modelname,
4262 &dev_attr_programtype,
4263 &dev_attr_portnum,
4264 &dev_attr_fwrev,
4265 &dev_attr_hdw,
4266 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004267 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004268 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004269 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004270 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004271 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004272 &dev_attr_lpfc_temp_sensor,
4273 &dev_attr_lpfc_log_verbose,
4274 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004275 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004276 &dev_attr_lpfc_hba_queue_depth,
4277 &dev_attr_lpfc_peer_port_login,
4278 &dev_attr_lpfc_nodev_tmo,
4279 &dev_attr_lpfc_devloss_tmo,
4280 &dev_attr_lpfc_fcp_class,
4281 &dev_attr_lpfc_use_adisc,
4282 &dev_attr_lpfc_ack0,
4283 &dev_attr_lpfc_topology,
4284 &dev_attr_lpfc_scan_down,
4285 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004286 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004287 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004288 &dev_attr_lpfc_cr_delay,
4289 &dev_attr_lpfc_cr_count,
4290 &dev_attr_lpfc_multi_ring_support,
4291 &dev_attr_lpfc_multi_ring_rctl,
4292 &dev_attr_lpfc_multi_ring_type,
4293 &dev_attr_lpfc_fdmi_on,
4294 &dev_attr_lpfc_max_luns,
4295 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004296 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004297 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004298 &dev_attr_nport_evt_cnt,
4299 &dev_attr_board_mode,
4300 &dev_attr_max_vpi,
4301 &dev_attr_used_vpi,
4302 &dev_attr_max_rpi,
4303 &dev_attr_used_rpi,
4304 &dev_attr_max_xri,
4305 &dev_attr_used_xri,
4306 &dev_attr_npiv_info,
4307 &dev_attr_issue_reset,
4308 &dev_attr_lpfc_poll,
4309 &dev_attr_lpfc_poll_tmo,
4310 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004311 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004312 &dev_attr_lpfc_fcp_cpu_map,
James Smartda0436e2009-05-22 14:51:39 -04004313 &dev_attr_lpfc_fcp_wq_count,
4314 &dev_attr_lpfc_fcp_eq_count,
James Smart67d12732012-08-03 12:36:13 -04004315 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004316 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004317 &dev_attr_lpfc_soft_wwnn,
4318 &dev_attr_lpfc_soft_wwpn,
4319 &dev_attr_lpfc_soft_wwn_enable,
4320 &dev_attr_lpfc_enable_hba_reset,
4321 &dev_attr_lpfc_enable_hba_heartbeat,
4322 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004323 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004324 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004325 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004326 &dev_attr_lpfc_aer_support,
4327 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004328 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004329 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004330 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004331 &dev_attr_lpfc_iocb_cnt,
4332 &dev_attr_iocb_hw,
4333 &dev_attr_txq_hw,
4334 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004335 &dev_attr_lpfc_fips_level,
4336 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004337 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004338 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004339 &dev_attr_protocol,
dea31012005-04-17 16:05:31 -05004340 NULL,
4341};
4342
Tony Jonesee959b02008-02-22 00:13:36 +01004343struct device_attribute *lpfc_vport_attrs[] = {
4344 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004345 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004346 &dev_attr_num_discovered_ports,
4347 &dev_attr_lpfc_drvr_version,
4348 &dev_attr_lpfc_log_verbose,
4349 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004350 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004351 &dev_attr_lpfc_nodev_tmo,
4352 &dev_attr_lpfc_devloss_tmo,
4353 &dev_attr_lpfc_hba_queue_depth,
4354 &dev_attr_lpfc_peer_port_login,
4355 &dev_attr_lpfc_restrict_login,
4356 &dev_attr_lpfc_fcp_class,
4357 &dev_attr_lpfc_use_adisc,
4358 &dev_attr_lpfc_fdmi_on,
4359 &dev_attr_lpfc_max_luns,
4360 &dev_attr_nport_evt_cnt,
4361 &dev_attr_npiv_info,
4362 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004363 &dev_attr_lpfc_max_scsicmpl_time,
4364 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004365 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004366 &dev_attr_lpfc_fips_level,
4367 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004368 NULL,
4369};
4370
James Smarte59058c2008-08-24 21:49:00 -04004371/**
James Smart3621a712009-04-06 18:47:14 -04004372 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004373 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004374 * @kobj: kernel kobject that contains the kernel class device.
4375 * @bin_attr: kernel attributes passed to us.
4376 * @buf: contains the data to be written to the adapter IOREG space.
4377 * @off: offset into buffer to beginning of data.
4378 * @count: bytes to transfer.
4379 *
4380 * Description:
4381 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4382 * Uses the adapter io control registers to send buf contents to the adapter.
4383 *
4384 * Returns:
4385 * -ERANGE off and count combo out of range
4386 * -EINVAL off, count or buff address invalid
4387 * -EPERM adapter is offline
4388 * value of count, buf contents written
4389 **/
dea31012005-04-17 16:05:31 -05004390static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004391sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4392 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004393 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004394{
4395 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004396 struct device *dev = container_of(kobj, struct device, kobj);
4397 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004398 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4399 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004400
James Smartf1126682009-06-10 17:22:44 -04004401 if (phba->sli_rev >= LPFC_SLI_REV4)
4402 return -EPERM;
4403
dea31012005-04-17 16:05:31 -05004404 if ((off + count) > FF_REG_AREA_SIZE)
4405 return -ERANGE;
4406
James Smartf7a919b2011-08-21 21:49:16 -04004407 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4408 return 0;
dea31012005-04-17 16:05:31 -05004409
4410 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4411 return -EINVAL;
4412
James Smartf7a919b2011-08-21 21:49:16 -04004413 /* This is to protect HBA registers from accidental writes. */
4414 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4415 return -EINVAL;
4416
4417 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004418 return -EPERM;
dea31012005-04-17 16:05:31 -05004419
James Smart2e0fef82007-06-17 19:56:36 -05004420 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004421 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4422 buf_off += sizeof(uint32_t))
4423 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004424 phba->ctrl_regs_memmap_p + off + buf_off);
4425
James Smart2e0fef82007-06-17 19:56:36 -05004426 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004427
4428 return count;
4429}
4430
James Smarte59058c2008-08-24 21:49:00 -04004431/**
James Smart3621a712009-04-06 18:47:14 -04004432 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004433 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004434 * @kobj: kernel kobject that contains the kernel class device.
4435 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004436 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004437 * @off: offset into buffer to beginning of data.
4438 * @count: bytes to transfer.
4439 *
4440 * Description:
4441 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4442 * Uses the adapter io control registers to read data into buf.
4443 *
4444 * Returns:
4445 * -ERANGE off and count combo out of range
4446 * -EINVAL off, count or buff address invalid
4447 * value of count, buf contents read
4448 **/
dea31012005-04-17 16:05:31 -05004449static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004450sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4451 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004452 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004453{
4454 size_t buf_off;
4455 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004456 struct device *dev = container_of(kobj, struct device, kobj);
4457 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004458 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4459 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004460
James Smartf1126682009-06-10 17:22:44 -04004461 if (phba->sli_rev >= LPFC_SLI_REV4)
4462 return -EPERM;
4463
dea31012005-04-17 16:05:31 -05004464 if (off > FF_REG_AREA_SIZE)
4465 return -ERANGE;
4466
4467 if ((off + count) > FF_REG_AREA_SIZE)
4468 count = FF_REG_AREA_SIZE - off;
4469
4470 if (count == 0) return 0;
4471
4472 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4473 return -EINVAL;
4474
James Smart2e0fef82007-06-17 19:56:36 -05004475 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004476
4477 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4478 tmp_ptr = (uint32_t *)(buf + buf_off);
4479 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4480 }
4481
James Smart2e0fef82007-06-17 19:56:36 -05004482 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004483
4484 return count;
4485}
4486
4487static struct bin_attribute sysfs_ctlreg_attr = {
4488 .attr = {
4489 .name = "ctlreg",
4490 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004491 },
4492 .size = 256,
4493 .read = sysfs_ctlreg_read,
4494 .write = sysfs_ctlreg_write,
4495};
4496
James Smarte59058c2008-08-24 21:49:00 -04004497/**
James Smart3621a712009-04-06 18:47:14 -04004498 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004499 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004500 * @kobj: kernel kobject that contains the kernel class device.
4501 * @bin_attr: kernel attributes passed to us.
4502 * @buf: contains the data to be written to sysfs mbox.
4503 * @off: offset into buffer to beginning of data.
4504 * @count: bytes to transfer.
4505 *
4506 * Description:
James Smart026abb82011-12-13 13:20:45 -05004507 * Deprecated function. All mailbox access from user space is performed via the
4508 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004509 *
4510 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004511 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004512 **/
dea31012005-04-17 16:05:31 -05004513static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004514sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4515 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004516 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004517{
James Smart026abb82011-12-13 13:20:45 -05004518 return -EPERM;
dea31012005-04-17 16:05:31 -05004519}
4520
James Smarte59058c2008-08-24 21:49:00 -04004521/**
James Smart3621a712009-04-06 18:47:14 -04004522 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004523 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004524 * @kobj: kernel kobject that contains the kernel class device.
4525 * @bin_attr: kernel attributes passed to us.
4526 * @buf: contains the data to be read from sysfs mbox.
4527 * @off: offset into buffer to beginning of data.
4528 * @count: bytes to transfer.
4529 *
4530 * Description:
James Smart026abb82011-12-13 13:20:45 -05004531 * Deprecated function. All mailbox access from user space is performed via the
4532 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004533 *
4534 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004535 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004536 **/
dea31012005-04-17 16:05:31 -05004537static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004538sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4539 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004540 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004541{
James Smart026abb82011-12-13 13:20:45 -05004542 return -EPERM;
dea31012005-04-17 16:05:31 -05004543}
4544
4545static struct bin_attribute sysfs_mbox_attr = {
4546 .attr = {
4547 .name = "mbox",
4548 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004549 },
James Smartc0c11512011-05-24 11:41:34 -04004550 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004551 .read = sysfs_mbox_read,
4552 .write = sysfs_mbox_write,
4553};
4554
James Smarte59058c2008-08-24 21:49:00 -04004555/**
James Smart3621a712009-04-06 18:47:14 -04004556 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004557 * @vport: address of lpfc vport structure.
4558 *
4559 * Return codes:
4560 * zero on success
4561 * error return code from sysfs_create_bin_file()
4562 **/
dea31012005-04-17 16:05:31 -05004563int
James Smart2e0fef82007-06-17 19:56:36 -05004564lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004565{
James Smart2e0fef82007-06-17 19:56:36 -05004566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004567 int error;
4568
Tony Jonesee959b02008-02-22 00:13:36 +01004569 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004570 &sysfs_drvr_stat_data_attr);
4571
4572 /* Virtual ports do not need ctrl_reg and mbox */
4573 if (error || vport->port_type == LPFC_NPIV_PORT)
4574 goto out;
4575
4576 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004577 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004578 if (error)
James Smarteada2722008-12-04 22:39:13 -05004579 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004580
Tony Jonesee959b02008-02-22 00:13:36 +01004581 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004582 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004583 if (error)
4584 goto out_remove_ctlreg_attr;
4585
4586 return 0;
4587out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004588 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004589out_remove_stat_attr:
4590 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4591 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004592out:
4593 return error;
4594}
4595
James Smarte59058c2008-08-24 21:49:00 -04004596/**
James Smart3621a712009-04-06 18:47:14 -04004597 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004598 * @vport: address of lpfc vport structure.
4599 **/
dea31012005-04-17 16:05:31 -05004600void
James Smart2e0fef82007-06-17 19:56:36 -05004601lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004602{
James Smart2e0fef82007-06-17 19:56:36 -05004603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004604 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4605 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004606 /* Virtual ports do not need ctrl_reg and mbox */
4607 if (vport->port_type == LPFC_NPIV_PORT)
4608 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004609 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4610 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004611}
4612
4613
4614/*
4615 * Dynamic FC Host Attributes Support
4616 */
4617
James Smarte59058c2008-08-24 21:49:00 -04004618/**
James Smart3621a712009-04-06 18:47:14 -04004619 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004620 * @shost: kernel scsi host pointer.
4621 **/
dea31012005-04-17 16:05:31 -05004622static void
4623lpfc_get_host_port_id(struct Scsi_Host *shost)
4624{
James Smart2e0fef82007-06-17 19:56:36 -05004625 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4626
dea31012005-04-17 16:05:31 -05004627 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004628 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004629}
4630
James Smarte59058c2008-08-24 21:49:00 -04004631/**
James Smart3621a712009-04-06 18:47:14 -04004632 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004633 * @shost: kernel scsi host pointer.
4634 **/
dea31012005-04-17 16:05:31 -05004635static void
4636lpfc_get_host_port_type(struct Scsi_Host *shost)
4637{
James Smart2e0fef82007-06-17 19:56:36 -05004638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4639 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004640
4641 spin_lock_irq(shost->host_lock);
4642
James Smart92d7f7b2007-06-17 19:56:38 -05004643 if (vport->port_type == LPFC_NPIV_PORT) {
4644 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4645 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004646 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004647 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004648 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4649 else
4650 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4651 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004652 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004653 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4654 else
4655 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4656 }
4657 } else
4658 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4659
4660 spin_unlock_irq(shost->host_lock);
4661}
4662
James Smarte59058c2008-08-24 21:49:00 -04004663/**
James Smart3621a712009-04-06 18:47:14 -04004664 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004665 * @shost: kernel scsi host pointer.
4666 **/
dea31012005-04-17 16:05:31 -05004667static void
4668lpfc_get_host_port_state(struct Scsi_Host *shost)
4669{
James Smart2e0fef82007-06-17 19:56:36 -05004670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4671 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004672
4673 spin_lock_irq(shost->host_lock);
4674
James Smart2e0fef82007-06-17 19:56:36 -05004675 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004676 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4677 else {
James Smart2e0fef82007-06-17 19:56:36 -05004678 switch (phba->link_state) {
4679 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004680 case LPFC_LINK_DOWN:
4681 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4682 break;
4683 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004684 case LPFC_CLEAR_LA:
4685 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05004686 /* Links up, reports port state accordingly */
4687 if (vport->port_state < LPFC_VPORT_READY)
4688 fc_host_port_state(shost) =
4689 FC_PORTSTATE_BYPASSED;
4690 else
4691 fc_host_port_state(shost) =
4692 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05004693 break;
4694 case LPFC_HBA_ERROR:
4695 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4696 break;
4697 default:
4698 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4699 break;
4700 }
4701 }
4702
4703 spin_unlock_irq(shost->host_lock);
4704}
4705
James Smarte59058c2008-08-24 21:49:00 -04004706/**
James Smart3621a712009-04-06 18:47:14 -04004707 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004708 * @shost: kernel scsi host pointer.
4709 **/
dea31012005-04-17 16:05:31 -05004710static void
4711lpfc_get_host_speed(struct Scsi_Host *shost)
4712{
James Smart2e0fef82007-06-17 19:56:36 -05004713 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4714 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004715
4716 spin_lock_irq(shost->host_lock);
4717
James Smart2e0fef82007-06-17 19:56:36 -05004718 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004719 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004720 case LPFC_LINK_SPEED_1GHZ:
4721 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004722 break;
James Smart76a95d72010-11-20 23:11:48 -05004723 case LPFC_LINK_SPEED_2GHZ:
4724 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004725 break;
James Smart76a95d72010-11-20 23:11:48 -05004726 case LPFC_LINK_SPEED_4GHZ:
4727 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004728 break;
James Smart76a95d72010-11-20 23:11:48 -05004729 case LPFC_LINK_SPEED_8GHZ:
4730 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004731 break;
James Smart76a95d72010-11-20 23:11:48 -05004732 case LPFC_LINK_SPEED_10GHZ:
4733 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004734 break;
James Smart76a95d72010-11-20 23:11:48 -05004735 case LPFC_LINK_SPEED_16GHZ:
4736 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4737 break;
4738 default:
4739 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004740 break;
4741 }
James Smart09372822008-01-11 01:52:54 -05004742 } else
4743 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004744
4745 spin_unlock_irq(shost->host_lock);
4746}
4747
James Smarte59058c2008-08-24 21:49:00 -04004748/**
James Smart3621a712009-04-06 18:47:14 -04004749 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004750 * @shost: kernel scsi host pointer.
4751 **/
dea31012005-04-17 16:05:31 -05004752static void
4753lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4754{
James Smart2e0fef82007-06-17 19:56:36 -05004755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4756 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004757 u64 node_name;
dea31012005-04-17 16:05:31 -05004758
4759 spin_lock_irq(shost->host_lock);
4760
James Smart73d91e52011-10-10 21:32:10 -04004761 if ((vport->port_state > LPFC_FLOGI) &&
4762 ((vport->fc_flag & FC_FABRIC) ||
4763 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4764 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004765 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004766 else
4767 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004768 node_name = 0;
dea31012005-04-17 16:05:31 -05004769
4770 spin_unlock_irq(shost->host_lock);
4771
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004772 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004773}
4774
James Smarte59058c2008-08-24 21:49:00 -04004775/**
James Smart3621a712009-04-06 18:47:14 -04004776 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004777 * @shost: kernel scsi host pointer.
4778 *
4779 * Notes:
4780 * NULL on error for link down, no mbox pool, sli2 active,
4781 * management not allowed, memory allocation error, or mbox error.
4782 *
4783 * Returns:
4784 * NULL for error
4785 * address of the adapter host statistics
4786 **/
dea31012005-04-17 16:05:31 -05004787static struct fc_host_statistics *
4788lpfc_get_stats(struct Scsi_Host *shost)
4789{
James Smart2e0fef82007-06-17 19:56:36 -05004790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4791 struct lpfc_hba *phba = vport->phba;
4792 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004793 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004794 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004795 LPFC_MBOXQ_t *pmboxq;
4796 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004797 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004798 int rc = 0;
dea31012005-04-17 16:05:31 -05004799
James Smart92d7f7b2007-06-17 19:56:38 -05004800 /*
4801 * prevent udev from issuing mailbox commands until the port is
4802 * configured.
4803 */
James Smart2e0fef82007-06-17 19:56:36 -05004804 if (phba->link_state < LPFC_LINK_DOWN ||
4805 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004806 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004807 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004808
4809 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004810 return NULL;
4811
dea31012005-04-17 16:05:31 -05004812 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4813 if (!pmboxq)
4814 return NULL;
4815 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4816
James Smart04c68492009-05-22 14:52:52 -04004817 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004818 pmb->mbxCommand = MBX_READ_STATUS;
4819 pmb->mbxOwner = OWN_HOST;
4820 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004821 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004822
James Smart75baf692010-06-08 18:31:21 -04004823 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004824 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004825 else
dea31012005-04-17 16:05:31 -05004826 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4827
4828 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004829 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004830 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004831 return NULL;
4832 }
4833
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004834 memset(hs, 0, sizeof (struct fc_host_statistics));
4835
dea31012005-04-17 16:05:31 -05004836 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004837 /*
4838 * The MBX_READ_STATUS returns tx_k_bytes which has to
4839 * converted to words
4840 */
4841 hs->tx_words = (uint64_t)
4842 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4843 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004844 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004845 hs->rx_words = (uint64_t)
4846 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4847 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004848
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004849 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004850 pmb->mbxCommand = MBX_READ_LNK_STAT;
4851 pmb->mbxOwner = OWN_HOST;
4852 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004853 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004854
James Smart75baf692010-06-08 18:31:21 -04004855 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004856 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004857 else
dea31012005-04-17 16:05:31 -05004858 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4859
4860 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004861 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004862 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004863 return NULL;
4864 }
4865
4866 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4867 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4868 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4869 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4870 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4871 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4872 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4873
James Smart64ba8812006-08-02 15:24:34 -04004874 hs->link_failure_count -= lso->link_failure_count;
4875 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4876 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4877 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4878 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4879 hs->invalid_crc_count -= lso->invalid_crc_count;
4880 hs->error_frames -= lso->error_frames;
4881
James Smart76a95d72010-11-20 23:11:48 -05004882 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004883 hs->lip_count = -1;
4884 hs->nos_count = (phba->link_events >> 1);
4885 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004886 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004887 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004888 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004889 hs->nos_count = -1;
4890 } else {
4891 hs->lip_count = -1;
4892 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004893 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004894 }
4895
4896 hs->dumped_frames = -1;
4897
James Smart64ba8812006-08-02 15:24:34 -04004898 seconds = get_seconds();
4899 if (seconds < psli->stats_start)
4900 hs->seconds_since_last_reset = seconds +
4901 ((unsigned long)-1 - psli->stats_start);
4902 else
4903 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004904
James Smart1dcb58e2007-04-25 09:51:30 -04004905 mempool_free(pmboxq, phba->mbox_mem_pool);
4906
dea31012005-04-17 16:05:31 -05004907 return hs;
4908}
4909
James Smarte59058c2008-08-24 21:49:00 -04004910/**
James Smart3621a712009-04-06 18:47:14 -04004911 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004912 * @shost: kernel scsi host pointer.
4913 **/
James Smart64ba8812006-08-02 15:24:34 -04004914static void
4915lpfc_reset_stats(struct Scsi_Host *shost)
4916{
James Smart2e0fef82007-06-17 19:56:36 -05004917 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4918 struct lpfc_hba *phba = vport->phba;
4919 struct lpfc_sli *psli = &phba->sli;
4920 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004921 LPFC_MBOXQ_t *pmboxq;
4922 MAILBOX_t *pmb;
4923 int rc = 0;
4924
James Smart2e0fef82007-06-17 19:56:36 -05004925 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004926 return;
4927
James Smart64ba8812006-08-02 15:24:34 -04004928 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4929 if (!pmboxq)
4930 return;
4931 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4932
James Smart04c68492009-05-22 14:52:52 -04004933 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004934 pmb->mbxCommand = MBX_READ_STATUS;
4935 pmb->mbxOwner = OWN_HOST;
4936 pmb->un.varWords[0] = 0x1; /* reset request */
4937 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004938 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004939
James Smart2e0fef82007-06-17 19:56:36 -05004940 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004941 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004942 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4943 else
4944 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4945
4946 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004947 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004948 mempool_free(pmboxq, phba->mbox_mem_pool);
4949 return;
4950 }
4951
4952 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4953 pmb->mbxCommand = MBX_READ_LNK_STAT;
4954 pmb->mbxOwner = OWN_HOST;
4955 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004956 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004957
James Smart2e0fef82007-06-17 19:56:36 -05004958 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004959 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004960 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4961 else
4962 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4963
4964 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004965 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004966 mempool_free( pmboxq, phba->mbox_mem_pool);
4967 return;
4968 }
4969
4970 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4971 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4972 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4973 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4974 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4975 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4976 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004977 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004978 lso->link_events = (phba->link_events >> 1);
4979 else
4980 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004981
4982 psli->stats_start = get_seconds();
4983
James Smart1dcb58e2007-04-25 09:51:30 -04004984 mempool_free(pmboxq, phba->mbox_mem_pool);
4985
James Smart64ba8812006-08-02 15:24:34 -04004986 return;
4987}
dea31012005-04-17 16:05:31 -05004988
4989/*
4990 * The LPFC driver treats linkdown handling as target loss events so there
4991 * are no sysfs handlers for link_down_tmo.
4992 */
James Smart685f0bf2007-04-25 09:53:08 -04004993
James Smarte59058c2008-08-24 21:49:00 -04004994/**
James Smart3621a712009-04-06 18:47:14 -04004995 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004996 * @starget: kernel scsi target pointer.
4997 *
4998 * Returns:
4999 * address of the node list if found
5000 * NULL target not found
5001 **/
James Smart685f0bf2007-04-25 09:53:08 -04005002static struct lpfc_nodelist *
5003lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005004{
James Smart2e0fef82007-06-17 19:56:36 -05005005 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5006 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005007 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005008
5009 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005010 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005011 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005012 if (NLP_CHK_NODE_ACT(ndlp) &&
5013 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005014 starget->id == ndlp->nlp_sid) {
5015 spin_unlock_irq(shost->host_lock);
5016 return ndlp;
dea31012005-04-17 16:05:31 -05005017 }
5018 }
5019 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005020 return NULL;
5021}
dea31012005-04-17 16:05:31 -05005022
James Smarte59058c2008-08-24 21:49:00 -04005023/**
James Smart3621a712009-04-06 18:47:14 -04005024 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005025 * @starget: kernel scsi target pointer.
5026 **/
James Smart685f0bf2007-04-25 09:53:08 -04005027static void
5028lpfc_get_starget_port_id(struct scsi_target *starget)
5029{
5030 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5031
5032 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005033}
5034
James Smarte59058c2008-08-24 21:49:00 -04005035/**
James Smart3621a712009-04-06 18:47:14 -04005036 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005037 * @starget: kernel scsi target pointer.
5038 *
5039 * Description: Set the target node name to the ndlp node name wwn or zero.
5040 **/
dea31012005-04-17 16:05:31 -05005041static void
5042lpfc_get_starget_node_name(struct scsi_target *starget)
5043{
James Smart685f0bf2007-04-25 09:53:08 -04005044 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005045
James Smart685f0bf2007-04-25 09:53:08 -04005046 fc_starget_node_name(starget) =
5047 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005048}
5049
James Smarte59058c2008-08-24 21:49:00 -04005050/**
James Smart3621a712009-04-06 18:47:14 -04005051 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005052 * @starget: kernel scsi target pointer.
5053 *
5054 * Description: set the target port name to the ndlp port name wwn or zero.
5055 **/
dea31012005-04-17 16:05:31 -05005056static void
5057lpfc_get_starget_port_name(struct scsi_target *starget)
5058{
James Smart685f0bf2007-04-25 09:53:08 -04005059 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005060
James Smart685f0bf2007-04-25 09:53:08 -04005061 fc_starget_port_name(starget) =
5062 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005063}
5064
James Smarte59058c2008-08-24 21:49:00 -04005065/**
James Smart3621a712009-04-06 18:47:14 -04005066 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005067 * @rport: fc rport address.
5068 * @timeout: new value for dev loss tmo.
5069 *
5070 * Description:
5071 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5072 * dev_loss_tmo to one.
5073 **/
dea31012005-04-17 16:05:31 -05005074static void
dea31012005-04-17 16:05:31 -05005075lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5076{
dea31012005-04-17 16:05:31 -05005077 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005078 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005079 else
James Smartc01f3202006-08-18 17:47:08 -04005080 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005081}
5082
James Smarte59058c2008-08-24 21:49:00 -04005083/**
James Smart3621a712009-04-06 18:47:14 -04005084 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005085 *
5086 * Description:
5087 * Macro that uses field to generate a function with the name lpfc_show_rport_
5088 *
5089 * lpfc_show_rport_##field: returns the bytes formatted in buf
5090 * @cdev: class converted to an fc_rport.
5091 * @buf: on return contains the target_field or zero.
5092 *
5093 * Returns: size of formatted string.
5094 **/
dea31012005-04-17 16:05:31 -05005095#define lpfc_rport_show_function(field, format_string, sz, cast) \
5096static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005097lpfc_show_rport_##field (struct device *dev, \
5098 struct device_attribute *attr, \
5099 char *buf) \
dea31012005-04-17 16:05:31 -05005100{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005101 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005102 struct lpfc_rport_data *rdata = rport->hostdata; \
5103 return snprintf(buf, sz, format_string, \
5104 (rdata->target) ? cast rdata->target->field : 0); \
5105}
5106
5107#define lpfc_rport_rd_attr(field, format_string, sz) \
5108 lpfc_rport_show_function(field, format_string, sz, ) \
5109static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5110
James Smarteada2722008-12-04 22:39:13 -05005111/**
James Smart3621a712009-04-06 18:47:14 -04005112 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005113 * @fc_vport: The fc_vport who's symbolic name has been changed.
5114 *
5115 * Description:
5116 * This function is called by the transport after the @fc_vport's symbolic name
5117 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005118 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005119 **/
5120static void
5121lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5122{
5123 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5124
5125 if (vport->port_state == LPFC_VPORT_READY)
5126 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5127}
dea31012005-04-17 16:05:31 -05005128
James Smartf4b4c682009-05-22 14:53:12 -04005129/**
5130 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5131 * @phba: Pointer to lpfc_hba struct.
5132 *
5133 * This function is called by the lpfc_get_cfgparam() routine to set the
5134 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005135 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005136 * before hba port or vport created.
5137 **/
5138static void
5139lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5140{
5141 phba->cfg_log_verbose = verbose;
5142}
5143
dea31012005-04-17 16:05:31 -05005144struct fc_function_template lpfc_transport_functions = {
5145 /* fixed attributes the driver supports */
5146 .show_host_node_name = 1,
5147 .show_host_port_name = 1,
5148 .show_host_supported_classes = 1,
5149 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005150 .show_host_supported_speeds = 1,
5151 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005152 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005153
5154 /* dynamic attributes the driver supports */
5155 .get_host_port_id = lpfc_get_host_port_id,
5156 .show_host_port_id = 1,
5157
5158 .get_host_port_type = lpfc_get_host_port_type,
5159 .show_host_port_type = 1,
5160
5161 .get_host_port_state = lpfc_get_host_port_state,
5162 .show_host_port_state = 1,
5163
5164 /* active_fc4s is shown but doesn't change (thus no get function) */
5165 .show_host_active_fc4s = 1,
5166
5167 .get_host_speed = lpfc_get_host_speed,
5168 .show_host_speed = 1,
5169
5170 .get_host_fabric_name = lpfc_get_host_fabric_name,
5171 .show_host_fabric_name = 1,
5172
5173 /*
5174 * The LPFC driver treats linkdown handling as target loss events
5175 * so there are no sysfs handlers for link_down_tmo.
5176 */
5177
5178 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005179 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005180
5181 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5182 .show_rport_maxframe_size = 1,
5183 .show_rport_supported_classes = 1,
5184
dea31012005-04-17 16:05:31 -05005185 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5186 .show_rport_dev_loss_tmo = 1,
5187
5188 .get_starget_port_id = lpfc_get_starget_port_id,
5189 .show_starget_port_id = 1,
5190
5191 .get_starget_node_name = lpfc_get_starget_node_name,
5192 .show_starget_node_name = 1,
5193
5194 .get_starget_port_name = lpfc_get_starget_port_name,
5195 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005196
5197 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005198 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5199 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005200
James Smart92d7f7b2007-06-17 19:56:38 -05005201 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005202
5203 .vport_disable = lpfc_vport_disable,
5204
5205 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005206
5207 .bsg_request = lpfc_bsg_request,
5208 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005209};
5210
James Smart98c9ea52007-10-27 13:37:33 -04005211struct fc_function_template lpfc_vport_transport_functions = {
5212 /* fixed attributes the driver supports */
5213 .show_host_node_name = 1,
5214 .show_host_port_name = 1,
5215 .show_host_supported_classes = 1,
5216 .show_host_supported_fc4s = 1,
5217 .show_host_supported_speeds = 1,
5218 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005219 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005220
5221 /* dynamic attributes the driver supports */
5222 .get_host_port_id = lpfc_get_host_port_id,
5223 .show_host_port_id = 1,
5224
5225 .get_host_port_type = lpfc_get_host_port_type,
5226 .show_host_port_type = 1,
5227
5228 .get_host_port_state = lpfc_get_host_port_state,
5229 .show_host_port_state = 1,
5230
5231 /* active_fc4s is shown but doesn't change (thus no get function) */
5232 .show_host_active_fc4s = 1,
5233
5234 .get_host_speed = lpfc_get_host_speed,
5235 .show_host_speed = 1,
5236
5237 .get_host_fabric_name = lpfc_get_host_fabric_name,
5238 .show_host_fabric_name = 1,
5239
5240 /*
5241 * The LPFC driver treats linkdown handling as target loss events
5242 * so there are no sysfs handlers for link_down_tmo.
5243 */
5244
5245 .get_fc_host_stats = lpfc_get_stats,
5246 .reset_fc_host_stats = lpfc_reset_stats,
5247
5248 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5249 .show_rport_maxframe_size = 1,
5250 .show_rport_supported_classes = 1,
5251
5252 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5253 .show_rport_dev_loss_tmo = 1,
5254
5255 .get_starget_port_id = lpfc_get_starget_port_id,
5256 .show_starget_port_id = 1,
5257
5258 .get_starget_node_name = lpfc_get_starget_node_name,
5259 .show_starget_node_name = 1,
5260
5261 .get_starget_port_name = lpfc_get_starget_port_name,
5262 .show_starget_port_name = 1,
5263
5264 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5265 .terminate_rport_io = lpfc_terminate_rport_io,
5266
5267 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005268
5269 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005270};
5271
James Smarte59058c2008-08-24 21:49:00 -04005272/**
James Smart3621a712009-04-06 18:47:14 -04005273 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005274 * @phba: lpfc_hba pointer.
5275 **/
dea31012005-04-17 16:05:31 -05005276void
5277lpfc_get_cfgparam(struct lpfc_hba *phba)
5278{
James Smart49aa1432012-08-03 12:36:42 -04005279 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005280 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005281 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5282 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005283 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005284 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5285 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005286 lpfc_ack0_init(phba, lpfc_ack0);
5287 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005288 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005289 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005290 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005291 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005292 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005293 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005294 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04005295 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smartda0436e2009-05-22 14:51:39 -04005296 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5297 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart67d12732012-08-03 12:36:13 -04005298 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005299 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5300 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005301 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005302 if (phba->sli_rev == LPFC_SLI_REV4)
5303 phba->cfg_poll = 0;
5304 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005305 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005306 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005307 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005308 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005309 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005310 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005311 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005312 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005313 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005314 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005315 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005316 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005317 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005318 return;
5319}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005320
James Smarte59058c2008-08-24 21:49:00 -04005321/**
James Smart3621a712009-04-06 18:47:14 -04005322 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005323 * @vport: lpfc_vport pointer.
5324 **/
James Smart3de2a652007-08-02 11:09:59 -04005325void
5326lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5327{
James Smarte8b62012007-08-02 11:10:09 -04005328 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005329 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005330 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005331 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5332 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5333 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5334 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5335 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5336 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005337 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005338 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5339 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5340 lpfc_max_luns_init(vport, lpfc_max_luns);
5341 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005342 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005343 return;
5344}