blob: cbd3a88a2963489ff1a19db505955f8ff2a739af [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 Smartd85296c2012-03-01 22:38:13 -05004 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040026#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040027#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070029#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050030
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_tcq.h>
35#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040036#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050037
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_hw.h"
40#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040041#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040042#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_disc.h"
44#include "lpfc_scsi.h"
45#include "lpfc.h"
46#include "lpfc_logmsg.h"
47#include "lpfc_version.h"
48#include "lpfc_compat.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050051
James Smartc01f3202006-08-18 17:47:08 -040052#define LPFC_DEF_DEVLOSS_TMO 30
53#define LPFC_MIN_DEVLOSS_TMO 1
54#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050055
James Smartf7a919b2011-08-21 21:49:16 -040056/*
57 * Write key size should be multiple of 4. If write key is changed
58 * make sure that library write key is also changed.
59 */
60#define LPFC_REG_WRITE_KEY_SIZE 4
61#define LPFC_REG_WRITE_KEY "EMLX"
62
James Smarte59058c2008-08-24 21:49:00 -040063/**
James Smart3621a712009-04-06 18:47:14 -040064 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040065 * @incr: integer to convert.
66 * @hdw: ascii string holding converted integer plus a string terminator.
67 *
68 * Description:
69 * JEDEC Joint Electron Device Engineering Council.
70 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71 * character string. The string is then terminated with a NULL in byte 9.
72 * Hex 0-9 becomes ascii '0' to '9'.
73 * Hex a-f becomes ascii '=' to 'B' capital B.
74 *
75 * Notes:
76 * Coded for 32 bit integers only.
77 **/
dea31012005-04-17 16:05:31 -050078static void
79lpfc_jedec_to_ascii(int incr, char hdw[])
80{
81 int i, j;
82 for (i = 0; i < 8; i++) {
83 j = (incr & 0xf);
84 if (j <= 9)
85 hdw[7 - i] = 0x30 + j;
86 else
87 hdw[7 - i] = 0x61 + j - 10;
88 incr = (incr >> 4);
89 }
90 hdw[8] = 0;
91 return;
92}
93
James Smarte59058c2008-08-24 21:49:00 -040094/**
James Smart3621a712009-04-06 18:47:14 -040095 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040096 * @dev: class unused variable.
97 * @attr: device attribute, not used.
98 * @buf: on return contains the module description text.
99 *
100 * Returns: size of formatted string.
101 **/
dea31012005-04-17 16:05:31 -0500102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100103lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
dea31012005-04-17 16:05:31 -0500105{
106 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
107}
108
James Smart45ed1192009-10-02 15:17:02 -0400109/**
110 * lpfc_enable_fip_show - Return the fip mode of the HBA
111 * @dev: class unused variable.
112 * @attr: device attribute, not used.
113 * @buf: on return contains the module description text.
114 *
115 * Returns: size of formatted string.
116 **/
117static ssize_t
118lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119 char *buf)
120{
121 struct Scsi_Host *shost = class_to_shost(dev);
122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
124
125 if (phba->hba_flag & HBA_FIP_SUPPORT)
126 return snprintf(buf, PAGE_SIZE, "1\n");
127 else
128 return snprintf(buf, PAGE_SIZE, "0\n");
129}
130
James Smart81301a92008-12-04 22:39:46 -0500131static ssize_t
132lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133 char *buf)
134{
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
138
139 if (phba->cfg_enable_bg)
140 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142 else
143 return snprintf(buf, PAGE_SIZE,
144 "BlockGuard Not Supported\n");
145 else
146 return snprintf(buf, PAGE_SIZE,
147 "BlockGuard Disabled\n");
148}
149
150static ssize_t
151lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152 char *buf)
153{
154 struct Scsi_Host *shost = class_to_shost(dev);
155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156 struct lpfc_hba *phba = vport->phba;
157
James Smart87b5c322008-12-16 10:34:09 -0500158 return snprintf(buf, PAGE_SIZE, "%llu\n",
159 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500160}
161
162static ssize_t
163lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164 char *buf)
165{
166 struct Scsi_Host *shost = class_to_shost(dev);
167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 struct lpfc_hba *phba = vport->phba;
169
James Smart87b5c322008-12-16 10:34:09 -0500170 return snprintf(buf, PAGE_SIZE, "%llu\n",
171 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500172}
173
174static ssize_t
175lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176 char *buf)
177{
178 struct Scsi_Host *shost = class_to_shost(dev);
179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 struct lpfc_hba *phba = vport->phba;
181
James Smart87b5c322008-12-16 10:34:09 -0500182 return snprintf(buf, PAGE_SIZE, "%llu\n",
183 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500184}
185
James Smarte59058c2008-08-24 21:49:00 -0400186/**
James Smart3621a712009-04-06 18:47:14 -0400187 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400188 * @dev: class converted to a Scsi_host structure.
189 * @attr: device attribute, not used.
190 * @buf: on return contains the formatted text from lpfc_info().
191 *
192 * Returns: size of formatted string.
193 **/
dea31012005-04-17 16:05:31 -0500194static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100195lpfc_info_show(struct device *dev, struct device_attribute *attr,
196 char *buf)
dea31012005-04-17 16:05:31 -0500197{
Tony Jonesee959b02008-02-22 00:13:36 +0100198 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500199
dea31012005-04-17 16:05:31 -0500200 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
201}
202
James Smarte59058c2008-08-24 21:49:00 -0400203/**
James Smart3621a712009-04-06 18:47:14 -0400204 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400205 * @dev: class converted to a Scsi_host structure.
206 * @attr: device attribute, not used.
207 * @buf: on return contains the formatted text serial number.
208 *
209 * Returns: size of formatted string.
210 **/
dea31012005-04-17 16:05:31 -0500211static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100212lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213 char *buf)
dea31012005-04-17 16:05:31 -0500214{
Tony Jonesee959b02008-02-22 00:13:36 +0100215 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217 struct lpfc_hba *phba = vport->phba;
218
dea31012005-04-17 16:05:31 -0500219 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
220}
221
James Smarte59058c2008-08-24 21:49:00 -0400222/**
James Smart3621a712009-04-06 18:47:14 -0400223 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400224 * @dev: class converted to a Scsi_host structure.
225 * @attr: device attribute, not used.
226 * @buf: on return contains the formatted support level.
227 *
228 * Description:
229 * Returns a number indicating the temperature sensor level currently
230 * supported, zero or one in ascii.
231 *
232 * Returns: size of formatted string.
233 **/
dea31012005-04-17 16:05:31 -0500234static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100235lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400237{
Tony Jonesee959b02008-02-22 00:13:36 +0100238 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 struct lpfc_hba *phba = vport->phba;
241 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
242}
243
James Smarte59058c2008-08-24 21:49:00 -0400244/**
James Smart3621a712009-04-06 18:47:14 -0400245 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400246 * @dev: class converted to a Scsi_host structure.
247 * @attr: device attribute, not used.
248 * @buf: on return contains the scsi vpd model description.
249 *
250 * Returns: size of formatted string.
251 **/
James Smart57127f12007-10-27 13:37:05 -0400252static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100253lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254 char *buf)
dea31012005-04-17 16:05:31 -0500255{
Tony Jonesee959b02008-02-22 00:13:36 +0100256 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258 struct lpfc_hba *phba = vport->phba;
259
dea31012005-04-17 16:05:31 -0500260 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
261}
262
James Smarte59058c2008-08-24 21:49:00 -0400263/**
James Smart3621a712009-04-06 18:47:14 -0400264 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400265 * @dev: class converted to a Scsi_host structure.
266 * @attr: device attribute, not used.
267 * @buf: on return contains the scsi vpd model name.
268 *
269 * Returns: size of formatted string.
270 **/
dea31012005-04-17 16:05:31 -0500271static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100272lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273 char *buf)
dea31012005-04-17 16:05:31 -0500274{
Tony Jonesee959b02008-02-22 00:13:36 +0100275 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277 struct lpfc_hba *phba = vport->phba;
278
dea31012005-04-17 16:05:31 -0500279 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
280}
281
James Smarte59058c2008-08-24 21:49:00 -0400282/**
James Smart3621a712009-04-06 18:47:14 -0400283 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400284 * @dev: class converted to a Scsi_host structure.
285 * @attr: device attribute, not used.
286 * @buf: on return contains the scsi vpd program type.
287 *
288 * Returns: size of formatted string.
289 **/
dea31012005-04-17 16:05:31 -0500290static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100291lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292 char *buf)
dea31012005-04-17 16:05:31 -0500293{
Tony Jonesee959b02008-02-22 00:13:36 +0100294 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500295 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296 struct lpfc_hba *phba = vport->phba;
297
dea31012005-04-17 16:05:31 -0500298 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
299}
300
James Smarte59058c2008-08-24 21:49:00 -0400301/**
James Smart3621a712009-04-06 18:47:14 -0400302 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400303 * @dev: class converted to a Scsi_host structure.
304 * @attr: device attribute, not used.
305 * @buf: on return contains the Menlo Maintenance sli flag.
306 *
307 * Returns: size of formatted string.
308 **/
309static ssize_t
310lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311{
312 struct Scsi_Host *shost = class_to_shost(dev);
313 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314 struct lpfc_hba *phba = vport->phba;
315
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
318}
319
320/**
James Smart3621a712009-04-06 18:47:14 -0400321 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400322 * @dev: class converted to a Scsi_host structure.
323 * @attr: device attribute, not used.
324 * @buf: on return contains scsi vpd program type.
325 *
326 * Returns: size of formatted string.
327 **/
dea31012005-04-17 16:05:31 -0500328static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100329lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330 char *buf)
dea31012005-04-17 16:05:31 -0500331{
Tony Jonesee959b02008-02-22 00:13:36 +0100332 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500333 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334 struct lpfc_hba *phba = vport->phba;
335
dea31012005-04-17 16:05:31 -0500336 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
337}
338
James Smarte59058c2008-08-24 21:49:00 -0400339/**
James Smart3621a712009-04-06 18:47:14 -0400340 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400341 * @dev: class converted to a Scsi_host structure.
342 * @attr: device attribute, not used.
343 * @buf: on return contains the scsi vpd program type.
344 *
345 * Returns: size of formatted string.
346 **/
dea31012005-04-17 16:05:31 -0500347static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100348lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349 char *buf)
dea31012005-04-17 16:05:31 -0500350{
Tony Jonesee959b02008-02-22 00:13:36 +0100351 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500354 uint32_t if_type;
355 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500356 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500357 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500358
dea31012005-04-17 16:05:31 -0500359 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500360 if_type = phba->sli4_hba.pc_sli4_params.if_type;
361 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
362
363 if (phba->sli_rev < LPFC_SLI_REV4)
364 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
365 fwrev, phba->sli_rev);
366 else
367 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
368 fwrev, phba->sli_rev, if_type, sli_family);
369
370 return len;
dea31012005-04-17 16:05:31 -0500371}
372
James Smarte59058c2008-08-24 21:49:00 -0400373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the scsi vpd program type.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500383{
384 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500388 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500389
dea31012005-04-17 16:05:31 -0500390 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
391 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
392}
James Smarte59058c2008-08-24 21:49:00 -0400393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains the ROM and FCode ascii strings.
399 *
400 * Returns: size of formatted string.
401 **/
dea31012005-04-17 16:05:31 -0500402static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100403lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
404 char *buf)
dea31012005-04-17 16:05:31 -0500405{
Tony Jonesee959b02008-02-22 00:13:36 +0100406 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
409
dea31012005-04-17 16:05:31 -0500410 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
411}
James Smarte59058c2008-08-24 21:49:00 -0400412
413/**
James Smart3621a712009-04-06 18:47:14 -0400414 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400415 * @dev: class converted to a Scsi_host structure.
416 * @attr: device attribute, not used.
417 * @buf: on return contains text describing the state of the link.
418 *
419 * Notes:
420 * The switch statement has no default so zero will be returned.
421 *
422 * Returns: size of formatted string.
423 **/
dea31012005-04-17 16:05:31 -0500424static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100425lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
426 char *buf)
dea31012005-04-17 16:05:31 -0500427{
Tony Jonesee959b02008-02-22 00:13:36 +0100428 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
430 struct lpfc_hba *phba = vport->phba;
431 int len = 0;
432
433 switch (phba->link_state) {
434 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500435 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500436 case LPFC_INIT_START:
437 case LPFC_INIT_MBX_CMDS:
438 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500439 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400440 if (phba->hba_flag & LINK_DISABLED)
441 len += snprintf(buf + len, PAGE_SIZE-len,
442 "Link Down - User disabled\n");
443 else
444 len += snprintf(buf + len, PAGE_SIZE-len,
445 "Link Down\n");
dea31012005-04-17 16:05:31 -0500446 break;
447 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500448 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500449 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400450 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500451
452 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500453 case LPFC_LOCAL_CFG_LINK:
454 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500455 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500456 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500457 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500458 case LPFC_FLOGI:
459 case LPFC_FABRIC_CFG_LINK:
460 case LPFC_NS_REG:
461 case LPFC_NS_QRY:
462 case LPFC_BUILD_DISC_LIST:
463 case LPFC_DISC_AUTH:
464 len += snprintf(buf + len, PAGE_SIZE - len,
465 "Discovery\n");
466 break;
467 case LPFC_VPORT_READY:
468 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
469 break;
470
James Smart92d7f7b2007-06-17 19:56:38 -0500471 case LPFC_VPORT_FAILED:
472 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
473 break;
474
475 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500476 len += snprintf(buf + len, PAGE_SIZE - len,
477 "Unknown\n");
478 break;
479 }
James Smart84774a42008-08-24 21:50:06 -0400480 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
481 len += snprintf(buf + len, PAGE_SIZE-len,
482 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500483 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500484 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500485 len += snprintf(buf + len, PAGE_SIZE-len,
486 " Public Loop\n");
487 else
488 len += snprintf(buf + len, PAGE_SIZE-len,
489 " Private Loop\n");
490 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500491 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500492 len += snprintf(buf + len, PAGE_SIZE-len,
493 " Fabric\n");
494 else
495 len += snprintf(buf + len, PAGE_SIZE-len,
496 " Point-2-Point\n");
497 }
498 }
James Smart2e0fef82007-06-17 19:56:36 -0500499
dea31012005-04-17 16:05:31 -0500500 return len;
501}
502
James Smarte59058c2008-08-24 21:49:00 -0400503/**
James Smart026abb82011-12-13 13:20:45 -0500504 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
505 * @dev: class unused variable.
506 * @attr: device attribute, not used.
507 * @buf: on return contains the module description text.
508 *
509 * Returns: size of formatted string.
510 **/
511static ssize_t
512lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
513 char *buf)
514{
515 struct Scsi_Host *shost = class_to_shost(dev);
516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
518
519 if (phba->sli_rev < LPFC_SLI_REV4)
520 return snprintf(buf, PAGE_SIZE, "fc\n");
521
522 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
523 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
524 return snprintf(buf, PAGE_SIZE, "fcoe\n");
525 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
526 return snprintf(buf, PAGE_SIZE, "fc\n");
527 }
528 return snprintf(buf, PAGE_SIZE, "unknown\n");
529}
530
531/**
James Smart84d1b002010-02-12 14:42:33 -0500532 * lpfc_link_state_store - Transition the link_state on an HBA port
533 * @dev: class device that is converted into a Scsi_host.
534 * @attr: device attribute, not used.
535 * @buf: one or more lpfc_polling_flags values.
536 * @count: not used.
537 *
538 * Returns:
539 * -EINVAL if the buffer is not "up" or "down"
540 * return from link state change function if non-zero
541 * length of the buf on success
542 **/
543static ssize_t
544lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
545 const char *buf, size_t count)
546{
547 struct Scsi_Host *shost = class_to_shost(dev);
548 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
549 struct lpfc_hba *phba = vport->phba;
550
551 int status = -EINVAL;
552
553 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
554 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400555 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500556 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
557 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400558 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500559
560 if (status == 0)
561 return strlen(buf);
562 else
563 return status;
564}
565
566/**
James Smart3621a712009-04-06 18:47:14 -0400567 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400568 * @dev: class device that is converted into a Scsi_host.
569 * @attr: device attribute, not used.
570 * @buf: on return contains the sum of fc mapped and unmapped.
571 *
572 * Description:
573 * Returns the ascii text number of the sum of the fc mapped and unmapped
574 * vport counts.
575 *
576 * Returns: size of formatted string.
577 **/
dea31012005-04-17 16:05:31 -0500578static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100579lpfc_num_discovered_ports_show(struct device *dev,
580 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500581{
Tony Jonesee959b02008-02-22 00:13:36 +0100582 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584
585 return snprintf(buf, PAGE_SIZE, "%d\n",
586 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500587}
588
James Smarte59058c2008-08-24 21:49:00 -0400589/**
James Smart3621a712009-04-06 18:47:14 -0400590 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400591 * @shost: Scsi_Host pointer.
592 *
593 * Description:
594 * Bring the link down gracefully then re-init the link. The firmware will
595 * re-init the fiber channel interface as required. Does not issue a LIP.
596 *
597 * Returns:
598 * -EPERM port offline or management commands are being blocked
599 * -ENOMEM cannot allocate memory for the mailbox command
600 * -EIO error sending the mailbox command
601 * zero for success
602 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700603static int
James Smart2e0fef82007-06-17 19:56:36 -0500604lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500605{
James Smart2e0fef82007-06-17 19:56:36 -0500606 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
607 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500608 LPFC_MBOXQ_t *pmboxq;
609 int mbxstatus = MBXERR_ERROR;
610
James Smart2e0fef82007-06-17 19:56:36 -0500611 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500612 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500613 return -EPERM;
614
615 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
616
617 if (!pmboxq)
618 return -ENOMEM;
619
620 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400621 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
622 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400623
James Smart33ccf8d2006-08-17 11:57:58 -0400624 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500625
James Smart04c68492009-05-22 14:52:52 -0400626 if ((mbxstatus == MBX_SUCCESS) &&
627 (pmboxq->u.mb.mbxStatus == 0 ||
628 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400629 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
630 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
631 phba->cfg_link_speed);
632 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
633 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400634 if ((mbxstatus == MBX_SUCCESS) &&
635 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
636 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
637 "2859 SLI authentication is required "
638 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400639 }
640
James Smart5b8bd0c2007-04-25 09:52:49 -0400641 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500642 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400643 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500644
645 if (mbxstatus == MBXERR_ERROR)
646 return -EIO;
647
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700648 return 0;
dea31012005-04-17 16:05:31 -0500649}
650
James Smarte59058c2008-08-24 21:49:00 -0400651/**
James Smart3621a712009-04-06 18:47:14 -0400652 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400653 * @phba: lpfc_hba pointer.
654 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
655 *
656 * Notes:
657 * Assumes any error from lpfc_do_offline() will be negative.
658 * Can wait up to 5 seconds for the port ring buffers count
659 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400660 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400661 *
662 * Returns:
663 * -EIO error posting the event
664 * zero for success
665 **/
James Smart40496f02006-07-06 15:50:22 -0400666static int
James Smart46fa3112007-04-25 09:51:45 -0400667lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
668{
669 struct completion online_compl;
670 struct lpfc_sli_ring *pring;
671 struct lpfc_sli *psli;
672 int status = 0;
673 int cnt = 0;
674 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500675 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400676
677 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500678 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400679 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500680 if (rc == 0)
681 return -ENOMEM;
682
James Smart46fa3112007-04-25 09:51:45 -0400683 wait_for_completion(&online_compl);
684
685 if (status != 0)
686 return -EIO;
687
688 psli = &phba->sli;
689
James Smart09372822008-01-11 01:52:54 -0500690 /* Wait a little for things to settle down, but not
691 * long enough for dev loss timeout to expire.
692 */
James Smart46fa3112007-04-25 09:51:45 -0400693 for (i = 0; i < psli->num_rings; i++) {
694 pring = &psli->ring[i];
James Smart0e9bb8d2013-03-01 16:35:12 -0500695 while (!list_empty(&pring->txcmplq)) {
James Smart46fa3112007-04-25 09:51:45 -0400696 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500697 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400698 lpfc_printf_log(phba,
699 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400700 "0466 Outstanding IO when "
701 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400702 break;
703 }
704 }
705 }
706
707 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500708 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
709 if (rc == 0)
710 return -ENOMEM;
711
James Smart46fa3112007-04-25 09:51:45 -0400712 wait_for_completion(&online_compl);
713
714 if (status != 0)
715 return -EIO;
716
717 return 0;
718}
719
James Smarte59058c2008-08-24 21:49:00 -0400720/**
James Smart3621a712009-04-06 18:47:14 -0400721 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400722 * @phba: lpfc_hba pointer.
723 *
724 * Description:
725 * If the port is configured to allow a reset then the hba is brought
726 * offline then online.
727 *
728 * Notes:
729 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500730 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400731 *
732 * Returns:
733 * lpfc_do_offline() return code if not zero
734 * -EIO reset not configured or error posting the event
735 * zero for success
736 **/
James Smart7f860592011-03-11 16:05:52 -0500737int
James Smart40496f02006-07-06 15:50:22 -0400738lpfc_selective_reset(struct lpfc_hba *phba)
739{
740 struct completion online_compl;
741 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500742 int rc;
James Smart40496f02006-07-06 15:50:22 -0400743
James Smart13815c82008-01-11 01:52:48 -0500744 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400745 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500746
James Smart46fa3112007-04-25 09:51:45 -0400747 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400748
749 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400750 return status;
James Smart40496f02006-07-06 15:50:22 -0400751
752 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500753 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400754 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500755 if (rc == 0)
756 return -ENOMEM;
757
James Smart40496f02006-07-06 15:50:22 -0400758 wait_for_completion(&online_compl);
759
760 if (status != 0)
761 return -EIO;
762
763 return 0;
764}
765
James Smarte59058c2008-08-24 21:49:00 -0400766/**
James Smart3621a712009-04-06 18:47:14 -0400767 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400768 * @dev: class device that is converted into a Scsi_host.
769 * @attr: device attribute, not used.
770 * @buf: containing the string "selective".
771 * @count: unused variable.
772 *
773 * Description:
774 * If the buf contains the string "selective" then lpfc_selective_reset()
775 * is called to perform the reset.
776 *
777 * Notes:
778 * Assumes any error from lpfc_selective_reset() will be negative.
779 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200780 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400781 *
782 * Returns:
783 * -EINVAL if the buffer does not contain the string "selective"
784 * length of buf if lpfc-selective_reset() if the call succeeds
785 * return value of lpfc_selective_reset() if the call fails
786**/
James Smart40496f02006-07-06 15:50:22 -0400787static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100788lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
789 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400790{
Tony Jonesee959b02008-02-22 00:13:36 +0100791 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500792 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
793 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400794 int status = -EINVAL;
795
James Smart73d91e52011-10-10 21:32:10 -0400796 if (!phba->cfg_enable_hba_reset)
797 return -EACCES;
798
James Smart40496f02006-07-06 15:50:22 -0400799 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500800 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400801
802 if (status == 0)
803 return strlen(buf);
804 else
805 return status;
806}
807
James Smarte59058c2008-08-24 21:49:00 -0400808/**
James Smart88a2cfb2011-07-22 18:36:33 -0400809 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
810 * @phba: lpfc_hba pointer.
811 *
812 * Description:
813 * SLI4 interface type-2 device to wait on the sliport status register for
814 * the readyness after performing a firmware reset.
815 *
816 * Returns:
James Smart026abb82011-12-13 13:20:45 -0500817 * zero for success, -EPERM when port does not have privilage to perform the
818 * reset, -EIO when port timeout from recovering from the reset.
819 *
820 * Note:
821 * As the caller will interpret the return code by value, be careful in making
822 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400823 **/
James Smart73d91e52011-10-10 21:32:10 -0400824int
James Smart88a2cfb2011-07-22 18:36:33 -0400825lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
826{
James Smartf7a919b2011-08-21 21:49:16 -0400827 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400828 int i;
829
James Smartf7a919b2011-08-21 21:49:16 -0400830 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400831 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
832 &portstat_reg.word0);
833
James Smartf7a919b2011-08-21 21:49:16 -0400834 /* verify if privilaged for the request operation */
835 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
836 !bf_get(lpfc_sliport_status_err, &portstat_reg))
837 return -EPERM;
838
James Smart88a2cfb2011-07-22 18:36:33 -0400839 /* wait for the SLI port firmware ready after firmware reset */
840 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
841 msleep(10);
842 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
843 &portstat_reg.word0);
844 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
845 continue;
846 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
847 continue;
848 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
849 continue;
850 break;
851 }
852
853 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
854 return 0;
855 else
856 return -EIO;
857}
858
859/**
James Smart52d52442011-05-24 11:42:45 -0400860 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400861 * @phba: lpfc_hba pointer.
862 *
863 * Description:
James Smart52d52442011-05-24 11:42:45 -0400864 * Request SLI4 interface type-2 device to perform a physical register set
865 * access.
James Smartc0c11512011-05-24 11:41:34 -0400866 *
867 * Returns:
868 * zero for success
869 **/
870static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400871lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400872{
873 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400874 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -0500875 uint32_t before_fc_flag;
876 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -0400877 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -0500878 int status = 0, rc = 0;
879 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -0400880
881 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400882 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400883
James Smart52d52442011-05-24 11:42:45 -0400884 if ((phba->sli_rev < LPFC_SLI_REV4) ||
885 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
886 LPFC_SLI_INTF_IF_TYPE_2))
887 return -EPERM;
888
James Smart026abb82011-12-13 13:20:45 -0500889 /* Keep state if we need to restore back */
890 before_fc_flag = phba->pport->fc_flag;
891 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
892
James Smartb76f2dc2011-07-22 18:37:42 -0400893 /* Disable SR-IOV virtual functions if enabled */
894 if (phba->cfg_sriov_nr_virtfn) {
895 pci_disable_sriov(pdev);
896 phba->cfg_sriov_nr_virtfn = 0;
897 }
James Smartc0c11512011-05-24 11:41:34 -0400898 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
899
900 if (status != 0)
901 return status;
902
903 /* wait for the device to be quiesced before firmware reset */
904 msleep(100);
905
906 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
907 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400908
909 if (opcode == LPFC_FW_DUMP)
910 reg_val |= LPFC_FW_DUMP_REQUEST;
911 else if (opcode == LPFC_FW_RESET)
912 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
913 else if (opcode == LPFC_DV_RESET)
914 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
915
James Smartc0c11512011-05-24 11:41:34 -0400916 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
917 LPFC_CTL_PDEV_CTL_OFFSET);
918 /* flush */
919 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
920
921 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400922 rc = lpfc_sli4_pdev_status_reg_wait(phba);
923
James Smart026abb82011-12-13 13:20:45 -0500924 if (rc == -EPERM) {
James Smart6b5151f2012-01-18 16:24:06 -0500925 /* no privilage for reset */
926 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
927 "3150 No privilage to perform the requested "
928 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -0500929 } else if (rc == -EIO) {
930 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -0500931 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
932 "3153 Fail to perform the requested "
933 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -0400934 return rc;
James Smart026abb82011-12-13 13:20:45 -0500935 }
936
937 /* keep the original port state */
938 if (before_fc_flag & FC_OFFLINE_MODE)
939 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400940
941 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500942 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
943 LPFC_EVT_ONLINE);
944 if (!job_posted)
945 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400946
947 wait_for_completion(&online_compl);
948
James Smart026abb82011-12-13 13:20:45 -0500949out:
950 /* in any case, restore the virtual functions enabled as before */
951 if (sriov_nr_virtfn) {
952 sriov_err =
953 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
954 if (!sriov_err)
955 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
956 }
James Smartc0c11512011-05-24 11:41:34 -0400957
James Smart026abb82011-12-13 13:20:45 -0500958 /* return proper error code */
959 if (!rc) {
960 if (!job_posted)
961 rc = -ENOMEM;
962 else if (status)
963 rc = -EIO;
964 }
965 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400966}
967
968/**
James Smart3621a712009-04-06 18:47:14 -0400969 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400970 * @dev: class device that is converted into a Scsi_host.
971 * @attr: device attribute, not used.
972 * @buf: on return contains the ascii number of nport events.
973 *
974 * Returns: size of formatted string.
975 **/
dea31012005-04-17 16:05:31 -0500976static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100977lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
978 char *buf)
dea31012005-04-17 16:05:31 -0500979{
Tony Jonesee959b02008-02-22 00:13:36 +0100980 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500981 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
982 struct lpfc_hba *phba = vport->phba;
983
dea31012005-04-17 16:05:31 -0500984 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
985}
986
James Smarte59058c2008-08-24 21:49:00 -0400987/**
James Smart3621a712009-04-06 18:47:14 -0400988 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400989 * @dev: class device that is converted into a Scsi_host.
990 * @attr: device attribute, not used.
991 * @buf: on return contains the state of the adapter.
992 *
993 * Returns: size of formatted string.
994 **/
dea31012005-04-17 16:05:31 -0500995static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100996lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
997 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500998{
Tony Jonesee959b02008-02-22 00:13:36 +0100999 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001000 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1001 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001002 char * state;
1003
James Smart2e0fef82007-06-17 19:56:36 -05001004 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001005 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001006 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001007 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001008 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001009 state = "offline";
1010 else
1011 state = "online";
1012
1013 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1014}
1015
James Smarte59058c2008-08-24 21:49:00 -04001016/**
James Smart3621a712009-04-06 18:47:14 -04001017 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001018 * @dev: class device that is converted into a Scsi_host.
1019 * @attr: device attribute, not used.
1020 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1021 * @count: unused variable.
1022 *
1023 * Returns:
1024 * -EACCES if enable hba reset not enabled
1025 * -EINVAL if the buffer does not contain a valid string (see above)
1026 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1027 * buf length greater than zero indicates success
1028 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001029static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001030lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1031 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001032{
Tony Jonesee959b02008-02-22 00:13:36 +01001033 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001034 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1035 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001036 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001037 char *board_mode_str = NULL;
1038 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001039 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001040
James Smart026abb82011-12-13 13:20:45 -05001041 if (!phba->cfg_enable_hba_reset) {
1042 status = -EACCES;
1043 goto board_mode_out;
1044 }
James Smart88a2cfb2011-07-22 18:36:33 -04001045
1046 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001047 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001048
Jamie Wellnitz41415862006-02-28 19:25:27 -05001049 init_completion(&online_compl);
1050
James Smart46fa3112007-04-25 09:51:45 -04001051 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001052 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001053 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001054 if (rc == 0) {
1055 status = -ENOMEM;
1056 goto board_mode_out;
1057 }
James Smart46fa3112007-04-25 09:51:45 -04001058 wait_for_completion(&online_compl);
1059 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1060 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001061 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001062 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001063 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001064 else
1065 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001066 else if (strncmp(buf, "error", sizeof("error") - 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_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001071 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001072 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1073 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1074 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1075 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1076 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001077 else
James Smart026abb82011-12-13 13:20:45 -05001078 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001079
James Smart026abb82011-12-13 13:20:45 -05001080board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001081 if (!status)
1082 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001083 else {
1084 board_mode_str = strchr(buf, '\n');
1085 if (board_mode_str)
1086 *board_mode_str = '\0';
1087 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1088 "3097 Failed \"%s\", status(%d), "
1089 "fc_flag(x%x)\n",
1090 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001091 return status;
James Smart026abb82011-12-13 13:20:45 -05001092 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001093}
1094
James Smarte59058c2008-08-24 21:49:00 -04001095/**
James Smart3621a712009-04-06 18:47:14 -04001096 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001097 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001098 * @mxri: max xri count.
1099 * @axri: available xri count.
1100 * @mrpi: max rpi count.
1101 * @arpi: available rpi count.
1102 * @mvpi: max vpi count.
1103 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001104 *
1105 * Description:
1106 * If an integer pointer for an count is not null then the value for the
1107 * count is returned.
1108 *
1109 * Returns:
1110 * zero on error
1111 * one for success
1112 **/
James Smart311464e2007-08-02 11:10:37 -04001113static int
James Smart858c9f62007-06-17 19:56:39 -05001114lpfc_get_hba_info(struct lpfc_hba *phba,
1115 uint32_t *mxri, uint32_t *axri,
1116 uint32_t *mrpi, uint32_t *arpi,
1117 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001118{
James Smart04c68492009-05-22 14:52:52 -04001119 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001120 LPFC_MBOXQ_t *pmboxq;
1121 MAILBOX_t *pmb;
1122 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001123 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001124
1125 /*
1126 * prevent udev from issuing mailbox commands until the port is
1127 * configured.
1128 */
1129 if (phba->link_state < LPFC_LINK_DOWN ||
1130 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001131 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001132 return 0;
1133
1134 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1135 return 0;
1136
1137 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1138 if (!pmboxq)
1139 return 0;
1140 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1141
James Smart04c68492009-05-22 14:52:52 -04001142 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001143 pmb->mbxCommand = MBX_READ_CONFIG;
1144 pmb->mbxOwner = OWN_HOST;
1145 pmboxq->context1 = NULL;
1146
James Smart75baf692010-06-08 18:31:21 -04001147 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001148 rc = MBX_NOT_FINISHED;
1149 else
1150 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1151
1152 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001153 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001154 mempool_free(pmboxq, phba->mbox_mem_pool);
1155 return 0;
1156 }
1157
James Smartda0436e2009-05-22 14:51:39 -04001158 if (phba->sli_rev == LPFC_SLI_REV4) {
1159 rd_config = &pmboxq->u.mqe.un.rd_config;
1160 if (mrpi)
1161 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1162 if (arpi)
1163 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1164 phba->sli4_hba.max_cfg_param.rpi_used;
1165 if (mxri)
1166 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1167 if (axri)
1168 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1169 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001170
1171 /* Account for differences with SLI-3. Get vpi count from
1172 * mailbox data and subtract one for max vpi value.
1173 */
1174 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1175 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1176
James Smartda0436e2009-05-22 14:51:39 -04001177 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001178 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001179 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001180 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001181 } else {
1182 if (mrpi)
1183 *mrpi = pmb->un.varRdConfig.max_rpi;
1184 if (arpi)
1185 *arpi = pmb->un.varRdConfig.avail_rpi;
1186 if (mxri)
1187 *mxri = pmb->un.varRdConfig.max_xri;
1188 if (axri)
1189 *axri = pmb->un.varRdConfig.avail_xri;
1190 if (mvpi)
1191 *mvpi = pmb->un.varRdConfig.max_vpi;
1192 if (avpi)
1193 *avpi = pmb->un.varRdConfig.avail_vpi;
1194 }
James Smart92d7f7b2007-06-17 19:56:38 -05001195
1196 mempool_free(pmboxq, phba->mbox_mem_pool);
1197 return 1;
1198}
1199
James Smarte59058c2008-08-24 21:49:00 -04001200/**
James Smart3621a712009-04-06 18:47:14 -04001201 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001202 * @dev: class device that is converted into a Scsi_host.
1203 * @attr: device attribute, not used.
1204 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1205 *
1206 * Description:
1207 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1208 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1209 * to "Unknown" and the buffer length is returned, therefore the caller
1210 * must check for "Unknown" in the buffer to detect a failure.
1211 *
1212 * Returns: size of formatted string.
1213 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001214static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001215lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1216 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001217{
Tony Jonesee959b02008-02-22 00:13:36 +01001218 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001219 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1220 struct lpfc_hba *phba = vport->phba;
1221 uint32_t cnt;
1222
James Smart858c9f62007-06-17 19:56:39 -05001223 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001224 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1225 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1226}
1227
James Smarte59058c2008-08-24 21:49:00 -04001228/**
James Smart3621a712009-04-06 18:47:14 -04001229 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001230 * @dev: class device that is converted into a Scsi_host.
1231 * @attr: device attribute, not used.
1232 * @buf: containing the used rpi count in decimal or "Unknown".
1233 *
1234 * Description:
1235 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1236 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1237 * to "Unknown" and the buffer length is returned, therefore the caller
1238 * must check for "Unknown" in the buffer to detect a failure.
1239 *
1240 * Returns: size of formatted string.
1241 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001242static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001243lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1244 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001245{
Tony Jonesee959b02008-02-22 00:13:36 +01001246 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001247 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1248 struct lpfc_hba *phba = vport->phba;
1249 uint32_t cnt, acnt;
1250
James Smart858c9f62007-06-17 19:56:39 -05001251 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001252 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1253 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1254}
1255
James Smarte59058c2008-08-24 21:49:00 -04001256/**
James Smart3621a712009-04-06 18:47:14 -04001257 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001258 * @dev: class device that is converted into a Scsi_host.
1259 * @attr: device attribute, not used.
1260 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1261 *
1262 * Description:
1263 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1264 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1265 * to "Unknown" and the buffer length is returned, therefore the caller
1266 * must check for "Unknown" in the buffer to detect a failure.
1267 *
1268 * Returns: size of formatted string.
1269 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001270static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001271lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1272 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001273{
Tony Jonesee959b02008-02-22 00:13:36 +01001274 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001275 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1276 struct lpfc_hba *phba = vport->phba;
1277 uint32_t cnt;
1278
James Smart858c9f62007-06-17 19:56:39 -05001279 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001280 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1281 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1282}
1283
James Smarte59058c2008-08-24 21:49:00 -04001284/**
James Smart3621a712009-04-06 18:47:14 -04001285 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001286 * @dev: class device that is converted into a Scsi_host.
1287 * @attr: device attribute, not used.
1288 * @buf: on return contains the used xri count in decimal or "Unknown".
1289 *
1290 * Description:
1291 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1292 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1293 * to "Unknown" and the buffer length is returned, therefore the caller
1294 * must check for "Unknown" in the buffer to detect a failure.
1295 *
1296 * Returns: size of formatted string.
1297 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001298static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001299lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1300 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001301{
Tony Jonesee959b02008-02-22 00:13:36 +01001302 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1304 struct lpfc_hba *phba = vport->phba;
1305 uint32_t cnt, acnt;
1306
James Smart858c9f62007-06-17 19:56:39 -05001307 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1308 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1309 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1310}
1311
James Smarte59058c2008-08-24 21:49:00 -04001312/**
James Smart3621a712009-04-06 18:47:14 -04001313 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001314 * @dev: class device that is converted into a Scsi_host.
1315 * @attr: device attribute, not used.
1316 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1317 *
1318 * Description:
1319 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1320 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1321 * to "Unknown" and the buffer length is returned, therefore the caller
1322 * must check for "Unknown" in the buffer to detect a failure.
1323 *
1324 * Returns: size of formatted string.
1325 **/
James Smart858c9f62007-06-17 19:56:39 -05001326static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001327lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1328 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001329{
Tony Jonesee959b02008-02-22 00:13:36 +01001330 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1332 struct lpfc_hba *phba = vport->phba;
1333 uint32_t cnt;
1334
1335 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1336 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1337 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1338}
1339
James Smarte59058c2008-08-24 21:49:00 -04001340/**
James Smart3621a712009-04-06 18:47:14 -04001341 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001342 * @dev: class device that is converted into a Scsi_host.
1343 * @attr: device attribute, not used.
1344 * @buf: on return contains the used vpi count in decimal or "Unknown".
1345 *
1346 * Description:
1347 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1348 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1349 * to "Unknown" and the buffer length is returned, therefore the caller
1350 * must check for "Unknown" in the buffer to detect a failure.
1351 *
1352 * Returns: size of formatted string.
1353 **/
James Smart858c9f62007-06-17 19:56:39 -05001354static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001355lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1356 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001357{
Tony Jonesee959b02008-02-22 00:13:36 +01001358 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001359 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1360 struct lpfc_hba *phba = vport->phba;
1361 uint32_t cnt, acnt;
1362
1363 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001364 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1365 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1366}
1367
James Smarte59058c2008-08-24 21:49:00 -04001368/**
James Smart3621a712009-04-06 18:47:14 -04001369 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001370 * @dev: class device that is converted into a Scsi_host.
1371 * @attr: device attribute, not used.
1372 * @buf: text that must be interpreted to determine if npiv is supported.
1373 *
1374 * Description:
1375 * Buffer will contain text indicating npiv is not suppoerted on the port,
1376 * the port is an NPIV physical port, or it is an npiv virtual port with
1377 * the id of the vport.
1378 *
1379 * Returns: size of formatted string.
1380 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001382lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1383 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001384{
Tony Jonesee959b02008-02-22 00:13:36 +01001385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1387 struct lpfc_hba *phba = vport->phba;
1388
1389 if (!(phba->max_vpi))
1390 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1391 if (vport->port_type == LPFC_PHYSICAL_PORT)
1392 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1393 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1394}
1395
James Smarte59058c2008-08-24 21:49:00 -04001396/**
James Smart3621a712009-04-06 18:47:14 -04001397 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001398 * @dev: class device that is converted into a Scsi_host.
1399 * @attr: device attribute, not used.
1400 * @buf: on return contains the cfg_poll in hex.
1401 *
1402 * Notes:
1403 * cfg_poll should be a lpfc_polling_flags type.
1404 *
1405 * Returns: size of formatted string.
1406 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001407static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001408lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1409 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001410{
Tony Jonesee959b02008-02-22 00:13:36 +01001411 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001412 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1413 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001414
1415 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1416}
1417
James Smarte59058c2008-08-24 21:49:00 -04001418/**
James Smart3621a712009-04-06 18:47:14 -04001419 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001420 * @dev: class device that is converted into a Scsi_host.
1421 * @attr: device attribute, not used.
1422 * @buf: one or more lpfc_polling_flags values.
1423 * @count: not used.
1424 *
1425 * Notes:
1426 * buf contents converted to integer and checked for a valid value.
1427 *
1428 * Returns:
1429 * -EINVAL if the buffer connot be converted or is out of range
1430 * length of the buf on success
1431 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001432static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001433lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1434 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001435{
Tony Jonesee959b02008-02-22 00:13:36 +01001436 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001437 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1438 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001439 uint32_t creg_val;
1440 uint32_t old_val;
1441 int val=0;
1442
1443 if (!isdigit(buf[0]))
1444 return -EINVAL;
1445
1446 if (sscanf(buf, "%i", &val) != 1)
1447 return -EINVAL;
1448
1449 if ((val & 0x3) != val)
1450 return -EINVAL;
1451
James Smart45ed1192009-10-02 15:17:02 -04001452 if (phba->sli_rev == LPFC_SLI_REV4)
1453 val = 0;
1454
James Smart88a2cfb2011-07-22 18:36:33 -04001455 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1456 "3051 lpfc_poll changed from %d to %d\n",
1457 phba->cfg_poll, val);
1458
James Smart2e0fef82007-06-17 19:56:36 -05001459 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001460
1461 old_val = phba->cfg_poll;
1462
1463 if (val & ENABLE_FCP_RING_POLLING) {
1464 if ((val & DISABLE_FCP_RING_INT) &&
1465 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001466 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1467 spin_unlock_irq(&phba->hbalock);
1468 return -EINVAL;
1469 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001470 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1471 writel(creg_val, phba->HCregaddr);
1472 readl(phba->HCregaddr); /* flush */
1473
1474 lpfc_poll_start_timer(phba);
1475 }
1476 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001477 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001478 return -EINVAL;
1479 }
1480
1481 if (!(val & DISABLE_FCP_RING_INT) &&
1482 (old_val & DISABLE_FCP_RING_INT))
1483 {
James Smart2e0fef82007-06-17 19:56:36 -05001484 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001485 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001486 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001487 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1488 spin_unlock_irq(&phba->hbalock);
1489 return -EINVAL;
1490 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001491 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1492 writel(creg_val, phba->HCregaddr);
1493 readl(phba->HCregaddr); /* flush */
1494 }
1495
1496 phba->cfg_poll = val;
1497
James Smart2e0fef82007-06-17 19:56:36 -05001498 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001499
1500 return strlen(buf);
1501}
dea31012005-04-17 16:05:31 -05001502
James Smarte59058c2008-08-24 21:49:00 -04001503/**
James Smartbc739052010-08-04 16:11:18 -04001504 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1505 * @dev: class unused variable.
1506 * @attr: device attribute, not used.
1507 * @buf: on return contains the module description text.
1508 *
1509 * Returns: size of formatted string.
1510 **/
1511static ssize_t
1512lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1513 char *buf)
1514{
1515 struct Scsi_Host *shost = class_to_shost(dev);
1516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1517 struct lpfc_hba *phba = vport->phba;
1518
1519 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1520}
1521
1522/**
1523 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1524 * @dev: class unused variable.
1525 * @attr: device attribute, not used.
1526 * @buf: on return contains the module description text.
1527 *
1528 * Returns: size of formatted string.
1529 **/
1530static ssize_t
1531lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1532 char *buf)
1533{
1534 struct Scsi_Host *shost = class_to_shost(dev);
1535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1536 struct lpfc_hba *phba = vport->phba;
1537
1538 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1539}
1540
1541/**
James Smartab56dc22011-02-16 12:39:57 -05001542 * lpfc_dss_show - Return the current state of dss and the configured state
1543 * @dev: class converted to a Scsi_host structure.
1544 * @attr: device attribute, not used.
1545 * @buf: on return contains the formatted text.
1546 *
1547 * Returns: size of formatted string.
1548 **/
1549static ssize_t
1550lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1551 char *buf)
1552{
1553 struct Scsi_Host *shost = class_to_shost(dev);
1554 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1555 struct lpfc_hba *phba = vport->phba;
1556
1557 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1558 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1559 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1560 "" : "Not ");
1561}
1562
1563/**
James Smart912e3ac2011-05-24 11:42:11 -04001564 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1565 * @dev: class converted to a Scsi_host structure.
1566 * @attr: device attribute, not used.
1567 * @buf: on return contains the formatted support level.
1568 *
1569 * Description:
1570 * Returns the maximum number of virtual functions a physical function can
1571 * support, 0 will be returned if called on virtual function.
1572 *
1573 * Returns: size of formatted string.
1574 **/
1575static ssize_t
1576lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1577 struct device_attribute *attr,
1578 char *buf)
1579{
1580 struct Scsi_Host *shost = class_to_shost(dev);
1581 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1582 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001583 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001584
James Smart0a96e972011-07-22 18:37:28 -04001585 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1586 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001587}
1588
1589/**
James Smart3621a712009-04-06 18:47:14 -04001590 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001591 *
1592 * Description:
1593 * Macro that given an attr e.g. hba_queue_depth expands
1594 * into a function with the name lpfc_hba_queue_depth_show.
1595 *
1596 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1597 * @dev: class device that is converted into a Scsi_host.
1598 * @attr: device attribute, not used.
1599 * @buf: on return contains the attribute value in decimal.
1600 *
1601 * Returns: size of formatted string.
1602 **/
dea31012005-04-17 16:05:31 -05001603#define lpfc_param_show(attr) \
1604static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001605lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1606 char *buf) \
dea31012005-04-17 16:05:31 -05001607{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001608 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1610 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001611 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001612 val = phba->cfg_##attr;\
1613 return snprintf(buf, PAGE_SIZE, "%d\n",\
1614 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001615}
1616
James Smarte59058c2008-08-24 21:49:00 -04001617/**
James Smart3621a712009-04-06 18:47:14 -04001618 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001619 *
1620 * Description:
1621 * Macro that given an attr e.g. hba_queue_depth expands
1622 * into a function with the name lpfc_hba_queue_depth_show
1623 *
1624 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1625 * @dev: class device that is converted into a Scsi_host.
1626 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001627 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001628 *
1629 * Returns: size of formatted string.
1630 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001631#define lpfc_param_hex_show(attr) \
1632static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001633lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1634 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001635{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001636 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1638 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001639 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001640 val = phba->cfg_##attr;\
1641 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1642 phba->cfg_##attr);\
1643}
1644
James Smarte59058c2008-08-24 21:49:00 -04001645/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001646 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001647 *
1648 * Description:
1649 * Macro that given an attr e.g. hba_queue_depth expands
1650 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1651 * takes a default argument, a minimum and maximum argument.
1652 *
1653 * lpfc_##attr##_init: Initializes an attribute.
1654 * @phba: pointer the the adapter structure.
1655 * @val: integer attribute value.
1656 *
1657 * Validates the min and max values then sets the adapter config field
1658 * accordingly, or uses the default if out of range and prints an error message.
1659 *
1660 * Returns:
1661 * zero on success
1662 * -EINVAL if default used
1663 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001664#define lpfc_param_init(attr, default, minval, maxval) \
1665static int \
James Smart84d1b002010-02-12 14:42:33 -05001666lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001667{ \
1668 if (val >= minval && val <= maxval) {\
1669 phba->cfg_##attr = val;\
1670 return 0;\
1671 }\
1672 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001673 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1674 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001675 phba->cfg_##attr = default;\
1676 return -EINVAL;\
1677}
1678
James Smarte59058c2008-08-24 21:49:00 -04001679/**
James Smart3621a712009-04-06 18:47:14 -04001680 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001681 *
1682 * Description:
1683 * Macro that given an attr e.g. hba_queue_depth expands
1684 * into a function with the name lpfc_hba_queue_depth_set
1685 *
1686 * lpfc_##attr##_set: Sets an attribute value.
1687 * @phba: pointer the the adapter structure.
1688 * @val: integer attribute value.
1689 *
1690 * Description:
1691 * Validates the min and max values then sets the
1692 * adapter config field if in the valid range. prints error message
1693 * and does not set the parameter if invalid.
1694 *
1695 * Returns:
1696 * zero on success
1697 * -EINVAL if val is invalid
1698 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001699#define lpfc_param_set(attr, default, minval, maxval) \
1700static int \
James Smart84d1b002010-02-12 14:42:33 -05001701lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001702{ \
1703 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1705 "3052 lpfc_" #attr " changed from %d to %d\n", \
1706 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001707 phba->cfg_##attr = val;\
1708 return 0;\
1709 }\
1710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001711 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1712 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001713 return -EINVAL;\
1714}
1715
James Smarte59058c2008-08-24 21:49:00 -04001716/**
James Smart3621a712009-04-06 18:47:14 -04001717 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001718 *
1719 * Description:
1720 * Macro that given an attr e.g. hba_queue_depth expands
1721 * into a function with the name lpfc_hba_queue_depth_store.
1722 *
1723 * lpfc_##attr##_store: Set an sttribute value.
1724 * @dev: class device that is converted into a Scsi_host.
1725 * @attr: device attribute, not used.
1726 * @buf: contains the attribute value in ascii.
1727 * @count: not used.
1728 *
1729 * Description:
1730 * Convert the ascii text number to an integer, then
1731 * use the lpfc_##attr##_set function to set the value.
1732 *
1733 * Returns:
1734 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1735 * length of buffer upon success.
1736 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001737#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001738static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001739lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1740 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001741{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001742 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1744 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001745 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001746 if (!isdigit(buf[0]))\
1747 return -EINVAL;\
1748 if (sscanf(buf, "%i", &val) != 1)\
1749 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001750 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001751 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001752 else \
1753 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001754}
1755
James Smarte59058c2008-08-24 21:49:00 -04001756/**
James Smart3621a712009-04-06 18:47:14 -04001757 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001758 *
1759 * Description:
1760 * Macro that given an attr e.g. hba_queue_depth expands
1761 * into a function with the name lpfc_hba_queue_depth_show
1762 *
1763 * lpfc_##attr##_show: prints the attribute value in decimal.
1764 * @dev: class device that is converted into a Scsi_host.
1765 * @attr: device attribute, not used.
1766 * @buf: on return contains the attribute value in decimal.
1767 *
1768 * Returns: length of formatted string.
1769 **/
James Smart3de2a652007-08-02 11:09:59 -04001770#define lpfc_vport_param_show(attr) \
1771static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001772lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1773 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001774{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001775 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001777 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001778 val = vport->cfg_##attr;\
1779 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1780}
1781
James Smarte59058c2008-08-24 21:49:00 -04001782/**
James Smart3621a712009-04-06 18:47:14 -04001783 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001784 *
1785 * Description:
1786 * Macro that given an attr e.g.
1787 * hba_queue_depth expands into a function with the name
1788 * lpfc_hba_queue_depth_show
1789 *
James Smart3621a712009-04-06 18:47:14 -04001790 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001791 * @dev: class device that is converted into a Scsi_host.
1792 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001793 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001794 *
1795 * Returns: length of formatted string.
1796 **/
James Smart3de2a652007-08-02 11:09:59 -04001797#define lpfc_vport_param_hex_show(attr) \
1798static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001799lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1800 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001801{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001802 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001803 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001804 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001805 val = vport->cfg_##attr;\
1806 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1807}
1808
James Smarte59058c2008-08-24 21:49:00 -04001809/**
James Smart3621a712009-04-06 18:47:14 -04001810 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001811 *
1812 * Description:
1813 * Macro that given an attr e.g. hba_queue_depth expands
1814 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1815 * takes a default argument, a minimum and maximum argument.
1816 *
1817 * lpfc_##attr##_init: validates the min and max values then sets the
1818 * adapter config field accordingly, or uses the default if out of range
1819 * and prints an error message.
1820 * @phba: pointer the the adapter structure.
1821 * @val: integer attribute value.
1822 *
1823 * Returns:
1824 * zero on success
1825 * -EINVAL if default used
1826 **/
James Smart3de2a652007-08-02 11:09:59 -04001827#define lpfc_vport_param_init(attr, default, minval, maxval) \
1828static int \
James Smart84d1b002010-02-12 14:42:33 -05001829lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001830{ \
1831 if (val >= minval && val <= maxval) {\
1832 vport->cfg_##attr = val;\
1833 return 0;\
1834 }\
James Smarte8b62012007-08-02 11:10:09 -04001835 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001836 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001837 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001838 vport->cfg_##attr = default;\
1839 return -EINVAL;\
1840}
1841
James Smarte59058c2008-08-24 21:49:00 -04001842/**
James Smart3621a712009-04-06 18:47:14 -04001843 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001844 *
1845 * Description:
1846 * Macro that given an attr e.g. hba_queue_depth expands
1847 * into a function with the name lpfc_hba_queue_depth_set
1848 *
1849 * lpfc_##attr##_set: validates the min and max values then sets the
1850 * adapter config field if in the valid range. prints error message
1851 * and does not set the parameter if invalid.
1852 * @phba: pointer the the adapter structure.
1853 * @val: integer attribute value.
1854 *
1855 * Returns:
1856 * zero on success
1857 * -EINVAL if val is invalid
1858 **/
James Smart3de2a652007-08-02 11:09:59 -04001859#define lpfc_vport_param_set(attr, default, minval, maxval) \
1860static int \
James Smart84d1b002010-02-12 14:42:33 -05001861lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001862{ \
1863 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001864 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1865 "3053 lpfc_" #attr " changed from %d to %d\n", \
1866 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001867 vport->cfg_##attr = val;\
1868 return 0;\
1869 }\
James Smarte8b62012007-08-02 11:10:09 -04001870 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001871 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001872 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001873 return -EINVAL;\
1874}
1875
James Smarte59058c2008-08-24 21:49:00 -04001876/**
James Smart3621a712009-04-06 18:47:14 -04001877 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001878 *
1879 * Description:
1880 * Macro that given an attr e.g. hba_queue_depth
1881 * expands into a function with the name lpfc_hba_queue_depth_store
1882 *
1883 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1884 * use the lpfc_##attr##_set function to set the value.
1885 * @cdev: class device that is converted into a Scsi_host.
1886 * @buf: contains the attribute value in decimal.
1887 * @count: not used.
1888 *
1889 * Returns:
1890 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1891 * length of buffer upon success.
1892 **/
James Smart3de2a652007-08-02 11:09:59 -04001893#define lpfc_vport_param_store(attr) \
1894static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001895lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1896 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001897{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001898 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001900 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001901 if (!isdigit(buf[0]))\
1902 return -EINVAL;\
1903 if (sscanf(buf, "%i", &val) != 1)\
1904 return -EINVAL;\
1905 if (lpfc_##attr##_set(vport, val) == 0) \
1906 return strlen(buf);\
1907 else \
1908 return -EINVAL;\
1909}
1910
1911
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001912#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001913static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001914module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001915MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001916lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001917
1918#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001919static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001920module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001921MODULE_PARM_DESC(lpfc_##name, desc);\
1922lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001923lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001924static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001925
1926#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001927static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001928module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001929MODULE_PARM_DESC(lpfc_##name, desc);\
1930lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001931lpfc_param_init(name, defval, minval, maxval)\
1932lpfc_param_set(name, defval, minval, maxval)\
1933lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001934static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1935 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001936
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001937#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001938static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001939module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001940MODULE_PARM_DESC(lpfc_##name, desc);\
1941lpfc_param_hex_show(name)\
1942lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001943static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001944
1945#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001946static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001947module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001948MODULE_PARM_DESC(lpfc_##name, desc);\
1949lpfc_param_hex_show(name)\
1950lpfc_param_init(name, defval, minval, maxval)\
1951lpfc_param_set(name, defval, minval, maxval)\
1952lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001953static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1954 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001955
James Smart3de2a652007-08-02 11:09:59 -04001956#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001957static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001958module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001959MODULE_PARM_DESC(lpfc_##name, desc);\
1960lpfc_vport_param_init(name, defval, minval, maxval)
1961
1962#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001963static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001964module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001965MODULE_PARM_DESC(lpfc_##name, desc);\
1966lpfc_vport_param_show(name)\
1967lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001968static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001969
1970#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001971static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001972module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001973MODULE_PARM_DESC(lpfc_##name, desc);\
1974lpfc_vport_param_show(name)\
1975lpfc_vport_param_init(name, defval, minval, maxval)\
1976lpfc_vport_param_set(name, defval, minval, maxval)\
1977lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001978static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1979 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001980
1981#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001982static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001983module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001984MODULE_PARM_DESC(lpfc_##name, desc);\
1985lpfc_vport_param_hex_show(name)\
1986lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001987static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001988
1989#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001990static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001991module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001992MODULE_PARM_DESC(lpfc_##name, desc);\
1993lpfc_vport_param_hex_show(name)\
1994lpfc_vport_param_init(name, defval, minval, maxval)\
1995lpfc_vport_param_set(name, defval, minval, maxval)\
1996lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001997static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1998 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001999
James Smart81301a92008-12-04 22:39:46 -05002000static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2001static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2002static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2003static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002004static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2005static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2006static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2007static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2008static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2009static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2010static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2011static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002012static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2013 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002014static DEVICE_ATTR(option_rom_version, S_IRUGO,
2015 lpfc_option_rom_version_show, NULL);
2016static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2017 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002018static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002019static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2020static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002021static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002022static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2023 lpfc_board_mode_show, lpfc_board_mode_store);
2024static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2025static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2026static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2027static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2028static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2029static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2030static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2031static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2032static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002033static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2034static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002035static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002036static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2037 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002038static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002039
James Smarta12e07b2006-12-02 13:35:30 -05002040static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04002041
James Smarte59058c2008-08-24 21:49:00 -04002042/**
James Smart3621a712009-04-06 18:47:14 -04002043 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002044 * @dev: class device that is converted into a Scsi_host.
2045 * @attr: device attribute, not used.
2046 * @buf: containing the string lpfc_soft_wwn_key.
2047 * @count: must be size of lpfc_soft_wwn_key.
2048 *
2049 * Returns:
2050 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2051 * length of buf indicates success
2052 **/
James Smartc3f28af2006-08-18 17:47:18 -04002053static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002054lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2055 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002056{
Tony Jonesee959b02008-02-22 00:13:36 +01002057 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002058 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2059 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002060 unsigned int cnt = count;
2061
2062 /*
2063 * We're doing a simple sanity check for soft_wwpn setting.
2064 * We require that the user write a specific key to enable
2065 * the soft_wwpn attribute to be settable. Once the attribute
2066 * is written, the enable key resets. If further updates are
2067 * desired, the key must be written again to re-enable the
2068 * attribute.
2069 *
2070 * The "key" is not secret - it is a hardcoded string shown
2071 * here. The intent is to protect against the random user or
2072 * application that is just writing attributes.
2073 */
2074
2075 /* count may include a LF at end of string */
2076 if (buf[cnt-1] == '\n')
2077 cnt--;
2078
James Smarta12e07b2006-12-02 13:35:30 -05002079 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2080 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002081 return -EINVAL;
2082
James Smarta12e07b2006-12-02 13:35:30 -05002083 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002084 return count;
2085}
Tony Jonesee959b02008-02-22 00:13:36 +01002086static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2087 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002088
James Smarte59058c2008-08-24 21:49:00 -04002089/**
James Smart3621a712009-04-06 18:47:14 -04002090 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002091 * @dev: class device that is converted into a Scsi_host.
2092 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002093 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002094 *
2095 * Returns: size of formatted string.
2096 **/
James Smartc3f28af2006-08-18 17:47:18 -04002097static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002098lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2099 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002100{
Tony Jonesee959b02008-02-22 00:13:36 +01002101 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2103 struct lpfc_hba *phba = vport->phba;
2104
Randy Dunlapafc071e2006-10-23 21:47:13 -07002105 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2106 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002107}
2108
James Smarte59058c2008-08-24 21:49:00 -04002109/**
James Smart3621a712009-04-06 18:47:14 -04002110 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002111 * @dev class device that is converted into a Scsi_host.
2112 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002113 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002114 * @count: number of wwpn bytes in buf
2115 *
2116 * Returns:
2117 * -EACCES hba reset not enabled, adapter over temp
2118 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2119 * -EIO error taking adapter offline or online
2120 * value of count on success
2121 **/
James Smartc3f28af2006-08-18 17:47:18 -04002122static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002123lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2124 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002125{
Tony Jonesee959b02008-02-22 00:13:36 +01002126 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002127 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2128 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002129 struct completion online_compl;
2130 int stat1=0, stat2=0;
2131 unsigned int i, j, cnt=count;
2132 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002133 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002134
James Smart13815c82008-01-11 01:52:48 -05002135 if (!phba->cfg_enable_hba_reset)
2136 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002137 spin_lock_irq(&phba->hbalock);
2138 if (phba->over_temp_state == HBA_OVER_TEMP) {
2139 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002140 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002141 }
2142 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002143 /* count may include a LF at end of string */
2144 if (buf[cnt-1] == '\n')
2145 cnt--;
2146
James Smarta12e07b2006-12-02 13:35:30 -05002147 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002148 ((cnt == 17) && (*buf++ != 'x')) ||
2149 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2150 return -EINVAL;
2151
James Smarta12e07b2006-12-02 13:35:30 -05002152 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002153
2154 memset(wwpn, 0, sizeof(wwpn));
2155
2156 /* Validate and store the new name */
2157 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002158 int value;
2159
2160 value = hex_to_bin(*buf++);
2161 if (value >= 0)
2162 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002163 else
2164 return -EINVAL;
2165 if (i % 2) {
2166 wwpn[i/2] = j & 0xff;
2167 j = 0;
2168 }
2169 }
2170 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002171 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002172 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002173 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002174
2175 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2176 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2177
James Smart46fa3112007-04-25 09:51:45 -04002178 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002179 if (stat1)
2180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002181 "0463 lpfc_soft_wwpn attribute set failed to "
2182 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002183 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002184 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2185 LPFC_EVT_ONLINE);
2186 if (rc == 0)
2187 return -ENOMEM;
2188
James Smartc3f28af2006-08-18 17:47:18 -04002189 wait_for_completion(&online_compl);
2190 if (stat2)
2191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002192 "0464 lpfc_soft_wwpn attribute set failed to "
2193 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002194 return (stat1 || stat2) ? -EIO : count;
2195}
Tony Jonesee959b02008-02-22 00:13:36 +01002196static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2197 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002198
James Smarte59058c2008-08-24 21:49:00 -04002199/**
James Smart3621a712009-04-06 18:47:14 -04002200 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002201 * @dev: class device that is converted into a Scsi_host.
2202 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002203 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002204 *
2205 * Returns: size of formatted string.
2206 **/
James Smarta12e07b2006-12-02 13:35:30 -05002207static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002208lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2209 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002210{
Tony Jonesee959b02008-02-22 00:13:36 +01002211 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002212 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002213 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2214 (unsigned long long)phba->cfg_soft_wwnn);
2215}
2216
James Smarte59058c2008-08-24 21:49:00 -04002217/**
James Smart3621a712009-04-06 18:47:14 -04002218 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002219 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002220 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002221 * @count: number of wwnn bytes in buf.
2222 *
2223 * Returns:
2224 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2225 * value of count on success
2226 **/
James Smarta12e07b2006-12-02 13:35:30 -05002227static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002228lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2229 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002230{
Tony Jonesee959b02008-02-22 00:13:36 +01002231 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002232 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002233 unsigned int i, j, cnt=count;
2234 u8 wwnn[8];
2235
2236 /* count may include a LF at end of string */
2237 if (buf[cnt-1] == '\n')
2238 cnt--;
2239
2240 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2241 ((cnt == 17) && (*buf++ != 'x')) ||
2242 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2243 return -EINVAL;
2244
2245 /*
2246 * Allow wwnn to be set many times, as long as the enable is set.
2247 * However, once the wwpn is set, everything locks.
2248 */
2249
2250 memset(wwnn, 0, sizeof(wwnn));
2251
2252 /* Validate and store the new name */
2253 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002254 int value;
2255
2256 value = hex_to_bin(*buf++);
2257 if (value >= 0)
2258 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002259 else
2260 return -EINVAL;
2261 if (i % 2) {
2262 wwnn[i/2] = j & 0xff;
2263 j = 0;
2264 }
2265 }
2266 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2267
2268 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2269 "lpfc%d: soft_wwnn set. Value will take effect upon "
2270 "setting of the soft_wwpn\n", phba->brd_no);
2271
2272 return count;
2273}
Tony Jonesee959b02008-02-22 00:13:36 +01002274static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2275 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002276
James Smartc3f28af2006-08-18 17:47:18 -04002277
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002278static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002279module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002280MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2281 " 0 - none,"
2282 " 1 - poll with interrupts enabled"
2283 " 3 - poll and disable FCP ring interrupts");
2284
Tony Jonesee959b02008-02-22 00:13:36 +01002285static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2286 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002287
James Smart92d7f7b2007-06-17 19:56:38 -05002288int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002289module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002290MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2291 " 0 - auto (SLI-3 if supported),"
2292 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2293 " 3 - select SLI-3");
2294
James Smart15672312010-04-06 14:49:03 -04002295int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002296module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002297MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2298lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002299lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002300static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002301
James Smart7d791df2011-07-22 18:37:52 -04002302LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2303 "FCF Fast failover=1 Priority failover=2");
2304
James Smart19ca7602010-11-20 23:11:55 -05002305int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002306module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002307MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2308lpfc_param_show(enable_rrq);
James Smarte5771b42013-03-01 16:37:14 -05002309/*
2310# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2311# 0x0 = disabled, XRI/OXID use not tracked.
2312# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2313# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2314*/
2315lpfc_param_init(enable_rrq, 2, 0, 2);
James Smart19ca7602010-11-20 23:11:55 -05002316static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2317
dea31012005-04-17 16:05:31 -05002318/*
James Smart84d1b002010-02-12 14:42:33 -05002319# lpfc_suppress_link_up: Bring link up at initialization
2320# 0x0 = bring link up (issue MBX_INIT_LINK)
2321# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2322# 0x2 = never bring up link
2323# Default value is 0.
2324*/
James Smarte40a02c2010-02-26 14:13:54 -05002325LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2326 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2327 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002328/*
2329# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2330# 1 - (1024)
2331# 2 - (2048)
2332# 3 - (3072)
2333# 4 - (4096)
2334# 5 - (5120)
2335*/
2336static ssize_t
2337lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2338{
2339 struct Scsi_Host *shost = class_to_shost(dev);
2340 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2341
2342 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2343}
2344
2345static DEVICE_ATTR(iocb_hw, S_IRUGO,
2346 lpfc_iocb_hw_show, NULL);
2347static ssize_t
2348lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2349{
2350 struct Scsi_Host *shost = class_to_shost(dev);
2351 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2352
2353 return snprintf(buf, PAGE_SIZE, "%d\n",
2354 phba->sli.ring[LPFC_ELS_RING].txq_max);
2355}
2356
2357static DEVICE_ATTR(txq_hw, S_IRUGO,
2358 lpfc_txq_hw_show, NULL);
2359static ssize_t
2360lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2361 char *buf)
2362{
2363 struct Scsi_Host *shost = class_to_shost(dev);
2364 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2365
2366 return snprintf(buf, PAGE_SIZE, "%d\n",
2367 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2368}
2369
2370static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2371 lpfc_txcmplq_hw_show, NULL);
2372
2373int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002374module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002375MODULE_PARM_DESC(lpfc_iocb_cnt,
2376 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2377lpfc_param_show(iocb_cnt);
2378lpfc_param_init(iocb_cnt, 2, 1, 5);
2379static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2380 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002381
2382/*
James Smartc01f3202006-08-18 17:47:08 -04002383# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2384# until the timer expires. Value range is [0,255]. Default value is 30.
2385*/
2386static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2387static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2388module_param(lpfc_nodev_tmo, int, 0);
2389MODULE_PARM_DESC(lpfc_nodev_tmo,
2390 "Seconds driver will hold I/O waiting "
2391 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002392
2393/**
James Smart3621a712009-04-06 18:47:14 -04002394 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002395 * @dev: class converted to a Scsi_host structure.
2396 * @attr: device attribute, not used.
2397 * @buf: on return contains the dev loss timeout in decimal.
2398 *
2399 * Returns: size of formatted string.
2400 **/
James Smartc01f3202006-08-18 17:47:08 -04002401static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002402lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2403 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002404{
Tony Jonesee959b02008-02-22 00:13:36 +01002405 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002406 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002407
James Smart3de2a652007-08-02 11:09:59 -04002408 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002409}
2410
James Smarte59058c2008-08-24 21:49:00 -04002411/**
James Smart3621a712009-04-06 18:47:14 -04002412 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002413 * @vport: lpfc vport structure pointer.
2414 * @val: contains the nodev timeout value.
2415 *
2416 * Description:
2417 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2418 * a kernel error message is printed and zero is returned.
2419 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2420 * Otherwise nodev tmo is set to the default value.
2421 *
2422 * Returns:
2423 * zero if already set or if val is in range
2424 * -EINVAL val out of range
2425 **/
James Smartc01f3202006-08-18 17:47:08 -04002426static int
James Smart3de2a652007-08-02 11:09:59 -04002427lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002428{
James Smart3de2a652007-08-02 11:09:59 -04002429 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2430 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2431 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002432 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002433 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002434 "parameter because devloss_tmo is "
2435 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002436 return 0;
2437 }
2438
2439 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002440 vport->cfg_nodev_tmo = val;
2441 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002442 return 0;
2443 }
James Smarte8b62012007-08-02 11:10:09 -04002444 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2445 "0400 lpfc_nodev_tmo attribute cannot be set to"
2446 " %d, allowed range is [%d, %d]\n",
2447 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002448 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002449 return -EINVAL;
2450}
2451
James Smarte59058c2008-08-24 21:49:00 -04002452/**
James Smart3621a712009-04-06 18:47:14 -04002453 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002454 * @vport: lpfc vport structure pointer.
2455 *
2456 * Description:
2457 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2458 **/
James Smart7054a602007-04-25 09:52:34 -04002459static void
James Smart3de2a652007-08-02 11:09:59 -04002460lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002461{
James Smart858c9f62007-06-17 19:56:39 -05002462 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002463 struct lpfc_nodelist *ndlp;
2464
James Smart51ef4c22007-08-02 11:10:31 -04002465 shost = lpfc_shost_from_vport(vport);
2466 spin_lock_irq(shost->host_lock);
2467 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002468 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002469 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2470 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002471}
2472
James Smarte59058c2008-08-24 21:49:00 -04002473/**
James Smart3621a712009-04-06 18:47:14 -04002474 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002475 * @vport: lpfc vport structure pointer.
2476 * @val: contains the tmo value.
2477 *
2478 * Description:
2479 * If the devloss tmo is already set or the vport dev loss tmo has changed
2480 * then a kernel error message is printed and zero is returned.
2481 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2482 * Otherwise nodev tmo is set to the default value.
2483 *
2484 * Returns:
2485 * zero if already set or if val is in range
2486 * -EINVAL val out of range
2487 **/
James Smartc01f3202006-08-18 17:47:08 -04002488static int
James Smart3de2a652007-08-02 11:09:59 -04002489lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002490{
James Smart3de2a652007-08-02 11:09:59 -04002491 if (vport->dev_loss_tmo_changed ||
2492 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002493 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2494 "0401 Ignoring change to nodev_tmo "
2495 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002496 return 0;
2497 }
James Smartc01f3202006-08-18 17:47:08 -04002498 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002499 vport->cfg_nodev_tmo = val;
2500 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002501 /*
2502 * For compat: set the fc_host dev loss so new rports
2503 * will get the value.
2504 */
2505 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002506 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002507 return 0;
2508 }
James Smarte8b62012007-08-02 11:10:09 -04002509 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2510 "0403 lpfc_nodev_tmo attribute cannot be set to"
2511 "%d, allowed range is [%d, %d]\n",
2512 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002513 return -EINVAL;
2514}
2515
James Smart3de2a652007-08-02 11:09:59 -04002516lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002517
Tony Jonesee959b02008-02-22 00:13:36 +01002518static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2519 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002520
2521/*
2522# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2523# disappear until the timer expires. Value range is [0,255]. Default
2524# value is 30.
2525*/
James Smartab56dc22011-02-16 12:39:57 -05002526module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002527MODULE_PARM_DESC(lpfc_devloss_tmo,
2528 "Seconds driver will hold I/O waiting "
2529 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002530lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2531 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2532lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002533
2534/**
James Smart3621a712009-04-06 18:47:14 -04002535 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002536 * @vport: lpfc vport structure pointer.
2537 * @val: contains the tmo value.
2538 *
2539 * Description:
2540 * If val is in a valid range then set the vport nodev tmo,
2541 * devloss tmo, also set the vport dev loss tmo changed flag.
2542 * Else a kernel error message is printed.
2543 *
2544 * Returns:
2545 * zero if val is in range
2546 * -EINVAL val out of range
2547 **/
James Smartc01f3202006-08-18 17:47:08 -04002548static int
James Smart3de2a652007-08-02 11:09:59 -04002549lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002550{
2551 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002552 vport->cfg_nodev_tmo = val;
2553 vport->cfg_devloss_tmo = val;
2554 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002555 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002556 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002557 return 0;
2558 }
2559
James Smarte8b62012007-08-02 11:10:09 -04002560 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2561 "0404 lpfc_devloss_tmo attribute cannot be set to"
2562 " %d, allowed range is [%d, %d]\n",
2563 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002564 return -EINVAL;
2565}
2566
James Smart3de2a652007-08-02 11:09:59 -04002567lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002568static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2569 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002570
2571/*
dea31012005-04-17 16:05:31 -05002572# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2573# deluged with LOTS of information.
2574# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002575# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002576*/
James Smartf4b4c682009-05-22 14:53:12 -04002577LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002578 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002579
2580/*
James Smart7ee5d432007-10-27 13:37:17 -04002581# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2582# objects that have been registered with the nameserver after login.
2583*/
James Smartcf971242012-03-01 22:37:32 -05002584LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04002585 "Deregister nameserver objects before LOGO");
2586
2587/*
dea31012005-04-17 16:05:31 -05002588# lun_queue_depth: This parameter is used to limit the number of outstanding
2589# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2590*/
James Smart3de2a652007-08-02 11:09:59 -04002591LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2592 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002593
2594/*
James Smart7dc517d2010-07-14 15:32:10 -04002595# tgt_queue_depth: This parameter is used to limit the number of outstanding
2596# commands per target port. Value range is [10,65535]. Default value is 65535.
2597*/
2598LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2599 "Max number of FCP commands we can queue to a specific target port");
2600
2601/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002602# hba_queue_depth: This parameter is used to limit the number of outstanding
2603# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2604# value is greater than the maximum number of exchanges supported by the HBA,
2605# then maximum number of exchanges supported by the HBA is used to determine
2606# the hba_queue_depth.
2607*/
2608LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2609 "Max number of FCP commands we can queue to a lpfc HBA");
2610
2611/*
James Smart92d7f7b2007-06-17 19:56:38 -05002612# peer_port_login: This parameter allows/prevents logins
2613# between peer ports hosted on the same physical port.
2614# When this parameter is set 0 peer ports of same physical port
2615# are not allowed to login to each other.
2616# When this parameter is set 1 peer ports of same physical port
2617# are allowed to login to each other.
2618# Default value of this parameter is 0.
2619*/
James Smart3de2a652007-08-02 11:09:59 -04002620LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2621 "Allow peer ports on the same physical port to login to each "
2622 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002623
2624/*
James Smart3de2a652007-08-02 11:09:59 -04002625# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002626# between Virtual Ports and remote initiators.
2627# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2628# other initiators and will attempt to PLOGI all remote ports.
2629# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2630# remote ports and will not attempt to PLOGI to other initiators.
2631# This parameter does not restrict to the physical port.
2632# This parameter does not restrict logins to Fabric resident remote ports.
2633# Default value of this parameter is 1.
2634*/
James Smart3de2a652007-08-02 11:09:59 -04002635static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002636module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002637MODULE_PARM_DESC(lpfc_restrict_login,
2638 "Restrict virtual ports login to remote initiators.");
2639lpfc_vport_param_show(restrict_login);
2640
James Smarte59058c2008-08-24 21:49:00 -04002641/**
James Smart3621a712009-04-06 18:47:14 -04002642 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002643 * @vport: lpfc vport structure pointer.
2644 * @val: contains the restrict login value.
2645 *
2646 * Description:
2647 * If val is not in a valid range then log a kernel error message and set
2648 * the vport restrict login to one.
2649 * If the port type is physical clear the restrict login flag and return.
2650 * Else set the restrict login flag to val.
2651 *
2652 * Returns:
2653 * zero if val is in range
2654 * -EINVAL val out of range
2655 **/
James Smart3de2a652007-08-02 11:09:59 -04002656static int
2657lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2658{
2659 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002660 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002661 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002662 "be set to %d, allowed range is [0, 1]\n",
2663 val);
James Smart3de2a652007-08-02 11:09:59 -04002664 vport->cfg_restrict_login = 1;
2665 return -EINVAL;
2666 }
2667 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2668 vport->cfg_restrict_login = 0;
2669 return 0;
2670 }
2671 vport->cfg_restrict_login = val;
2672 return 0;
2673}
2674
James Smarte59058c2008-08-24 21:49:00 -04002675/**
James Smart3621a712009-04-06 18:47:14 -04002676 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002677 * @vport: lpfc vport structure pointer.
2678 * @val: contains the restrict login value.
2679 *
2680 * Description:
2681 * If val is not in a valid range then log a kernel error message and set
2682 * the vport restrict login to one.
2683 * If the port type is physical and the val is not zero log a kernel
2684 * error message, clear the restrict login flag and return zero.
2685 * Else set the restrict login flag to val.
2686 *
2687 * Returns:
2688 * zero if val is in range
2689 * -EINVAL val out of range
2690 **/
James Smart3de2a652007-08-02 11:09:59 -04002691static int
2692lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2693{
2694 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002695 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002696 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002697 "be set to %d, allowed range is [0, 1]\n",
2698 val);
James Smart3de2a652007-08-02 11:09:59 -04002699 vport->cfg_restrict_login = 1;
2700 return -EINVAL;
2701 }
2702 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002703 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2704 "0468 lpfc_restrict_login must be 0 for "
2705 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002706 vport->cfg_restrict_login = 0;
2707 return 0;
2708 }
2709 vport->cfg_restrict_login = val;
2710 return 0;
2711}
2712lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002713static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2714 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002715
2716/*
dea31012005-04-17 16:05:31 -05002717# Some disk devices have a "select ID" or "select Target" capability.
2718# From a protocol standpoint "select ID" usually means select the
2719# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2720# annex" which contains a table that maps a "select ID" (a number
2721# between 0 and 7F) to an ALPA. By default, for compatibility with
2722# older drivers, the lpfc driver scans this table from low ALPA to high
2723# ALPA.
2724#
2725# Turning on the scan-down variable (on = 1, off = 0) will
2726# cause the lpfc driver to use an inverted table, effectively
2727# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2728#
2729# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2730# and will not work across a fabric. Also this parameter will take
2731# effect only in the case when ALPA map is not available.)
2732*/
James Smart3de2a652007-08-02 11:09:59 -04002733LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2734 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002735
2736/*
dea31012005-04-17 16:05:31 -05002737# lpfc_topology: link topology for init link
2738# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002739# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002740# 0x02 = attempt point-to-point mode only
2741# 0x04 = attempt loop mode only
2742# 0x06 = attempt point-to-point mode then loop
2743# Set point-to-point mode if you want to run as an N_Port.
2744# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2745# Default value is 0.
2746*/
James Smarte59058c2008-08-24 21:49:00 -04002747
2748/**
James Smart3621a712009-04-06 18:47:14 -04002749 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002750 * @phba: lpfc_hba pointer.
2751 * @val: topology value.
2752 *
2753 * Description:
2754 * If val is in a valid range then set the adapter's topology field and
2755 * issue a lip; if the lip fails reset the topology to the old value.
2756 *
2757 * If the value is not in range log a kernel error message and return an error.
2758 *
2759 * Returns:
2760 * zero if val is in range and lip okay
2761 * non-zero return value from lpfc_issue_lip()
2762 * -EINVAL val out of range
2763 **/
James Smarta257bf92009-04-06 18:48:10 -04002764static ssize_t
2765lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2766 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002767{
James Smarta257bf92009-04-06 18:48:10 -04002768 struct Scsi_Host *shost = class_to_shost(dev);
2769 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2770 struct lpfc_hba *phba = vport->phba;
2771 int val = 0;
2772 int nolip = 0;
2773 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002774 int err;
2775 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002776
2777 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2778 nolip = 1;
2779 val_buf = &buf[strlen("nolip ")];
2780 }
2781
2782 if (!isdigit(val_buf[0]))
2783 return -EINVAL;
2784 if (sscanf(val_buf, "%i", &val) != 1)
2785 return -EINVAL;
2786
James Smart83108bd2008-01-11 01:53:09 -05002787 if (val >= 0 && val <= 6) {
2788 prev_val = phba->cfg_topology;
2789 phba->cfg_topology = val;
James Smartff78d8f2011-12-13 13:21:35 -05002790 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
2791 val == 4) {
2792 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2793 "3113 Loop mode not supported at speed %d\n",
2794 phba->cfg_link_speed);
2795 phba->cfg_topology = prev_val;
2796 return -EINVAL;
2797 }
James Smarta257bf92009-04-06 18:48:10 -04002798 if (nolip)
2799 return strlen(buf);
2800
James Smart88a2cfb2011-07-22 18:36:33 -04002801 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2802 "3054 lpfc_topology changed from %d to %d\n",
2803 prev_val, val);
James Smart83108bd2008-01-11 01:53:09 -05002804 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002805 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002806 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002807 return -EINVAL;
2808 } else
2809 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002810 }
2811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2812 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2813 "allowed range is [0, 6]\n",
2814 phba->brd_no, val);
2815 return -EINVAL;
2816}
2817static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002818module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002819MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2820lpfc_param_show(topology)
2821lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002822static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002823 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002824
James Smart21e9a0a2009-05-22 14:53:21 -04002825/**
2826 * lpfc_static_vport_show: Read callback function for
2827 * lpfc_static_vport sysfs file.
2828 * @dev: Pointer to class device object.
2829 * @attr: device attribute structure.
2830 * @buf: Data buffer.
2831 *
2832 * This function is the read call back function for
2833 * lpfc_static_vport sysfs file. The lpfc_static_vport
2834 * sysfs file report the mageability of the vport.
2835 **/
2836static ssize_t
2837lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2838 char *buf)
2839{
2840 struct Scsi_Host *shost = class_to_shost(dev);
2841 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2842 if (vport->vport_flag & STATIC_VPORT)
2843 sprintf(buf, "1\n");
2844 else
2845 sprintf(buf, "0\n");
2846
2847 return strlen(buf);
2848}
2849
2850/*
2851 * Sysfs attribute to control the statistical data collection.
2852 */
2853static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2854 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002855
2856/**
James Smart3621a712009-04-06 18:47:14 -04002857 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002858 * @dev: Pointer to class device.
2859 * @buf: Data buffer.
2860 * @count: Size of the data buffer.
2861 *
2862 * This function get called when an user write to the lpfc_stat_data_ctrl
2863 * sysfs file. This function parse the command written to the sysfs file
2864 * and take appropriate action. These commands are used for controlling
2865 * driver statistical data collection.
2866 * Following are the command this function handles.
2867 *
2868 * setbucket <bucket_type> <base> <step>
2869 * = Set the latency buckets.
2870 * destroybucket = destroy all the buckets.
2871 * start = start data collection
2872 * stop = stop data collection
2873 * reset = reset the collected data
2874 **/
2875static ssize_t
2876lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2877 const char *buf, size_t count)
2878{
2879 struct Scsi_Host *shost = class_to_shost(dev);
2880 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2881 struct lpfc_hba *phba = vport->phba;
2882#define LPFC_MAX_DATA_CTRL_LEN 1024
2883 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2884 unsigned long i;
2885 char *str_ptr, *token;
2886 struct lpfc_vport **vports;
2887 struct Scsi_Host *v_shost;
2888 char *bucket_type_str, *base_str, *step_str;
2889 unsigned long base, step, bucket_type;
2890
2891 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002892 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002893 return -EINVAL;
2894
2895 strcpy(bucket_data, buf);
2896 str_ptr = &bucket_data[0];
2897 /* Ignore this token - this is command token */
2898 token = strsep(&str_ptr, "\t ");
2899 if (!token)
2900 return -EINVAL;
2901
2902 bucket_type_str = strsep(&str_ptr, "\t ");
2903 if (!bucket_type_str)
2904 return -EINVAL;
2905
2906 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2907 bucket_type = LPFC_LINEAR_BUCKET;
2908 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2909 bucket_type = LPFC_POWER2_BUCKET;
2910 else
2911 return -EINVAL;
2912
2913 base_str = strsep(&str_ptr, "\t ");
2914 if (!base_str)
2915 return -EINVAL;
2916 base = simple_strtoul(base_str, NULL, 0);
2917
2918 step_str = strsep(&str_ptr, "\t ");
2919 if (!step_str)
2920 return -EINVAL;
2921 step = simple_strtoul(step_str, NULL, 0);
2922 if (!step)
2923 return -EINVAL;
2924
2925 /* Block the data collection for every vport */
2926 vports = lpfc_create_vport_work_array(phba);
2927 if (vports == NULL)
2928 return -ENOMEM;
2929
James Smartf4b4c682009-05-22 14:53:12 -04002930 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002931 v_shost = lpfc_shost_from_vport(vports[i]);
2932 spin_lock_irq(v_shost->host_lock);
2933 /* Block and reset data collection */
2934 vports[i]->stat_data_blocked = 1;
2935 if (vports[i]->stat_data_enabled)
2936 lpfc_vport_reset_stat_data(vports[i]);
2937 spin_unlock_irq(v_shost->host_lock);
2938 }
2939
2940 /* Set the bucket attributes */
2941 phba->bucket_type = bucket_type;
2942 phba->bucket_base = base;
2943 phba->bucket_step = step;
2944
James Smartf4b4c682009-05-22 14:53:12 -04002945 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002946 v_shost = lpfc_shost_from_vport(vports[i]);
2947
2948 /* Unblock data collection */
2949 spin_lock_irq(v_shost->host_lock);
2950 vports[i]->stat_data_blocked = 0;
2951 spin_unlock_irq(v_shost->host_lock);
2952 }
2953 lpfc_destroy_vport_work_array(phba, vports);
2954 return strlen(buf);
2955 }
2956
2957 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2958 vports = lpfc_create_vport_work_array(phba);
2959 if (vports == NULL)
2960 return -ENOMEM;
2961
James Smartf4b4c682009-05-22 14:53:12 -04002962 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002963 v_shost = lpfc_shost_from_vport(vports[i]);
2964 spin_lock_irq(shost->host_lock);
2965 vports[i]->stat_data_blocked = 1;
2966 lpfc_free_bucket(vport);
2967 vport->stat_data_enabled = 0;
2968 vports[i]->stat_data_blocked = 0;
2969 spin_unlock_irq(shost->host_lock);
2970 }
2971 lpfc_destroy_vport_work_array(phba, vports);
2972 phba->bucket_type = LPFC_NO_BUCKET;
2973 phba->bucket_base = 0;
2974 phba->bucket_step = 0;
2975 return strlen(buf);
2976 }
2977
2978 if (!strncmp(buf, "start", strlen("start"))) {
2979 /* If no buckets configured return error */
2980 if (phba->bucket_type == LPFC_NO_BUCKET)
2981 return -EINVAL;
2982 spin_lock_irq(shost->host_lock);
2983 if (vport->stat_data_enabled) {
2984 spin_unlock_irq(shost->host_lock);
2985 return strlen(buf);
2986 }
2987 lpfc_alloc_bucket(vport);
2988 vport->stat_data_enabled = 1;
2989 spin_unlock_irq(shost->host_lock);
2990 return strlen(buf);
2991 }
2992
2993 if (!strncmp(buf, "stop", strlen("stop"))) {
2994 spin_lock_irq(shost->host_lock);
2995 if (vport->stat_data_enabled == 0) {
2996 spin_unlock_irq(shost->host_lock);
2997 return strlen(buf);
2998 }
2999 lpfc_free_bucket(vport);
3000 vport->stat_data_enabled = 0;
3001 spin_unlock_irq(shost->host_lock);
3002 return strlen(buf);
3003 }
3004
3005 if (!strncmp(buf, "reset", strlen("reset"))) {
3006 if ((phba->bucket_type == LPFC_NO_BUCKET)
3007 || !vport->stat_data_enabled)
3008 return strlen(buf);
3009 spin_lock_irq(shost->host_lock);
3010 vport->stat_data_blocked = 1;
3011 lpfc_vport_reset_stat_data(vport);
3012 vport->stat_data_blocked = 0;
3013 spin_unlock_irq(shost->host_lock);
3014 return strlen(buf);
3015 }
3016 return -EINVAL;
3017}
3018
3019
3020/**
James Smart3621a712009-04-06 18:47:14 -04003021 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003022 * @dev: Pointer to class device object.
3023 * @buf: Data buffer.
3024 *
3025 * This function is the read call back function for
3026 * lpfc_stat_data_ctrl sysfs file. This function report the
3027 * current statistical data collection state.
3028 **/
3029static ssize_t
3030lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3031 char *buf)
3032{
3033 struct Scsi_Host *shost = class_to_shost(dev);
3034 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3035 struct lpfc_hba *phba = vport->phba;
3036 int index = 0;
3037 int i;
3038 char *bucket_type;
3039 unsigned long bucket_value;
3040
3041 switch (phba->bucket_type) {
3042 case LPFC_LINEAR_BUCKET:
3043 bucket_type = "linear";
3044 break;
3045 case LPFC_POWER2_BUCKET:
3046 bucket_type = "power2";
3047 break;
3048 default:
3049 bucket_type = "No Bucket";
3050 break;
3051 }
3052
3053 sprintf(&buf[index], "Statistical Data enabled :%d, "
3054 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3055 " Bucket step :%d\nLatency Ranges :",
3056 vport->stat_data_enabled, vport->stat_data_blocked,
3057 bucket_type, phba->bucket_base, phba->bucket_step);
3058 index = strlen(buf);
3059 if (phba->bucket_type != LPFC_NO_BUCKET) {
3060 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3061 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3062 bucket_value = phba->bucket_base +
3063 phba->bucket_step * i;
3064 else
3065 bucket_value = phba->bucket_base +
3066 (1 << i) * phba->bucket_step;
3067
3068 if (index + 10 > PAGE_SIZE)
3069 break;
3070 sprintf(&buf[index], "%08ld ", bucket_value);
3071 index = strlen(buf);
3072 }
3073 }
3074 sprintf(&buf[index], "\n");
3075 return strlen(buf);
3076}
3077
3078/*
3079 * Sysfs attribute to control the statistical data collection.
3080 */
3081static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3082 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3083
3084/*
3085 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3086 */
3087
3088/*
3089 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3090 * for each target.
3091 */
3092#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3093#define MAX_STAT_DATA_SIZE_PER_TARGET \
3094 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3095
3096
3097/**
James Smart3621a712009-04-06 18:47:14 -04003098 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003099 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003100 * @kobj: Pointer to the kernel object
3101 * @bin_attr: Attribute object
3102 * @buff: Buffer pointer
3103 * @off: File offset
3104 * @count: Buffer size
3105 *
3106 * This function is the read call back function for lpfc_drvr_stat_data
3107 * sysfs file. This function export the statistical data to user
3108 * applications.
3109 **/
3110static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003111sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3112 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003113 char *buf, loff_t off, size_t count)
3114{
3115 struct device *dev = container_of(kobj, struct device,
3116 kobj);
3117 struct Scsi_Host *shost = class_to_shost(dev);
3118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3119 struct lpfc_hba *phba = vport->phba;
3120 int i = 0, index = 0;
3121 unsigned long nport_index;
3122 struct lpfc_nodelist *ndlp = NULL;
3123 nport_index = (unsigned long)off /
3124 MAX_STAT_DATA_SIZE_PER_TARGET;
3125
3126 if (!vport->stat_data_enabled || vport->stat_data_blocked
3127 || (phba->bucket_type == LPFC_NO_BUCKET))
3128 return 0;
3129
3130 spin_lock_irq(shost->host_lock);
3131 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3132 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3133 continue;
3134
3135 if (nport_index > 0) {
3136 nport_index--;
3137 continue;
3138 }
3139
3140 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3141 > count)
3142 break;
3143
3144 if (!ndlp->lat_data)
3145 continue;
3146
3147 /* Print the WWN */
3148 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3149 ndlp->nlp_portname.u.wwn[0],
3150 ndlp->nlp_portname.u.wwn[1],
3151 ndlp->nlp_portname.u.wwn[2],
3152 ndlp->nlp_portname.u.wwn[3],
3153 ndlp->nlp_portname.u.wwn[4],
3154 ndlp->nlp_portname.u.wwn[5],
3155 ndlp->nlp_portname.u.wwn[6],
3156 ndlp->nlp_portname.u.wwn[7]);
3157
3158 index = strlen(buf);
3159
3160 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3161 sprintf(&buf[index], "%010u,",
3162 ndlp->lat_data[i].cmd_count);
3163 index = strlen(buf);
3164 }
3165 sprintf(&buf[index], "\n");
3166 index = strlen(buf);
3167 }
3168 spin_unlock_irq(shost->host_lock);
3169 return index;
3170}
3171
3172static struct bin_attribute sysfs_drvr_stat_data_attr = {
3173 .attr = {
3174 .name = "lpfc_drvr_stat_data",
3175 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003176 },
3177 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3178 .read = sysfs_drvr_stat_data_read,
3179 .write = NULL,
3180};
3181
dea31012005-04-17 16:05:31 -05003182/*
3183# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3184# connection.
James Smart76a95d72010-11-20 23:11:48 -05003185# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003186*/
James Smarte59058c2008-08-24 21:49:00 -04003187/**
James Smart3621a712009-04-06 18:47:14 -04003188 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003189 * @phba: lpfc_hba pointer.
3190 * @val: link speed value.
3191 *
3192 * Description:
3193 * If val is in a valid range then set the adapter's link speed field and
3194 * issue a lip; if the lip fails reset the link speed to the old value.
3195 *
3196 * Notes:
3197 * If the value is not in range log a kernel error message and return an error.
3198 *
3199 * Returns:
3200 * zero if val is in range and lip okay.
3201 * non-zero return value from lpfc_issue_lip()
3202 * -EINVAL val out of range
3203 **/
James Smarta257bf92009-04-06 18:48:10 -04003204static ssize_t
3205lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3206 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003207{
James Smarta257bf92009-04-06 18:48:10 -04003208 struct Scsi_Host *shost = class_to_shost(dev);
3209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3210 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003211 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003212 int nolip = 0;
3213 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003214 int err;
3215 uint32_t prev_val;
3216
James Smarta257bf92009-04-06 18:48:10 -04003217 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3218 nolip = 1;
3219 val_buf = &buf[strlen("nolip ")];
3220 }
3221
3222 if (!isdigit(val_buf[0]))
3223 return -EINVAL;
3224 if (sscanf(val_buf, "%i", &val) != 1)
3225 return -EINVAL;
3226
James Smart88a2cfb2011-07-22 18:36:33 -04003227 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3228 "3055 lpfc_link_speed changed from %d to %d %s\n",
3229 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3230
James Smart76a95d72010-11-20 23:11:48 -05003231 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3232 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3233 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3234 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3235 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3236 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3238 "2879 lpfc_link_speed attribute cannot be set "
3239 "to %d. Speed is not supported by this port.\n",
3240 val);
James Smart83108bd2008-01-11 01:53:09 -05003241 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003242 }
James Smartff78d8f2011-12-13 13:21:35 -05003243 if (val == LPFC_USER_LINK_SPEED_16G &&
3244 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3245 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3246 "3112 lpfc_link_speed attribute cannot be set "
3247 "to %d. Speed is not supported in loop mode.\n",
3248 val);
3249 return -EINVAL;
3250 }
James Smart76a95d72010-11-20 23:11:48 -05003251 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3252 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003253 prev_val = phba->cfg_link_speed;
3254 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003255 if (nolip)
3256 return strlen(buf);
3257
James Smart83108bd2008-01-11 01:53:09 -05003258 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003259 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003260 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003261 return -EINVAL;
3262 } else
3263 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003264 }
James Smart83108bd2008-01-11 01:53:09 -05003265 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003266 "0469 lpfc_link_speed attribute cannot be set to %d, "
3267 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003268 return -EINVAL;
3269}
3270
3271static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003272module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003273MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3274lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003275
3276/**
James Smart3621a712009-04-06 18:47:14 -04003277 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003278 * @phba: lpfc_hba pointer.
3279 * @val: link speed value.
3280 *
3281 * Description:
3282 * If val is in a valid range then set the adapter's link speed field.
3283 *
3284 * Notes:
3285 * If the value is not in range log a kernel error message, clear the link
3286 * speed and return an error.
3287 *
3288 * Returns:
3289 * zero if val saved.
3290 * -EINVAL val out of range
3291 **/
James Smart83108bd2008-01-11 01:53:09 -05003292static int
3293lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3294{
James Smartff78d8f2011-12-13 13:21:35 -05003295 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3297 "3111 lpfc_link_speed of %d cannot "
3298 "support loop mode, setting topology to default.\n",
3299 val);
3300 phba->cfg_topology = 0;
3301 }
James Smart76a95d72010-11-20 23:11:48 -05003302 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3303 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003304 phba->cfg_link_speed = val;
3305 return 0;
3306 }
3307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003308 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003309 "be set to %d, allowed values are "
3310 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003311 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003312 return -EINVAL;
3313}
3314
Tony Jonesee959b02008-02-22 00:13:36 +01003315static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003316 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003317
3318/*
James Smart0d878412009-10-02 15:16:56 -04003319# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3320# 0 = aer disabled or not supported
3321# 1 = aer supported and enabled (default)
3322# Value range is [0,1]. Default value is 1.
3323*/
3324
3325/**
3326 * lpfc_aer_support_store - Set the adapter for aer support
3327 *
3328 * @dev: class device that is converted into a Scsi_host.
3329 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003330 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003331 * @count: unused variable.
3332 *
3333 * Description:
3334 * If the val is 1 and currently the device's AER capability was not
3335 * enabled, invoke the kernel's enable AER helper routine, trying to
3336 * enable the device's AER capability. If the helper routine enabling
3337 * AER returns success, update the device's cfg_aer_support flag to
3338 * indicate AER is supported by the device; otherwise, if the device
3339 * AER capability is already enabled to support AER, then do nothing.
3340 *
3341 * If the val is 0 and currently the device's AER support was enabled,
3342 * invoke the kernel's disable AER helper routine. After that, update
3343 * the device's cfg_aer_support flag to indicate AER is not supported
3344 * by the device; otherwise, if the device AER capability is already
3345 * disabled from supporting AER, then do nothing.
3346 *
3347 * Returns:
3348 * length of the buf on success if val is in range the intended mode
3349 * is supported.
3350 * -EINVAL if val out of range or intended mode is not supported.
3351 **/
3352static ssize_t
3353lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3354 const char *buf, size_t count)
3355{
3356 struct Scsi_Host *shost = class_to_shost(dev);
3357 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3358 struct lpfc_hba *phba = vport->phba;
3359 int val = 0, rc = -EINVAL;
3360
3361 if (!isdigit(buf[0]))
3362 return -EINVAL;
3363 if (sscanf(buf, "%i", &val) != 1)
3364 return -EINVAL;
3365
3366 switch (val) {
3367 case 0:
3368 if (phba->hba_flag & HBA_AER_ENABLED) {
3369 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3370 if (!rc) {
3371 spin_lock_irq(&phba->hbalock);
3372 phba->hba_flag &= ~HBA_AER_ENABLED;
3373 spin_unlock_irq(&phba->hbalock);
3374 phba->cfg_aer_support = 0;
3375 rc = strlen(buf);
3376 } else
James Smart891478a2009-11-18 15:40:23 -05003377 rc = -EPERM;
3378 } else {
James Smart0d878412009-10-02 15:16:56 -04003379 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003380 rc = strlen(buf);
3381 }
James Smart0d878412009-10-02 15:16:56 -04003382 break;
3383 case 1:
3384 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3385 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3386 if (!rc) {
3387 spin_lock_irq(&phba->hbalock);
3388 phba->hba_flag |= HBA_AER_ENABLED;
3389 spin_unlock_irq(&phba->hbalock);
3390 phba->cfg_aer_support = 1;
3391 rc = strlen(buf);
3392 } else
James Smart891478a2009-11-18 15:40:23 -05003393 rc = -EPERM;
3394 } else {
James Smart0d878412009-10-02 15:16:56 -04003395 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003396 rc = strlen(buf);
3397 }
James Smart0d878412009-10-02 15:16:56 -04003398 break;
3399 default:
3400 rc = -EINVAL;
3401 break;
3402 }
3403 return rc;
3404}
3405
3406static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003407module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003408MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3409lpfc_param_show(aer_support)
3410
3411/**
3412 * lpfc_aer_support_init - Set the initial adapters aer support flag
3413 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003414 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003415 *
3416 * Description:
3417 * If val is in a valid range [0,1], then set the adapter's initial
3418 * cfg_aer_support field. It will be up to the driver's probe_one
3419 * routine to determine whether the device's AER support can be set
3420 * or not.
3421 *
3422 * Notes:
3423 * If the value is not in range log a kernel error message, and
3424 * choose the default value of setting AER support and return.
3425 *
3426 * Returns:
3427 * zero if val saved.
3428 * -EINVAL val out of range
3429 **/
3430static int
3431lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3432{
3433 if (val == 0 || val == 1) {
3434 phba->cfg_aer_support = val;
3435 return 0;
3436 }
3437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3438 "2712 lpfc_aer_support attribute value %d out "
3439 "of range, allowed values are 0|1, setting it "
3440 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003441 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003442 phba->cfg_aer_support = 1;
3443 return -EINVAL;
3444}
3445
3446static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3447 lpfc_aer_support_show, lpfc_aer_support_store);
3448
3449/**
3450 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3451 * @dev: class device that is converted into a Scsi_host.
3452 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003453 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003454 * @count: unused variable.
3455 *
3456 * Description:
3457 * If the @buf contains 1 and the device currently has the AER support
3458 * enabled, then invokes the kernel AER helper routine
3459 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3460 * error status register.
3461 *
3462 * Notes:
3463 *
3464 * Returns:
3465 * -EINVAL if the buf does not contain the 1 or the device is not currently
3466 * enabled with the AER support.
3467 **/
3468static ssize_t
3469lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3470 const char *buf, size_t count)
3471{
3472 struct Scsi_Host *shost = class_to_shost(dev);
3473 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3474 struct lpfc_hba *phba = vport->phba;
3475 int val, rc = -1;
3476
3477 if (!isdigit(buf[0]))
3478 return -EINVAL;
3479 if (sscanf(buf, "%i", &val) != 1)
3480 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003481 if (val != 1)
3482 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003483
James Smart891478a2009-11-18 15:40:23 -05003484 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003485 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3486
3487 if (rc == 0)
3488 return strlen(buf);
3489 else
James Smart891478a2009-11-18 15:40:23 -05003490 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003491}
3492
3493static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3494 lpfc_aer_cleanup_state);
3495
James Smart912e3ac2011-05-24 11:42:11 -04003496/**
3497 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3498 *
3499 * @dev: class device that is converted into a Scsi_host.
3500 * @attr: device attribute, not used.
3501 * @buf: containing the string the number of vfs to be enabled.
3502 * @count: unused variable.
3503 *
3504 * Description:
3505 * When this api is called either through user sysfs, the driver shall
3506 * try to enable or disable SR-IOV virtual functions according to the
3507 * following:
3508 *
3509 * If zero virtual function has been enabled to the physical function,
3510 * the driver shall invoke the pci enable virtual function api trying
3511 * to enable the virtual functions. If the nr_vfn provided is greater
3512 * than the maximum supported, the maximum virtual function number will
3513 * be used for invoking the api; otherwise, the nr_vfn provided shall
3514 * be used for invoking the api. If the api call returned success, the
3515 * actual number of virtual functions enabled will be set to the driver
3516 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3517 * cfg_sriov_nr_virtfn remains zero.
3518 *
3519 * If none-zero virtual functions have already been enabled to the
3520 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3521 * -EINVAL will be returned and the driver does nothing;
3522 *
3523 * If the nr_vfn provided is zero and none-zero virtual functions have
3524 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3525 * disabling virtual function api shall be invoded to disable all the
3526 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3527 * zero. Otherwise, if zero virtual function has been enabled, do
3528 * nothing.
3529 *
3530 * Returns:
3531 * length of the buf on success if val is in range the intended mode
3532 * is supported.
3533 * -EINVAL if val out of range or intended mode is not supported.
3534 **/
3535static ssize_t
3536lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3537 const char *buf, size_t count)
3538{
3539 struct Scsi_Host *shost = class_to_shost(dev);
3540 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3541 struct lpfc_hba *phba = vport->phba;
3542 struct pci_dev *pdev = phba->pcidev;
3543 int val = 0, rc = -EINVAL;
3544
3545 /* Sanity check on user data */
3546 if (!isdigit(buf[0]))
3547 return -EINVAL;
3548 if (sscanf(buf, "%i", &val) != 1)
3549 return -EINVAL;
3550 if (val < 0)
3551 return -EINVAL;
3552
3553 /* Request disabling virtual functions */
3554 if (val == 0) {
3555 if (phba->cfg_sriov_nr_virtfn > 0) {
3556 pci_disable_sriov(pdev);
3557 phba->cfg_sriov_nr_virtfn = 0;
3558 }
3559 return strlen(buf);
3560 }
3561
3562 /* Request enabling virtual functions */
3563 if (phba->cfg_sriov_nr_virtfn > 0) {
3564 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3565 "3018 There are %d virtual functions "
3566 "enabled on physical function.\n",
3567 phba->cfg_sriov_nr_virtfn);
3568 return -EEXIST;
3569 }
3570
3571 if (val <= LPFC_MAX_VFN_PER_PFN)
3572 phba->cfg_sriov_nr_virtfn = val;
3573 else {
3574 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3575 "3019 Enabling %d virtual functions is not "
3576 "allowed.\n", val);
3577 return -EINVAL;
3578 }
3579
3580 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3581 if (rc) {
3582 phba->cfg_sriov_nr_virtfn = 0;
3583 rc = -EPERM;
3584 } else
3585 rc = strlen(buf);
3586
3587 return rc;
3588}
3589
3590static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3591module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3592MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3593lpfc_param_show(sriov_nr_virtfn)
3594
3595/**
3596 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3597 * @phba: lpfc_hba pointer.
3598 * @val: link speed value.
3599 *
3600 * Description:
3601 * If val is in a valid range [0,255], then set the adapter's initial
3602 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3603 * number shall be used instead. It will be up to the driver's probe_one
3604 * routine to determine whether the device's SR-IOV is supported or not.
3605 *
3606 * Returns:
3607 * zero if val saved.
3608 * -EINVAL val out of range
3609 **/
3610static int
3611lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3612{
3613 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3614 phba->cfg_sriov_nr_virtfn = val;
3615 return 0;
3616 }
3617
3618 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3619 "3017 Enabling %d virtual functions is not "
3620 "allowed.\n", val);
3621 return -EINVAL;
3622}
3623static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3624 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3625
James Smart173edbb2012-06-12 13:54:50 -04003626/**
James Smartc71ab862012-10-31 14:44:33 -04003627 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
3628 *
3629 * @dev: class device that is converted into a Scsi_host.
3630 * @attr: device attribute, not used.
3631 * @buf: containing the string the number of vfs to be enabled.
3632 * @count: unused variable.
3633 *
3634 * Description:
3635 *
3636 * Returns:
3637 * length of the buf on success if val is in range the intended mode
3638 * is supported.
3639 * -EINVAL if val out of range or intended mode is not supported.
3640 **/
3641static ssize_t
3642lpfc_request_firmware_upgrade_store(struct device *dev,
3643 struct device_attribute *attr,
3644 const char *buf, size_t count)
3645{
3646 struct Scsi_Host *shost = class_to_shost(dev);
3647 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3648 struct lpfc_hba *phba = vport->phba;
3649 int val = 0, rc = -EINVAL;
3650
3651 /* Sanity check on user data */
3652 if (!isdigit(buf[0]))
3653 return -EINVAL;
3654 if (sscanf(buf, "%i", &val) != 1)
3655 return -EINVAL;
3656 if (val != 1)
3657 return -EINVAL;
3658
3659 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
3660 if (rc)
3661 rc = -EPERM;
3662 else
3663 rc = strlen(buf);
3664 return rc;
3665}
3666
3667static int lpfc_req_fw_upgrade;
3668module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
3669MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
3670lpfc_param_show(request_firmware_upgrade)
3671
3672/**
3673 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
3674 * @phba: lpfc_hba pointer.
3675 * @val: 0 or 1.
3676 *
3677 * Description:
3678 * Set the initial Linux generic firmware upgrade enable or disable flag.
3679 *
3680 * Returns:
3681 * zero if val saved.
3682 * -EINVAL val out of range
3683 **/
3684static int
3685lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
3686{
3687 if (val >= 0 && val <= 1) {
3688 phba->cfg_request_firmware_upgrade = val;
3689 return 0;
3690 }
3691 return -EINVAL;
3692}
3693static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
3694 lpfc_request_firmware_upgrade_show,
3695 lpfc_request_firmware_upgrade_store);
3696
3697/**
James Smart173edbb2012-06-12 13:54:50 -04003698 * lpfc_fcp_imax_store
3699 *
3700 * @dev: class device that is converted into a Scsi_host.
3701 * @attr: device attribute, not used.
3702 * @buf: string with the number of fast-path FCP interrupts per second.
3703 * @count: unused variable.
3704 *
3705 * Description:
3706 * If val is in a valid range [636,651042], then set the adapter's
3707 * maximum number of fast-path FCP interrupts per second.
3708 *
3709 * Returns:
3710 * length of the buf on success if val is in range the intended mode
3711 * is supported.
3712 * -EINVAL if val out of range or intended mode is not supported.
3713 **/
3714static ssize_t
3715lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
3716 const char *buf, size_t count)
3717{
3718 struct Scsi_Host *shost = class_to_shost(dev);
3719 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3720 struct lpfc_hba *phba = vport->phba;
3721 int val = 0, i;
3722
James Smartbf8dae82012-08-03 12:36:24 -04003723 /* fcp_imax is only valid for SLI4 */
3724 if (phba->sli_rev != LPFC_SLI_REV4)
3725 return -EINVAL;
3726
James Smart173edbb2012-06-12 13:54:50 -04003727 /* Sanity check on user data */
3728 if (!isdigit(buf[0]))
3729 return -EINVAL;
3730 if (sscanf(buf, "%i", &val) != 1)
3731 return -EINVAL;
3732
James Smartbf8dae82012-08-03 12:36:24 -04003733 /*
3734 * Value range for the HBA is [5000,5000000]
3735 * The value for each EQ depends on how many EQs are configured.
3736 */
3737 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
James Smart173edbb2012-06-12 13:54:50 -04003738 return -EINVAL;
3739
3740 phba->cfg_fcp_imax = (uint32_t)val;
James Smart67d12732012-08-03 12:36:13 -04003741 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
James Smart173edbb2012-06-12 13:54:50 -04003742 lpfc_modify_fcp_eq_delay(phba, i);
3743
3744 return strlen(buf);
3745}
3746
3747/*
3748# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04003749# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04003750#
James Smartbf8dae82012-08-03 12:36:24 -04003751# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04003752*/
James Smartbf8dae82012-08-03 12:36:24 -04003753static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003754module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
3755MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04003756 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04003757lpfc_param_show(fcp_imax)
3758
3759/**
3760 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
3761 * @phba: lpfc_hba pointer.
3762 * @val: link speed value.
3763 *
3764 * Description:
3765 * If val is in a valid range [636,651042], then initialize the adapter's
3766 * maximum number of fast-path FCP interrupts per second.
3767 *
3768 * Returns:
3769 * zero if val saved.
3770 * -EINVAL val out of range
3771 **/
3772static int
3773lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
3774{
James Smartbf8dae82012-08-03 12:36:24 -04003775 if (phba->sli_rev != LPFC_SLI_REV4) {
3776 phba->cfg_fcp_imax = 0;
3777 return 0;
3778 }
3779
3780 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
James Smart173edbb2012-06-12 13:54:50 -04003781 phba->cfg_fcp_imax = val;
3782 return 0;
3783 }
3784
3785 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3786 "3016 fcp_imax: %d out of range, using default\n", val);
James Smartbf8dae82012-08-03 12:36:24 -04003787 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04003788
3789 return 0;
3790}
3791
3792static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
3793 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
3794
James Smart0d878412009-10-02 15:16:56 -04003795/*
dea31012005-04-17 16:05:31 -05003796# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3797# Value range is [2,3]. Default value is 3.
3798*/
James Smart3de2a652007-08-02 11:09:59 -04003799LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3800 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003801
3802/*
3803# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3804# is [0,1]. Default value is 0.
3805*/
James Smart3de2a652007-08-02 11:09:59 -04003806LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3807 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003808
3809/*
James Smart977b5a02008-09-07 11:52:04 -04003810# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3811# depth. Default value is 0. When the value of this parameter is zero the
3812# SCSI command completion time is not used for controlling I/O queue depth. When
3813# the parameter is set to a non-zero value, the I/O queue depth is controlled
3814# to limit the I/O completion time to the parameter value.
3815# The value is set in milliseconds.
3816*/
3817static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003818module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003819MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3820 "Use command completion time to control queue depth");
3821lpfc_vport_param_show(max_scsicmpl_time);
3822lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3823static int
3824lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3825{
3826 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3827 struct lpfc_nodelist *ndlp, *next_ndlp;
3828
3829 if (val == vport->cfg_max_scsicmpl_time)
3830 return 0;
3831 if ((val < 0) || (val > 60000))
3832 return -EINVAL;
3833 vport->cfg_max_scsicmpl_time = val;
3834
3835 spin_lock_irq(shost->host_lock);
3836 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3837 if (!NLP_CHK_NODE_ACT(ndlp))
3838 continue;
3839 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3840 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003841 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003842 }
3843 spin_unlock_irq(shost->host_lock);
3844 return 0;
3845}
3846lpfc_vport_param_store(max_scsicmpl_time);
3847static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3848 lpfc_max_scsicmpl_time_show,
3849 lpfc_max_scsicmpl_time_store);
3850
3851/*
dea31012005-04-17 16:05:31 -05003852# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3853# range is [0,1]. Default value is 0.
3854*/
3855LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3856
3857/*
James Smart49aa1432012-08-03 12:36:42 -04003858# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
3859# range is [0,1]. Default value is 0.
3860# For [0], FCP commands are issued to Work Queues ina round robin fashion.
3861# For [1], FCP commands are issued to a Work Queue associated with the
3862# current CPU.
3863*/
3864LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algrithmn for "
3865 "issuing commands [0] - Round Robin, [1] - Current CPU");
3866
3867/*
James Smarta6571c62012-10-31 14:44:42 -04003868# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
3869# range is [0,1]. Default value is 0.
3870# For [0], bus reset issues target reset to ALL devices
3871# For [1], bus reset issues target reset to non-FCP2 devices
3872*/
3873LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
3874 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
3875
3876
3877/*
dea31012005-04-17 16:05:31 -05003878# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3879# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003880# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003881# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3882# cr_delay is set to 0.
3883*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003884LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003885 "interrupt response is generated");
3886
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003887LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003888 "interrupt response is generated");
3889
3890/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003891# lpfc_multi_ring_support: Determines how many rings to spread available
3892# cmd/rsp IOCB entries across.
3893# Value range is [1,2]. Default value is 1.
3894*/
3895LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3896 "SLI rings to spread IOCB entries across");
3897
3898/*
James Smarta4bc3372006-12-02 13:34:16 -05003899# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3900# identifies what rctl value to configure the additional ring for.
3901# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3902*/
James Smart6a9c52c2009-10-02 15:16:51 -04003903LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003904 255, "Identifies RCTL for additional ring configuration");
3905
3906/*
3907# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3908# identifies what type value to configure the additional ring for.
3909# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3910*/
James Smart6a9c52c2009-10-02 15:16:51 -04003911LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003912 255, "Identifies TYPE for additional ring configuration");
3913
3914/*
dea31012005-04-17 16:05:31 -05003915# lpfc_fdmi_on: controls FDMI support.
3916# 0 = no FDMI support
3917# 1 = support FDMI without attribute of hostname
3918# 2 = support FDMI with attribute of hostname
3919# Value range [0,2]. Default value is 0.
3920*/
James Smart3de2a652007-08-02 11:09:59 -04003921LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003922
3923/*
3924# Specifies the maximum number of ELS cmds we can have outstanding (for
3925# discovery). Value range is [1,64]. Default value = 32.
3926*/
James Smart3de2a652007-08-02 11:09:59 -04003927LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003928 "during discovery");
3929
3930/*
James Smart65a29c12006-07-06 15:50:50 -04003931# lpfc_max_luns: maximum allowed LUN.
3932# Value range is [0,65535]. Default value is 255.
3933# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003934*/
James Smart3de2a652007-08-02 11:09:59 -04003935LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003936
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003937/*
3938# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3939# Value range is [1,255], default value is 10.
3940*/
3941LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3942 "Milliseconds driver will wait between polling FCP ring");
3943
James Smart4ff43242006-12-02 13:34:56 -05003944/*
3945# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3946# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003947# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003948# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003949# 2 = MSI-X enabled (default)
3950# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003951*/
George Kadianakis8605c462010-01-17 21:19:31 +02003952LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003953 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003954
James Smart13815c82008-01-11 01:52:48 -05003955/*
James Smartda0436e2009-05-22 14:51:39 -04003956# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
James Smart67d12732012-08-03 12:36:13 -04003957# This parameter is ignored and will eventually be depricated
James Smartda0436e2009-05-22 14:51:39 -04003958#
James Smart67d12732012-08-03 12:36:13 -04003959# Value range is [1,7]. Default value is 4.
James Smartda0436e2009-05-22 14:51:39 -04003960*/
James Smart67d12732012-08-03 12:36:13 -04003961LPFC_ATTR_R(fcp_wq_count, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
3962 LPFC_FCP_IO_CHAN_MAX,
James Smartda0436e2009-05-22 14:51:39 -04003963 "Set the number of fast-path FCP work queues, if possible");
3964
3965/*
James Smart67d12732012-08-03 12:36:13 -04003966# lpfc_fcp_eq_count: Set the number of FCP EQ/CQ/WQ IO channels
James Smartda0436e2009-05-22 14:51:39 -04003967#
James Smart67d12732012-08-03 12:36:13 -04003968# Value range is [1,7]. Default value is 4.
James Smartda0436e2009-05-22 14:51:39 -04003969*/
James Smart67d12732012-08-03 12:36:13 -04003970LPFC_ATTR_R(fcp_eq_count, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
3971 LPFC_FCP_IO_CHAN_MAX,
James Smartda0436e2009-05-22 14:51:39 -04003972 "Set the number of fast-path FCP event queues, if possible");
3973
3974/*
James Smart67d12732012-08-03 12:36:13 -04003975# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
3976#
3977# Value range is [1,7]. Default value is 4.
3978*/
3979LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
3980 LPFC_FCP_IO_CHAN_MAX,
3981 "Set the number of FCP I/O channels");
3982
3983/*
James Smart13815c82008-01-11 01:52:48 -05003984# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3985# 0 = HBA resets disabled
3986# 1 = HBA resets enabled (default)
3987# Value range is [0,1]. Default value is 1.
3988*/
3989LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003990
James Smart13815c82008-01-11 01:52:48 -05003991/*
James Smarteb7a3392010-11-20 23:12:02 -05003992# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003993# 0 = HBA Heartbeat disabled
3994# 1 = HBA Heartbeat enabled (default)
3995# Value range is [0,1]. Default value is 1.
3996*/
James Smarteb7a3392010-11-20 23:12:02 -05003997LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003998
James Smart83108bd2008-01-11 01:53:09 -05003999/*
James Smart81301a92008-12-04 22:39:46 -05004000# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4001# 0 = BlockGuard disabled (default)
4002# 1 = BlockGuard enabled
4003# Value range is [0,1]. Default value is 0.
4004*/
4005LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4006
James Smart6fb120a2009-05-22 14:52:59 -04004007/*
James Smartba20c852012-08-03 12:36:52 -04004008# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4009# 0 = disabled (default)
4010# 1 = enabled
4011# Value range is [0,1]. Default value is 0.
4012*/
4013unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4014
4015module_param(lpfc_fcp_look_ahead, uint, S_IRUGO);
4016MODULE_PARM_DESC(lpfc_fcp_look_ahead, "Look ahead for completions");
4017
4018/*
James Smart81301a92008-12-04 22:39:46 -05004019# lpfc_prot_mask: i
4020# - Bit mask of host protection capabilities used to register with the
4021# SCSI mid-layer
4022# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4023# - Allows you to ultimately specify which profiles to use
4024# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004025# - SHOST_DIF_TYPE1_PROTECTION 1
4026# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4027# - SHOST_DIX_TYPE0_PROTECTION 8
4028# HBA supports DIX Type 0: Host to HBA protection only
4029# - SHOST_DIX_TYPE1_PROTECTION 16
4030# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004031#
4032*/
James Smart7c56b9f2011-07-22 18:36:25 -04004033unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4034 SHOST_DIX_TYPE0_PROTECTION |
4035 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05004036
James Smartab56dc22011-02-16 12:39:57 -05004037module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004038MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4039
4040/*
4041# lpfc_prot_guard: i
4042# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004043# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004044# - Allows you to ultimately specify which profiles to use
4045# - Default will result in registering capabilities for all guard types
4046#
4047*/
4048unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05004049module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05004050MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4051
James Smart92494142011-02-16 12:39:44 -05004052/*
4053 * Delay initial NPort discovery when Clean Address bit is cleared in
4054 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4055 * This parameter can have value 0 or 1.
4056 * When this parameter is set to 0, no delay is added to the initial
4057 * discovery.
4058 * When this parameter is set to non-zero value, initial Nport discovery is
4059 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4060 * accept and FCID/Fabric name/Fabric portname is changed.
4061 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4062 * when Clean Address bit is cleared in FLOGI/FDISC
4063 * accept and FCID/Fabric name/Fabric portname is changed.
4064 * Default value is 0.
4065 */
4066int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05004067module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05004068MODULE_PARM_DESC(lpfc_delay_discovery,
4069 "Delay NPort discovery when Clean Address bit is cleared. "
4070 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05004071
4072/*
James Smart3621a712009-04-06 18:47:14 -04004073 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05004074 * This value can be set to values between 64 and 256. The default value is
4075 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4076 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
4077 */
4078LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4079 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4080
James Smart81301a92008-12-04 22:39:46 -05004081LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
4082 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
4083 "Max Protection Scatter Gather Segment Count");
4084
Tony Jonesee959b02008-02-22 00:13:36 +01004085struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05004086 &dev_attr_bg_info,
4087 &dev_attr_bg_guard_err,
4088 &dev_attr_bg_apptag_err,
4089 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004090 &dev_attr_info,
4091 &dev_attr_serialnum,
4092 &dev_attr_modeldesc,
4093 &dev_attr_modelname,
4094 &dev_attr_programtype,
4095 &dev_attr_portnum,
4096 &dev_attr_fwrev,
4097 &dev_attr_hdw,
4098 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004099 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004100 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004101 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004102 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004103 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004104 &dev_attr_lpfc_temp_sensor,
4105 &dev_attr_lpfc_log_verbose,
4106 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004107 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004108 &dev_attr_lpfc_hba_queue_depth,
4109 &dev_attr_lpfc_peer_port_login,
4110 &dev_attr_lpfc_nodev_tmo,
4111 &dev_attr_lpfc_devloss_tmo,
4112 &dev_attr_lpfc_fcp_class,
4113 &dev_attr_lpfc_use_adisc,
4114 &dev_attr_lpfc_ack0,
4115 &dev_attr_lpfc_topology,
4116 &dev_attr_lpfc_scan_down,
4117 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004118 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004119 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004120 &dev_attr_lpfc_cr_delay,
4121 &dev_attr_lpfc_cr_count,
4122 &dev_attr_lpfc_multi_ring_support,
4123 &dev_attr_lpfc_multi_ring_rctl,
4124 &dev_attr_lpfc_multi_ring_type,
4125 &dev_attr_lpfc_fdmi_on,
4126 &dev_attr_lpfc_max_luns,
4127 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004128 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004129 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004130 &dev_attr_nport_evt_cnt,
4131 &dev_attr_board_mode,
4132 &dev_attr_max_vpi,
4133 &dev_attr_used_vpi,
4134 &dev_attr_max_rpi,
4135 &dev_attr_used_rpi,
4136 &dev_attr_max_xri,
4137 &dev_attr_used_xri,
4138 &dev_attr_npiv_info,
4139 &dev_attr_issue_reset,
4140 &dev_attr_lpfc_poll,
4141 &dev_attr_lpfc_poll_tmo,
4142 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04004143 &dev_attr_lpfc_fcp_imax,
4144 &dev_attr_lpfc_fcp_wq_count,
4145 &dev_attr_lpfc_fcp_eq_count,
James Smart67d12732012-08-03 12:36:13 -04004146 &dev_attr_lpfc_fcp_io_channel,
James Smart81301a92008-12-04 22:39:46 -05004147 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01004148 &dev_attr_lpfc_soft_wwnn,
4149 &dev_attr_lpfc_soft_wwpn,
4150 &dev_attr_lpfc_soft_wwn_enable,
4151 &dev_attr_lpfc_enable_hba_reset,
4152 &dev_attr_lpfc_enable_hba_heartbeat,
4153 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04004154 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04004155 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05004156 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04004157 &dev_attr_lpfc_aer_support,
4158 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04004159 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04004160 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05004161 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04004162 &dev_attr_lpfc_iocb_cnt,
4163 &dev_attr_iocb_hw,
4164 &dev_attr_txq_hw,
4165 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04004166 &dev_attr_lpfc_fips_level,
4167 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05004168 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04004169 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05004170 &dev_attr_protocol,
dea31012005-04-17 16:05:31 -05004171 NULL,
4172};
4173
Tony Jonesee959b02008-02-22 00:13:36 +01004174struct device_attribute *lpfc_vport_attrs[] = {
4175 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004176 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004177 &dev_attr_num_discovered_ports,
4178 &dev_attr_lpfc_drvr_version,
4179 &dev_attr_lpfc_log_verbose,
4180 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004181 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004182 &dev_attr_lpfc_nodev_tmo,
4183 &dev_attr_lpfc_devloss_tmo,
4184 &dev_attr_lpfc_hba_queue_depth,
4185 &dev_attr_lpfc_peer_port_login,
4186 &dev_attr_lpfc_restrict_login,
4187 &dev_attr_lpfc_fcp_class,
4188 &dev_attr_lpfc_use_adisc,
4189 &dev_attr_lpfc_fdmi_on,
4190 &dev_attr_lpfc_max_luns,
4191 &dev_attr_nport_evt_cnt,
4192 &dev_attr_npiv_info,
4193 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04004194 &dev_attr_lpfc_max_scsicmpl_time,
4195 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04004196 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04004197 &dev_attr_lpfc_fips_level,
4198 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04004199 NULL,
4200};
4201
James Smarte59058c2008-08-24 21:49:00 -04004202/**
James Smart3621a712009-04-06 18:47:14 -04004203 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004204 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004205 * @kobj: kernel kobject that contains the kernel class device.
4206 * @bin_attr: kernel attributes passed to us.
4207 * @buf: contains the data to be written to the adapter IOREG space.
4208 * @off: offset into buffer to beginning of data.
4209 * @count: bytes to transfer.
4210 *
4211 * Description:
4212 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4213 * Uses the adapter io control registers to send buf contents to the adapter.
4214 *
4215 * Returns:
4216 * -ERANGE off and count combo out of range
4217 * -EINVAL off, count or buff address invalid
4218 * -EPERM adapter is offline
4219 * value of count, buf contents written
4220 **/
dea31012005-04-17 16:05:31 -05004221static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004222sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4223 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004224 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004225{
4226 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01004227 struct device *dev = container_of(kobj, struct device, kobj);
4228 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004229 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4230 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004231
James Smartf1126682009-06-10 17:22:44 -04004232 if (phba->sli_rev >= LPFC_SLI_REV4)
4233 return -EPERM;
4234
dea31012005-04-17 16:05:31 -05004235 if ((off + count) > FF_REG_AREA_SIZE)
4236 return -ERANGE;
4237
James Smartf7a919b2011-08-21 21:49:16 -04004238 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4239 return 0;
dea31012005-04-17 16:05:31 -05004240
4241 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4242 return -EINVAL;
4243
James Smartf7a919b2011-08-21 21:49:16 -04004244 /* This is to protect HBA registers from accidental writes. */
4245 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4246 return -EINVAL;
4247
4248 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004249 return -EPERM;
dea31012005-04-17 16:05:31 -05004250
James Smart2e0fef82007-06-17 19:56:36 -05004251 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004252 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4253 buf_off += sizeof(uint32_t))
4254 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004255 phba->ctrl_regs_memmap_p + off + buf_off);
4256
James Smart2e0fef82007-06-17 19:56:36 -05004257 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004258
4259 return count;
4260}
4261
James Smarte59058c2008-08-24 21:49:00 -04004262/**
James Smart3621a712009-04-06 18:47:14 -04004263 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004264 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004265 * @kobj: kernel kobject that contains the kernel class device.
4266 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004267 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004268 * @off: offset into buffer to beginning of data.
4269 * @count: bytes to transfer.
4270 *
4271 * Description:
4272 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4273 * Uses the adapter io control registers to read data into buf.
4274 *
4275 * Returns:
4276 * -ERANGE off and count combo out of range
4277 * -EINVAL off, count or buff address invalid
4278 * value of count, buf contents read
4279 **/
dea31012005-04-17 16:05:31 -05004280static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004281sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4282 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004283 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004284{
4285 size_t buf_off;
4286 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004287 struct device *dev = container_of(kobj, struct device, kobj);
4288 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4290 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004291
James Smartf1126682009-06-10 17:22:44 -04004292 if (phba->sli_rev >= LPFC_SLI_REV4)
4293 return -EPERM;
4294
dea31012005-04-17 16:05:31 -05004295 if (off > FF_REG_AREA_SIZE)
4296 return -ERANGE;
4297
4298 if ((off + count) > FF_REG_AREA_SIZE)
4299 count = FF_REG_AREA_SIZE - off;
4300
4301 if (count == 0) return 0;
4302
4303 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4304 return -EINVAL;
4305
James Smart2e0fef82007-06-17 19:56:36 -05004306 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004307
4308 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4309 tmp_ptr = (uint32_t *)(buf + buf_off);
4310 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4311 }
4312
James Smart2e0fef82007-06-17 19:56:36 -05004313 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004314
4315 return count;
4316}
4317
4318static struct bin_attribute sysfs_ctlreg_attr = {
4319 .attr = {
4320 .name = "ctlreg",
4321 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004322 },
4323 .size = 256,
4324 .read = sysfs_ctlreg_read,
4325 .write = sysfs_ctlreg_write,
4326};
4327
James Smarte59058c2008-08-24 21:49:00 -04004328/**
James Smart3621a712009-04-06 18:47:14 -04004329 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004330 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004331 * @kobj: kernel kobject that contains the kernel class device.
4332 * @bin_attr: kernel attributes passed to us.
4333 * @buf: contains the data to be written to sysfs mbox.
4334 * @off: offset into buffer to beginning of data.
4335 * @count: bytes to transfer.
4336 *
4337 * Description:
James Smart026abb82011-12-13 13:20:45 -05004338 * Deprecated function. All mailbox access from user space is performed via the
4339 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004340 *
4341 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004342 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004343 **/
dea31012005-04-17 16:05:31 -05004344static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004345sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4346 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004347 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004348{
James Smart026abb82011-12-13 13:20:45 -05004349 return -EPERM;
dea31012005-04-17 16:05:31 -05004350}
4351
James Smarte59058c2008-08-24 21:49:00 -04004352/**
James Smart3621a712009-04-06 18:47:14 -04004353 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004354 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004355 * @kobj: kernel kobject that contains the kernel class device.
4356 * @bin_attr: kernel attributes passed to us.
4357 * @buf: contains the data to be read from sysfs mbox.
4358 * @off: offset into buffer to beginning of data.
4359 * @count: bytes to transfer.
4360 *
4361 * Description:
James Smart026abb82011-12-13 13:20:45 -05004362 * Deprecated function. All mailbox access from user space is performed via the
4363 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004364 *
4365 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004366 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004367 **/
dea31012005-04-17 16:05:31 -05004368static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004369sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4370 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004371 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004372{
James Smart026abb82011-12-13 13:20:45 -05004373 return -EPERM;
dea31012005-04-17 16:05:31 -05004374}
4375
4376static struct bin_attribute sysfs_mbox_attr = {
4377 .attr = {
4378 .name = "mbox",
4379 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004380 },
James Smartc0c11512011-05-24 11:41:34 -04004381 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004382 .read = sysfs_mbox_read,
4383 .write = sysfs_mbox_write,
4384};
4385
James Smarte59058c2008-08-24 21:49:00 -04004386/**
James Smart3621a712009-04-06 18:47:14 -04004387 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004388 * @vport: address of lpfc vport structure.
4389 *
4390 * Return codes:
4391 * zero on success
4392 * error return code from sysfs_create_bin_file()
4393 **/
dea31012005-04-17 16:05:31 -05004394int
James Smart2e0fef82007-06-17 19:56:36 -05004395lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004396{
James Smart2e0fef82007-06-17 19:56:36 -05004397 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004398 int error;
4399
Tony Jonesee959b02008-02-22 00:13:36 +01004400 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004401 &sysfs_drvr_stat_data_attr);
4402
4403 /* Virtual ports do not need ctrl_reg and mbox */
4404 if (error || vport->port_type == LPFC_NPIV_PORT)
4405 goto out;
4406
4407 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004408 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004409 if (error)
James Smarteada2722008-12-04 22:39:13 -05004410 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004411
Tony Jonesee959b02008-02-22 00:13:36 +01004412 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004413 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004414 if (error)
4415 goto out_remove_ctlreg_attr;
4416
4417 return 0;
4418out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004419 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004420out_remove_stat_attr:
4421 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4422 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004423out:
4424 return error;
4425}
4426
James Smarte59058c2008-08-24 21:49:00 -04004427/**
James Smart3621a712009-04-06 18:47:14 -04004428 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004429 * @vport: address of lpfc vport structure.
4430 **/
dea31012005-04-17 16:05:31 -05004431void
James Smart2e0fef82007-06-17 19:56:36 -05004432lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004433{
James Smart2e0fef82007-06-17 19:56:36 -05004434 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004435 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4436 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004437 /* Virtual ports do not need ctrl_reg and mbox */
4438 if (vport->port_type == LPFC_NPIV_PORT)
4439 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004440 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4441 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004442}
4443
4444
4445/*
4446 * Dynamic FC Host Attributes Support
4447 */
4448
James Smarte59058c2008-08-24 21:49:00 -04004449/**
James Smart3621a712009-04-06 18:47:14 -04004450 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004451 * @shost: kernel scsi host pointer.
4452 **/
dea31012005-04-17 16:05:31 -05004453static void
4454lpfc_get_host_port_id(struct Scsi_Host *shost)
4455{
James Smart2e0fef82007-06-17 19:56:36 -05004456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4457
dea31012005-04-17 16:05:31 -05004458 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004459 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004460}
4461
James Smarte59058c2008-08-24 21:49:00 -04004462/**
James Smart3621a712009-04-06 18:47:14 -04004463 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004464 * @shost: kernel scsi host pointer.
4465 **/
dea31012005-04-17 16:05:31 -05004466static void
4467lpfc_get_host_port_type(struct Scsi_Host *shost)
4468{
James Smart2e0fef82007-06-17 19:56:36 -05004469 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4470 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004471
4472 spin_lock_irq(shost->host_lock);
4473
James Smart92d7f7b2007-06-17 19:56:38 -05004474 if (vport->port_type == LPFC_NPIV_PORT) {
4475 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4476 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004477 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004478 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004479 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4480 else
4481 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4482 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004483 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004484 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4485 else
4486 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4487 }
4488 } else
4489 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4490
4491 spin_unlock_irq(shost->host_lock);
4492}
4493
James Smarte59058c2008-08-24 21:49:00 -04004494/**
James Smart3621a712009-04-06 18:47:14 -04004495 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004496 * @shost: kernel scsi host pointer.
4497 **/
dea31012005-04-17 16:05:31 -05004498static void
4499lpfc_get_host_port_state(struct Scsi_Host *shost)
4500{
James Smart2e0fef82007-06-17 19:56:36 -05004501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4502 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004503
4504 spin_lock_irq(shost->host_lock);
4505
James Smart2e0fef82007-06-17 19:56:36 -05004506 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004507 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4508 else {
James Smart2e0fef82007-06-17 19:56:36 -05004509 switch (phba->link_state) {
4510 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004511 case LPFC_LINK_DOWN:
4512 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4513 break;
4514 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004515 case LPFC_CLEAR_LA:
4516 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05004517 /* Links up, reports port state accordingly */
4518 if (vport->port_state < LPFC_VPORT_READY)
4519 fc_host_port_state(shost) =
4520 FC_PORTSTATE_BYPASSED;
4521 else
4522 fc_host_port_state(shost) =
4523 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05004524 break;
4525 case LPFC_HBA_ERROR:
4526 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4527 break;
4528 default:
4529 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4530 break;
4531 }
4532 }
4533
4534 spin_unlock_irq(shost->host_lock);
4535}
4536
James Smarte59058c2008-08-24 21:49:00 -04004537/**
James Smart3621a712009-04-06 18:47:14 -04004538 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004539 * @shost: kernel scsi host pointer.
4540 **/
dea31012005-04-17 16:05:31 -05004541static void
4542lpfc_get_host_speed(struct Scsi_Host *shost)
4543{
James Smart2e0fef82007-06-17 19:56:36 -05004544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4545 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004546
4547 spin_lock_irq(shost->host_lock);
4548
James Smart2e0fef82007-06-17 19:56:36 -05004549 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004550 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004551 case LPFC_LINK_SPEED_1GHZ:
4552 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004553 break;
James Smart76a95d72010-11-20 23:11:48 -05004554 case LPFC_LINK_SPEED_2GHZ:
4555 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004556 break;
James Smart76a95d72010-11-20 23:11:48 -05004557 case LPFC_LINK_SPEED_4GHZ:
4558 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004559 break;
James Smart76a95d72010-11-20 23:11:48 -05004560 case LPFC_LINK_SPEED_8GHZ:
4561 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004562 break;
James Smart76a95d72010-11-20 23:11:48 -05004563 case LPFC_LINK_SPEED_10GHZ:
4564 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004565 break;
James Smart76a95d72010-11-20 23:11:48 -05004566 case LPFC_LINK_SPEED_16GHZ:
4567 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4568 break;
4569 default:
4570 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004571 break;
4572 }
James Smart09372822008-01-11 01:52:54 -05004573 } else
4574 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004575
4576 spin_unlock_irq(shost->host_lock);
4577}
4578
James Smarte59058c2008-08-24 21:49:00 -04004579/**
James Smart3621a712009-04-06 18:47:14 -04004580 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004581 * @shost: kernel scsi host pointer.
4582 **/
dea31012005-04-17 16:05:31 -05004583static void
4584lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4585{
James Smart2e0fef82007-06-17 19:56:36 -05004586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4587 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004588 u64 node_name;
dea31012005-04-17 16:05:31 -05004589
4590 spin_lock_irq(shost->host_lock);
4591
James Smart73d91e52011-10-10 21:32:10 -04004592 if ((vport->port_state > LPFC_FLOGI) &&
4593 ((vport->fc_flag & FC_FABRIC) ||
4594 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4595 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004596 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004597 else
4598 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004599 node_name = 0;
dea31012005-04-17 16:05:31 -05004600
4601 spin_unlock_irq(shost->host_lock);
4602
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004603 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004604}
4605
James Smarte59058c2008-08-24 21:49:00 -04004606/**
James Smart3621a712009-04-06 18:47:14 -04004607 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004608 * @shost: kernel scsi host pointer.
4609 *
4610 * Notes:
4611 * NULL on error for link down, no mbox pool, sli2 active,
4612 * management not allowed, memory allocation error, or mbox error.
4613 *
4614 * Returns:
4615 * NULL for error
4616 * address of the adapter host statistics
4617 **/
dea31012005-04-17 16:05:31 -05004618static struct fc_host_statistics *
4619lpfc_get_stats(struct Scsi_Host *shost)
4620{
James Smart2e0fef82007-06-17 19:56:36 -05004621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4622 struct lpfc_hba *phba = vport->phba;
4623 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004624 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004625 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004626 LPFC_MBOXQ_t *pmboxq;
4627 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004628 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004629 int rc = 0;
dea31012005-04-17 16:05:31 -05004630
James Smart92d7f7b2007-06-17 19:56:38 -05004631 /*
4632 * prevent udev from issuing mailbox commands until the port is
4633 * configured.
4634 */
James Smart2e0fef82007-06-17 19:56:36 -05004635 if (phba->link_state < LPFC_LINK_DOWN ||
4636 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004637 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004638 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004639
4640 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004641 return NULL;
4642
dea31012005-04-17 16:05:31 -05004643 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4644 if (!pmboxq)
4645 return NULL;
4646 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4647
James Smart04c68492009-05-22 14:52:52 -04004648 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004649 pmb->mbxCommand = MBX_READ_STATUS;
4650 pmb->mbxOwner = OWN_HOST;
4651 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004652 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004653
James Smart75baf692010-06-08 18:31:21 -04004654 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004655 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004656 else
dea31012005-04-17 16:05:31 -05004657 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4658
4659 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004660 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004661 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004662 return NULL;
4663 }
4664
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004665 memset(hs, 0, sizeof (struct fc_host_statistics));
4666
dea31012005-04-17 16:05:31 -05004667 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004668 /*
4669 * The MBX_READ_STATUS returns tx_k_bytes which has to
4670 * converted to words
4671 */
4672 hs->tx_words = (uint64_t)
4673 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4674 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004675 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004676 hs->rx_words = (uint64_t)
4677 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4678 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004679
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004680 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004681 pmb->mbxCommand = MBX_READ_LNK_STAT;
4682 pmb->mbxOwner = OWN_HOST;
4683 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004684 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004685
James Smart75baf692010-06-08 18:31:21 -04004686 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004687 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004688 else
dea31012005-04-17 16:05:31 -05004689 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4690
4691 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004692 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004693 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004694 return NULL;
4695 }
4696
4697 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4698 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4699 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4700 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4701 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4702 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4703 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4704
James Smart64ba8812006-08-02 15:24:34 -04004705 hs->link_failure_count -= lso->link_failure_count;
4706 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4707 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4708 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4709 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4710 hs->invalid_crc_count -= lso->invalid_crc_count;
4711 hs->error_frames -= lso->error_frames;
4712
James Smart76a95d72010-11-20 23:11:48 -05004713 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004714 hs->lip_count = -1;
4715 hs->nos_count = (phba->link_events >> 1);
4716 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004717 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004718 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004719 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004720 hs->nos_count = -1;
4721 } else {
4722 hs->lip_count = -1;
4723 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004724 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004725 }
4726
4727 hs->dumped_frames = -1;
4728
James Smart64ba8812006-08-02 15:24:34 -04004729 seconds = get_seconds();
4730 if (seconds < psli->stats_start)
4731 hs->seconds_since_last_reset = seconds +
4732 ((unsigned long)-1 - psli->stats_start);
4733 else
4734 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004735
James Smart1dcb58e2007-04-25 09:51:30 -04004736 mempool_free(pmboxq, phba->mbox_mem_pool);
4737
dea31012005-04-17 16:05:31 -05004738 return hs;
4739}
4740
James Smarte59058c2008-08-24 21:49:00 -04004741/**
James Smart3621a712009-04-06 18:47:14 -04004742 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004743 * @shost: kernel scsi host pointer.
4744 **/
James Smart64ba8812006-08-02 15:24:34 -04004745static void
4746lpfc_reset_stats(struct Scsi_Host *shost)
4747{
James Smart2e0fef82007-06-17 19:56:36 -05004748 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4749 struct lpfc_hba *phba = vport->phba;
4750 struct lpfc_sli *psli = &phba->sli;
4751 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004752 LPFC_MBOXQ_t *pmboxq;
4753 MAILBOX_t *pmb;
4754 int rc = 0;
4755
James Smart2e0fef82007-06-17 19:56:36 -05004756 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004757 return;
4758
James Smart64ba8812006-08-02 15:24:34 -04004759 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4760 if (!pmboxq)
4761 return;
4762 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4763
James Smart04c68492009-05-22 14:52:52 -04004764 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004765 pmb->mbxCommand = MBX_READ_STATUS;
4766 pmb->mbxOwner = OWN_HOST;
4767 pmb->un.varWords[0] = 0x1; /* reset request */
4768 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004769 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004770
James Smart2e0fef82007-06-17 19:56:36 -05004771 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004772 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004773 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4774 else
4775 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4776
4777 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004778 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004779 mempool_free(pmboxq, phba->mbox_mem_pool);
4780 return;
4781 }
4782
4783 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4784 pmb->mbxCommand = MBX_READ_LNK_STAT;
4785 pmb->mbxOwner = OWN_HOST;
4786 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004787 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004788
James Smart2e0fef82007-06-17 19:56:36 -05004789 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004790 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004791 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4792 else
4793 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4794
4795 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004796 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004797 mempool_free( pmboxq, phba->mbox_mem_pool);
4798 return;
4799 }
4800
4801 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4802 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4803 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4804 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4805 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4806 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4807 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004808 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004809 lso->link_events = (phba->link_events >> 1);
4810 else
4811 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004812
4813 psli->stats_start = get_seconds();
4814
James Smart1dcb58e2007-04-25 09:51:30 -04004815 mempool_free(pmboxq, phba->mbox_mem_pool);
4816
James Smart64ba8812006-08-02 15:24:34 -04004817 return;
4818}
dea31012005-04-17 16:05:31 -05004819
4820/*
4821 * The LPFC driver treats linkdown handling as target loss events so there
4822 * are no sysfs handlers for link_down_tmo.
4823 */
James Smart685f0bf2007-04-25 09:53:08 -04004824
James Smarte59058c2008-08-24 21:49:00 -04004825/**
James Smart3621a712009-04-06 18:47:14 -04004826 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004827 * @starget: kernel scsi target pointer.
4828 *
4829 * Returns:
4830 * address of the node list if found
4831 * NULL target not found
4832 **/
James Smart685f0bf2007-04-25 09:53:08 -04004833static struct lpfc_nodelist *
4834lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004835{
James Smart2e0fef82007-06-17 19:56:36 -05004836 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4837 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004838 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004839
4840 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004841 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004842 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004843 if (NLP_CHK_NODE_ACT(ndlp) &&
4844 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004845 starget->id == ndlp->nlp_sid) {
4846 spin_unlock_irq(shost->host_lock);
4847 return ndlp;
dea31012005-04-17 16:05:31 -05004848 }
4849 }
4850 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004851 return NULL;
4852}
dea31012005-04-17 16:05:31 -05004853
James Smarte59058c2008-08-24 21:49:00 -04004854/**
James Smart3621a712009-04-06 18:47:14 -04004855 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004856 * @starget: kernel scsi target pointer.
4857 **/
James Smart685f0bf2007-04-25 09:53:08 -04004858static void
4859lpfc_get_starget_port_id(struct scsi_target *starget)
4860{
4861 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4862
4863 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004864}
4865
James Smarte59058c2008-08-24 21:49:00 -04004866/**
James Smart3621a712009-04-06 18:47:14 -04004867 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004868 * @starget: kernel scsi target pointer.
4869 *
4870 * Description: Set the target node name to the ndlp node name wwn or zero.
4871 **/
dea31012005-04-17 16:05:31 -05004872static void
4873lpfc_get_starget_node_name(struct scsi_target *starget)
4874{
James Smart685f0bf2007-04-25 09:53:08 -04004875 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004876
James Smart685f0bf2007-04-25 09:53:08 -04004877 fc_starget_node_name(starget) =
4878 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004879}
4880
James Smarte59058c2008-08-24 21:49:00 -04004881/**
James Smart3621a712009-04-06 18:47:14 -04004882 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004883 * @starget: kernel scsi target pointer.
4884 *
4885 * Description: set the target port name to the ndlp port name wwn or zero.
4886 **/
dea31012005-04-17 16:05:31 -05004887static void
4888lpfc_get_starget_port_name(struct scsi_target *starget)
4889{
James Smart685f0bf2007-04-25 09:53:08 -04004890 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004891
James Smart685f0bf2007-04-25 09:53:08 -04004892 fc_starget_port_name(starget) =
4893 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004894}
4895
James Smarte59058c2008-08-24 21:49:00 -04004896/**
James Smart3621a712009-04-06 18:47:14 -04004897 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004898 * @rport: fc rport address.
4899 * @timeout: new value for dev loss tmo.
4900 *
4901 * Description:
4902 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4903 * dev_loss_tmo to one.
4904 **/
dea31012005-04-17 16:05:31 -05004905static void
dea31012005-04-17 16:05:31 -05004906lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4907{
dea31012005-04-17 16:05:31 -05004908 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004909 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004910 else
James Smartc01f3202006-08-18 17:47:08 -04004911 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004912}
4913
James Smarte59058c2008-08-24 21:49:00 -04004914/**
James Smart3621a712009-04-06 18:47:14 -04004915 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004916 *
4917 * Description:
4918 * Macro that uses field to generate a function with the name lpfc_show_rport_
4919 *
4920 * lpfc_show_rport_##field: returns the bytes formatted in buf
4921 * @cdev: class converted to an fc_rport.
4922 * @buf: on return contains the target_field or zero.
4923 *
4924 * Returns: size of formatted string.
4925 **/
dea31012005-04-17 16:05:31 -05004926#define lpfc_rport_show_function(field, format_string, sz, cast) \
4927static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004928lpfc_show_rport_##field (struct device *dev, \
4929 struct device_attribute *attr, \
4930 char *buf) \
dea31012005-04-17 16:05:31 -05004931{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004932 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004933 struct lpfc_rport_data *rdata = rport->hostdata; \
4934 return snprintf(buf, sz, format_string, \
4935 (rdata->target) ? cast rdata->target->field : 0); \
4936}
4937
4938#define lpfc_rport_rd_attr(field, format_string, sz) \
4939 lpfc_rport_show_function(field, format_string, sz, ) \
4940static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4941
James Smarteada2722008-12-04 22:39:13 -05004942/**
James Smart3621a712009-04-06 18:47:14 -04004943 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004944 * @fc_vport: The fc_vport who's symbolic name has been changed.
4945 *
4946 * Description:
4947 * This function is called by the transport after the @fc_vport's symbolic name
4948 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004949 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004950 **/
4951static void
4952lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4953{
4954 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4955
4956 if (vport->port_state == LPFC_VPORT_READY)
4957 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4958}
dea31012005-04-17 16:05:31 -05004959
James Smartf4b4c682009-05-22 14:53:12 -04004960/**
4961 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4962 * @phba: Pointer to lpfc_hba struct.
4963 *
4964 * This function is called by the lpfc_get_cfgparam() routine to set the
4965 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004966 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004967 * before hba port or vport created.
4968 **/
4969static void
4970lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4971{
4972 phba->cfg_log_verbose = verbose;
4973}
4974
dea31012005-04-17 16:05:31 -05004975struct fc_function_template lpfc_transport_functions = {
4976 /* fixed attributes the driver supports */
4977 .show_host_node_name = 1,
4978 .show_host_port_name = 1,
4979 .show_host_supported_classes = 1,
4980 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004981 .show_host_supported_speeds = 1,
4982 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004983 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004984
4985 /* dynamic attributes the driver supports */
4986 .get_host_port_id = lpfc_get_host_port_id,
4987 .show_host_port_id = 1,
4988
4989 .get_host_port_type = lpfc_get_host_port_type,
4990 .show_host_port_type = 1,
4991
4992 .get_host_port_state = lpfc_get_host_port_state,
4993 .show_host_port_state = 1,
4994
4995 /* active_fc4s is shown but doesn't change (thus no get function) */
4996 .show_host_active_fc4s = 1,
4997
4998 .get_host_speed = lpfc_get_host_speed,
4999 .show_host_speed = 1,
5000
5001 .get_host_fabric_name = lpfc_get_host_fabric_name,
5002 .show_host_fabric_name = 1,
5003
5004 /*
5005 * The LPFC driver treats linkdown handling as target loss events
5006 * so there are no sysfs handlers for link_down_tmo.
5007 */
5008
5009 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005010 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005011
5012 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5013 .show_rport_maxframe_size = 1,
5014 .show_rport_supported_classes = 1,
5015
dea31012005-04-17 16:05:31 -05005016 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5017 .show_rport_dev_loss_tmo = 1,
5018
5019 .get_starget_port_id = lpfc_get_starget_port_id,
5020 .show_starget_port_id = 1,
5021
5022 .get_starget_node_name = lpfc_get_starget_node_name,
5023 .show_starget_node_name = 1,
5024
5025 .get_starget_port_name = lpfc_get_starget_port_name,
5026 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005027
5028 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005029 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5030 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005031
James Smart92d7f7b2007-06-17 19:56:38 -05005032 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005033
5034 .vport_disable = lpfc_vport_disable,
5035
5036 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005037
5038 .bsg_request = lpfc_bsg_request,
5039 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005040};
5041
James Smart98c9ea52007-10-27 13:37:33 -04005042struct fc_function_template lpfc_vport_transport_functions = {
5043 /* fixed attributes the driver supports */
5044 .show_host_node_name = 1,
5045 .show_host_port_name = 1,
5046 .show_host_supported_classes = 1,
5047 .show_host_supported_fc4s = 1,
5048 .show_host_supported_speeds = 1,
5049 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05005050 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005051
5052 /* dynamic attributes the driver supports */
5053 .get_host_port_id = lpfc_get_host_port_id,
5054 .show_host_port_id = 1,
5055
5056 .get_host_port_type = lpfc_get_host_port_type,
5057 .show_host_port_type = 1,
5058
5059 .get_host_port_state = lpfc_get_host_port_state,
5060 .show_host_port_state = 1,
5061
5062 /* active_fc4s is shown but doesn't change (thus no get function) */
5063 .show_host_active_fc4s = 1,
5064
5065 .get_host_speed = lpfc_get_host_speed,
5066 .show_host_speed = 1,
5067
5068 .get_host_fabric_name = lpfc_get_host_fabric_name,
5069 .show_host_fabric_name = 1,
5070
5071 /*
5072 * The LPFC driver treats linkdown handling as target loss events
5073 * so there are no sysfs handlers for link_down_tmo.
5074 */
5075
5076 .get_fc_host_stats = lpfc_get_stats,
5077 .reset_fc_host_stats = lpfc_reset_stats,
5078
5079 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5080 .show_rport_maxframe_size = 1,
5081 .show_rport_supported_classes = 1,
5082
5083 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5084 .show_rport_dev_loss_tmo = 1,
5085
5086 .get_starget_port_id = lpfc_get_starget_port_id,
5087 .show_starget_port_id = 1,
5088
5089 .get_starget_node_name = lpfc_get_starget_node_name,
5090 .show_starget_node_name = 1,
5091
5092 .get_starget_port_name = lpfc_get_starget_port_name,
5093 .show_starget_port_name = 1,
5094
5095 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5096 .terminate_rport_io = lpfc_terminate_rport_io,
5097
5098 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005099
5100 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005101};
5102
James Smarte59058c2008-08-24 21:49:00 -04005103/**
James Smart3621a712009-04-06 18:47:14 -04005104 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005105 * @phba: lpfc_hba pointer.
5106 **/
dea31012005-04-17 16:05:31 -05005107void
5108lpfc_get_cfgparam(struct lpfc_hba *phba)
5109{
James Smart49aa1432012-08-03 12:36:42 -04005110 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005111 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005112 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5113 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005114 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005115 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5116 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005117 lpfc_ack0_init(phba, lpfc_ack0);
5118 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005119 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005120 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005121 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005122 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005123 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005124 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005125 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5126 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5127 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart67d12732012-08-03 12:36:13 -04005128 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
James Smart13815c82008-01-11 01:52:48 -05005129 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5130 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005131 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005132 if (phba->sli_rev == LPFC_SLI_REV4)
5133 phba->cfg_poll = 0;
5134 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005135 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005136 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005137 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005138 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005139 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005140 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005141 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005142 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005143 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04005144 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05005145 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005146 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005147 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005148 return;
5149}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005150
James Smarte59058c2008-08-24 21:49:00 -04005151/**
James Smart3621a712009-04-06 18:47:14 -04005152 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005153 * @vport: lpfc_vport pointer.
5154 **/
James Smart3de2a652007-08-02 11:09:59 -04005155void
5156lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5157{
James Smarte8b62012007-08-02 11:10:09 -04005158 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005159 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005160 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005161 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5162 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5163 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5164 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5165 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5166 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005167 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005168 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5169 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5170 lpfc_max_luns_init(vport, lpfc_max_luns);
5171 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005172 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005173 return;
5174}