blob: 7bf492e156d9d5fa9dac1c0c601a2984115c5099 [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 Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 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;
dea31012005-04-17 16:05:31 -0500356 char fwrev[32];
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 Smart46fa3112007-04-25 09:51:45 -0400695 while (pring->txcmplq_cnt) {
696 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) {
925 /* no privilage for reset, restore if needed */
926 if (before_fc_flag & FC_OFFLINE_MODE)
927 goto out;
928 } else if (rc == -EIO) {
929 /* reset failed, there is nothing more we can do */
James Smartf7a919b2011-08-21 21:49:16 -0400930 return rc;
James Smart026abb82011-12-13 13:20:45 -0500931 }
932
933 /* keep the original port state */
934 if (before_fc_flag & FC_OFFLINE_MODE)
935 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400936
937 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -0500938 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
939 LPFC_EVT_ONLINE);
940 if (!job_posted)
941 goto out;
James Smartc0c11512011-05-24 11:41:34 -0400942
943 wait_for_completion(&online_compl);
944
James Smart026abb82011-12-13 13:20:45 -0500945out:
946 /* in any case, restore the virtual functions enabled as before */
947 if (sriov_nr_virtfn) {
948 sriov_err =
949 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
950 if (!sriov_err)
951 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
952 }
James Smartc0c11512011-05-24 11:41:34 -0400953
James Smart026abb82011-12-13 13:20:45 -0500954 /* return proper error code */
955 if (!rc) {
956 if (!job_posted)
957 rc = -ENOMEM;
958 else if (status)
959 rc = -EIO;
960 }
961 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400962}
963
964/**
James Smart3621a712009-04-06 18:47:14 -0400965 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400966 * @dev: class device that is converted into a Scsi_host.
967 * @attr: device attribute, not used.
968 * @buf: on return contains the ascii number of nport events.
969 *
970 * Returns: size of formatted string.
971 **/
dea31012005-04-17 16:05:31 -0500972static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100973lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
974 char *buf)
dea31012005-04-17 16:05:31 -0500975{
Tony Jonesee959b02008-02-22 00:13:36 +0100976 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500977 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
978 struct lpfc_hba *phba = vport->phba;
979
dea31012005-04-17 16:05:31 -0500980 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
981}
982
James Smarte59058c2008-08-24 21:49:00 -0400983/**
James Smart3621a712009-04-06 18:47:14 -0400984 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400985 * @dev: class device that is converted into a Scsi_host.
986 * @attr: device attribute, not used.
987 * @buf: on return contains the state of the adapter.
988 *
989 * Returns: size of formatted string.
990 **/
dea31012005-04-17 16:05:31 -0500991static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100992lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
993 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500994{
Tony Jonesee959b02008-02-22 00:13:36 +0100995 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500996 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
997 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500998 char * state;
999
James Smart2e0fef82007-06-17 19:56:36 -05001000 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001001 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001002 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001003 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001004 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001005 state = "offline";
1006 else
1007 state = "online";
1008
1009 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1010}
1011
James Smarte59058c2008-08-24 21:49:00 -04001012/**
James Smart3621a712009-04-06 18:47:14 -04001013 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001014 * @dev: class device that is converted into a Scsi_host.
1015 * @attr: device attribute, not used.
1016 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1017 * @count: unused variable.
1018 *
1019 * Returns:
1020 * -EACCES if enable hba reset not enabled
1021 * -EINVAL if the buffer does not contain a valid string (see above)
1022 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1023 * buf length greater than zero indicates success
1024 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001025static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001026lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1027 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001028{
Tony Jonesee959b02008-02-22 00:13:36 +01001029 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1031 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001032 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001033 char *board_mode_str = NULL;
1034 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001035 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001036
James Smart026abb82011-12-13 13:20:45 -05001037 if (!phba->cfg_enable_hba_reset) {
1038 status = -EACCES;
1039 goto board_mode_out;
1040 }
James Smart88a2cfb2011-07-22 18:36:33 -04001041
1042 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001043 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001044
Jamie Wellnitz41415862006-02-28 19:25:27 -05001045 init_completion(&online_compl);
1046
James Smart46fa3112007-04-25 09:51:45 -04001047 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001048 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001049 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001050 if (rc == 0) {
1051 status = -ENOMEM;
1052 goto board_mode_out;
1053 }
James Smart46fa3112007-04-25 09:51:45 -04001054 wait_for_completion(&online_compl);
1055 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1056 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001057 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001058 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001059 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001060 else
1061 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001062 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001063 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001064 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001065 else
1066 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001067 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001068 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1069 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1070 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1071 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1072 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001073 else
James Smart026abb82011-12-13 13:20:45 -05001074 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001075
James Smart026abb82011-12-13 13:20:45 -05001076board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001077 if (!status)
1078 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001079 else {
1080 board_mode_str = strchr(buf, '\n');
1081 if (board_mode_str)
1082 *board_mode_str = '\0';
1083 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1084 "3097 Failed \"%s\", status(%d), "
1085 "fc_flag(x%x)\n",
1086 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001087 return status;
James Smart026abb82011-12-13 13:20:45 -05001088 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001089}
1090
James Smarte59058c2008-08-24 21:49:00 -04001091/**
James Smart3621a712009-04-06 18:47:14 -04001092 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001093 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001094 * @mxri: max xri count.
1095 * @axri: available xri count.
1096 * @mrpi: max rpi count.
1097 * @arpi: available rpi count.
1098 * @mvpi: max vpi count.
1099 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001100 *
1101 * Description:
1102 * If an integer pointer for an count is not null then the value for the
1103 * count is returned.
1104 *
1105 * Returns:
1106 * zero on error
1107 * one for success
1108 **/
James Smart311464e2007-08-02 11:10:37 -04001109static int
James Smart858c9f62007-06-17 19:56:39 -05001110lpfc_get_hba_info(struct lpfc_hba *phba,
1111 uint32_t *mxri, uint32_t *axri,
1112 uint32_t *mrpi, uint32_t *arpi,
1113 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001114{
James Smart04c68492009-05-22 14:52:52 -04001115 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001116 LPFC_MBOXQ_t *pmboxq;
1117 MAILBOX_t *pmb;
1118 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001119 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001120
1121 /*
1122 * prevent udev from issuing mailbox commands until the port is
1123 * configured.
1124 */
1125 if (phba->link_state < LPFC_LINK_DOWN ||
1126 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001127 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001128 return 0;
1129
1130 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1131 return 0;
1132
1133 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1134 if (!pmboxq)
1135 return 0;
1136 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1137
James Smart04c68492009-05-22 14:52:52 -04001138 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001139 pmb->mbxCommand = MBX_READ_CONFIG;
1140 pmb->mbxOwner = OWN_HOST;
1141 pmboxq->context1 = NULL;
1142
James Smart75baf692010-06-08 18:31:21 -04001143 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001144 rc = MBX_NOT_FINISHED;
1145 else
1146 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1147
1148 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001149 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001150 mempool_free(pmboxq, phba->mbox_mem_pool);
1151 return 0;
1152 }
1153
James Smartda0436e2009-05-22 14:51:39 -04001154 if (phba->sli_rev == LPFC_SLI_REV4) {
1155 rd_config = &pmboxq->u.mqe.un.rd_config;
1156 if (mrpi)
1157 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1158 if (arpi)
1159 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1160 phba->sli4_hba.max_cfg_param.rpi_used;
1161 if (mxri)
1162 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1163 if (axri)
1164 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1165 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001166
1167 /* Account for differences with SLI-3. Get vpi count from
1168 * mailbox data and subtract one for max vpi value.
1169 */
1170 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1171 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1172
James Smartda0436e2009-05-22 14:51:39 -04001173 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001174 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001175 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001176 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001177 } else {
1178 if (mrpi)
1179 *mrpi = pmb->un.varRdConfig.max_rpi;
1180 if (arpi)
1181 *arpi = pmb->un.varRdConfig.avail_rpi;
1182 if (mxri)
1183 *mxri = pmb->un.varRdConfig.max_xri;
1184 if (axri)
1185 *axri = pmb->un.varRdConfig.avail_xri;
1186 if (mvpi)
1187 *mvpi = pmb->un.varRdConfig.max_vpi;
1188 if (avpi)
1189 *avpi = pmb->un.varRdConfig.avail_vpi;
1190 }
James Smart92d7f7b2007-06-17 19:56:38 -05001191
1192 mempool_free(pmboxq, phba->mbox_mem_pool);
1193 return 1;
1194}
1195
James Smarte59058c2008-08-24 21:49:00 -04001196/**
James Smart3621a712009-04-06 18:47:14 -04001197 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001198 * @dev: class device that is converted into a Scsi_host.
1199 * @attr: device attribute, not used.
1200 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1201 *
1202 * Description:
1203 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1204 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1205 * to "Unknown" and the buffer length is returned, therefore the caller
1206 * must check for "Unknown" in the buffer to detect a failure.
1207 *
1208 * Returns: size of formatted string.
1209 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001210static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001211lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1212 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001213{
Tony Jonesee959b02008-02-22 00:13:36 +01001214 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001215 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1216 struct lpfc_hba *phba = vport->phba;
1217 uint32_t cnt;
1218
James Smart858c9f62007-06-17 19:56:39 -05001219 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001220 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1221 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1222}
1223
James Smarte59058c2008-08-24 21:49:00 -04001224/**
James Smart3621a712009-04-06 18:47:14 -04001225 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001226 * @dev: class device that is converted into a Scsi_host.
1227 * @attr: device attribute, not used.
1228 * @buf: containing the used rpi count in decimal or "Unknown".
1229 *
1230 * Description:
1231 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1232 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1233 * to "Unknown" and the buffer length is returned, therefore the caller
1234 * must check for "Unknown" in the buffer to detect a failure.
1235 *
1236 * Returns: size of formatted string.
1237 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001238static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001239lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1240 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001241{
Tony Jonesee959b02008-02-22 00:13:36 +01001242 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001243 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1244 struct lpfc_hba *phba = vport->phba;
1245 uint32_t cnt, acnt;
1246
James Smart858c9f62007-06-17 19:56:39 -05001247 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001248 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1249 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1250}
1251
James Smarte59058c2008-08-24 21:49:00 -04001252/**
James Smart3621a712009-04-06 18:47:14 -04001253 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001254 * @dev: class device that is converted into a Scsi_host.
1255 * @attr: device attribute, not used.
1256 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1257 *
1258 * Description:
1259 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1260 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1261 * to "Unknown" and the buffer length is returned, therefore the caller
1262 * must check for "Unknown" in the buffer to detect a failure.
1263 *
1264 * Returns: size of formatted string.
1265 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001266static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001267lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1268 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001269{
Tony Jonesee959b02008-02-22 00:13:36 +01001270 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1272 struct lpfc_hba *phba = vport->phba;
1273 uint32_t cnt;
1274
James Smart858c9f62007-06-17 19:56:39 -05001275 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001276 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1277 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1278}
1279
James Smarte59058c2008-08-24 21:49:00 -04001280/**
James Smart3621a712009-04-06 18:47:14 -04001281 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001282 * @dev: class device that is converted into a Scsi_host.
1283 * @attr: device attribute, not used.
1284 * @buf: on return contains the used xri count in decimal or "Unknown".
1285 *
1286 * Description:
1287 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1288 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1289 * to "Unknown" and the buffer length is returned, therefore the caller
1290 * must check for "Unknown" in the buffer to detect a failure.
1291 *
1292 * Returns: size of formatted string.
1293 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001294static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001295lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1296 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001297{
Tony Jonesee959b02008-02-22 00:13:36 +01001298 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001299 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1300 struct lpfc_hba *phba = vport->phba;
1301 uint32_t cnt, acnt;
1302
James Smart858c9f62007-06-17 19:56:39 -05001303 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1304 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1305 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1306}
1307
James Smarte59058c2008-08-24 21:49:00 -04001308/**
James Smart3621a712009-04-06 18:47:14 -04001309 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001310 * @dev: class device that is converted into a Scsi_host.
1311 * @attr: device attribute, not used.
1312 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1313 *
1314 * Description:
1315 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1316 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1317 * to "Unknown" and the buffer length is returned, therefore the caller
1318 * must check for "Unknown" in the buffer to detect a failure.
1319 *
1320 * Returns: size of formatted string.
1321 **/
James Smart858c9f62007-06-17 19:56:39 -05001322static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001323lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1324 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001325{
Tony Jonesee959b02008-02-22 00:13:36 +01001326 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001327 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1328 struct lpfc_hba *phba = vport->phba;
1329 uint32_t cnt;
1330
1331 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1332 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1333 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1334}
1335
James Smarte59058c2008-08-24 21:49:00 -04001336/**
James Smart3621a712009-04-06 18:47:14 -04001337 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001338 * @dev: class device that is converted into a Scsi_host.
1339 * @attr: device attribute, not used.
1340 * @buf: on return contains the used vpi count in decimal or "Unknown".
1341 *
1342 * Description:
1343 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1344 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1345 * to "Unknown" and the buffer length is returned, therefore the caller
1346 * must check for "Unknown" in the buffer to detect a failure.
1347 *
1348 * Returns: size of formatted string.
1349 **/
James Smart858c9f62007-06-17 19:56:39 -05001350static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001351lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1352 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001353{
Tony Jonesee959b02008-02-22 00:13:36 +01001354 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001355 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1356 struct lpfc_hba *phba = vport->phba;
1357 uint32_t cnt, acnt;
1358
1359 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001360 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1361 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1362}
1363
James Smarte59058c2008-08-24 21:49:00 -04001364/**
James Smart3621a712009-04-06 18:47:14 -04001365 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001366 * @dev: class device that is converted into a Scsi_host.
1367 * @attr: device attribute, not used.
1368 * @buf: text that must be interpreted to determine if npiv is supported.
1369 *
1370 * Description:
1371 * Buffer will contain text indicating npiv is not suppoerted on the port,
1372 * the port is an NPIV physical port, or it is an npiv virtual port with
1373 * the id of the vport.
1374 *
1375 * Returns: size of formatted string.
1376 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001377static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001378lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1379 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001380{
Tony Jonesee959b02008-02-22 00:13:36 +01001381 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001382 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1383 struct lpfc_hba *phba = vport->phba;
1384
1385 if (!(phba->max_vpi))
1386 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1387 if (vport->port_type == LPFC_PHYSICAL_PORT)
1388 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1389 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1390}
1391
James Smarte59058c2008-08-24 21:49:00 -04001392/**
James Smart3621a712009-04-06 18:47:14 -04001393 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001394 * @dev: class device that is converted into a Scsi_host.
1395 * @attr: device attribute, not used.
1396 * @buf: on return contains the cfg_poll in hex.
1397 *
1398 * Notes:
1399 * cfg_poll should be a lpfc_polling_flags type.
1400 *
1401 * Returns: size of formatted string.
1402 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001403static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001404lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1405 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001406{
Tony Jonesee959b02008-02-22 00:13:36 +01001407 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1409 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001410
1411 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1412}
1413
James Smarte59058c2008-08-24 21:49:00 -04001414/**
James Smart3621a712009-04-06 18:47:14 -04001415 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001416 * @dev: class device that is converted into a Scsi_host.
1417 * @attr: device attribute, not used.
1418 * @buf: one or more lpfc_polling_flags values.
1419 * @count: not used.
1420 *
1421 * Notes:
1422 * buf contents converted to integer and checked for a valid value.
1423 *
1424 * Returns:
1425 * -EINVAL if the buffer connot be converted or is out of range
1426 * length of the buf on success
1427 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001428static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001429lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1430 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001431{
Tony Jonesee959b02008-02-22 00:13:36 +01001432 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001433 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1434 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001435 uint32_t creg_val;
1436 uint32_t old_val;
1437 int val=0;
1438
1439 if (!isdigit(buf[0]))
1440 return -EINVAL;
1441
1442 if (sscanf(buf, "%i", &val) != 1)
1443 return -EINVAL;
1444
1445 if ((val & 0x3) != val)
1446 return -EINVAL;
1447
James Smart45ed1192009-10-02 15:17:02 -04001448 if (phba->sli_rev == LPFC_SLI_REV4)
1449 val = 0;
1450
James Smart88a2cfb2011-07-22 18:36:33 -04001451 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1452 "3051 lpfc_poll changed from %d to %d\n",
1453 phba->cfg_poll, val);
1454
James Smart2e0fef82007-06-17 19:56:36 -05001455 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001456
1457 old_val = phba->cfg_poll;
1458
1459 if (val & ENABLE_FCP_RING_POLLING) {
1460 if ((val & DISABLE_FCP_RING_INT) &&
1461 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001462 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1463 spin_unlock_irq(&phba->hbalock);
1464 return -EINVAL;
1465 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001466 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1467 writel(creg_val, phba->HCregaddr);
1468 readl(phba->HCregaddr); /* flush */
1469
1470 lpfc_poll_start_timer(phba);
1471 }
1472 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001473 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001474 return -EINVAL;
1475 }
1476
1477 if (!(val & DISABLE_FCP_RING_INT) &&
1478 (old_val & DISABLE_FCP_RING_INT))
1479 {
James Smart2e0fef82007-06-17 19:56:36 -05001480 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001481 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001482 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001483 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1484 spin_unlock_irq(&phba->hbalock);
1485 return -EINVAL;
1486 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001487 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1488 writel(creg_val, phba->HCregaddr);
1489 readl(phba->HCregaddr); /* flush */
1490 }
1491
1492 phba->cfg_poll = val;
1493
James Smart2e0fef82007-06-17 19:56:36 -05001494 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001495
1496 return strlen(buf);
1497}
dea31012005-04-17 16:05:31 -05001498
James Smarte59058c2008-08-24 21:49:00 -04001499/**
James Smartbc739052010-08-04 16:11:18 -04001500 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1501 * @dev: class unused variable.
1502 * @attr: device attribute, not used.
1503 * @buf: on return contains the module description text.
1504 *
1505 * Returns: size of formatted string.
1506 **/
1507static ssize_t
1508lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1509 char *buf)
1510{
1511 struct Scsi_Host *shost = class_to_shost(dev);
1512 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1513 struct lpfc_hba *phba = vport->phba;
1514
1515 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1516}
1517
1518/**
1519 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1520 * @dev: class unused variable.
1521 * @attr: device attribute, not used.
1522 * @buf: on return contains the module description text.
1523 *
1524 * Returns: size of formatted string.
1525 **/
1526static ssize_t
1527lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1528 char *buf)
1529{
1530 struct Scsi_Host *shost = class_to_shost(dev);
1531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1532 struct lpfc_hba *phba = vport->phba;
1533
1534 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1535}
1536
1537/**
James Smartab56dc22011-02-16 12:39:57 -05001538 * lpfc_dss_show - Return the current state of dss and the configured state
1539 * @dev: class converted to a Scsi_host structure.
1540 * @attr: device attribute, not used.
1541 * @buf: on return contains the formatted text.
1542 *
1543 * Returns: size of formatted string.
1544 **/
1545static ssize_t
1546lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1547 char *buf)
1548{
1549 struct Scsi_Host *shost = class_to_shost(dev);
1550 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1551 struct lpfc_hba *phba = vport->phba;
1552
1553 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1554 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1555 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1556 "" : "Not ");
1557}
1558
1559/**
James Smart912e3ac2011-05-24 11:42:11 -04001560 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1561 * @dev: class converted to a Scsi_host structure.
1562 * @attr: device attribute, not used.
1563 * @buf: on return contains the formatted support level.
1564 *
1565 * Description:
1566 * Returns the maximum number of virtual functions a physical function can
1567 * support, 0 will be returned if called on virtual function.
1568 *
1569 * Returns: size of formatted string.
1570 **/
1571static ssize_t
1572lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1573 struct device_attribute *attr,
1574 char *buf)
1575{
1576 struct Scsi_Host *shost = class_to_shost(dev);
1577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1578 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001579 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001580
James Smart0a96e972011-07-22 18:37:28 -04001581 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1582 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001583}
1584
1585/**
James Smart3621a712009-04-06 18:47:14 -04001586 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001587 *
1588 * Description:
1589 * Macro that given an attr e.g. hba_queue_depth expands
1590 * into a function with the name lpfc_hba_queue_depth_show.
1591 *
1592 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1593 * @dev: class device that is converted into a Scsi_host.
1594 * @attr: device attribute, not used.
1595 * @buf: on return contains the attribute value in decimal.
1596 *
1597 * Returns: size of formatted string.
1598 **/
dea31012005-04-17 16:05:31 -05001599#define lpfc_param_show(attr) \
1600static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001601lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1602 char *buf) \
dea31012005-04-17 16:05:31 -05001603{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001604 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1606 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001607 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001608 val = phba->cfg_##attr;\
1609 return snprintf(buf, PAGE_SIZE, "%d\n",\
1610 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001611}
1612
James Smarte59058c2008-08-24 21:49:00 -04001613/**
James Smart3621a712009-04-06 18:47:14 -04001614 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001615 *
1616 * Description:
1617 * Macro that given an attr e.g. hba_queue_depth expands
1618 * into a function with the name lpfc_hba_queue_depth_show
1619 *
1620 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1621 * @dev: class device that is converted into a Scsi_host.
1622 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001623 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001624 *
1625 * Returns: size of formatted string.
1626 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001627#define lpfc_param_hex_show(attr) \
1628static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001629lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1630 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001631{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001632 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001633 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1634 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001635 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001636 val = phba->cfg_##attr;\
1637 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1638 phba->cfg_##attr);\
1639}
1640
James Smarte59058c2008-08-24 21:49:00 -04001641/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001642 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001643 *
1644 * Description:
1645 * Macro that given an attr e.g. hba_queue_depth expands
1646 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1647 * takes a default argument, a minimum and maximum argument.
1648 *
1649 * lpfc_##attr##_init: Initializes an attribute.
1650 * @phba: pointer the the adapter structure.
1651 * @val: integer attribute value.
1652 *
1653 * Validates the min and max values then sets the adapter config field
1654 * accordingly, or uses the default if out of range and prints an error message.
1655 *
1656 * Returns:
1657 * zero on success
1658 * -EINVAL if default used
1659 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001660#define lpfc_param_init(attr, default, minval, maxval) \
1661static int \
James Smart84d1b002010-02-12 14:42:33 -05001662lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001663{ \
1664 if (val >= minval && val <= maxval) {\
1665 phba->cfg_##attr = val;\
1666 return 0;\
1667 }\
1668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001669 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1670 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001671 phba->cfg_##attr = default;\
1672 return -EINVAL;\
1673}
1674
James Smarte59058c2008-08-24 21:49:00 -04001675/**
James Smart3621a712009-04-06 18:47:14 -04001676 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001677 *
1678 * Description:
1679 * Macro that given an attr e.g. hba_queue_depth expands
1680 * into a function with the name lpfc_hba_queue_depth_set
1681 *
1682 * lpfc_##attr##_set: Sets an attribute value.
1683 * @phba: pointer the the adapter structure.
1684 * @val: integer attribute value.
1685 *
1686 * Description:
1687 * Validates the min and max values then sets the
1688 * adapter config field if in the valid range. prints error message
1689 * and does not set the parameter if invalid.
1690 *
1691 * Returns:
1692 * zero on success
1693 * -EINVAL if val is invalid
1694 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001695#define lpfc_param_set(attr, default, minval, maxval) \
1696static int \
James Smart84d1b002010-02-12 14:42:33 -05001697lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001698{ \
1699 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1701 "3052 lpfc_" #attr " changed from %d to %d\n", \
1702 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001703 phba->cfg_##attr = val;\
1704 return 0;\
1705 }\
1706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001707 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1708 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001709 return -EINVAL;\
1710}
1711
James Smarte59058c2008-08-24 21:49:00 -04001712/**
James Smart3621a712009-04-06 18:47:14 -04001713 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001714 *
1715 * Description:
1716 * Macro that given an attr e.g. hba_queue_depth expands
1717 * into a function with the name lpfc_hba_queue_depth_store.
1718 *
1719 * lpfc_##attr##_store: Set an sttribute value.
1720 * @dev: class device that is converted into a Scsi_host.
1721 * @attr: device attribute, not used.
1722 * @buf: contains the attribute value in ascii.
1723 * @count: not used.
1724 *
1725 * Description:
1726 * Convert the ascii text number to an integer, then
1727 * use the lpfc_##attr##_set function to set the value.
1728 *
1729 * Returns:
1730 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1731 * length of buffer upon success.
1732 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001733#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001734static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001735lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1736 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001737{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001738 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1740 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001741 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001742 if (!isdigit(buf[0]))\
1743 return -EINVAL;\
1744 if (sscanf(buf, "%i", &val) != 1)\
1745 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001746 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001747 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001748 else \
1749 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001750}
1751
James Smarte59058c2008-08-24 21:49:00 -04001752/**
James Smart3621a712009-04-06 18:47:14 -04001753 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001754 *
1755 * Description:
1756 * Macro that given an attr e.g. hba_queue_depth expands
1757 * into a function with the name lpfc_hba_queue_depth_show
1758 *
1759 * lpfc_##attr##_show: prints the attribute value in decimal.
1760 * @dev: class device that is converted into a Scsi_host.
1761 * @attr: device attribute, not used.
1762 * @buf: on return contains the attribute value in decimal.
1763 *
1764 * Returns: length of formatted string.
1765 **/
James Smart3de2a652007-08-02 11:09:59 -04001766#define lpfc_vport_param_show(attr) \
1767static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001768lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1769 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001770{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001771 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001772 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001773 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001774 val = vport->cfg_##attr;\
1775 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1776}
1777
James Smarte59058c2008-08-24 21:49:00 -04001778/**
James Smart3621a712009-04-06 18:47:14 -04001779 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001780 *
1781 * Description:
1782 * Macro that given an attr e.g.
1783 * hba_queue_depth expands into a function with the name
1784 * lpfc_hba_queue_depth_show
1785 *
James Smart3621a712009-04-06 18:47:14 -04001786 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001787 * @dev: class device that is converted into a Scsi_host.
1788 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001789 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001790 *
1791 * Returns: length of formatted string.
1792 **/
James Smart3de2a652007-08-02 11:09:59 -04001793#define lpfc_vport_param_hex_show(attr) \
1794static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001795lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1796 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001797{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001798 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001799 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001800 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001801 val = vport->cfg_##attr;\
1802 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1803}
1804
James Smarte59058c2008-08-24 21:49:00 -04001805/**
James Smart3621a712009-04-06 18:47:14 -04001806 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001807 *
1808 * Description:
1809 * Macro that given an attr e.g. hba_queue_depth expands
1810 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1811 * takes a default argument, a minimum and maximum argument.
1812 *
1813 * lpfc_##attr##_init: validates the min and max values then sets the
1814 * adapter config field accordingly, or uses the default if out of range
1815 * and prints an error message.
1816 * @phba: pointer the the adapter structure.
1817 * @val: integer attribute value.
1818 *
1819 * Returns:
1820 * zero on success
1821 * -EINVAL if default used
1822 **/
James Smart3de2a652007-08-02 11:09:59 -04001823#define lpfc_vport_param_init(attr, default, minval, maxval) \
1824static int \
James Smart84d1b002010-02-12 14:42:33 -05001825lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001826{ \
1827 if (val >= minval && val <= maxval) {\
1828 vport->cfg_##attr = val;\
1829 return 0;\
1830 }\
James Smarte8b62012007-08-02 11:10:09 -04001831 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001832 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001833 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001834 vport->cfg_##attr = default;\
1835 return -EINVAL;\
1836}
1837
James Smarte59058c2008-08-24 21:49:00 -04001838/**
James Smart3621a712009-04-06 18:47:14 -04001839 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001840 *
1841 * Description:
1842 * Macro that given an attr e.g. hba_queue_depth expands
1843 * into a function with the name lpfc_hba_queue_depth_set
1844 *
1845 * lpfc_##attr##_set: validates the min and max values then sets the
1846 * adapter config field if in the valid range. prints error message
1847 * and does not set the parameter if invalid.
1848 * @phba: pointer the the adapter structure.
1849 * @val: integer attribute value.
1850 *
1851 * Returns:
1852 * zero on success
1853 * -EINVAL if val is invalid
1854 **/
James Smart3de2a652007-08-02 11:09:59 -04001855#define lpfc_vport_param_set(attr, default, minval, maxval) \
1856static int \
James Smart84d1b002010-02-12 14:42:33 -05001857lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001858{ \
1859 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001860 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1861 "3053 lpfc_" #attr " changed from %d to %d\n", \
1862 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001863 vport->cfg_##attr = val;\
1864 return 0;\
1865 }\
James Smarte8b62012007-08-02 11:10:09 -04001866 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001867 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001868 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001869 return -EINVAL;\
1870}
1871
James Smarte59058c2008-08-24 21:49:00 -04001872/**
James Smart3621a712009-04-06 18:47:14 -04001873 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001874 *
1875 * Description:
1876 * Macro that given an attr e.g. hba_queue_depth
1877 * expands into a function with the name lpfc_hba_queue_depth_store
1878 *
1879 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1880 * use the lpfc_##attr##_set function to set the value.
1881 * @cdev: class device that is converted into a Scsi_host.
1882 * @buf: contains the attribute value in decimal.
1883 * @count: not used.
1884 *
1885 * Returns:
1886 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1887 * length of buffer upon success.
1888 **/
James Smart3de2a652007-08-02 11:09:59 -04001889#define lpfc_vport_param_store(attr) \
1890static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001891lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1892 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001893{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001894 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001895 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001896 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001897 if (!isdigit(buf[0]))\
1898 return -EINVAL;\
1899 if (sscanf(buf, "%i", &val) != 1)\
1900 return -EINVAL;\
1901 if (lpfc_##attr##_set(vport, val) == 0) \
1902 return strlen(buf);\
1903 else \
1904 return -EINVAL;\
1905}
1906
1907
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001908#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001909static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001910module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001911MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001912lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001913
1914#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001915static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001916module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001917MODULE_PARM_DESC(lpfc_##name, desc);\
1918lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001919lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001920static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001921
1922#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001923static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001924module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001925MODULE_PARM_DESC(lpfc_##name, desc);\
1926lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001927lpfc_param_init(name, defval, minval, maxval)\
1928lpfc_param_set(name, defval, minval, maxval)\
1929lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001930static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1931 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001932
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001933#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001934static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001935module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001936MODULE_PARM_DESC(lpfc_##name, desc);\
1937lpfc_param_hex_show(name)\
1938lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001939static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001940
1941#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001942static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001943module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001944MODULE_PARM_DESC(lpfc_##name, desc);\
1945lpfc_param_hex_show(name)\
1946lpfc_param_init(name, defval, minval, maxval)\
1947lpfc_param_set(name, defval, minval, maxval)\
1948lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001949static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1950 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001951
James Smart3de2a652007-08-02 11:09:59 -04001952#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001953static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001954module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001955MODULE_PARM_DESC(lpfc_##name, desc);\
1956lpfc_vport_param_init(name, defval, minval, maxval)
1957
1958#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001959static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001960module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001961MODULE_PARM_DESC(lpfc_##name, desc);\
1962lpfc_vport_param_show(name)\
1963lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001964static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001965
1966#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001967static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001968module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001969MODULE_PARM_DESC(lpfc_##name, desc);\
1970lpfc_vport_param_show(name)\
1971lpfc_vport_param_init(name, defval, minval, maxval)\
1972lpfc_vport_param_set(name, defval, minval, maxval)\
1973lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001974static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1975 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001976
1977#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001978static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001979module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001980MODULE_PARM_DESC(lpfc_##name, desc);\
1981lpfc_vport_param_hex_show(name)\
1982lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001983static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001984
1985#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001986static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001987module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001988MODULE_PARM_DESC(lpfc_##name, desc);\
1989lpfc_vport_param_hex_show(name)\
1990lpfc_vport_param_init(name, defval, minval, maxval)\
1991lpfc_vport_param_set(name, defval, minval, maxval)\
1992lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001993static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1994 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001995
James Smart81301a92008-12-04 22:39:46 -05001996static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1997static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1998static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1999static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002000static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2001static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2002static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2003static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2004static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2005static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2006static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2007static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002008static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2009 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002010static DEVICE_ATTR(option_rom_version, S_IRUGO,
2011 lpfc_option_rom_version_show, NULL);
2012static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2013 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002014static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002015static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2016static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002017static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002018static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2019 lpfc_board_mode_show, lpfc_board_mode_store);
2020static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2021static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2022static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2023static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2024static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2025static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2026static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2027static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2028static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002029static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2030static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002031static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002032static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2033 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002034static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002035
James Smarta12e07b2006-12-02 13:35:30 -05002036static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04002037
James Smarte59058c2008-08-24 21:49:00 -04002038/**
James Smart3621a712009-04-06 18:47:14 -04002039 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04002040 * @dev: class device that is converted into a Scsi_host.
2041 * @attr: device attribute, not used.
2042 * @buf: containing the string lpfc_soft_wwn_key.
2043 * @count: must be size of lpfc_soft_wwn_key.
2044 *
2045 * Returns:
2046 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2047 * length of buf indicates success
2048 **/
James Smartc3f28af2006-08-18 17:47:18 -04002049static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002050lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2051 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002052{
Tony Jonesee959b02008-02-22 00:13:36 +01002053 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002054 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2055 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002056 unsigned int cnt = count;
2057
2058 /*
2059 * We're doing a simple sanity check for soft_wwpn setting.
2060 * We require that the user write a specific key to enable
2061 * the soft_wwpn attribute to be settable. Once the attribute
2062 * is written, the enable key resets. If further updates are
2063 * desired, the key must be written again to re-enable the
2064 * attribute.
2065 *
2066 * The "key" is not secret - it is a hardcoded string shown
2067 * here. The intent is to protect against the random user or
2068 * application that is just writing attributes.
2069 */
2070
2071 /* count may include a LF at end of string */
2072 if (buf[cnt-1] == '\n')
2073 cnt--;
2074
James Smarta12e07b2006-12-02 13:35:30 -05002075 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2076 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04002077 return -EINVAL;
2078
James Smarta12e07b2006-12-02 13:35:30 -05002079 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04002080 return count;
2081}
Tony Jonesee959b02008-02-22 00:13:36 +01002082static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2083 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04002084
James Smarte59058c2008-08-24 21:49:00 -04002085/**
James Smart3621a712009-04-06 18:47:14 -04002086 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002087 * @dev: class device that is converted into a Scsi_host.
2088 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002089 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002090 *
2091 * Returns: size of formatted string.
2092 **/
James Smartc3f28af2006-08-18 17:47:18 -04002093static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002094lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2095 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002096{
Tony Jonesee959b02008-02-22 00:13:36 +01002097 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002098 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2099 struct lpfc_hba *phba = vport->phba;
2100
Randy Dunlapafc071e2006-10-23 21:47:13 -07002101 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2102 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002103}
2104
James Smarte59058c2008-08-24 21:49:00 -04002105/**
James Smart3621a712009-04-06 18:47:14 -04002106 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002107 * @dev class device that is converted into a Scsi_host.
2108 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002109 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002110 * @count: number of wwpn bytes in buf
2111 *
2112 * Returns:
2113 * -EACCES hba reset not enabled, adapter over temp
2114 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2115 * -EIO error taking adapter offline or online
2116 * value of count on success
2117 **/
James Smartc3f28af2006-08-18 17:47:18 -04002118static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002119lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2120 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002121{
Tony Jonesee959b02008-02-22 00:13:36 +01002122 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2124 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002125 struct completion online_compl;
2126 int stat1=0, stat2=0;
2127 unsigned int i, j, cnt=count;
2128 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002129 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002130
James Smart13815c82008-01-11 01:52:48 -05002131 if (!phba->cfg_enable_hba_reset)
2132 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002133 spin_lock_irq(&phba->hbalock);
2134 if (phba->over_temp_state == HBA_OVER_TEMP) {
2135 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002136 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002137 }
2138 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002139 /* count may include a LF at end of string */
2140 if (buf[cnt-1] == '\n')
2141 cnt--;
2142
James Smarta12e07b2006-12-02 13:35:30 -05002143 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002144 ((cnt == 17) && (*buf++ != 'x')) ||
2145 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2146 return -EINVAL;
2147
James Smarta12e07b2006-12-02 13:35:30 -05002148 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002149
2150 memset(wwpn, 0, sizeof(wwpn));
2151
2152 /* Validate and store the new name */
2153 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002154 int value;
2155
2156 value = hex_to_bin(*buf++);
2157 if (value >= 0)
2158 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002159 else
2160 return -EINVAL;
2161 if (i % 2) {
2162 wwpn[i/2] = j & 0xff;
2163 j = 0;
2164 }
2165 }
2166 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002167 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002168 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002169 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002170
2171 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2172 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2173
James Smart46fa3112007-04-25 09:51:45 -04002174 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002175 if (stat1)
2176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002177 "0463 lpfc_soft_wwpn attribute set failed to "
2178 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002179 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002180 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2181 LPFC_EVT_ONLINE);
2182 if (rc == 0)
2183 return -ENOMEM;
2184
James Smartc3f28af2006-08-18 17:47:18 -04002185 wait_for_completion(&online_compl);
2186 if (stat2)
2187 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002188 "0464 lpfc_soft_wwpn attribute set failed to "
2189 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002190 return (stat1 || stat2) ? -EIO : count;
2191}
Tony Jonesee959b02008-02-22 00:13:36 +01002192static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2193 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002194
James Smarte59058c2008-08-24 21:49:00 -04002195/**
James Smart3621a712009-04-06 18:47:14 -04002196 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002197 * @dev: class device that is converted into a Scsi_host.
2198 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002199 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002200 *
2201 * Returns: size of formatted string.
2202 **/
James Smarta12e07b2006-12-02 13:35:30 -05002203static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002204lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2205 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002206{
Tony Jonesee959b02008-02-22 00:13:36 +01002207 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002208 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002209 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2210 (unsigned long long)phba->cfg_soft_wwnn);
2211}
2212
James Smarte59058c2008-08-24 21:49:00 -04002213/**
James Smart3621a712009-04-06 18:47:14 -04002214 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002215 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002216 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002217 * @count: number of wwnn bytes in buf.
2218 *
2219 * Returns:
2220 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2221 * value of count on success
2222 **/
James Smarta12e07b2006-12-02 13:35:30 -05002223static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002224lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2225 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002226{
Tony Jonesee959b02008-02-22 00:13:36 +01002227 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002228 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002229 unsigned int i, j, cnt=count;
2230 u8 wwnn[8];
2231
2232 /* count may include a LF at end of string */
2233 if (buf[cnt-1] == '\n')
2234 cnt--;
2235
2236 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2237 ((cnt == 17) && (*buf++ != 'x')) ||
2238 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2239 return -EINVAL;
2240
2241 /*
2242 * Allow wwnn to be set many times, as long as the enable is set.
2243 * However, once the wwpn is set, everything locks.
2244 */
2245
2246 memset(wwnn, 0, sizeof(wwnn));
2247
2248 /* Validate and store the new name */
2249 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002250 int value;
2251
2252 value = hex_to_bin(*buf++);
2253 if (value >= 0)
2254 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002255 else
2256 return -EINVAL;
2257 if (i % 2) {
2258 wwnn[i/2] = j & 0xff;
2259 j = 0;
2260 }
2261 }
2262 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2263
2264 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2265 "lpfc%d: soft_wwnn set. Value will take effect upon "
2266 "setting of the soft_wwpn\n", phba->brd_no);
2267
2268 return count;
2269}
Tony Jonesee959b02008-02-22 00:13:36 +01002270static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2271 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002272
James Smartc3f28af2006-08-18 17:47:18 -04002273
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002274static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002275module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002276MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2277 " 0 - none,"
2278 " 1 - poll with interrupts enabled"
2279 " 3 - poll and disable FCP ring interrupts");
2280
Tony Jonesee959b02008-02-22 00:13:36 +01002281static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2282 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002283
James Smart92d7f7b2007-06-17 19:56:38 -05002284int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002285module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002286MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2287 " 0 - auto (SLI-3 if supported),"
2288 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2289 " 3 - select SLI-3");
2290
James Smart15672312010-04-06 14:49:03 -04002291int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002292module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002293MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2294lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002295lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002296static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002297
James Smart7d791df2011-07-22 18:37:52 -04002298LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2299 "FCF Fast failover=1 Priority failover=2");
2300
James Smart19ca7602010-11-20 23:11:55 -05002301int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002302module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002303MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2304lpfc_param_show(enable_rrq);
2305lpfc_param_init(enable_rrq, 0, 0, 1);
2306static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2307
dea31012005-04-17 16:05:31 -05002308/*
James Smart84d1b002010-02-12 14:42:33 -05002309# lpfc_suppress_link_up: Bring link up at initialization
2310# 0x0 = bring link up (issue MBX_INIT_LINK)
2311# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2312# 0x2 = never bring up link
2313# Default value is 0.
2314*/
James Smarte40a02c2010-02-26 14:13:54 -05002315LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2316 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2317 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002318/*
2319# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2320# 1 - (1024)
2321# 2 - (2048)
2322# 3 - (3072)
2323# 4 - (4096)
2324# 5 - (5120)
2325*/
2326static ssize_t
2327lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2328{
2329 struct Scsi_Host *shost = class_to_shost(dev);
2330 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2331
2332 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2333}
2334
2335static DEVICE_ATTR(iocb_hw, S_IRUGO,
2336 lpfc_iocb_hw_show, NULL);
2337static ssize_t
2338lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2339{
2340 struct Scsi_Host *shost = class_to_shost(dev);
2341 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2342
2343 return snprintf(buf, PAGE_SIZE, "%d\n",
2344 phba->sli.ring[LPFC_ELS_RING].txq_max);
2345}
2346
2347static DEVICE_ATTR(txq_hw, S_IRUGO,
2348 lpfc_txq_hw_show, NULL);
2349static ssize_t
2350lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2351 char *buf)
2352{
2353 struct Scsi_Host *shost = class_to_shost(dev);
2354 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2355
2356 return snprintf(buf, PAGE_SIZE, "%d\n",
2357 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2358}
2359
2360static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2361 lpfc_txcmplq_hw_show, NULL);
2362
2363int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002364module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002365MODULE_PARM_DESC(lpfc_iocb_cnt,
2366 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2367lpfc_param_show(iocb_cnt);
2368lpfc_param_init(iocb_cnt, 2, 1, 5);
2369static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2370 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002371
2372/*
James Smartc01f3202006-08-18 17:47:08 -04002373# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2374# until the timer expires. Value range is [0,255]. Default value is 30.
2375*/
2376static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2377static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2378module_param(lpfc_nodev_tmo, int, 0);
2379MODULE_PARM_DESC(lpfc_nodev_tmo,
2380 "Seconds driver will hold I/O waiting "
2381 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002382
2383/**
James Smart3621a712009-04-06 18:47:14 -04002384 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002385 * @dev: class converted to a Scsi_host structure.
2386 * @attr: device attribute, not used.
2387 * @buf: on return contains the dev loss timeout in decimal.
2388 *
2389 * Returns: size of formatted string.
2390 **/
James Smartc01f3202006-08-18 17:47:08 -04002391static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002392lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2393 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002394{
Tony Jonesee959b02008-02-22 00:13:36 +01002395 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002396 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002397
James Smart3de2a652007-08-02 11:09:59 -04002398 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002399}
2400
James Smarte59058c2008-08-24 21:49:00 -04002401/**
James Smart3621a712009-04-06 18:47:14 -04002402 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002403 * @vport: lpfc vport structure pointer.
2404 * @val: contains the nodev timeout value.
2405 *
2406 * Description:
2407 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2408 * a kernel error message is printed and zero is returned.
2409 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2410 * Otherwise nodev tmo is set to the default value.
2411 *
2412 * Returns:
2413 * zero if already set or if val is in range
2414 * -EINVAL val out of range
2415 **/
James Smartc01f3202006-08-18 17:47:08 -04002416static int
James Smart3de2a652007-08-02 11:09:59 -04002417lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002418{
James Smart3de2a652007-08-02 11:09:59 -04002419 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2420 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2421 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002422 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002423 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002424 "parameter because devloss_tmo is "
2425 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002426 return 0;
2427 }
2428
2429 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002430 vport->cfg_nodev_tmo = val;
2431 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002432 return 0;
2433 }
James Smarte8b62012007-08-02 11:10:09 -04002434 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2435 "0400 lpfc_nodev_tmo attribute cannot be set to"
2436 " %d, allowed range is [%d, %d]\n",
2437 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002438 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002439 return -EINVAL;
2440}
2441
James Smarte59058c2008-08-24 21:49:00 -04002442/**
James Smart3621a712009-04-06 18:47:14 -04002443 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002444 * @vport: lpfc vport structure pointer.
2445 *
2446 * Description:
2447 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2448 **/
James Smart7054a602007-04-25 09:52:34 -04002449static void
James Smart3de2a652007-08-02 11:09:59 -04002450lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002451{
James Smart858c9f62007-06-17 19:56:39 -05002452 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002453 struct lpfc_nodelist *ndlp;
2454
James Smart51ef4c22007-08-02 11:10:31 -04002455 shost = lpfc_shost_from_vport(vport);
2456 spin_lock_irq(shost->host_lock);
2457 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002458 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002459 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2460 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002461}
2462
James Smarte59058c2008-08-24 21:49:00 -04002463/**
James Smart3621a712009-04-06 18:47:14 -04002464 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002465 * @vport: lpfc vport structure pointer.
2466 * @val: contains the tmo value.
2467 *
2468 * Description:
2469 * If the devloss tmo is already set or the vport dev loss tmo has changed
2470 * then a kernel error message is printed and zero is returned.
2471 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2472 * Otherwise nodev tmo is set to the default value.
2473 *
2474 * Returns:
2475 * zero if already set or if val is in range
2476 * -EINVAL val out of range
2477 **/
James Smartc01f3202006-08-18 17:47:08 -04002478static int
James Smart3de2a652007-08-02 11:09:59 -04002479lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002480{
James Smart3de2a652007-08-02 11:09:59 -04002481 if (vport->dev_loss_tmo_changed ||
2482 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002483 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2484 "0401 Ignoring change to nodev_tmo "
2485 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002486 return 0;
2487 }
James Smartc01f3202006-08-18 17:47:08 -04002488 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002489 vport->cfg_nodev_tmo = val;
2490 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002491 /*
2492 * For compat: set the fc_host dev loss so new rports
2493 * will get the value.
2494 */
2495 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002496 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002497 return 0;
2498 }
James Smarte8b62012007-08-02 11:10:09 -04002499 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2500 "0403 lpfc_nodev_tmo attribute cannot be set to"
2501 "%d, allowed range is [%d, %d]\n",
2502 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002503 return -EINVAL;
2504}
2505
James Smart3de2a652007-08-02 11:09:59 -04002506lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002507
Tony Jonesee959b02008-02-22 00:13:36 +01002508static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2509 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002510
2511/*
2512# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2513# disappear until the timer expires. Value range is [0,255]. Default
2514# value is 30.
2515*/
James Smartab56dc22011-02-16 12:39:57 -05002516module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002517MODULE_PARM_DESC(lpfc_devloss_tmo,
2518 "Seconds driver will hold I/O waiting "
2519 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002520lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2521 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2522lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002523
2524/**
James Smart3621a712009-04-06 18:47:14 -04002525 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002526 * @vport: lpfc vport structure pointer.
2527 * @val: contains the tmo value.
2528 *
2529 * Description:
2530 * If val is in a valid range then set the vport nodev tmo,
2531 * devloss tmo, also set the vport dev loss tmo changed flag.
2532 * Else a kernel error message is printed.
2533 *
2534 * Returns:
2535 * zero if val is in range
2536 * -EINVAL val out of range
2537 **/
James Smartc01f3202006-08-18 17:47:08 -04002538static int
James Smart3de2a652007-08-02 11:09:59 -04002539lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002540{
2541 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002542 vport->cfg_nodev_tmo = val;
2543 vport->cfg_devloss_tmo = val;
2544 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002545 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002546 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002547 return 0;
2548 }
2549
James Smarte8b62012007-08-02 11:10:09 -04002550 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2551 "0404 lpfc_devloss_tmo attribute cannot be set to"
2552 " %d, allowed range is [%d, %d]\n",
2553 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002554 return -EINVAL;
2555}
2556
James Smart3de2a652007-08-02 11:09:59 -04002557lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002558static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2559 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002560
2561/*
dea31012005-04-17 16:05:31 -05002562# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2563# deluged with LOTS of information.
2564# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002565# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002566*/
James Smartf4b4c682009-05-22 14:53:12 -04002567LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002568 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002569
2570/*
James Smart7ee5d432007-10-27 13:37:17 -04002571# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2572# objects that have been registered with the nameserver after login.
2573*/
2574LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2575 "Deregister nameserver objects before LOGO");
2576
2577/*
dea31012005-04-17 16:05:31 -05002578# lun_queue_depth: This parameter is used to limit the number of outstanding
2579# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2580*/
James Smart3de2a652007-08-02 11:09:59 -04002581LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2582 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002583
2584/*
James Smart7dc517d2010-07-14 15:32:10 -04002585# tgt_queue_depth: This parameter is used to limit the number of outstanding
2586# commands per target port. Value range is [10,65535]. Default value is 65535.
2587*/
2588LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2589 "Max number of FCP commands we can queue to a specific target port");
2590
2591/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002592# hba_queue_depth: This parameter is used to limit the number of outstanding
2593# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2594# value is greater than the maximum number of exchanges supported by the HBA,
2595# then maximum number of exchanges supported by the HBA is used to determine
2596# the hba_queue_depth.
2597*/
2598LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2599 "Max number of FCP commands we can queue to a lpfc HBA");
2600
2601/*
James Smart92d7f7b2007-06-17 19:56:38 -05002602# peer_port_login: This parameter allows/prevents logins
2603# between peer ports hosted on the same physical port.
2604# When this parameter is set 0 peer ports of same physical port
2605# are not allowed to login to each other.
2606# When this parameter is set 1 peer ports of same physical port
2607# are allowed to login to each other.
2608# Default value of this parameter is 0.
2609*/
James Smart3de2a652007-08-02 11:09:59 -04002610LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2611 "Allow peer ports on the same physical port to login to each "
2612 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002613
2614/*
James Smart3de2a652007-08-02 11:09:59 -04002615# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002616# between Virtual Ports and remote initiators.
2617# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2618# other initiators and will attempt to PLOGI all remote ports.
2619# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2620# remote ports and will not attempt to PLOGI to other initiators.
2621# This parameter does not restrict to the physical port.
2622# This parameter does not restrict logins to Fabric resident remote ports.
2623# Default value of this parameter is 1.
2624*/
James Smart3de2a652007-08-02 11:09:59 -04002625static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002626module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002627MODULE_PARM_DESC(lpfc_restrict_login,
2628 "Restrict virtual ports login to remote initiators.");
2629lpfc_vport_param_show(restrict_login);
2630
James Smarte59058c2008-08-24 21:49:00 -04002631/**
James Smart3621a712009-04-06 18:47:14 -04002632 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002633 * @vport: lpfc vport structure pointer.
2634 * @val: contains the restrict login value.
2635 *
2636 * Description:
2637 * If val is not in a valid range then log a kernel error message and set
2638 * the vport restrict login to one.
2639 * If the port type is physical clear the restrict login flag and return.
2640 * Else set the restrict login flag to val.
2641 *
2642 * Returns:
2643 * zero if val is in range
2644 * -EINVAL val out of range
2645 **/
James Smart3de2a652007-08-02 11:09:59 -04002646static int
2647lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2648{
2649 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002650 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002651 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002652 "be set to %d, allowed range is [0, 1]\n",
2653 val);
James Smart3de2a652007-08-02 11:09:59 -04002654 vport->cfg_restrict_login = 1;
2655 return -EINVAL;
2656 }
2657 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2658 vport->cfg_restrict_login = 0;
2659 return 0;
2660 }
2661 vport->cfg_restrict_login = val;
2662 return 0;
2663}
2664
James Smarte59058c2008-08-24 21:49:00 -04002665/**
James Smart3621a712009-04-06 18:47:14 -04002666 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002667 * @vport: lpfc vport structure pointer.
2668 * @val: contains the restrict login value.
2669 *
2670 * Description:
2671 * If val is not in a valid range then log a kernel error message and set
2672 * the vport restrict login to one.
2673 * If the port type is physical and the val is not zero log a kernel
2674 * error message, clear the restrict login flag and return zero.
2675 * Else set the restrict login flag to val.
2676 *
2677 * Returns:
2678 * zero if val is in range
2679 * -EINVAL val out of range
2680 **/
James Smart3de2a652007-08-02 11:09:59 -04002681static int
2682lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2683{
2684 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002685 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002686 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002687 "be set to %d, allowed range is [0, 1]\n",
2688 val);
James Smart3de2a652007-08-02 11:09:59 -04002689 vport->cfg_restrict_login = 1;
2690 return -EINVAL;
2691 }
2692 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002693 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2694 "0468 lpfc_restrict_login must be 0 for "
2695 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002696 vport->cfg_restrict_login = 0;
2697 return 0;
2698 }
2699 vport->cfg_restrict_login = val;
2700 return 0;
2701}
2702lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002703static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2704 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002705
2706/*
dea31012005-04-17 16:05:31 -05002707# Some disk devices have a "select ID" or "select Target" capability.
2708# From a protocol standpoint "select ID" usually means select the
2709# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2710# annex" which contains a table that maps a "select ID" (a number
2711# between 0 and 7F) to an ALPA. By default, for compatibility with
2712# older drivers, the lpfc driver scans this table from low ALPA to high
2713# ALPA.
2714#
2715# Turning on the scan-down variable (on = 1, off = 0) will
2716# cause the lpfc driver to use an inverted table, effectively
2717# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2718#
2719# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2720# and will not work across a fabric. Also this parameter will take
2721# effect only in the case when ALPA map is not available.)
2722*/
James Smart3de2a652007-08-02 11:09:59 -04002723LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2724 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002725
2726/*
dea31012005-04-17 16:05:31 -05002727# lpfc_topology: link topology for init link
2728# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002729# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002730# 0x02 = attempt point-to-point mode only
2731# 0x04 = attempt loop mode only
2732# 0x06 = attempt point-to-point mode then loop
2733# Set point-to-point mode if you want to run as an N_Port.
2734# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2735# Default value is 0.
2736*/
James Smarte59058c2008-08-24 21:49:00 -04002737
2738/**
James Smart3621a712009-04-06 18:47:14 -04002739 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002740 * @phba: lpfc_hba pointer.
2741 * @val: topology value.
2742 *
2743 * Description:
2744 * If val is in a valid range then set the adapter's topology field and
2745 * issue a lip; if the lip fails reset the topology to the old value.
2746 *
2747 * If the value is not in range log a kernel error message and return an error.
2748 *
2749 * Returns:
2750 * zero if val is in range and lip okay
2751 * non-zero return value from lpfc_issue_lip()
2752 * -EINVAL val out of range
2753 **/
James Smarta257bf92009-04-06 18:48:10 -04002754static ssize_t
2755lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2756 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002757{
James Smarta257bf92009-04-06 18:48:10 -04002758 struct Scsi_Host *shost = class_to_shost(dev);
2759 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2760 struct lpfc_hba *phba = vport->phba;
2761 int val = 0;
2762 int nolip = 0;
2763 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002764 int err;
2765 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002766
2767 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2768 nolip = 1;
2769 val_buf = &buf[strlen("nolip ")];
2770 }
2771
2772 if (!isdigit(val_buf[0]))
2773 return -EINVAL;
2774 if (sscanf(val_buf, "%i", &val) != 1)
2775 return -EINVAL;
2776
James Smart83108bd2008-01-11 01:53:09 -05002777 if (val >= 0 && val <= 6) {
2778 prev_val = phba->cfg_topology;
2779 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002780 if (nolip)
2781 return strlen(buf);
2782
James Smart88a2cfb2011-07-22 18:36:33 -04002783 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2784 "3054 lpfc_topology changed from %d to %d\n",
2785 prev_val, val);
James Smart83108bd2008-01-11 01:53:09 -05002786 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002787 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002788 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002789 return -EINVAL;
2790 } else
2791 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002792 }
2793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2794 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2795 "allowed range is [0, 6]\n",
2796 phba->brd_no, val);
2797 return -EINVAL;
2798}
2799static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002800module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002801MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2802lpfc_param_show(topology)
2803lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002804static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002805 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002806
James Smart21e9a0a2009-05-22 14:53:21 -04002807/**
2808 * lpfc_static_vport_show: Read callback function for
2809 * lpfc_static_vport sysfs file.
2810 * @dev: Pointer to class device object.
2811 * @attr: device attribute structure.
2812 * @buf: Data buffer.
2813 *
2814 * This function is the read call back function for
2815 * lpfc_static_vport sysfs file. The lpfc_static_vport
2816 * sysfs file report the mageability of the vport.
2817 **/
2818static ssize_t
2819lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2820 char *buf)
2821{
2822 struct Scsi_Host *shost = class_to_shost(dev);
2823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2824 if (vport->vport_flag & STATIC_VPORT)
2825 sprintf(buf, "1\n");
2826 else
2827 sprintf(buf, "0\n");
2828
2829 return strlen(buf);
2830}
2831
2832/*
2833 * Sysfs attribute to control the statistical data collection.
2834 */
2835static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2836 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002837
2838/**
James Smart3621a712009-04-06 18:47:14 -04002839 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002840 * @dev: Pointer to class device.
2841 * @buf: Data buffer.
2842 * @count: Size of the data buffer.
2843 *
2844 * This function get called when an user write to the lpfc_stat_data_ctrl
2845 * sysfs file. This function parse the command written to the sysfs file
2846 * and take appropriate action. These commands are used for controlling
2847 * driver statistical data collection.
2848 * Following are the command this function handles.
2849 *
2850 * setbucket <bucket_type> <base> <step>
2851 * = Set the latency buckets.
2852 * destroybucket = destroy all the buckets.
2853 * start = start data collection
2854 * stop = stop data collection
2855 * reset = reset the collected data
2856 **/
2857static ssize_t
2858lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2859 const char *buf, size_t count)
2860{
2861 struct Scsi_Host *shost = class_to_shost(dev);
2862 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2863 struct lpfc_hba *phba = vport->phba;
2864#define LPFC_MAX_DATA_CTRL_LEN 1024
2865 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2866 unsigned long i;
2867 char *str_ptr, *token;
2868 struct lpfc_vport **vports;
2869 struct Scsi_Host *v_shost;
2870 char *bucket_type_str, *base_str, *step_str;
2871 unsigned long base, step, bucket_type;
2872
2873 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002874 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002875 return -EINVAL;
2876
2877 strcpy(bucket_data, buf);
2878 str_ptr = &bucket_data[0];
2879 /* Ignore this token - this is command token */
2880 token = strsep(&str_ptr, "\t ");
2881 if (!token)
2882 return -EINVAL;
2883
2884 bucket_type_str = strsep(&str_ptr, "\t ");
2885 if (!bucket_type_str)
2886 return -EINVAL;
2887
2888 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2889 bucket_type = LPFC_LINEAR_BUCKET;
2890 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2891 bucket_type = LPFC_POWER2_BUCKET;
2892 else
2893 return -EINVAL;
2894
2895 base_str = strsep(&str_ptr, "\t ");
2896 if (!base_str)
2897 return -EINVAL;
2898 base = simple_strtoul(base_str, NULL, 0);
2899
2900 step_str = strsep(&str_ptr, "\t ");
2901 if (!step_str)
2902 return -EINVAL;
2903 step = simple_strtoul(step_str, NULL, 0);
2904 if (!step)
2905 return -EINVAL;
2906
2907 /* Block the data collection for every vport */
2908 vports = lpfc_create_vport_work_array(phba);
2909 if (vports == NULL)
2910 return -ENOMEM;
2911
James Smartf4b4c682009-05-22 14:53:12 -04002912 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002913 v_shost = lpfc_shost_from_vport(vports[i]);
2914 spin_lock_irq(v_shost->host_lock);
2915 /* Block and reset data collection */
2916 vports[i]->stat_data_blocked = 1;
2917 if (vports[i]->stat_data_enabled)
2918 lpfc_vport_reset_stat_data(vports[i]);
2919 spin_unlock_irq(v_shost->host_lock);
2920 }
2921
2922 /* Set the bucket attributes */
2923 phba->bucket_type = bucket_type;
2924 phba->bucket_base = base;
2925 phba->bucket_step = step;
2926
James Smartf4b4c682009-05-22 14:53:12 -04002927 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002928 v_shost = lpfc_shost_from_vport(vports[i]);
2929
2930 /* Unblock data collection */
2931 spin_lock_irq(v_shost->host_lock);
2932 vports[i]->stat_data_blocked = 0;
2933 spin_unlock_irq(v_shost->host_lock);
2934 }
2935 lpfc_destroy_vport_work_array(phba, vports);
2936 return strlen(buf);
2937 }
2938
2939 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2940 vports = lpfc_create_vport_work_array(phba);
2941 if (vports == NULL)
2942 return -ENOMEM;
2943
James Smartf4b4c682009-05-22 14:53:12 -04002944 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002945 v_shost = lpfc_shost_from_vport(vports[i]);
2946 spin_lock_irq(shost->host_lock);
2947 vports[i]->stat_data_blocked = 1;
2948 lpfc_free_bucket(vport);
2949 vport->stat_data_enabled = 0;
2950 vports[i]->stat_data_blocked = 0;
2951 spin_unlock_irq(shost->host_lock);
2952 }
2953 lpfc_destroy_vport_work_array(phba, vports);
2954 phba->bucket_type = LPFC_NO_BUCKET;
2955 phba->bucket_base = 0;
2956 phba->bucket_step = 0;
2957 return strlen(buf);
2958 }
2959
2960 if (!strncmp(buf, "start", strlen("start"))) {
2961 /* If no buckets configured return error */
2962 if (phba->bucket_type == LPFC_NO_BUCKET)
2963 return -EINVAL;
2964 spin_lock_irq(shost->host_lock);
2965 if (vport->stat_data_enabled) {
2966 spin_unlock_irq(shost->host_lock);
2967 return strlen(buf);
2968 }
2969 lpfc_alloc_bucket(vport);
2970 vport->stat_data_enabled = 1;
2971 spin_unlock_irq(shost->host_lock);
2972 return strlen(buf);
2973 }
2974
2975 if (!strncmp(buf, "stop", strlen("stop"))) {
2976 spin_lock_irq(shost->host_lock);
2977 if (vport->stat_data_enabled == 0) {
2978 spin_unlock_irq(shost->host_lock);
2979 return strlen(buf);
2980 }
2981 lpfc_free_bucket(vport);
2982 vport->stat_data_enabled = 0;
2983 spin_unlock_irq(shost->host_lock);
2984 return strlen(buf);
2985 }
2986
2987 if (!strncmp(buf, "reset", strlen("reset"))) {
2988 if ((phba->bucket_type == LPFC_NO_BUCKET)
2989 || !vport->stat_data_enabled)
2990 return strlen(buf);
2991 spin_lock_irq(shost->host_lock);
2992 vport->stat_data_blocked = 1;
2993 lpfc_vport_reset_stat_data(vport);
2994 vport->stat_data_blocked = 0;
2995 spin_unlock_irq(shost->host_lock);
2996 return strlen(buf);
2997 }
2998 return -EINVAL;
2999}
3000
3001
3002/**
James Smart3621a712009-04-06 18:47:14 -04003003 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003004 * @dev: Pointer to class device object.
3005 * @buf: Data buffer.
3006 *
3007 * This function is the read call back function for
3008 * lpfc_stat_data_ctrl sysfs file. This function report the
3009 * current statistical data collection state.
3010 **/
3011static ssize_t
3012lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3013 char *buf)
3014{
3015 struct Scsi_Host *shost = class_to_shost(dev);
3016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3017 struct lpfc_hba *phba = vport->phba;
3018 int index = 0;
3019 int i;
3020 char *bucket_type;
3021 unsigned long bucket_value;
3022
3023 switch (phba->bucket_type) {
3024 case LPFC_LINEAR_BUCKET:
3025 bucket_type = "linear";
3026 break;
3027 case LPFC_POWER2_BUCKET:
3028 bucket_type = "power2";
3029 break;
3030 default:
3031 bucket_type = "No Bucket";
3032 break;
3033 }
3034
3035 sprintf(&buf[index], "Statistical Data enabled :%d, "
3036 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3037 " Bucket step :%d\nLatency Ranges :",
3038 vport->stat_data_enabled, vport->stat_data_blocked,
3039 bucket_type, phba->bucket_base, phba->bucket_step);
3040 index = strlen(buf);
3041 if (phba->bucket_type != LPFC_NO_BUCKET) {
3042 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3043 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3044 bucket_value = phba->bucket_base +
3045 phba->bucket_step * i;
3046 else
3047 bucket_value = phba->bucket_base +
3048 (1 << i) * phba->bucket_step;
3049
3050 if (index + 10 > PAGE_SIZE)
3051 break;
3052 sprintf(&buf[index], "%08ld ", bucket_value);
3053 index = strlen(buf);
3054 }
3055 }
3056 sprintf(&buf[index], "\n");
3057 return strlen(buf);
3058}
3059
3060/*
3061 * Sysfs attribute to control the statistical data collection.
3062 */
3063static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3064 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3065
3066/*
3067 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3068 */
3069
3070/*
3071 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3072 * for each target.
3073 */
3074#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3075#define MAX_STAT_DATA_SIZE_PER_TARGET \
3076 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3077
3078
3079/**
James Smart3621a712009-04-06 18:47:14 -04003080 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003081 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003082 * @kobj: Pointer to the kernel object
3083 * @bin_attr: Attribute object
3084 * @buff: Buffer pointer
3085 * @off: File offset
3086 * @count: Buffer size
3087 *
3088 * This function is the read call back function for lpfc_drvr_stat_data
3089 * sysfs file. This function export the statistical data to user
3090 * applications.
3091 **/
3092static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003093sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3094 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003095 char *buf, loff_t off, size_t count)
3096{
3097 struct device *dev = container_of(kobj, struct device,
3098 kobj);
3099 struct Scsi_Host *shost = class_to_shost(dev);
3100 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3101 struct lpfc_hba *phba = vport->phba;
3102 int i = 0, index = 0;
3103 unsigned long nport_index;
3104 struct lpfc_nodelist *ndlp = NULL;
3105 nport_index = (unsigned long)off /
3106 MAX_STAT_DATA_SIZE_PER_TARGET;
3107
3108 if (!vport->stat_data_enabled || vport->stat_data_blocked
3109 || (phba->bucket_type == LPFC_NO_BUCKET))
3110 return 0;
3111
3112 spin_lock_irq(shost->host_lock);
3113 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3114 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3115 continue;
3116
3117 if (nport_index > 0) {
3118 nport_index--;
3119 continue;
3120 }
3121
3122 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3123 > count)
3124 break;
3125
3126 if (!ndlp->lat_data)
3127 continue;
3128
3129 /* Print the WWN */
3130 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3131 ndlp->nlp_portname.u.wwn[0],
3132 ndlp->nlp_portname.u.wwn[1],
3133 ndlp->nlp_portname.u.wwn[2],
3134 ndlp->nlp_portname.u.wwn[3],
3135 ndlp->nlp_portname.u.wwn[4],
3136 ndlp->nlp_portname.u.wwn[5],
3137 ndlp->nlp_portname.u.wwn[6],
3138 ndlp->nlp_portname.u.wwn[7]);
3139
3140 index = strlen(buf);
3141
3142 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3143 sprintf(&buf[index], "%010u,",
3144 ndlp->lat_data[i].cmd_count);
3145 index = strlen(buf);
3146 }
3147 sprintf(&buf[index], "\n");
3148 index = strlen(buf);
3149 }
3150 spin_unlock_irq(shost->host_lock);
3151 return index;
3152}
3153
3154static struct bin_attribute sysfs_drvr_stat_data_attr = {
3155 .attr = {
3156 .name = "lpfc_drvr_stat_data",
3157 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003158 },
3159 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3160 .read = sysfs_drvr_stat_data_read,
3161 .write = NULL,
3162};
3163
dea31012005-04-17 16:05:31 -05003164/*
3165# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3166# connection.
James Smart76a95d72010-11-20 23:11:48 -05003167# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003168*/
James Smarte59058c2008-08-24 21:49:00 -04003169/**
James Smart3621a712009-04-06 18:47:14 -04003170 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003171 * @phba: lpfc_hba pointer.
3172 * @val: link speed value.
3173 *
3174 * Description:
3175 * If val is in a valid range then set the adapter's link speed field and
3176 * issue a lip; if the lip fails reset the link speed to the old value.
3177 *
3178 * Notes:
3179 * If the value is not in range log a kernel error message and return an error.
3180 *
3181 * Returns:
3182 * zero if val is in range and lip okay.
3183 * non-zero return value from lpfc_issue_lip()
3184 * -EINVAL val out of range
3185 **/
James Smarta257bf92009-04-06 18:48:10 -04003186static ssize_t
3187lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3188 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003189{
James Smarta257bf92009-04-06 18:48:10 -04003190 struct Scsi_Host *shost = class_to_shost(dev);
3191 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3192 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003193 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003194 int nolip = 0;
3195 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003196 int err;
3197 uint32_t prev_val;
3198
James Smarta257bf92009-04-06 18:48:10 -04003199 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3200 nolip = 1;
3201 val_buf = &buf[strlen("nolip ")];
3202 }
3203
3204 if (!isdigit(val_buf[0]))
3205 return -EINVAL;
3206 if (sscanf(val_buf, "%i", &val) != 1)
3207 return -EINVAL;
3208
James Smart88a2cfb2011-07-22 18:36:33 -04003209 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3210 "3055 lpfc_link_speed changed from %d to %d %s\n",
3211 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3212
James Smart76a95d72010-11-20 23:11:48 -05003213 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3214 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3215 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3216 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3217 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3218 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3219 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3220 "2879 lpfc_link_speed attribute cannot be set "
3221 "to %d. Speed is not supported by this port.\n",
3222 val);
James Smart83108bd2008-01-11 01:53:09 -05003223 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003224 }
3225 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3226 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003227 prev_val = phba->cfg_link_speed;
3228 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003229 if (nolip)
3230 return strlen(buf);
3231
James Smart83108bd2008-01-11 01:53:09 -05003232 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003233 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003234 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003235 return -EINVAL;
3236 } else
3237 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003238 }
James Smart83108bd2008-01-11 01:53:09 -05003239 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003240 "0469 lpfc_link_speed attribute cannot be set to %d, "
3241 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003242 return -EINVAL;
3243}
3244
3245static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003246module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003247MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3248lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003249
3250/**
James Smart3621a712009-04-06 18:47:14 -04003251 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003252 * @phba: lpfc_hba pointer.
3253 * @val: link speed value.
3254 *
3255 * Description:
3256 * If val is in a valid range then set the adapter's link speed field.
3257 *
3258 * Notes:
3259 * If the value is not in range log a kernel error message, clear the link
3260 * speed and return an error.
3261 *
3262 * Returns:
3263 * zero if val saved.
3264 * -EINVAL val out of range
3265 **/
James Smart83108bd2008-01-11 01:53:09 -05003266static int
3267lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3268{
James Smart76a95d72010-11-20 23:11:48 -05003269 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3270 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003271 phba->cfg_link_speed = val;
3272 return 0;
3273 }
3274 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003275 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003276 "be set to %d, allowed values are "
3277 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003278 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003279 return -EINVAL;
3280}
3281
Tony Jonesee959b02008-02-22 00:13:36 +01003282static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003283 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003284
3285/*
James Smart0d878412009-10-02 15:16:56 -04003286# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3287# 0 = aer disabled or not supported
3288# 1 = aer supported and enabled (default)
3289# Value range is [0,1]. Default value is 1.
3290*/
3291
3292/**
3293 * lpfc_aer_support_store - Set the adapter for aer support
3294 *
3295 * @dev: class device that is converted into a Scsi_host.
3296 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003297 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003298 * @count: unused variable.
3299 *
3300 * Description:
3301 * If the val is 1 and currently the device's AER capability was not
3302 * enabled, invoke the kernel's enable AER helper routine, trying to
3303 * enable the device's AER capability. If the helper routine enabling
3304 * AER returns success, update the device's cfg_aer_support flag to
3305 * indicate AER is supported by the device; otherwise, if the device
3306 * AER capability is already enabled to support AER, then do nothing.
3307 *
3308 * If the val is 0 and currently the device's AER support was enabled,
3309 * invoke the kernel's disable AER helper routine. After that, update
3310 * the device's cfg_aer_support flag to indicate AER is not supported
3311 * by the device; otherwise, if the device AER capability is already
3312 * disabled from supporting AER, then do nothing.
3313 *
3314 * Returns:
3315 * length of the buf on success if val is in range the intended mode
3316 * is supported.
3317 * -EINVAL if val out of range or intended mode is not supported.
3318 **/
3319static ssize_t
3320lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3321 const char *buf, size_t count)
3322{
3323 struct Scsi_Host *shost = class_to_shost(dev);
3324 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3325 struct lpfc_hba *phba = vport->phba;
3326 int val = 0, rc = -EINVAL;
3327
3328 if (!isdigit(buf[0]))
3329 return -EINVAL;
3330 if (sscanf(buf, "%i", &val) != 1)
3331 return -EINVAL;
3332
3333 switch (val) {
3334 case 0:
3335 if (phba->hba_flag & HBA_AER_ENABLED) {
3336 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3337 if (!rc) {
3338 spin_lock_irq(&phba->hbalock);
3339 phba->hba_flag &= ~HBA_AER_ENABLED;
3340 spin_unlock_irq(&phba->hbalock);
3341 phba->cfg_aer_support = 0;
3342 rc = strlen(buf);
3343 } else
James Smart891478a2009-11-18 15:40:23 -05003344 rc = -EPERM;
3345 } else {
James Smart0d878412009-10-02 15:16:56 -04003346 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003347 rc = strlen(buf);
3348 }
James Smart0d878412009-10-02 15:16:56 -04003349 break;
3350 case 1:
3351 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3352 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3353 if (!rc) {
3354 spin_lock_irq(&phba->hbalock);
3355 phba->hba_flag |= HBA_AER_ENABLED;
3356 spin_unlock_irq(&phba->hbalock);
3357 phba->cfg_aer_support = 1;
3358 rc = strlen(buf);
3359 } else
James Smart891478a2009-11-18 15:40:23 -05003360 rc = -EPERM;
3361 } else {
James Smart0d878412009-10-02 15:16:56 -04003362 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003363 rc = strlen(buf);
3364 }
James Smart0d878412009-10-02 15:16:56 -04003365 break;
3366 default:
3367 rc = -EINVAL;
3368 break;
3369 }
3370 return rc;
3371}
3372
3373static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003374module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003375MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3376lpfc_param_show(aer_support)
3377
3378/**
3379 * lpfc_aer_support_init - Set the initial adapters aer support flag
3380 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003381 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003382 *
3383 * Description:
3384 * If val is in a valid range [0,1], then set the adapter's initial
3385 * cfg_aer_support field. It will be up to the driver's probe_one
3386 * routine to determine whether the device's AER support can be set
3387 * or not.
3388 *
3389 * Notes:
3390 * If the value is not in range log a kernel error message, and
3391 * choose the default value of setting AER support and return.
3392 *
3393 * Returns:
3394 * zero if val saved.
3395 * -EINVAL val out of range
3396 **/
3397static int
3398lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3399{
3400 if (val == 0 || val == 1) {
3401 phba->cfg_aer_support = val;
3402 return 0;
3403 }
3404 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3405 "2712 lpfc_aer_support attribute value %d out "
3406 "of range, allowed values are 0|1, setting it "
3407 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003408 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003409 phba->cfg_aer_support = 1;
3410 return -EINVAL;
3411}
3412
3413static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3414 lpfc_aer_support_show, lpfc_aer_support_store);
3415
3416/**
3417 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3418 * @dev: class device that is converted into a Scsi_host.
3419 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003420 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003421 * @count: unused variable.
3422 *
3423 * Description:
3424 * If the @buf contains 1 and the device currently has the AER support
3425 * enabled, then invokes the kernel AER helper routine
3426 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3427 * error status register.
3428 *
3429 * Notes:
3430 *
3431 * Returns:
3432 * -EINVAL if the buf does not contain the 1 or the device is not currently
3433 * enabled with the AER support.
3434 **/
3435static ssize_t
3436lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3437 const char *buf, size_t count)
3438{
3439 struct Scsi_Host *shost = class_to_shost(dev);
3440 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3441 struct lpfc_hba *phba = vport->phba;
3442 int val, rc = -1;
3443
3444 if (!isdigit(buf[0]))
3445 return -EINVAL;
3446 if (sscanf(buf, "%i", &val) != 1)
3447 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003448 if (val != 1)
3449 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003450
James Smart891478a2009-11-18 15:40:23 -05003451 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003452 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3453
3454 if (rc == 0)
3455 return strlen(buf);
3456 else
James Smart891478a2009-11-18 15:40:23 -05003457 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003458}
3459
3460static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3461 lpfc_aer_cleanup_state);
3462
James Smart912e3ac2011-05-24 11:42:11 -04003463/**
3464 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3465 *
3466 * @dev: class device that is converted into a Scsi_host.
3467 * @attr: device attribute, not used.
3468 * @buf: containing the string the number of vfs to be enabled.
3469 * @count: unused variable.
3470 *
3471 * Description:
3472 * When this api is called either through user sysfs, the driver shall
3473 * try to enable or disable SR-IOV virtual functions according to the
3474 * following:
3475 *
3476 * If zero virtual function has been enabled to the physical function,
3477 * the driver shall invoke the pci enable virtual function api trying
3478 * to enable the virtual functions. If the nr_vfn provided is greater
3479 * than the maximum supported, the maximum virtual function number will
3480 * be used for invoking the api; otherwise, the nr_vfn provided shall
3481 * be used for invoking the api. If the api call returned success, the
3482 * actual number of virtual functions enabled will be set to the driver
3483 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3484 * cfg_sriov_nr_virtfn remains zero.
3485 *
3486 * If none-zero virtual functions have already been enabled to the
3487 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3488 * -EINVAL will be returned and the driver does nothing;
3489 *
3490 * If the nr_vfn provided is zero and none-zero virtual functions have
3491 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3492 * disabling virtual function api shall be invoded to disable all the
3493 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3494 * zero. Otherwise, if zero virtual function has been enabled, do
3495 * nothing.
3496 *
3497 * Returns:
3498 * length of the buf on success if val is in range the intended mode
3499 * is supported.
3500 * -EINVAL if val out of range or intended mode is not supported.
3501 **/
3502static ssize_t
3503lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3504 const char *buf, size_t count)
3505{
3506 struct Scsi_Host *shost = class_to_shost(dev);
3507 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3508 struct lpfc_hba *phba = vport->phba;
3509 struct pci_dev *pdev = phba->pcidev;
3510 int val = 0, rc = -EINVAL;
3511
3512 /* Sanity check on user data */
3513 if (!isdigit(buf[0]))
3514 return -EINVAL;
3515 if (sscanf(buf, "%i", &val) != 1)
3516 return -EINVAL;
3517 if (val < 0)
3518 return -EINVAL;
3519
3520 /* Request disabling virtual functions */
3521 if (val == 0) {
3522 if (phba->cfg_sriov_nr_virtfn > 0) {
3523 pci_disable_sriov(pdev);
3524 phba->cfg_sriov_nr_virtfn = 0;
3525 }
3526 return strlen(buf);
3527 }
3528
3529 /* Request enabling virtual functions */
3530 if (phba->cfg_sriov_nr_virtfn > 0) {
3531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3532 "3018 There are %d virtual functions "
3533 "enabled on physical function.\n",
3534 phba->cfg_sriov_nr_virtfn);
3535 return -EEXIST;
3536 }
3537
3538 if (val <= LPFC_MAX_VFN_PER_PFN)
3539 phba->cfg_sriov_nr_virtfn = val;
3540 else {
3541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3542 "3019 Enabling %d virtual functions is not "
3543 "allowed.\n", val);
3544 return -EINVAL;
3545 }
3546
3547 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3548 if (rc) {
3549 phba->cfg_sriov_nr_virtfn = 0;
3550 rc = -EPERM;
3551 } else
3552 rc = strlen(buf);
3553
3554 return rc;
3555}
3556
3557static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3558module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3559MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3560lpfc_param_show(sriov_nr_virtfn)
3561
3562/**
3563 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3564 * @phba: lpfc_hba pointer.
3565 * @val: link speed value.
3566 *
3567 * Description:
3568 * If val is in a valid range [0,255], then set the adapter's initial
3569 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3570 * number shall be used instead. It will be up to the driver's probe_one
3571 * routine to determine whether the device's SR-IOV is supported or not.
3572 *
3573 * Returns:
3574 * zero if val saved.
3575 * -EINVAL val out of range
3576 **/
3577static int
3578lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3579{
3580 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3581 phba->cfg_sriov_nr_virtfn = val;
3582 return 0;
3583 }
3584
3585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3586 "3017 Enabling %d virtual functions is not "
3587 "allowed.\n", val);
3588 return -EINVAL;
3589}
3590static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3591 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3592
James Smart0d878412009-10-02 15:16:56 -04003593/*
dea31012005-04-17 16:05:31 -05003594# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3595# Value range is [2,3]. Default value is 3.
3596*/
James Smart3de2a652007-08-02 11:09:59 -04003597LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3598 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003599
3600/*
3601# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3602# is [0,1]. Default value is 0.
3603*/
James Smart3de2a652007-08-02 11:09:59 -04003604LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3605 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003606
3607/*
James Smart977b5a02008-09-07 11:52:04 -04003608# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3609# depth. Default value is 0. When the value of this parameter is zero the
3610# SCSI command completion time is not used for controlling I/O queue depth. When
3611# the parameter is set to a non-zero value, the I/O queue depth is controlled
3612# to limit the I/O completion time to the parameter value.
3613# The value is set in milliseconds.
3614*/
3615static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003616module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003617MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3618 "Use command completion time to control queue depth");
3619lpfc_vport_param_show(max_scsicmpl_time);
3620lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3621static int
3622lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3623{
3624 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3625 struct lpfc_nodelist *ndlp, *next_ndlp;
3626
3627 if (val == vport->cfg_max_scsicmpl_time)
3628 return 0;
3629 if ((val < 0) || (val > 60000))
3630 return -EINVAL;
3631 vport->cfg_max_scsicmpl_time = val;
3632
3633 spin_lock_irq(shost->host_lock);
3634 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3635 if (!NLP_CHK_NODE_ACT(ndlp))
3636 continue;
3637 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3638 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003639 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003640 }
3641 spin_unlock_irq(shost->host_lock);
3642 return 0;
3643}
3644lpfc_vport_param_store(max_scsicmpl_time);
3645static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3646 lpfc_max_scsicmpl_time_show,
3647 lpfc_max_scsicmpl_time_store);
3648
3649/*
dea31012005-04-17 16:05:31 -05003650# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3651# range is [0,1]. Default value is 0.
3652*/
3653LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3654
3655/*
3656# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3657# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003658# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003659# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3660# cr_delay is set to 0.
3661*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003662LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003663 "interrupt response is generated");
3664
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003665LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003666 "interrupt response is generated");
3667
3668/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003669# lpfc_multi_ring_support: Determines how many rings to spread available
3670# cmd/rsp IOCB entries across.
3671# Value range is [1,2]. Default value is 1.
3672*/
3673LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3674 "SLI rings to spread IOCB entries across");
3675
3676/*
James Smarta4bc3372006-12-02 13:34:16 -05003677# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3678# identifies what rctl value to configure the additional ring for.
3679# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3680*/
James Smart6a9c52c2009-10-02 15:16:51 -04003681LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003682 255, "Identifies RCTL for additional ring configuration");
3683
3684/*
3685# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3686# identifies what type value to configure the additional ring for.
3687# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3688*/
James Smart6a9c52c2009-10-02 15:16:51 -04003689LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003690 255, "Identifies TYPE for additional ring configuration");
3691
3692/*
dea31012005-04-17 16:05:31 -05003693# lpfc_fdmi_on: controls FDMI support.
3694# 0 = no FDMI support
3695# 1 = support FDMI without attribute of hostname
3696# 2 = support FDMI with attribute of hostname
3697# Value range [0,2]. Default value is 0.
3698*/
James Smart3de2a652007-08-02 11:09:59 -04003699LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003700
3701/*
3702# Specifies the maximum number of ELS cmds we can have outstanding (for
3703# discovery). Value range is [1,64]. Default value = 32.
3704*/
James Smart3de2a652007-08-02 11:09:59 -04003705LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003706 "during discovery");
3707
3708/*
James Smart65a29c12006-07-06 15:50:50 -04003709# lpfc_max_luns: maximum allowed LUN.
3710# Value range is [0,65535]. Default value is 255.
3711# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003712*/
James Smart3de2a652007-08-02 11:09:59 -04003713LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003714
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003715/*
3716# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3717# Value range is [1,255], default value is 10.
3718*/
3719LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3720 "Milliseconds driver will wait between polling FCP ring");
3721
James Smart4ff43242006-12-02 13:34:56 -05003722/*
3723# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3724# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003725# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003726# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003727# 2 = MSI-X enabled (default)
3728# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003729*/
George Kadianakis8605c462010-01-17 21:19:31 +02003730LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003731 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003732
James Smart13815c82008-01-11 01:52:48 -05003733/*
James Smartda0436e2009-05-22 14:51:39 -04003734# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3735#
3736# Value range is [636,651042]. Default value is 10000.
3737*/
3738LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3739 "Set the maximum number of fast-path FCP interrupts per second");
3740
3741/*
3742# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3743#
3744# Value range is [1,31]. Default value is 4.
3745*/
3746LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3747 "Set the number of fast-path FCP work queues, if possible");
3748
3749/*
3750# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3751#
3752# Value range is [1,7]. Default value is 1.
3753*/
3754LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3755 "Set the number of fast-path FCP event queues, if possible");
3756
3757/*
James Smart13815c82008-01-11 01:52:48 -05003758# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3759# 0 = HBA resets disabled
3760# 1 = HBA resets enabled (default)
3761# Value range is [0,1]. Default value is 1.
3762*/
3763LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003764
James Smart13815c82008-01-11 01:52:48 -05003765/*
James Smarteb7a3392010-11-20 23:12:02 -05003766# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003767# 0 = HBA Heartbeat disabled
3768# 1 = HBA Heartbeat enabled (default)
3769# Value range is [0,1]. Default value is 1.
3770*/
James Smarteb7a3392010-11-20 23:12:02 -05003771LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003772
James Smart83108bd2008-01-11 01:53:09 -05003773/*
James Smart81301a92008-12-04 22:39:46 -05003774# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3775# 0 = BlockGuard disabled (default)
3776# 1 = BlockGuard enabled
3777# Value range is [0,1]. Default value is 0.
3778*/
3779LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3780
James Smart6fb120a2009-05-22 14:52:59 -04003781/*
James Smart81301a92008-12-04 22:39:46 -05003782# lpfc_prot_mask: i
3783# - Bit mask of host protection capabilities used to register with the
3784# SCSI mid-layer
3785# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3786# - Allows you to ultimately specify which profiles to use
3787# - Default will result in registering capabilities for all profiles.
3788#
3789*/
James Smart7c56b9f2011-07-22 18:36:25 -04003790unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3791 SHOST_DIX_TYPE0_PROTECTION |
3792 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003793
James Smartab56dc22011-02-16 12:39:57 -05003794module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003795MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3796
3797/*
3798# lpfc_prot_guard: i
3799# - Bit mask of protection guard types to register with the SCSI mid-layer
3800# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3801# - Allows you to ultimately specify which profiles to use
3802# - Default will result in registering capabilities for all guard types
3803#
3804*/
3805unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003806module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003807MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3808
James Smart92494142011-02-16 12:39:44 -05003809/*
3810 * Delay initial NPort discovery when Clean Address bit is cleared in
3811 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3812 * This parameter can have value 0 or 1.
3813 * When this parameter is set to 0, no delay is added to the initial
3814 * discovery.
3815 * When this parameter is set to non-zero value, initial Nport discovery is
3816 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3817 * accept and FCID/Fabric name/Fabric portname is changed.
3818 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3819 * when Clean Address bit is cleared in FLOGI/FDISC
3820 * accept and FCID/Fabric name/Fabric portname is changed.
3821 * Default value is 0.
3822 */
3823int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003824module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003825MODULE_PARM_DESC(lpfc_delay_discovery,
3826 "Delay NPort discovery when Clean Address bit is cleared. "
3827 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003828
3829/*
James Smart3621a712009-04-06 18:47:14 -04003830 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003831 * This value can be set to values between 64 and 256. The default value is
3832 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3833 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3834 */
3835LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3836 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3837
James Smart81301a92008-12-04 22:39:46 -05003838LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3839 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3840 "Max Protection Scatter Gather Segment Count");
3841
Tony Jonesee959b02008-02-22 00:13:36 +01003842struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003843 &dev_attr_bg_info,
3844 &dev_attr_bg_guard_err,
3845 &dev_attr_bg_apptag_err,
3846 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003847 &dev_attr_info,
3848 &dev_attr_serialnum,
3849 &dev_attr_modeldesc,
3850 &dev_attr_modelname,
3851 &dev_attr_programtype,
3852 &dev_attr_portnum,
3853 &dev_attr_fwrev,
3854 &dev_attr_hdw,
3855 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003856 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003857 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003858 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003859 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003860 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003861 &dev_attr_lpfc_temp_sensor,
3862 &dev_attr_lpfc_log_verbose,
3863 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003864 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003865 &dev_attr_lpfc_hba_queue_depth,
3866 &dev_attr_lpfc_peer_port_login,
3867 &dev_attr_lpfc_nodev_tmo,
3868 &dev_attr_lpfc_devloss_tmo,
3869 &dev_attr_lpfc_fcp_class,
3870 &dev_attr_lpfc_use_adisc,
3871 &dev_attr_lpfc_ack0,
3872 &dev_attr_lpfc_topology,
3873 &dev_attr_lpfc_scan_down,
3874 &dev_attr_lpfc_link_speed,
3875 &dev_attr_lpfc_cr_delay,
3876 &dev_attr_lpfc_cr_count,
3877 &dev_attr_lpfc_multi_ring_support,
3878 &dev_attr_lpfc_multi_ring_rctl,
3879 &dev_attr_lpfc_multi_ring_type,
3880 &dev_attr_lpfc_fdmi_on,
3881 &dev_attr_lpfc_max_luns,
3882 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04003883 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05003884 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003885 &dev_attr_nport_evt_cnt,
3886 &dev_attr_board_mode,
3887 &dev_attr_max_vpi,
3888 &dev_attr_used_vpi,
3889 &dev_attr_max_rpi,
3890 &dev_attr_used_rpi,
3891 &dev_attr_max_xri,
3892 &dev_attr_used_xri,
3893 &dev_attr_npiv_info,
3894 &dev_attr_issue_reset,
3895 &dev_attr_lpfc_poll,
3896 &dev_attr_lpfc_poll_tmo,
3897 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003898 &dev_attr_lpfc_fcp_imax,
3899 &dev_attr_lpfc_fcp_wq_count,
3900 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003901 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003902 &dev_attr_lpfc_soft_wwnn,
3903 &dev_attr_lpfc_soft_wwpn,
3904 &dev_attr_lpfc_soft_wwn_enable,
3905 &dev_attr_lpfc_enable_hba_reset,
3906 &dev_attr_lpfc_enable_hba_heartbeat,
3907 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003908 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003909 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003910 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003911 &dev_attr_lpfc_aer_support,
3912 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04003913 &dev_attr_lpfc_sriov_nr_virtfn,
James Smart84d1b002010-02-12 14:42:33 -05003914 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003915 &dev_attr_lpfc_iocb_cnt,
3916 &dev_attr_iocb_hw,
3917 &dev_attr_txq_hw,
3918 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003919 &dev_attr_lpfc_fips_level,
3920 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003921 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04003922 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05003923 &dev_attr_protocol,
dea31012005-04-17 16:05:31 -05003924 NULL,
3925};
3926
Tony Jonesee959b02008-02-22 00:13:36 +01003927struct device_attribute *lpfc_vport_attrs[] = {
3928 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003929 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003930 &dev_attr_num_discovered_ports,
3931 &dev_attr_lpfc_drvr_version,
3932 &dev_attr_lpfc_log_verbose,
3933 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003934 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003935 &dev_attr_lpfc_nodev_tmo,
3936 &dev_attr_lpfc_devloss_tmo,
3937 &dev_attr_lpfc_hba_queue_depth,
3938 &dev_attr_lpfc_peer_port_login,
3939 &dev_attr_lpfc_restrict_login,
3940 &dev_attr_lpfc_fcp_class,
3941 &dev_attr_lpfc_use_adisc,
3942 &dev_attr_lpfc_fdmi_on,
3943 &dev_attr_lpfc_max_luns,
3944 &dev_attr_nport_evt_cnt,
3945 &dev_attr_npiv_info,
3946 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003947 &dev_attr_lpfc_max_scsicmpl_time,
3948 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003949 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003950 &dev_attr_lpfc_fips_level,
3951 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003952 NULL,
3953};
3954
James Smarte59058c2008-08-24 21:49:00 -04003955/**
James Smart3621a712009-04-06 18:47:14 -04003956 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003957 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003958 * @kobj: kernel kobject that contains the kernel class device.
3959 * @bin_attr: kernel attributes passed to us.
3960 * @buf: contains the data to be written to the adapter IOREG space.
3961 * @off: offset into buffer to beginning of data.
3962 * @count: bytes to transfer.
3963 *
3964 * Description:
3965 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3966 * Uses the adapter io control registers to send buf contents to the adapter.
3967 *
3968 * Returns:
3969 * -ERANGE off and count combo out of range
3970 * -EINVAL off, count or buff address invalid
3971 * -EPERM adapter is offline
3972 * value of count, buf contents written
3973 **/
dea31012005-04-17 16:05:31 -05003974static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003975sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3976 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003977 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003978{
3979 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003980 struct device *dev = container_of(kobj, struct device, kobj);
3981 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003982 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3983 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003984
James Smartf1126682009-06-10 17:22:44 -04003985 if (phba->sli_rev >= LPFC_SLI_REV4)
3986 return -EPERM;
3987
dea31012005-04-17 16:05:31 -05003988 if ((off + count) > FF_REG_AREA_SIZE)
3989 return -ERANGE;
3990
James Smartf7a919b2011-08-21 21:49:16 -04003991 if (count <= LPFC_REG_WRITE_KEY_SIZE)
3992 return 0;
dea31012005-04-17 16:05:31 -05003993
3994 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3995 return -EINVAL;
3996
James Smartf7a919b2011-08-21 21:49:16 -04003997 /* This is to protect HBA registers from accidental writes. */
3998 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3999 return -EINVAL;
4000
4001 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05004002 return -EPERM;
dea31012005-04-17 16:05:31 -05004003
James Smart2e0fef82007-06-17 19:56:36 -05004004 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04004005 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4006 buf_off += sizeof(uint32_t))
4007 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05004008 phba->ctrl_regs_memmap_p + off + buf_off);
4009
James Smart2e0fef82007-06-17 19:56:36 -05004010 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004011
4012 return count;
4013}
4014
James Smarte59058c2008-08-24 21:49:00 -04004015/**
James Smart3621a712009-04-06 18:47:14 -04004016 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07004017 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004018 * @kobj: kernel kobject that contains the kernel class device.
4019 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004020 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04004021 * @off: offset into buffer to beginning of data.
4022 * @count: bytes to transfer.
4023 *
4024 * Description:
4025 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4026 * Uses the adapter io control registers to read data into buf.
4027 *
4028 * Returns:
4029 * -ERANGE off and count combo out of range
4030 * -EINVAL off, count or buff address invalid
4031 * value of count, buf contents read
4032 **/
dea31012005-04-17 16:05:31 -05004033static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004034sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4035 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004036 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004037{
4038 size_t buf_off;
4039 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01004040 struct device *dev = container_of(kobj, struct device, kobj);
4041 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004042 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4043 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004044
James Smartf1126682009-06-10 17:22:44 -04004045 if (phba->sli_rev >= LPFC_SLI_REV4)
4046 return -EPERM;
4047
dea31012005-04-17 16:05:31 -05004048 if (off > FF_REG_AREA_SIZE)
4049 return -ERANGE;
4050
4051 if ((off + count) > FF_REG_AREA_SIZE)
4052 count = FF_REG_AREA_SIZE - off;
4053
4054 if (count == 0) return 0;
4055
4056 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4057 return -EINVAL;
4058
James Smart2e0fef82007-06-17 19:56:36 -05004059 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004060
4061 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4062 tmp_ptr = (uint32_t *)(buf + buf_off);
4063 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4064 }
4065
James Smart2e0fef82007-06-17 19:56:36 -05004066 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004067
4068 return count;
4069}
4070
4071static struct bin_attribute sysfs_ctlreg_attr = {
4072 .attr = {
4073 .name = "ctlreg",
4074 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004075 },
4076 .size = 256,
4077 .read = sysfs_ctlreg_read,
4078 .write = sysfs_ctlreg_write,
4079};
4080
James Smarte59058c2008-08-24 21:49:00 -04004081/**
James Smart3621a712009-04-06 18:47:14 -04004082 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004083 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004084 * @kobj: kernel kobject that contains the kernel class device.
4085 * @bin_attr: kernel attributes passed to us.
4086 * @buf: contains the data to be written to sysfs mbox.
4087 * @off: offset into buffer to beginning of data.
4088 * @count: bytes to transfer.
4089 *
4090 * Description:
James Smart026abb82011-12-13 13:20:45 -05004091 * Deprecated function. All mailbox access from user space is performed via the
4092 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004093 *
4094 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004095 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004096 **/
dea31012005-04-17 16:05:31 -05004097static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004098sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4099 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004100 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004101{
James Smart026abb82011-12-13 13:20:45 -05004102 return -EPERM;
dea31012005-04-17 16:05:31 -05004103}
4104
James Smarte59058c2008-08-24 21:49:00 -04004105/**
James Smart3621a712009-04-06 18:47:14 -04004106 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004107 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004108 * @kobj: kernel kobject that contains the kernel class device.
4109 * @bin_attr: kernel attributes passed to us.
4110 * @buf: contains the data to be read from sysfs mbox.
4111 * @off: offset into buffer to beginning of data.
4112 * @count: bytes to transfer.
4113 *
4114 * Description:
James Smart026abb82011-12-13 13:20:45 -05004115 * Deprecated function. All mailbox access from user space is performed via the
4116 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04004117 *
4118 * Returns:
James Smart026abb82011-12-13 13:20:45 -05004119 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04004120 **/
dea31012005-04-17 16:05:31 -05004121static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004122sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4123 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004124 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004125{
James Smart026abb82011-12-13 13:20:45 -05004126 return -EPERM;
dea31012005-04-17 16:05:31 -05004127}
4128
4129static struct bin_attribute sysfs_mbox_attr = {
4130 .attr = {
4131 .name = "mbox",
4132 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004133 },
James Smartc0c11512011-05-24 11:41:34 -04004134 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004135 .read = sysfs_mbox_read,
4136 .write = sysfs_mbox_write,
4137};
4138
James Smarte59058c2008-08-24 21:49:00 -04004139/**
James Smart3621a712009-04-06 18:47:14 -04004140 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004141 * @vport: address of lpfc vport structure.
4142 *
4143 * Return codes:
4144 * zero on success
4145 * error return code from sysfs_create_bin_file()
4146 **/
dea31012005-04-17 16:05:31 -05004147int
James Smart2e0fef82007-06-17 19:56:36 -05004148lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004149{
James Smart2e0fef82007-06-17 19:56:36 -05004150 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004151 int error;
4152
Tony Jonesee959b02008-02-22 00:13:36 +01004153 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004154 &sysfs_drvr_stat_data_attr);
4155
4156 /* Virtual ports do not need ctrl_reg and mbox */
4157 if (error || vport->port_type == LPFC_NPIV_PORT)
4158 goto out;
4159
4160 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004161 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004162 if (error)
James Smarteada2722008-12-04 22:39:13 -05004163 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004164
Tony Jonesee959b02008-02-22 00:13:36 +01004165 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004166 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004167 if (error)
4168 goto out_remove_ctlreg_attr;
4169
4170 return 0;
4171out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004172 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004173out_remove_stat_attr:
4174 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4175 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004176out:
4177 return error;
4178}
4179
James Smarte59058c2008-08-24 21:49:00 -04004180/**
James Smart3621a712009-04-06 18:47:14 -04004181 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004182 * @vport: address of lpfc vport structure.
4183 **/
dea31012005-04-17 16:05:31 -05004184void
James Smart2e0fef82007-06-17 19:56:36 -05004185lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004186{
James Smart2e0fef82007-06-17 19:56:36 -05004187 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004188 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4189 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004190 /* Virtual ports do not need ctrl_reg and mbox */
4191 if (vport->port_type == LPFC_NPIV_PORT)
4192 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004193 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4194 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004195}
4196
4197
4198/*
4199 * Dynamic FC Host Attributes Support
4200 */
4201
James Smarte59058c2008-08-24 21:49:00 -04004202/**
James Smart3621a712009-04-06 18:47:14 -04004203 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004204 * @shost: kernel scsi host pointer.
4205 **/
dea31012005-04-17 16:05:31 -05004206static void
4207lpfc_get_host_port_id(struct Scsi_Host *shost)
4208{
James Smart2e0fef82007-06-17 19:56:36 -05004209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4210
dea31012005-04-17 16:05:31 -05004211 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004212 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004213}
4214
James Smarte59058c2008-08-24 21:49:00 -04004215/**
James Smart3621a712009-04-06 18:47:14 -04004216 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004217 * @shost: kernel scsi host pointer.
4218 **/
dea31012005-04-17 16:05:31 -05004219static void
4220lpfc_get_host_port_type(struct Scsi_Host *shost)
4221{
James Smart2e0fef82007-06-17 19:56:36 -05004222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4223 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004224
4225 spin_lock_irq(shost->host_lock);
4226
James Smart92d7f7b2007-06-17 19:56:38 -05004227 if (vport->port_type == LPFC_NPIV_PORT) {
4228 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4229 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004230 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004231 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004232 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4233 else
4234 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4235 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004236 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004237 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4238 else
4239 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4240 }
4241 } else
4242 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4243
4244 spin_unlock_irq(shost->host_lock);
4245}
4246
James Smarte59058c2008-08-24 21:49:00 -04004247/**
James Smart3621a712009-04-06 18:47:14 -04004248 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004249 * @shost: kernel scsi host pointer.
4250 **/
dea31012005-04-17 16:05:31 -05004251static void
4252lpfc_get_host_port_state(struct Scsi_Host *shost)
4253{
James Smart2e0fef82007-06-17 19:56:36 -05004254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4255 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004256
4257 spin_lock_irq(shost->host_lock);
4258
James Smart2e0fef82007-06-17 19:56:36 -05004259 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004260 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4261 else {
James Smart2e0fef82007-06-17 19:56:36 -05004262 switch (phba->link_state) {
4263 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004264 case LPFC_LINK_DOWN:
4265 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4266 break;
4267 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004268 case LPFC_CLEAR_LA:
4269 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05004270 /* Links up, reports port state accordingly */
4271 if (vport->port_state < LPFC_VPORT_READY)
4272 fc_host_port_state(shost) =
4273 FC_PORTSTATE_BYPASSED;
4274 else
4275 fc_host_port_state(shost) =
4276 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05004277 break;
4278 case LPFC_HBA_ERROR:
4279 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4280 break;
4281 default:
4282 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4283 break;
4284 }
4285 }
4286
4287 spin_unlock_irq(shost->host_lock);
4288}
4289
James Smarte59058c2008-08-24 21:49:00 -04004290/**
James Smart3621a712009-04-06 18:47:14 -04004291 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004292 * @shost: kernel scsi host pointer.
4293 **/
dea31012005-04-17 16:05:31 -05004294static void
4295lpfc_get_host_speed(struct Scsi_Host *shost)
4296{
James Smart2e0fef82007-06-17 19:56:36 -05004297 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4298 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004299
4300 spin_lock_irq(shost->host_lock);
4301
James Smart2e0fef82007-06-17 19:56:36 -05004302 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004303 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004304 case LPFC_LINK_SPEED_1GHZ:
4305 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004306 break;
James Smart76a95d72010-11-20 23:11:48 -05004307 case LPFC_LINK_SPEED_2GHZ:
4308 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004309 break;
James Smart76a95d72010-11-20 23:11:48 -05004310 case LPFC_LINK_SPEED_4GHZ:
4311 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004312 break;
James Smart76a95d72010-11-20 23:11:48 -05004313 case LPFC_LINK_SPEED_8GHZ:
4314 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004315 break;
James Smart76a95d72010-11-20 23:11:48 -05004316 case LPFC_LINK_SPEED_10GHZ:
4317 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004318 break;
James Smart76a95d72010-11-20 23:11:48 -05004319 case LPFC_LINK_SPEED_16GHZ:
4320 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4321 break;
4322 default:
4323 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004324 break;
4325 }
James Smart09372822008-01-11 01:52:54 -05004326 } else
4327 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004328
4329 spin_unlock_irq(shost->host_lock);
4330}
4331
James Smarte59058c2008-08-24 21:49:00 -04004332/**
James Smart3621a712009-04-06 18:47:14 -04004333 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004334 * @shost: kernel scsi host pointer.
4335 **/
dea31012005-04-17 16:05:31 -05004336static void
4337lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4338{
James Smart2e0fef82007-06-17 19:56:36 -05004339 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4340 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004341 u64 node_name;
dea31012005-04-17 16:05:31 -05004342
4343 spin_lock_irq(shost->host_lock);
4344
James Smart73d91e52011-10-10 21:32:10 -04004345 if ((vport->port_state > LPFC_FLOGI) &&
4346 ((vport->fc_flag & FC_FABRIC) ||
4347 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4348 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004349 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004350 else
4351 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004352 node_name = 0;
dea31012005-04-17 16:05:31 -05004353
4354 spin_unlock_irq(shost->host_lock);
4355
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004356 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004357}
4358
James Smarte59058c2008-08-24 21:49:00 -04004359/**
James Smart3621a712009-04-06 18:47:14 -04004360 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004361 * @shost: kernel scsi host pointer.
4362 *
4363 * Notes:
4364 * NULL on error for link down, no mbox pool, sli2 active,
4365 * management not allowed, memory allocation error, or mbox error.
4366 *
4367 * Returns:
4368 * NULL for error
4369 * address of the adapter host statistics
4370 **/
dea31012005-04-17 16:05:31 -05004371static struct fc_host_statistics *
4372lpfc_get_stats(struct Scsi_Host *shost)
4373{
James Smart2e0fef82007-06-17 19:56:36 -05004374 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4375 struct lpfc_hba *phba = vport->phba;
4376 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004377 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004378 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004379 LPFC_MBOXQ_t *pmboxq;
4380 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004381 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004382 int rc = 0;
dea31012005-04-17 16:05:31 -05004383
James Smart92d7f7b2007-06-17 19:56:38 -05004384 /*
4385 * prevent udev from issuing mailbox commands until the port is
4386 * configured.
4387 */
James Smart2e0fef82007-06-17 19:56:36 -05004388 if (phba->link_state < LPFC_LINK_DOWN ||
4389 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004390 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004391 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004392
4393 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004394 return NULL;
4395
dea31012005-04-17 16:05:31 -05004396 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4397 if (!pmboxq)
4398 return NULL;
4399 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4400
James Smart04c68492009-05-22 14:52:52 -04004401 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004402 pmb->mbxCommand = MBX_READ_STATUS;
4403 pmb->mbxOwner = OWN_HOST;
4404 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004405 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004406
James Smart75baf692010-06-08 18:31:21 -04004407 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004408 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004409 else
dea31012005-04-17 16:05:31 -05004410 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4411
4412 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004413 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004414 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004415 return NULL;
4416 }
4417
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004418 memset(hs, 0, sizeof (struct fc_host_statistics));
4419
dea31012005-04-17 16:05:31 -05004420 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004421 /*
4422 * The MBX_READ_STATUS returns tx_k_bytes which has to
4423 * converted to words
4424 */
4425 hs->tx_words = (uint64_t)
4426 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4427 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004428 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004429 hs->rx_words = (uint64_t)
4430 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4431 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004432
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004433 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004434 pmb->mbxCommand = MBX_READ_LNK_STAT;
4435 pmb->mbxOwner = OWN_HOST;
4436 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004437 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004438
James Smart75baf692010-06-08 18:31:21 -04004439 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004440 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004441 else
dea31012005-04-17 16:05:31 -05004442 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4443
4444 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004445 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004446 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004447 return NULL;
4448 }
4449
4450 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4451 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4452 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4453 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4454 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4455 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4456 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4457
James Smart64ba8812006-08-02 15:24:34 -04004458 hs->link_failure_count -= lso->link_failure_count;
4459 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4460 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4461 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4462 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4463 hs->invalid_crc_count -= lso->invalid_crc_count;
4464 hs->error_frames -= lso->error_frames;
4465
James Smart76a95d72010-11-20 23:11:48 -05004466 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004467 hs->lip_count = -1;
4468 hs->nos_count = (phba->link_events >> 1);
4469 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004470 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004471 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004472 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004473 hs->nos_count = -1;
4474 } else {
4475 hs->lip_count = -1;
4476 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004477 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004478 }
4479
4480 hs->dumped_frames = -1;
4481
James Smart64ba8812006-08-02 15:24:34 -04004482 seconds = get_seconds();
4483 if (seconds < psli->stats_start)
4484 hs->seconds_since_last_reset = seconds +
4485 ((unsigned long)-1 - psli->stats_start);
4486 else
4487 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004488
James Smart1dcb58e2007-04-25 09:51:30 -04004489 mempool_free(pmboxq, phba->mbox_mem_pool);
4490
dea31012005-04-17 16:05:31 -05004491 return hs;
4492}
4493
James Smarte59058c2008-08-24 21:49:00 -04004494/**
James Smart3621a712009-04-06 18:47:14 -04004495 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004496 * @shost: kernel scsi host pointer.
4497 **/
James Smart64ba8812006-08-02 15:24:34 -04004498static void
4499lpfc_reset_stats(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;
4503 struct lpfc_sli *psli = &phba->sli;
4504 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004505 LPFC_MBOXQ_t *pmboxq;
4506 MAILBOX_t *pmb;
4507 int rc = 0;
4508
James Smart2e0fef82007-06-17 19:56:36 -05004509 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004510 return;
4511
James Smart64ba8812006-08-02 15:24:34 -04004512 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4513 if (!pmboxq)
4514 return;
4515 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4516
James Smart04c68492009-05-22 14:52:52 -04004517 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004518 pmb->mbxCommand = MBX_READ_STATUS;
4519 pmb->mbxOwner = OWN_HOST;
4520 pmb->un.varWords[0] = 0x1; /* reset request */
4521 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004522 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004523
James Smart2e0fef82007-06-17 19:56:36 -05004524 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004525 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004526 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4527 else
4528 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4529
4530 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004531 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004532 mempool_free(pmboxq, phba->mbox_mem_pool);
4533 return;
4534 }
4535
4536 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4537 pmb->mbxCommand = MBX_READ_LNK_STAT;
4538 pmb->mbxOwner = OWN_HOST;
4539 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004540 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004541
James Smart2e0fef82007-06-17 19:56:36 -05004542 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004543 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004544 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4545 else
4546 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4547
4548 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004549 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004550 mempool_free( pmboxq, phba->mbox_mem_pool);
4551 return;
4552 }
4553
4554 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4555 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4556 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4557 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4558 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4559 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4560 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004561 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004562 lso->link_events = (phba->link_events >> 1);
4563 else
4564 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004565
4566 psli->stats_start = get_seconds();
4567
James Smart1dcb58e2007-04-25 09:51:30 -04004568 mempool_free(pmboxq, phba->mbox_mem_pool);
4569
James Smart64ba8812006-08-02 15:24:34 -04004570 return;
4571}
dea31012005-04-17 16:05:31 -05004572
4573/*
4574 * The LPFC driver treats linkdown handling as target loss events so there
4575 * are no sysfs handlers for link_down_tmo.
4576 */
James Smart685f0bf2007-04-25 09:53:08 -04004577
James Smarte59058c2008-08-24 21:49:00 -04004578/**
James Smart3621a712009-04-06 18:47:14 -04004579 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004580 * @starget: kernel scsi target pointer.
4581 *
4582 * Returns:
4583 * address of the node list if found
4584 * NULL target not found
4585 **/
James Smart685f0bf2007-04-25 09:53:08 -04004586static struct lpfc_nodelist *
4587lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004588{
James Smart2e0fef82007-06-17 19:56:36 -05004589 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4590 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004591 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004592
4593 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004594 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004595 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004596 if (NLP_CHK_NODE_ACT(ndlp) &&
4597 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004598 starget->id == ndlp->nlp_sid) {
4599 spin_unlock_irq(shost->host_lock);
4600 return ndlp;
dea31012005-04-17 16:05:31 -05004601 }
4602 }
4603 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004604 return NULL;
4605}
dea31012005-04-17 16:05:31 -05004606
James Smarte59058c2008-08-24 21:49:00 -04004607/**
James Smart3621a712009-04-06 18:47:14 -04004608 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004609 * @starget: kernel scsi target pointer.
4610 **/
James Smart685f0bf2007-04-25 09:53:08 -04004611static void
4612lpfc_get_starget_port_id(struct scsi_target *starget)
4613{
4614 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4615
4616 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004617}
4618
James Smarte59058c2008-08-24 21:49:00 -04004619/**
James Smart3621a712009-04-06 18:47:14 -04004620 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004621 * @starget: kernel scsi target pointer.
4622 *
4623 * Description: Set the target node name to the ndlp node name wwn or zero.
4624 **/
dea31012005-04-17 16:05:31 -05004625static void
4626lpfc_get_starget_node_name(struct scsi_target *starget)
4627{
James Smart685f0bf2007-04-25 09:53:08 -04004628 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004629
James Smart685f0bf2007-04-25 09:53:08 -04004630 fc_starget_node_name(starget) =
4631 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004632}
4633
James Smarte59058c2008-08-24 21:49:00 -04004634/**
James Smart3621a712009-04-06 18:47:14 -04004635 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004636 * @starget: kernel scsi target pointer.
4637 *
4638 * Description: set the target port name to the ndlp port name wwn or zero.
4639 **/
dea31012005-04-17 16:05:31 -05004640static void
4641lpfc_get_starget_port_name(struct scsi_target *starget)
4642{
James Smart685f0bf2007-04-25 09:53:08 -04004643 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004644
James Smart685f0bf2007-04-25 09:53:08 -04004645 fc_starget_port_name(starget) =
4646 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004647}
4648
James Smarte59058c2008-08-24 21:49:00 -04004649/**
James Smart3621a712009-04-06 18:47:14 -04004650 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004651 * @rport: fc rport address.
4652 * @timeout: new value for dev loss tmo.
4653 *
4654 * Description:
4655 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4656 * dev_loss_tmo to one.
4657 **/
dea31012005-04-17 16:05:31 -05004658static void
dea31012005-04-17 16:05:31 -05004659lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4660{
dea31012005-04-17 16:05:31 -05004661 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004662 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004663 else
James Smartc01f3202006-08-18 17:47:08 -04004664 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004665}
4666
James Smarte59058c2008-08-24 21:49:00 -04004667/**
James Smart3621a712009-04-06 18:47:14 -04004668 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004669 *
4670 * Description:
4671 * Macro that uses field to generate a function with the name lpfc_show_rport_
4672 *
4673 * lpfc_show_rport_##field: returns the bytes formatted in buf
4674 * @cdev: class converted to an fc_rport.
4675 * @buf: on return contains the target_field or zero.
4676 *
4677 * Returns: size of formatted string.
4678 **/
dea31012005-04-17 16:05:31 -05004679#define lpfc_rport_show_function(field, format_string, sz, cast) \
4680static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004681lpfc_show_rport_##field (struct device *dev, \
4682 struct device_attribute *attr, \
4683 char *buf) \
dea31012005-04-17 16:05:31 -05004684{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004685 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004686 struct lpfc_rport_data *rdata = rport->hostdata; \
4687 return snprintf(buf, sz, format_string, \
4688 (rdata->target) ? cast rdata->target->field : 0); \
4689}
4690
4691#define lpfc_rport_rd_attr(field, format_string, sz) \
4692 lpfc_rport_show_function(field, format_string, sz, ) \
4693static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4694
James Smarteada2722008-12-04 22:39:13 -05004695/**
James Smart3621a712009-04-06 18:47:14 -04004696 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004697 * @fc_vport: The fc_vport who's symbolic name has been changed.
4698 *
4699 * Description:
4700 * This function is called by the transport after the @fc_vport's symbolic name
4701 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004702 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004703 **/
4704static void
4705lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4706{
4707 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4708
4709 if (vport->port_state == LPFC_VPORT_READY)
4710 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4711}
dea31012005-04-17 16:05:31 -05004712
James Smartf4b4c682009-05-22 14:53:12 -04004713/**
4714 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4715 * @phba: Pointer to lpfc_hba struct.
4716 *
4717 * This function is called by the lpfc_get_cfgparam() routine to set the
4718 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004719 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004720 * before hba port or vport created.
4721 **/
4722static void
4723lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4724{
4725 phba->cfg_log_verbose = verbose;
4726}
4727
dea31012005-04-17 16:05:31 -05004728struct fc_function_template lpfc_transport_functions = {
4729 /* fixed attributes the driver supports */
4730 .show_host_node_name = 1,
4731 .show_host_port_name = 1,
4732 .show_host_supported_classes = 1,
4733 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004734 .show_host_supported_speeds = 1,
4735 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004736 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004737
4738 /* dynamic attributes the driver supports */
4739 .get_host_port_id = lpfc_get_host_port_id,
4740 .show_host_port_id = 1,
4741
4742 .get_host_port_type = lpfc_get_host_port_type,
4743 .show_host_port_type = 1,
4744
4745 .get_host_port_state = lpfc_get_host_port_state,
4746 .show_host_port_state = 1,
4747
4748 /* active_fc4s is shown but doesn't change (thus no get function) */
4749 .show_host_active_fc4s = 1,
4750
4751 .get_host_speed = lpfc_get_host_speed,
4752 .show_host_speed = 1,
4753
4754 .get_host_fabric_name = lpfc_get_host_fabric_name,
4755 .show_host_fabric_name = 1,
4756
4757 /*
4758 * The LPFC driver treats linkdown handling as target loss events
4759 * so there are no sysfs handlers for link_down_tmo.
4760 */
4761
4762 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004763 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004764
4765 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4766 .show_rport_maxframe_size = 1,
4767 .show_rport_supported_classes = 1,
4768
dea31012005-04-17 16:05:31 -05004769 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4770 .show_rport_dev_loss_tmo = 1,
4771
4772 .get_starget_port_id = lpfc_get_starget_port_id,
4773 .show_starget_port_id = 1,
4774
4775 .get_starget_node_name = lpfc_get_starget_node_name,
4776 .show_starget_node_name = 1,
4777
4778 .get_starget_port_name = lpfc_get_starget_port_name,
4779 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004780
4781 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004782 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4783 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004784
James Smart92d7f7b2007-06-17 19:56:38 -05004785 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004786
4787 .vport_disable = lpfc_vport_disable,
4788
4789 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004790
4791 .bsg_request = lpfc_bsg_request,
4792 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004793};
4794
James Smart98c9ea52007-10-27 13:37:33 -04004795struct fc_function_template lpfc_vport_transport_functions = {
4796 /* fixed attributes the driver supports */
4797 .show_host_node_name = 1,
4798 .show_host_port_name = 1,
4799 .show_host_supported_classes = 1,
4800 .show_host_supported_fc4s = 1,
4801 .show_host_supported_speeds = 1,
4802 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004803 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004804
4805 /* dynamic attributes the driver supports */
4806 .get_host_port_id = lpfc_get_host_port_id,
4807 .show_host_port_id = 1,
4808
4809 .get_host_port_type = lpfc_get_host_port_type,
4810 .show_host_port_type = 1,
4811
4812 .get_host_port_state = lpfc_get_host_port_state,
4813 .show_host_port_state = 1,
4814
4815 /* active_fc4s is shown but doesn't change (thus no get function) */
4816 .show_host_active_fc4s = 1,
4817
4818 .get_host_speed = lpfc_get_host_speed,
4819 .show_host_speed = 1,
4820
4821 .get_host_fabric_name = lpfc_get_host_fabric_name,
4822 .show_host_fabric_name = 1,
4823
4824 /*
4825 * The LPFC driver treats linkdown handling as target loss events
4826 * so there are no sysfs handlers for link_down_tmo.
4827 */
4828
4829 .get_fc_host_stats = lpfc_get_stats,
4830 .reset_fc_host_stats = lpfc_reset_stats,
4831
4832 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4833 .show_rport_maxframe_size = 1,
4834 .show_rport_supported_classes = 1,
4835
4836 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4837 .show_rport_dev_loss_tmo = 1,
4838
4839 .get_starget_port_id = lpfc_get_starget_port_id,
4840 .show_starget_port_id = 1,
4841
4842 .get_starget_node_name = lpfc_get_starget_node_name,
4843 .show_starget_node_name = 1,
4844
4845 .get_starget_port_name = lpfc_get_starget_port_name,
4846 .show_starget_port_name = 1,
4847
4848 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4849 .terminate_rport_io = lpfc_terminate_rport_io,
4850
4851 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004852
4853 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004854};
4855
James Smarte59058c2008-08-24 21:49:00 -04004856/**
James Smart3621a712009-04-06 18:47:14 -04004857 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004858 * @phba: lpfc_hba pointer.
4859 **/
dea31012005-04-17 16:05:31 -05004860void
4861lpfc_get_cfgparam(struct lpfc_hba *phba)
4862{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004863 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4864 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004865 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004866 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4867 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004868 lpfc_ack0_init(phba, lpfc_ack0);
4869 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004870 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004871 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004872 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04004873 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05004874 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05004875 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004876 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4877 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4878 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004879 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4880 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004881 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004882 if (phba->sli_rev == LPFC_SLI_REV4)
4883 phba->cfg_poll = 0;
4884 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004885 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004886 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004887 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004888 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004889 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004890 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004891 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004892 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04004893 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smart84d1b002010-02-12 14:42:33 -05004894 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004895 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05004896 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04004897 return;
4898}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004899
James Smarte59058c2008-08-24 21:49:00 -04004900/**
James Smart3621a712009-04-06 18:47:14 -04004901 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004902 * @vport: lpfc_vport pointer.
4903 **/
James Smart3de2a652007-08-02 11:09:59 -04004904void
4905lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4906{
James Smarte8b62012007-08-02 11:10:09 -04004907 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004908 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004909 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004910 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4911 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4912 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4913 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4914 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4915 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004916 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004917 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4918 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4919 lpfc_max_luns_init(vport, lpfc_max_luns);
4920 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004921 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004922 return;
4923}