blob: d0ebaeb7ef60e96857c18999a6048a39247126e2 [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;
dea31012005-04-17 16:05:31 -0500354 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500355
dea31012005-04-17 16:05:31 -0500356 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500357 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500358}
359
James Smarte59058c2008-08-24 21:49:00 -0400360/**
James Smart3621a712009-04-06 18:47:14 -0400361 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400362 * @dev: class converted to a Scsi_host structure.
363 * @attr: device attribute, not used.
364 * @buf: on return contains the scsi vpd program type.
365 *
366 * Returns: size of formatted string.
367 **/
dea31012005-04-17 16:05:31 -0500368static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100369lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500370{
371 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100372 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
374 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500375 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500376
dea31012005-04-17 16:05:31 -0500377 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
378 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
379}
James Smarte59058c2008-08-24 21:49:00 -0400380
381/**
James Smart3621a712009-04-06 18:47:14 -0400382 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400383 * @dev: class converted to a Scsi_host structure.
384 * @attr: device attribute, not used.
385 * @buf: on return contains the ROM and FCode ascii strings.
386 *
387 * Returns: size of formatted string.
388 **/
dea31012005-04-17 16:05:31 -0500389static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100390lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
391 char *buf)
dea31012005-04-17 16:05:31 -0500392{
Tony Jonesee959b02008-02-22 00:13:36 +0100393 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500394 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
395 struct lpfc_hba *phba = vport->phba;
396
dea31012005-04-17 16:05:31 -0500397 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
398}
James Smarte59058c2008-08-24 21:49:00 -0400399
400/**
James Smart3621a712009-04-06 18:47:14 -0400401 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400402 * @dev: class converted to a Scsi_host structure.
403 * @attr: device attribute, not used.
404 * @buf: on return contains text describing the state of the link.
405 *
406 * Notes:
407 * The switch statement has no default so zero will be returned.
408 *
409 * Returns: size of formatted string.
410 **/
dea31012005-04-17 16:05:31 -0500411static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100412lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
413 char *buf)
dea31012005-04-17 16:05:31 -0500414{
Tony Jonesee959b02008-02-22 00:13:36 +0100415 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
418 int len = 0;
419
420 switch (phba->link_state) {
421 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500422 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500423 case LPFC_INIT_START:
424 case LPFC_INIT_MBX_CMDS:
425 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500426 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400427 if (phba->hba_flag & LINK_DISABLED)
428 len += snprintf(buf + len, PAGE_SIZE-len,
429 "Link Down - User disabled\n");
430 else
431 len += snprintf(buf + len, PAGE_SIZE-len,
432 "Link Down\n");
dea31012005-04-17 16:05:31 -0500433 break;
434 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500435 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500436 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400437 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500438
439 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500440 case LPFC_LOCAL_CFG_LINK:
441 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500442 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500443 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500444 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500445 case LPFC_FLOGI:
446 case LPFC_FABRIC_CFG_LINK:
447 case LPFC_NS_REG:
448 case LPFC_NS_QRY:
449 case LPFC_BUILD_DISC_LIST:
450 case LPFC_DISC_AUTH:
451 len += snprintf(buf + len, PAGE_SIZE - len,
452 "Discovery\n");
453 break;
454 case LPFC_VPORT_READY:
455 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
456 break;
457
James Smart92d7f7b2007-06-17 19:56:38 -0500458 case LPFC_VPORT_FAILED:
459 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
460 break;
461
462 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500463 len += snprintf(buf + len, PAGE_SIZE - len,
464 "Unknown\n");
465 break;
466 }
James Smart84774a42008-08-24 21:50:06 -0400467 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
468 len += snprintf(buf + len, PAGE_SIZE-len,
469 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500470 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500471 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500472 len += snprintf(buf + len, PAGE_SIZE-len,
473 " Public Loop\n");
474 else
475 len += snprintf(buf + len, PAGE_SIZE-len,
476 " Private Loop\n");
477 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500478 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500479 len += snprintf(buf + len, PAGE_SIZE-len,
480 " Fabric\n");
481 else
482 len += snprintf(buf + len, PAGE_SIZE-len,
483 " Point-2-Point\n");
484 }
485 }
James Smart2e0fef82007-06-17 19:56:36 -0500486
dea31012005-04-17 16:05:31 -0500487 return len;
488}
489
James Smarte59058c2008-08-24 21:49:00 -0400490/**
James Smart84d1b002010-02-12 14:42:33 -0500491 * lpfc_link_state_store - Transition the link_state on an HBA port
492 * @dev: class device that is converted into a Scsi_host.
493 * @attr: device attribute, not used.
494 * @buf: one or more lpfc_polling_flags values.
495 * @count: not used.
496 *
497 * Returns:
498 * -EINVAL if the buffer is not "up" or "down"
499 * return from link state change function if non-zero
500 * length of the buf on success
501 **/
502static ssize_t
503lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
504 const char *buf, size_t count)
505{
506 struct Scsi_Host *shost = class_to_shost(dev);
507 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
508 struct lpfc_hba *phba = vport->phba;
509
510 int status = -EINVAL;
511
512 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
513 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400514 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500515 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
516 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400517 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500518
519 if (status == 0)
520 return strlen(buf);
521 else
522 return status;
523}
524
525/**
James Smart3621a712009-04-06 18:47:14 -0400526 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400527 * @dev: class device that is converted into a Scsi_host.
528 * @attr: device attribute, not used.
529 * @buf: on return contains the sum of fc mapped and unmapped.
530 *
531 * Description:
532 * Returns the ascii text number of the sum of the fc mapped and unmapped
533 * vport counts.
534 *
535 * Returns: size of formatted string.
536 **/
dea31012005-04-17 16:05:31 -0500537static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100538lpfc_num_discovered_ports_show(struct device *dev,
539 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500540{
Tony Jonesee959b02008-02-22 00:13:36 +0100541 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
543
544 return snprintf(buf, PAGE_SIZE, "%d\n",
545 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500546}
547
James Smarte59058c2008-08-24 21:49:00 -0400548/**
James Smart3621a712009-04-06 18:47:14 -0400549 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400550 * @shost: Scsi_Host pointer.
551 *
552 * Description:
553 * Bring the link down gracefully then re-init the link. The firmware will
554 * re-init the fiber channel interface as required. Does not issue a LIP.
555 *
556 * Returns:
557 * -EPERM port offline or management commands are being blocked
558 * -ENOMEM cannot allocate memory for the mailbox command
559 * -EIO error sending the mailbox command
560 * zero for success
561 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700562static int
James Smart2e0fef82007-06-17 19:56:36 -0500563lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500564{
James Smart2e0fef82007-06-17 19:56:36 -0500565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
566 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500567 LPFC_MBOXQ_t *pmboxq;
568 int mbxstatus = MBXERR_ERROR;
569
James Smart2e0fef82007-06-17 19:56:36 -0500570 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500571 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500572 return -EPERM;
573
574 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
575
576 if (!pmboxq)
577 return -ENOMEM;
578
579 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400580 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
581 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400582
James Smart33ccf8d2006-08-17 11:57:58 -0400583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500584
James Smart04c68492009-05-22 14:52:52 -0400585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == 0 ||
587 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400588 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
589 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
590 phba->cfg_link_speed);
591 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
592 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400593 if ((mbxstatus == MBX_SUCCESS) &&
594 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
595 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
596 "2859 SLI authentication is required "
597 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400598 }
599
James Smart5b8bd0c2007-04-25 09:52:49 -0400600 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500601 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400602 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500603
604 if (mbxstatus == MBXERR_ERROR)
605 return -EIO;
606
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700607 return 0;
dea31012005-04-17 16:05:31 -0500608}
609
James Smarte59058c2008-08-24 21:49:00 -0400610/**
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400612 * @phba: lpfc_hba pointer.
613 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
614 *
615 * Notes:
616 * Assumes any error from lpfc_do_offline() will be negative.
617 * Can wait up to 5 seconds for the port ring buffers count
618 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400619 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400620 *
621 * Returns:
622 * -EIO error posting the event
623 * zero for success
624 **/
James Smart40496f02006-07-06 15:50:22 -0400625static int
James Smart46fa3112007-04-25 09:51:45 -0400626lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
627{
628 struct completion online_compl;
629 struct lpfc_sli_ring *pring;
630 struct lpfc_sli *psli;
631 int status = 0;
632 int cnt = 0;
633 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500634 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400635
636 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500637 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400638 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500639 if (rc == 0)
640 return -ENOMEM;
641
James Smart46fa3112007-04-25 09:51:45 -0400642 wait_for_completion(&online_compl);
643
644 if (status != 0)
645 return -EIO;
646
647 psli = &phba->sli;
648
James Smart09372822008-01-11 01:52:54 -0500649 /* Wait a little for things to settle down, but not
650 * long enough for dev loss timeout to expire.
651 */
James Smart46fa3112007-04-25 09:51:45 -0400652 for (i = 0; i < psli->num_rings; i++) {
653 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400654 while (pring->txcmplq_cnt) {
655 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500656 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400657 lpfc_printf_log(phba,
658 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400659 "0466 Outstanding IO when "
660 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400661 break;
662 }
663 }
664 }
665
666 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500667 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
668 if (rc == 0)
669 return -ENOMEM;
670
James Smart46fa3112007-04-25 09:51:45 -0400671 wait_for_completion(&online_compl);
672
673 if (status != 0)
674 return -EIO;
675
676 return 0;
677}
678
James Smarte59058c2008-08-24 21:49:00 -0400679/**
James Smart3621a712009-04-06 18:47:14 -0400680 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400681 * @phba: lpfc_hba pointer.
682 *
683 * Description:
684 * If the port is configured to allow a reset then the hba is brought
685 * offline then online.
686 *
687 * Notes:
688 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500689 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400690 *
691 * Returns:
692 * lpfc_do_offline() return code if not zero
693 * -EIO reset not configured or error posting the event
694 * zero for success
695 **/
James Smart7f860592011-03-11 16:05:52 -0500696int
James Smart40496f02006-07-06 15:50:22 -0400697lpfc_selective_reset(struct lpfc_hba *phba)
698{
699 struct completion online_compl;
700 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500701 int rc;
James Smart40496f02006-07-06 15:50:22 -0400702
James Smart13815c82008-01-11 01:52:48 -0500703 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400704 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500705
James Smart46fa3112007-04-25 09:51:45 -0400706 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400707
708 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400709 return status;
James Smart40496f02006-07-06 15:50:22 -0400710
711 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500712 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400713 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500714 if (rc == 0)
715 return -ENOMEM;
716
James Smart40496f02006-07-06 15:50:22 -0400717 wait_for_completion(&online_compl);
718
719 if (status != 0)
720 return -EIO;
721
722 return 0;
723}
724
James Smarte59058c2008-08-24 21:49:00 -0400725/**
James Smart3621a712009-04-06 18:47:14 -0400726 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400727 * @dev: class device that is converted into a Scsi_host.
728 * @attr: device attribute, not used.
729 * @buf: containing the string "selective".
730 * @count: unused variable.
731 *
732 * Description:
733 * If the buf contains the string "selective" then lpfc_selective_reset()
734 * is called to perform the reset.
735 *
736 * Notes:
737 * Assumes any error from lpfc_selective_reset() will be negative.
738 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200739 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400740 *
741 * Returns:
742 * -EINVAL if the buffer does not contain the string "selective"
743 * length of buf if lpfc-selective_reset() if the call succeeds
744 * return value of lpfc_selective_reset() if the call fails
745**/
James Smart40496f02006-07-06 15:50:22 -0400746static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100747lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
748 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400749{
Tony Jonesee959b02008-02-22 00:13:36 +0100750 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
752 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400753 int status = -EINVAL;
754
James Smart73d91e52011-10-10 21:32:10 -0400755 if (!phba->cfg_enable_hba_reset)
756 return -EACCES;
757
James Smart40496f02006-07-06 15:50:22 -0400758 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500759 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400760
761 if (status == 0)
762 return strlen(buf);
763 else
764 return status;
765}
766
James Smarte59058c2008-08-24 21:49:00 -0400767/**
James Smart88a2cfb2011-07-22 18:36:33 -0400768 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
769 * @phba: lpfc_hba pointer.
770 *
771 * Description:
772 * SLI4 interface type-2 device to wait on the sliport status register for
773 * the readyness after performing a firmware reset.
774 *
775 * Returns:
776 * zero for success
777 **/
James Smart73d91e52011-10-10 21:32:10 -0400778int
James Smart88a2cfb2011-07-22 18:36:33 -0400779lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
780{
James Smartf7a919b2011-08-21 21:49:16 -0400781 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -0400782 int i;
783
James Smartf7a919b2011-08-21 21:49:16 -0400784 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -0400785 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
786 &portstat_reg.word0);
787
James Smartf7a919b2011-08-21 21:49:16 -0400788 /* verify if privilaged for the request operation */
789 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
790 !bf_get(lpfc_sliport_status_err, &portstat_reg))
791 return -EPERM;
792
James Smart88a2cfb2011-07-22 18:36:33 -0400793 /* wait for the SLI port firmware ready after firmware reset */
794 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
795 msleep(10);
796 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
797 &portstat_reg.word0);
798 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
799 continue;
800 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
801 continue;
802 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
803 continue;
804 break;
805 }
806
807 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
808 return 0;
809 else
810 return -EIO;
811}
812
813/**
James Smart52d52442011-05-24 11:42:45 -0400814 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -0400815 * @phba: lpfc_hba pointer.
816 *
817 * Description:
James Smart52d52442011-05-24 11:42:45 -0400818 * Request SLI4 interface type-2 device to perform a physical register set
819 * access.
James Smartc0c11512011-05-24 11:41:34 -0400820 *
821 * Returns:
822 * zero for success
823 **/
824static ssize_t
James Smart52d52442011-05-24 11:42:45 -0400825lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -0400826{
827 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -0400828 struct pci_dev *pdev = phba->pcidev;
James Smartc0c11512011-05-24 11:41:34 -0400829 uint32_t reg_val;
830 int status = 0;
831 int rc;
832
833 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400834 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -0400835
James Smart52d52442011-05-24 11:42:45 -0400836 if ((phba->sli_rev < LPFC_SLI_REV4) ||
837 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
838 LPFC_SLI_INTF_IF_TYPE_2))
839 return -EPERM;
840
James Smartb76f2dc2011-07-22 18:37:42 -0400841 /* Disable SR-IOV virtual functions if enabled */
842 if (phba->cfg_sriov_nr_virtfn) {
843 pci_disable_sriov(pdev);
844 phba->cfg_sriov_nr_virtfn = 0;
845 }
James Smartc0c11512011-05-24 11:41:34 -0400846 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
847
848 if (status != 0)
849 return status;
850
851 /* wait for the device to be quiesced before firmware reset */
852 msleep(100);
853
854 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
855 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -0400856
857 if (opcode == LPFC_FW_DUMP)
858 reg_val |= LPFC_FW_DUMP_REQUEST;
859 else if (opcode == LPFC_FW_RESET)
860 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
861 else if (opcode == LPFC_DV_RESET)
862 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
863
James Smartc0c11512011-05-24 11:41:34 -0400864 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
865 LPFC_CTL_PDEV_CTL_OFFSET);
866 /* flush */
867 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
868
869 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -0400870 rc = lpfc_sli4_pdev_status_reg_wait(phba);
871
872 if (rc)
James Smartf7a919b2011-08-21 21:49:16 -0400873 return rc;
James Smartc0c11512011-05-24 11:41:34 -0400874
875 init_completion(&online_compl);
876 rc = lpfc_workq_post_event(phba, &status, &online_compl,
877 LPFC_EVT_ONLINE);
878 if (rc == 0)
879 return -ENOMEM;
880
881 wait_for_completion(&online_compl);
882
883 if (status != 0)
884 return -EIO;
885
886 return 0;
887}
888
889/**
James Smart3621a712009-04-06 18:47:14 -0400890 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400891 * @dev: class device that is converted into a Scsi_host.
892 * @attr: device attribute, not used.
893 * @buf: on return contains the ascii number of nport events.
894 *
895 * Returns: size of formatted string.
896 **/
dea31012005-04-17 16:05:31 -0500897static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100898lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
899 char *buf)
dea31012005-04-17 16:05:31 -0500900{
Tony Jonesee959b02008-02-22 00:13:36 +0100901 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500902 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
903 struct lpfc_hba *phba = vport->phba;
904
dea31012005-04-17 16:05:31 -0500905 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
906}
907
James Smarte59058c2008-08-24 21:49:00 -0400908/**
James Smart3621a712009-04-06 18:47:14 -0400909 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400910 * @dev: class device that is converted into a Scsi_host.
911 * @attr: device attribute, not used.
912 * @buf: on return contains the state of the adapter.
913 *
914 * Returns: size of formatted string.
915 **/
dea31012005-04-17 16:05:31 -0500916static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100917lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
918 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500919{
Tony Jonesee959b02008-02-22 00:13:36 +0100920 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
922 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500923 char * state;
924
James Smart2e0fef82007-06-17 19:56:36 -0500925 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500926 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500927 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500928 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500929 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500930 state = "offline";
931 else
932 state = "online";
933
934 return snprintf(buf, PAGE_SIZE, "%s\n", state);
935}
936
James Smarte59058c2008-08-24 21:49:00 -0400937/**
James Smart3621a712009-04-06 18:47:14 -0400938 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400939 * @dev: class device that is converted into a Scsi_host.
940 * @attr: device attribute, not used.
941 * @buf: containing one of the strings "online", "offline", "warm" or "error".
942 * @count: unused variable.
943 *
944 * Returns:
945 * -EACCES if enable hba reset not enabled
946 * -EINVAL if the buffer does not contain a valid string (see above)
947 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
948 * buf length greater than zero indicates success
949 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500950static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100951lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
952 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500953{
Tony Jonesee959b02008-02-22 00:13:36 +0100954 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500955 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
956 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500957 struct completion online_compl;
958 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500959 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500960
James Smart13815c82008-01-11 01:52:48 -0500961 if (!phba->cfg_enable_hba_reset)
962 return -EACCES;
James Smart88a2cfb2011-07-22 18:36:33 -0400963
964 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
965 "3050 lpfc_board_mode set to %s\n", buf);
966
Jamie Wellnitz41415862006-02-28 19:25:27 -0500967 init_completion(&online_compl);
968
James Smart46fa3112007-04-25 09:51:45 -0400969 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500970 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500971 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500972 if (rc == 0)
973 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400974 wait_for_completion(&online_compl);
975 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
976 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500977 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400978 if (phba->sli_rev == LPFC_SLI_REV4)
979 return -EINVAL;
980 else
981 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400982 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400983 if (phba->sli_rev == LPFC_SLI_REV4)
984 return -EINVAL;
985 else
986 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -0400987 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -0400988 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
989 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
990 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
991 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
992 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500993 else
994 return -EINVAL;
995
Jamie Wellnitz41415862006-02-28 19:25:27 -0500996 if (!status)
997 return strlen(buf);
998 else
James Smartf7a919b2011-08-21 21:49:16 -0400999 return status;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001000}
1001
James Smarte59058c2008-08-24 21:49:00 -04001002/**
James Smart3621a712009-04-06 18:47:14 -04001003 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001004 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001005 * @mxri: max xri count.
1006 * @axri: available xri count.
1007 * @mrpi: max rpi count.
1008 * @arpi: available rpi count.
1009 * @mvpi: max vpi count.
1010 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001011 *
1012 * Description:
1013 * If an integer pointer for an count is not null then the value for the
1014 * count is returned.
1015 *
1016 * Returns:
1017 * zero on error
1018 * one for success
1019 **/
James Smart311464e2007-08-02 11:10:37 -04001020static int
James Smart858c9f62007-06-17 19:56:39 -05001021lpfc_get_hba_info(struct lpfc_hba *phba,
1022 uint32_t *mxri, uint32_t *axri,
1023 uint32_t *mrpi, uint32_t *arpi,
1024 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001025{
James Smart04c68492009-05-22 14:52:52 -04001026 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001027 LPFC_MBOXQ_t *pmboxq;
1028 MAILBOX_t *pmb;
1029 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001030 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001031
1032 /*
1033 * prevent udev from issuing mailbox commands until the port is
1034 * configured.
1035 */
1036 if (phba->link_state < LPFC_LINK_DOWN ||
1037 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001038 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001039 return 0;
1040
1041 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1042 return 0;
1043
1044 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1045 if (!pmboxq)
1046 return 0;
1047 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1048
James Smart04c68492009-05-22 14:52:52 -04001049 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001050 pmb->mbxCommand = MBX_READ_CONFIG;
1051 pmb->mbxOwner = OWN_HOST;
1052 pmboxq->context1 = NULL;
1053
James Smart75baf692010-06-08 18:31:21 -04001054 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001055 rc = MBX_NOT_FINISHED;
1056 else
1057 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1058
1059 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001060 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001061 mempool_free(pmboxq, phba->mbox_mem_pool);
1062 return 0;
1063 }
1064
James Smartda0436e2009-05-22 14:51:39 -04001065 if (phba->sli_rev == LPFC_SLI_REV4) {
1066 rd_config = &pmboxq->u.mqe.un.rd_config;
1067 if (mrpi)
1068 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1069 if (arpi)
1070 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1071 phba->sli4_hba.max_cfg_param.rpi_used;
1072 if (mxri)
1073 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1074 if (axri)
1075 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1076 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001077
1078 /* Account for differences with SLI-3. Get vpi count from
1079 * mailbox data and subtract one for max vpi value.
1080 */
1081 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1082 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1083
James Smartda0436e2009-05-22 14:51:39 -04001084 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001085 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001086 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001087 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001088 } else {
1089 if (mrpi)
1090 *mrpi = pmb->un.varRdConfig.max_rpi;
1091 if (arpi)
1092 *arpi = pmb->un.varRdConfig.avail_rpi;
1093 if (mxri)
1094 *mxri = pmb->un.varRdConfig.max_xri;
1095 if (axri)
1096 *axri = pmb->un.varRdConfig.avail_xri;
1097 if (mvpi)
1098 *mvpi = pmb->un.varRdConfig.max_vpi;
1099 if (avpi)
1100 *avpi = pmb->un.varRdConfig.avail_vpi;
1101 }
James Smart92d7f7b2007-06-17 19:56:38 -05001102
1103 mempool_free(pmboxq, phba->mbox_mem_pool);
1104 return 1;
1105}
1106
James Smarte59058c2008-08-24 21:49:00 -04001107/**
James Smart3621a712009-04-06 18:47:14 -04001108 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001109 * @dev: class device that is converted into a Scsi_host.
1110 * @attr: device attribute, not used.
1111 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1112 *
1113 * Description:
1114 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1115 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1116 * to "Unknown" and the buffer length is returned, therefore the caller
1117 * must check for "Unknown" in the buffer to detect a failure.
1118 *
1119 * Returns: size of formatted string.
1120 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001121static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001122lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1123 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001124{
Tony Jonesee959b02008-02-22 00:13:36 +01001125 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001126 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1127 struct lpfc_hba *phba = vport->phba;
1128 uint32_t cnt;
1129
James Smart858c9f62007-06-17 19:56:39 -05001130 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001131 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1132 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1133}
1134
James Smarte59058c2008-08-24 21:49:00 -04001135/**
James Smart3621a712009-04-06 18:47:14 -04001136 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001137 * @dev: class device that is converted into a Scsi_host.
1138 * @attr: device attribute, not used.
1139 * @buf: containing the used rpi count in decimal or "Unknown".
1140 *
1141 * Description:
1142 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1143 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1144 * to "Unknown" and the buffer length is returned, therefore the caller
1145 * must check for "Unknown" in the buffer to detect a failure.
1146 *
1147 * Returns: size of formatted string.
1148 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001149static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001150lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1151 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001152{
Tony Jonesee959b02008-02-22 00:13:36 +01001153 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1155 struct lpfc_hba *phba = vport->phba;
1156 uint32_t cnt, acnt;
1157
James Smart858c9f62007-06-17 19:56:39 -05001158 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001159 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1160 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1161}
1162
James Smarte59058c2008-08-24 21:49:00 -04001163/**
James Smart3621a712009-04-06 18:47:14 -04001164 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001165 * @dev: class device that is converted into a Scsi_host.
1166 * @attr: device attribute, not used.
1167 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1168 *
1169 * Description:
1170 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1171 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1172 * to "Unknown" and the buffer length is returned, therefore the caller
1173 * must check for "Unknown" in the buffer to detect a failure.
1174 *
1175 * Returns: size of formatted string.
1176 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001177static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001178lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1179 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001180{
Tony Jonesee959b02008-02-22 00:13:36 +01001181 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001182 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1183 struct lpfc_hba *phba = vport->phba;
1184 uint32_t cnt;
1185
James Smart858c9f62007-06-17 19:56:39 -05001186 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001187 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1188 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1189}
1190
James Smarte59058c2008-08-24 21:49:00 -04001191/**
James Smart3621a712009-04-06 18:47:14 -04001192 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001193 * @dev: class device that is converted into a Scsi_host.
1194 * @attr: device attribute, not used.
1195 * @buf: on return contains the used xri count in decimal or "Unknown".
1196 *
1197 * Description:
1198 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1199 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1200 * to "Unknown" and the buffer length is returned, therefore the caller
1201 * must check for "Unknown" in the buffer to detect a failure.
1202 *
1203 * Returns: size of formatted string.
1204 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001205static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001206lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1207 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001208{
Tony Jonesee959b02008-02-22 00:13:36 +01001209 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1211 struct lpfc_hba *phba = vport->phba;
1212 uint32_t cnt, acnt;
1213
James Smart858c9f62007-06-17 19:56:39 -05001214 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1215 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1216 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1217}
1218
James Smarte59058c2008-08-24 21:49:00 -04001219/**
James Smart3621a712009-04-06 18:47:14 -04001220 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001221 * @dev: class device that is converted into a Scsi_host.
1222 * @attr: device attribute, not used.
1223 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1224 *
1225 * Description:
1226 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1227 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1228 * to "Unknown" and the buffer length is returned, therefore the caller
1229 * must check for "Unknown" in the buffer to detect a failure.
1230 *
1231 * Returns: size of formatted string.
1232 **/
James Smart858c9f62007-06-17 19:56:39 -05001233static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001234lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1235 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001236{
Tony Jonesee959b02008-02-22 00:13:36 +01001237 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1239 struct lpfc_hba *phba = vport->phba;
1240 uint32_t cnt;
1241
1242 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1243 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1244 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1245}
1246
James Smarte59058c2008-08-24 21:49:00 -04001247/**
James Smart3621a712009-04-06 18:47:14 -04001248 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001249 * @dev: class device that is converted into a Scsi_host.
1250 * @attr: device attribute, not used.
1251 * @buf: on return contains the used vpi count in decimal or "Unknown".
1252 *
1253 * Description:
1254 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1255 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1256 * to "Unknown" and the buffer length is returned, therefore the caller
1257 * must check for "Unknown" in the buffer to detect a failure.
1258 *
1259 * Returns: size of formatted string.
1260 **/
James Smart858c9f62007-06-17 19:56:39 -05001261static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001262lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1263 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001264{
Tony Jonesee959b02008-02-22 00:13:36 +01001265 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1267 struct lpfc_hba *phba = vport->phba;
1268 uint32_t cnt, acnt;
1269
1270 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001271 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1272 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1273}
1274
James Smarte59058c2008-08-24 21:49:00 -04001275/**
James Smart3621a712009-04-06 18:47:14 -04001276 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001277 * @dev: class device that is converted into a Scsi_host.
1278 * @attr: device attribute, not used.
1279 * @buf: text that must be interpreted to determine if npiv is supported.
1280 *
1281 * Description:
1282 * Buffer will contain text indicating npiv is not suppoerted on the port,
1283 * the port is an NPIV physical port, or it is an npiv virtual port with
1284 * the id of the vport.
1285 *
1286 * Returns: size of formatted string.
1287 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001288static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001289lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1290 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001291{
Tony Jonesee959b02008-02-22 00:13:36 +01001292 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001293 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1294 struct lpfc_hba *phba = vport->phba;
1295
1296 if (!(phba->max_vpi))
1297 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1298 if (vport->port_type == LPFC_PHYSICAL_PORT)
1299 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1300 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1301}
1302
James Smarte59058c2008-08-24 21:49:00 -04001303/**
James Smart3621a712009-04-06 18:47:14 -04001304 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001305 * @dev: class device that is converted into a Scsi_host.
1306 * @attr: device attribute, not used.
1307 * @buf: on return contains the cfg_poll in hex.
1308 *
1309 * Notes:
1310 * cfg_poll should be a lpfc_polling_flags type.
1311 *
1312 * Returns: size of formatted string.
1313 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001314static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001315lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1316 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001317{
Tony Jonesee959b02008-02-22 00:13:36 +01001318 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001319 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1320 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001321
1322 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1323}
1324
James Smarte59058c2008-08-24 21:49:00 -04001325/**
James Smart3621a712009-04-06 18:47:14 -04001326 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001327 * @dev: class device that is converted into a Scsi_host.
1328 * @attr: device attribute, not used.
1329 * @buf: one or more lpfc_polling_flags values.
1330 * @count: not used.
1331 *
1332 * Notes:
1333 * buf contents converted to integer and checked for a valid value.
1334 *
1335 * Returns:
1336 * -EINVAL if the buffer connot be converted or is out of range
1337 * length of the buf on success
1338 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001339static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001340lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1341 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001342{
Tony Jonesee959b02008-02-22 00:13:36 +01001343 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1345 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001346 uint32_t creg_val;
1347 uint32_t old_val;
1348 int val=0;
1349
1350 if (!isdigit(buf[0]))
1351 return -EINVAL;
1352
1353 if (sscanf(buf, "%i", &val) != 1)
1354 return -EINVAL;
1355
1356 if ((val & 0x3) != val)
1357 return -EINVAL;
1358
James Smart45ed1192009-10-02 15:17:02 -04001359 if (phba->sli_rev == LPFC_SLI_REV4)
1360 val = 0;
1361
James Smart88a2cfb2011-07-22 18:36:33 -04001362 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1363 "3051 lpfc_poll changed from %d to %d\n",
1364 phba->cfg_poll, val);
1365
James Smart2e0fef82007-06-17 19:56:36 -05001366 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001367
1368 old_val = phba->cfg_poll;
1369
1370 if (val & ENABLE_FCP_RING_POLLING) {
1371 if ((val & DISABLE_FCP_RING_INT) &&
1372 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001373 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1374 spin_unlock_irq(&phba->hbalock);
1375 return -EINVAL;
1376 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001377 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1378 writel(creg_val, phba->HCregaddr);
1379 readl(phba->HCregaddr); /* flush */
1380
1381 lpfc_poll_start_timer(phba);
1382 }
1383 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001384 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001385 return -EINVAL;
1386 }
1387
1388 if (!(val & DISABLE_FCP_RING_INT) &&
1389 (old_val & DISABLE_FCP_RING_INT))
1390 {
James Smart2e0fef82007-06-17 19:56:36 -05001391 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001392 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001393 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001394 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1395 spin_unlock_irq(&phba->hbalock);
1396 return -EINVAL;
1397 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001398 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1399 writel(creg_val, phba->HCregaddr);
1400 readl(phba->HCregaddr); /* flush */
1401 }
1402
1403 phba->cfg_poll = val;
1404
James Smart2e0fef82007-06-17 19:56:36 -05001405 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001406
1407 return strlen(buf);
1408}
dea31012005-04-17 16:05:31 -05001409
James Smarte59058c2008-08-24 21:49:00 -04001410/**
James Smartbc739052010-08-04 16:11:18 -04001411 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1412 * @dev: class unused variable.
1413 * @attr: device attribute, not used.
1414 * @buf: on return contains the module description text.
1415 *
1416 * Returns: size of formatted string.
1417 **/
1418static ssize_t
1419lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1420 char *buf)
1421{
1422 struct Scsi_Host *shost = class_to_shost(dev);
1423 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1424 struct lpfc_hba *phba = vport->phba;
1425
1426 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1427}
1428
1429/**
1430 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1431 * @dev: class unused variable.
1432 * @attr: device attribute, not used.
1433 * @buf: on return contains the module description text.
1434 *
1435 * Returns: size of formatted string.
1436 **/
1437static ssize_t
1438lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1439 char *buf)
1440{
1441 struct Scsi_Host *shost = class_to_shost(dev);
1442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1443 struct lpfc_hba *phba = vport->phba;
1444
1445 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1446}
1447
1448/**
James Smartab56dc22011-02-16 12:39:57 -05001449 * lpfc_dss_show - Return the current state of dss and the configured state
1450 * @dev: class converted to a Scsi_host structure.
1451 * @attr: device attribute, not used.
1452 * @buf: on return contains the formatted text.
1453 *
1454 * Returns: size of formatted string.
1455 **/
1456static ssize_t
1457lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1458 char *buf)
1459{
1460 struct Scsi_Host *shost = class_to_shost(dev);
1461 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1462 struct lpfc_hba *phba = vport->phba;
1463
1464 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1465 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1466 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1467 "" : "Not ");
1468}
1469
1470/**
James Smart912e3ac2011-05-24 11:42:11 -04001471 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1472 * @dev: class converted to a Scsi_host structure.
1473 * @attr: device attribute, not used.
1474 * @buf: on return contains the formatted support level.
1475 *
1476 * Description:
1477 * Returns the maximum number of virtual functions a physical function can
1478 * support, 0 will be returned if called on virtual function.
1479 *
1480 * Returns: size of formatted string.
1481 **/
1482static ssize_t
1483lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1484 struct device_attribute *attr,
1485 char *buf)
1486{
1487 struct Scsi_Host *shost = class_to_shost(dev);
1488 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1489 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001490 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001491
James Smart0a96e972011-07-22 18:37:28 -04001492 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1493 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001494}
1495
1496/**
James Smart3621a712009-04-06 18:47:14 -04001497 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001498 *
1499 * Description:
1500 * Macro that given an attr e.g. hba_queue_depth expands
1501 * into a function with the name lpfc_hba_queue_depth_show.
1502 *
1503 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1504 * @dev: class device that is converted into a Scsi_host.
1505 * @attr: device attribute, not used.
1506 * @buf: on return contains the attribute value in decimal.
1507 *
1508 * Returns: size of formatted string.
1509 **/
dea31012005-04-17 16:05:31 -05001510#define lpfc_param_show(attr) \
1511static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001512lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1513 char *buf) \
dea31012005-04-17 16:05:31 -05001514{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001515 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1517 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001518 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001519 val = phba->cfg_##attr;\
1520 return snprintf(buf, PAGE_SIZE, "%d\n",\
1521 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001522}
1523
James Smarte59058c2008-08-24 21:49:00 -04001524/**
James Smart3621a712009-04-06 18:47:14 -04001525 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001526 *
1527 * Description:
1528 * Macro that given an attr e.g. hba_queue_depth expands
1529 * into a function with the name lpfc_hba_queue_depth_show
1530 *
1531 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1532 * @dev: class device that is converted into a Scsi_host.
1533 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001534 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001535 *
1536 * Returns: size of formatted string.
1537 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001538#define lpfc_param_hex_show(attr) \
1539static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001540lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1541 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001542{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001543 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1545 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001546 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001547 val = phba->cfg_##attr;\
1548 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1549 phba->cfg_##attr);\
1550}
1551
James Smarte59058c2008-08-24 21:49:00 -04001552/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001553 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001554 *
1555 * Description:
1556 * Macro that given an attr e.g. hba_queue_depth expands
1557 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1558 * takes a default argument, a minimum and maximum argument.
1559 *
1560 * lpfc_##attr##_init: Initializes an attribute.
1561 * @phba: pointer the the adapter structure.
1562 * @val: integer attribute value.
1563 *
1564 * Validates the min and max values then sets the adapter config field
1565 * accordingly, or uses the default if out of range and prints an error message.
1566 *
1567 * Returns:
1568 * zero on success
1569 * -EINVAL if default used
1570 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001571#define lpfc_param_init(attr, default, minval, maxval) \
1572static int \
James Smart84d1b002010-02-12 14:42:33 -05001573lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001574{ \
1575 if (val >= minval && val <= maxval) {\
1576 phba->cfg_##attr = val;\
1577 return 0;\
1578 }\
1579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001580 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1581 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001582 phba->cfg_##attr = default;\
1583 return -EINVAL;\
1584}
1585
James Smarte59058c2008-08-24 21:49:00 -04001586/**
James Smart3621a712009-04-06 18:47:14 -04001587 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001588 *
1589 * Description:
1590 * Macro that given an attr e.g. hba_queue_depth expands
1591 * into a function with the name lpfc_hba_queue_depth_set
1592 *
1593 * lpfc_##attr##_set: Sets an attribute value.
1594 * @phba: pointer the the adapter structure.
1595 * @val: integer attribute value.
1596 *
1597 * Description:
1598 * Validates the min and max values then sets the
1599 * adapter config field if in the valid range. prints error message
1600 * and does not set the parameter if invalid.
1601 *
1602 * Returns:
1603 * zero on success
1604 * -EINVAL if val is invalid
1605 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001606#define lpfc_param_set(attr, default, minval, maxval) \
1607static int \
James Smart84d1b002010-02-12 14:42:33 -05001608lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001609{ \
1610 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001611 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1612 "3052 lpfc_" #attr " changed from %d to %d\n", \
1613 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001614 phba->cfg_##attr = val;\
1615 return 0;\
1616 }\
1617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001618 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1619 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001620 return -EINVAL;\
1621}
1622
James Smarte59058c2008-08-24 21:49:00 -04001623/**
James Smart3621a712009-04-06 18:47:14 -04001624 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001625 *
1626 * Description:
1627 * Macro that given an attr e.g. hba_queue_depth expands
1628 * into a function with the name lpfc_hba_queue_depth_store.
1629 *
1630 * lpfc_##attr##_store: Set an sttribute value.
1631 * @dev: class device that is converted into a Scsi_host.
1632 * @attr: device attribute, not used.
1633 * @buf: contains the attribute value in ascii.
1634 * @count: not used.
1635 *
1636 * Description:
1637 * Convert the ascii text number to an integer, then
1638 * use the lpfc_##attr##_set function to set the value.
1639 *
1640 * Returns:
1641 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1642 * length of buffer upon success.
1643 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001644#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001645static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001646lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1647 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001648{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001649 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1651 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001652 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001653 if (!isdigit(buf[0]))\
1654 return -EINVAL;\
1655 if (sscanf(buf, "%i", &val) != 1)\
1656 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001657 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001658 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001659 else \
1660 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001661}
1662
James Smarte59058c2008-08-24 21:49:00 -04001663/**
James Smart3621a712009-04-06 18:47:14 -04001664 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001665 *
1666 * Description:
1667 * Macro that given an attr e.g. hba_queue_depth expands
1668 * into a function with the name lpfc_hba_queue_depth_show
1669 *
1670 * lpfc_##attr##_show: prints the attribute value in decimal.
1671 * @dev: class device that is converted into a Scsi_host.
1672 * @attr: device attribute, not used.
1673 * @buf: on return contains the attribute value in decimal.
1674 *
1675 * Returns: length of formatted string.
1676 **/
James Smart3de2a652007-08-02 11:09:59 -04001677#define lpfc_vport_param_show(attr) \
1678static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001679lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1680 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001681{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001682 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001683 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001684 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001685 val = vport->cfg_##attr;\
1686 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1687}
1688
James Smarte59058c2008-08-24 21:49:00 -04001689/**
James Smart3621a712009-04-06 18:47:14 -04001690 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001691 *
1692 * Description:
1693 * Macro that given an attr e.g.
1694 * hba_queue_depth expands into a function with the name
1695 * lpfc_hba_queue_depth_show
1696 *
James Smart3621a712009-04-06 18:47:14 -04001697 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001698 * @dev: class device that is converted into a Scsi_host.
1699 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001700 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001701 *
1702 * Returns: length of formatted string.
1703 **/
James Smart3de2a652007-08-02 11:09:59 -04001704#define lpfc_vport_param_hex_show(attr) \
1705static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001706lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1707 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001708{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001709 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001710 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001711 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001712 val = vport->cfg_##attr;\
1713 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1714}
1715
James Smarte59058c2008-08-24 21:49:00 -04001716/**
James Smart3621a712009-04-06 18:47:14 -04001717 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001718 *
1719 * Description:
1720 * Macro that given an attr e.g. hba_queue_depth expands
1721 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1722 * takes a default argument, a minimum and maximum argument.
1723 *
1724 * lpfc_##attr##_init: validates the min and max values then sets the
1725 * adapter config field accordingly, or uses the default if out of range
1726 * and prints an error message.
1727 * @phba: pointer the the adapter structure.
1728 * @val: integer attribute value.
1729 *
1730 * Returns:
1731 * zero on success
1732 * -EINVAL if default used
1733 **/
James Smart3de2a652007-08-02 11:09:59 -04001734#define lpfc_vport_param_init(attr, default, minval, maxval) \
1735static int \
James Smart84d1b002010-02-12 14:42:33 -05001736lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001737{ \
1738 if (val >= minval && val <= maxval) {\
1739 vport->cfg_##attr = val;\
1740 return 0;\
1741 }\
James Smarte8b62012007-08-02 11:10:09 -04001742 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001743 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001744 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001745 vport->cfg_##attr = default;\
1746 return -EINVAL;\
1747}
1748
James Smarte59058c2008-08-24 21:49:00 -04001749/**
James Smart3621a712009-04-06 18:47:14 -04001750 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001751 *
1752 * Description:
1753 * Macro that given an attr e.g. hba_queue_depth expands
1754 * into a function with the name lpfc_hba_queue_depth_set
1755 *
1756 * lpfc_##attr##_set: validates the min and max values then sets the
1757 * adapter config field if in the valid range. prints error message
1758 * and does not set the parameter if invalid.
1759 * @phba: pointer the the adapter structure.
1760 * @val: integer attribute value.
1761 *
1762 * Returns:
1763 * zero on success
1764 * -EINVAL if val is invalid
1765 **/
James Smart3de2a652007-08-02 11:09:59 -04001766#define lpfc_vport_param_set(attr, default, minval, maxval) \
1767static int \
James Smart84d1b002010-02-12 14:42:33 -05001768lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001769{ \
1770 if (val >= minval && val <= maxval) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001771 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1772 "3053 lpfc_" #attr " changed from %d to %d\n", \
1773 vport->cfg_##attr, val); \
James Smart3de2a652007-08-02 11:09:59 -04001774 vport->cfg_##attr = val;\
1775 return 0;\
1776 }\
James Smarte8b62012007-08-02 11:10:09 -04001777 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001778 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001779 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001780 return -EINVAL;\
1781}
1782
James Smarte59058c2008-08-24 21:49:00 -04001783/**
James Smart3621a712009-04-06 18:47:14 -04001784 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001785 *
1786 * Description:
1787 * Macro that given an attr e.g. hba_queue_depth
1788 * expands into a function with the name lpfc_hba_queue_depth_store
1789 *
1790 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1791 * use the lpfc_##attr##_set function to set the value.
1792 * @cdev: class device that is converted into a Scsi_host.
1793 * @buf: contains the attribute value in decimal.
1794 * @count: not used.
1795 *
1796 * Returns:
1797 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1798 * length of buffer upon success.
1799 **/
James Smart3de2a652007-08-02 11:09:59 -04001800#define lpfc_vport_param_store(attr) \
1801static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001802lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1803 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001804{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001805 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001806 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001807 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001808 if (!isdigit(buf[0]))\
1809 return -EINVAL;\
1810 if (sscanf(buf, "%i", &val) != 1)\
1811 return -EINVAL;\
1812 if (lpfc_##attr##_set(vport, val) == 0) \
1813 return strlen(buf);\
1814 else \
1815 return -EINVAL;\
1816}
1817
1818
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001819#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001820static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001821module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001822MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001823lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001824
1825#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001826static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001827module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001828MODULE_PARM_DESC(lpfc_##name, desc);\
1829lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001830lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001831static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001832
1833#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001834static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001835module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001836MODULE_PARM_DESC(lpfc_##name, desc);\
1837lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001838lpfc_param_init(name, defval, minval, maxval)\
1839lpfc_param_set(name, defval, minval, maxval)\
1840lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001841static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1842 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001843
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001844#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001845static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001846module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001847MODULE_PARM_DESC(lpfc_##name, desc);\
1848lpfc_param_hex_show(name)\
1849lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001850static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001851
1852#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001853static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001854module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001855MODULE_PARM_DESC(lpfc_##name, desc);\
1856lpfc_param_hex_show(name)\
1857lpfc_param_init(name, defval, minval, maxval)\
1858lpfc_param_set(name, defval, minval, maxval)\
1859lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001860static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1861 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001862
James Smart3de2a652007-08-02 11:09:59 -04001863#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001864static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001865module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001866MODULE_PARM_DESC(lpfc_##name, desc);\
1867lpfc_vport_param_init(name, defval, minval, maxval)
1868
1869#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001870static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001871module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001872MODULE_PARM_DESC(lpfc_##name, desc);\
1873lpfc_vport_param_show(name)\
1874lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001875static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001876
1877#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001878static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001879module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001880MODULE_PARM_DESC(lpfc_##name, desc);\
1881lpfc_vport_param_show(name)\
1882lpfc_vport_param_init(name, defval, minval, maxval)\
1883lpfc_vport_param_set(name, defval, minval, maxval)\
1884lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001885static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1886 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001887
1888#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001889static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001890module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001891MODULE_PARM_DESC(lpfc_##name, desc);\
1892lpfc_vport_param_hex_show(name)\
1893lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001894static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001895
1896#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001897static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001898module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001899MODULE_PARM_DESC(lpfc_##name, desc);\
1900lpfc_vport_param_hex_show(name)\
1901lpfc_vport_param_init(name, defval, minval, maxval)\
1902lpfc_vport_param_set(name, defval, minval, maxval)\
1903lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001904static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1905 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001906
James Smart81301a92008-12-04 22:39:46 -05001907static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1908static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1909static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1910static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001911static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1912static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1913static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1914static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1915static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1916static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1917static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1918static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001919static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1920 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001921static DEVICE_ATTR(option_rom_version, S_IRUGO,
1922 lpfc_option_rom_version_show, NULL);
1923static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1924 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001925static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001926static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1927static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001928static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001929static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1930 lpfc_board_mode_show, lpfc_board_mode_store);
1931static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1932static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1933static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1934static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1935static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1936static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1937static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1938static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1939static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001940static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1941static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001942static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04001943static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1944 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001945
James Smarta12e07b2006-12-02 13:35:30 -05001946static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001947
James Smarte59058c2008-08-24 21:49:00 -04001948/**
James Smart3621a712009-04-06 18:47:14 -04001949 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001950 * @dev: class device that is converted into a Scsi_host.
1951 * @attr: device attribute, not used.
1952 * @buf: containing the string lpfc_soft_wwn_key.
1953 * @count: must be size of lpfc_soft_wwn_key.
1954 *
1955 * Returns:
1956 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1957 * length of buf indicates success
1958 **/
James Smartc3f28af2006-08-18 17:47:18 -04001959static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001960lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1961 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001962{
Tony Jonesee959b02008-02-22 00:13:36 +01001963 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001964 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1965 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001966 unsigned int cnt = count;
1967
1968 /*
1969 * We're doing a simple sanity check for soft_wwpn setting.
1970 * We require that the user write a specific key to enable
1971 * the soft_wwpn attribute to be settable. Once the attribute
1972 * is written, the enable key resets. If further updates are
1973 * desired, the key must be written again to re-enable the
1974 * attribute.
1975 *
1976 * The "key" is not secret - it is a hardcoded string shown
1977 * here. The intent is to protect against the random user or
1978 * application that is just writing attributes.
1979 */
1980
1981 /* count may include a LF at end of string */
1982 if (buf[cnt-1] == '\n')
1983 cnt--;
1984
James Smarta12e07b2006-12-02 13:35:30 -05001985 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1986 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001987 return -EINVAL;
1988
James Smarta12e07b2006-12-02 13:35:30 -05001989 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001990 return count;
1991}
Tony Jonesee959b02008-02-22 00:13:36 +01001992static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1993 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001994
James Smarte59058c2008-08-24 21:49:00 -04001995/**
James Smart3621a712009-04-06 18:47:14 -04001996 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001997 * @dev: class device that is converted into a Scsi_host.
1998 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001999 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002000 *
2001 * Returns: size of formatted string.
2002 **/
James Smartc3f28af2006-08-18 17:47:18 -04002003static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002004lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2005 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04002006{
Tony Jonesee959b02008-02-22 00:13:36 +01002007 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002008 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2009 struct lpfc_hba *phba = vport->phba;
2010
Randy Dunlapafc071e2006-10-23 21:47:13 -07002011 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2012 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04002013}
2014
James Smarte59058c2008-08-24 21:49:00 -04002015/**
James Smart3621a712009-04-06 18:47:14 -04002016 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002017 * @dev class device that is converted into a Scsi_host.
2018 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002019 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002020 * @count: number of wwpn bytes in buf
2021 *
2022 * Returns:
2023 * -EACCES hba reset not enabled, adapter over temp
2024 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2025 * -EIO error taking adapter offline or online
2026 * value of count on success
2027 **/
James Smartc3f28af2006-08-18 17:47:18 -04002028static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002029lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2030 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04002031{
Tony Jonesee959b02008-02-22 00:13:36 +01002032 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2034 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04002035 struct completion online_compl;
2036 int stat1=0, stat2=0;
2037 unsigned int i, j, cnt=count;
2038 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05002039 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04002040
James Smart13815c82008-01-11 01:52:48 -05002041 if (!phba->cfg_enable_hba_reset)
2042 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002043 spin_lock_irq(&phba->hbalock);
2044 if (phba->over_temp_state == HBA_OVER_TEMP) {
2045 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002046 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002047 }
2048 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04002049 /* count may include a LF at end of string */
2050 if (buf[cnt-1] == '\n')
2051 cnt--;
2052
James Smarta12e07b2006-12-02 13:35:30 -05002053 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04002054 ((cnt == 17) && (*buf++ != 'x')) ||
2055 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2056 return -EINVAL;
2057
James Smarta12e07b2006-12-02 13:35:30 -05002058 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04002059
2060 memset(wwpn, 0, sizeof(wwpn));
2061
2062 /* Validate and store the new name */
2063 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002064 int value;
2065
2066 value = hex_to_bin(*buf++);
2067 if (value >= 0)
2068 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04002069 else
2070 return -EINVAL;
2071 if (i % 2) {
2072 wwpn[i/2] = j & 0xff;
2073 j = 0;
2074 }
2075 }
2076 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05002077 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05002078 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002079 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04002080
2081 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2082 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2083
James Smart46fa3112007-04-25 09:51:45 -04002084 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04002085 if (stat1)
2086 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002087 "0463 lpfc_soft_wwpn attribute set failed to "
2088 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04002089 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05002090 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2091 LPFC_EVT_ONLINE);
2092 if (rc == 0)
2093 return -ENOMEM;
2094
James Smartc3f28af2006-08-18 17:47:18 -04002095 wait_for_completion(&online_compl);
2096 if (stat2)
2097 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002098 "0464 lpfc_soft_wwpn attribute set failed to "
2099 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04002100 return (stat1 || stat2) ? -EIO : count;
2101}
Tony Jonesee959b02008-02-22 00:13:36 +01002102static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2103 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04002104
James Smarte59058c2008-08-24 21:49:00 -04002105/**
James Smart3621a712009-04-06 18:47:14 -04002106 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for 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: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002110 *
2111 * Returns: size of formatted string.
2112 **/
James Smarta12e07b2006-12-02 13:35:30 -05002113static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002114lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2115 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05002116{
Tony Jonesee959b02008-02-22 00:13:36 +01002117 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002118 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002119 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2120 (unsigned long long)phba->cfg_soft_wwnn);
2121}
2122
James Smarte59058c2008-08-24 21:49:00 -04002123/**
James Smart3621a712009-04-06 18:47:14 -04002124 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002125 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002126 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002127 * @count: number of wwnn bytes in buf.
2128 *
2129 * Returns:
2130 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2131 * value of count on success
2132 **/
James Smarta12e07b2006-12-02 13:35:30 -05002133static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002134lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2135 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002136{
Tony Jonesee959b02008-02-22 00:13:36 +01002137 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002138 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002139 unsigned int i, j, cnt=count;
2140 u8 wwnn[8];
2141
2142 /* count may include a LF at end of string */
2143 if (buf[cnt-1] == '\n')
2144 cnt--;
2145
2146 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2147 ((cnt == 17) && (*buf++ != 'x')) ||
2148 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2149 return -EINVAL;
2150
2151 /*
2152 * Allow wwnn to be set many times, as long as the enable is set.
2153 * However, once the wwpn is set, everything locks.
2154 */
2155
2156 memset(wwnn, 0, sizeof(wwnn));
2157
2158 /* Validate and store the new name */
2159 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002160 int value;
2161
2162 value = hex_to_bin(*buf++);
2163 if (value >= 0)
2164 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002165 else
2166 return -EINVAL;
2167 if (i % 2) {
2168 wwnn[i/2] = j & 0xff;
2169 j = 0;
2170 }
2171 }
2172 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2173
2174 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2175 "lpfc%d: soft_wwnn set. Value will take effect upon "
2176 "setting of the soft_wwpn\n", phba->brd_no);
2177
2178 return count;
2179}
Tony Jonesee959b02008-02-22 00:13:36 +01002180static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2181 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002182
James Smartc3f28af2006-08-18 17:47:18 -04002183
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002184static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002185module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002186MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2187 " 0 - none,"
2188 " 1 - poll with interrupts enabled"
2189 " 3 - poll and disable FCP ring interrupts");
2190
Tony Jonesee959b02008-02-22 00:13:36 +01002191static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2192 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002193
James Smart92d7f7b2007-06-17 19:56:38 -05002194int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002195module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002196MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2197 " 0 - auto (SLI-3 if supported),"
2198 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2199 " 3 - select SLI-3");
2200
James Smart15672312010-04-06 14:49:03 -04002201int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002202module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002203MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2204lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002205lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002206static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002207
James Smart7d791df2011-07-22 18:37:52 -04002208LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2209 "FCF Fast failover=1 Priority failover=2");
2210
James Smart19ca7602010-11-20 23:11:55 -05002211int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002212module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002213MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2214lpfc_param_show(enable_rrq);
2215lpfc_param_init(enable_rrq, 0, 0, 1);
2216static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2217
dea31012005-04-17 16:05:31 -05002218/*
James Smart84d1b002010-02-12 14:42:33 -05002219# lpfc_suppress_link_up: Bring link up at initialization
2220# 0x0 = bring link up (issue MBX_INIT_LINK)
2221# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2222# 0x2 = never bring up link
2223# Default value is 0.
2224*/
James Smarte40a02c2010-02-26 14:13:54 -05002225LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2226 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2227 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002228/*
2229# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2230# 1 - (1024)
2231# 2 - (2048)
2232# 3 - (3072)
2233# 4 - (4096)
2234# 5 - (5120)
2235*/
2236static ssize_t
2237lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2238{
2239 struct Scsi_Host *shost = class_to_shost(dev);
2240 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2241
2242 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2243}
2244
2245static DEVICE_ATTR(iocb_hw, S_IRUGO,
2246 lpfc_iocb_hw_show, NULL);
2247static ssize_t
2248lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2249{
2250 struct Scsi_Host *shost = class_to_shost(dev);
2251 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2252
2253 return snprintf(buf, PAGE_SIZE, "%d\n",
2254 phba->sli.ring[LPFC_ELS_RING].txq_max);
2255}
2256
2257static DEVICE_ATTR(txq_hw, S_IRUGO,
2258 lpfc_txq_hw_show, NULL);
2259static ssize_t
2260lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2261 char *buf)
2262{
2263 struct Scsi_Host *shost = class_to_shost(dev);
2264 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2265
2266 return snprintf(buf, PAGE_SIZE, "%d\n",
2267 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2268}
2269
2270static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2271 lpfc_txcmplq_hw_show, NULL);
2272
2273int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002274module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002275MODULE_PARM_DESC(lpfc_iocb_cnt,
2276 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2277lpfc_param_show(iocb_cnt);
2278lpfc_param_init(iocb_cnt, 2, 1, 5);
2279static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2280 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002281
2282/*
James Smartc01f3202006-08-18 17:47:08 -04002283# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2284# until the timer expires. Value range is [0,255]. Default value is 30.
2285*/
2286static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2287static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2288module_param(lpfc_nodev_tmo, int, 0);
2289MODULE_PARM_DESC(lpfc_nodev_tmo,
2290 "Seconds driver will hold I/O waiting "
2291 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002292
2293/**
James Smart3621a712009-04-06 18:47:14 -04002294 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002295 * @dev: class converted to a Scsi_host structure.
2296 * @attr: device attribute, not used.
2297 * @buf: on return contains the dev loss timeout in decimal.
2298 *
2299 * Returns: size of formatted string.
2300 **/
James Smartc01f3202006-08-18 17:47:08 -04002301static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002302lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2303 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002304{
Tony Jonesee959b02008-02-22 00:13:36 +01002305 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002307
James Smart3de2a652007-08-02 11:09:59 -04002308 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002309}
2310
James Smarte59058c2008-08-24 21:49:00 -04002311/**
James Smart3621a712009-04-06 18:47:14 -04002312 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002313 * @vport: lpfc vport structure pointer.
2314 * @val: contains the nodev timeout value.
2315 *
2316 * Description:
2317 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2318 * a kernel error message is printed and zero is returned.
2319 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2320 * Otherwise nodev tmo is set to the default value.
2321 *
2322 * Returns:
2323 * zero if already set or if val is in range
2324 * -EINVAL val out of range
2325 **/
James Smartc01f3202006-08-18 17:47:08 -04002326static int
James Smart3de2a652007-08-02 11:09:59 -04002327lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002328{
James Smart3de2a652007-08-02 11:09:59 -04002329 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2330 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2331 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002332 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002333 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002334 "parameter because devloss_tmo is "
2335 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002336 return 0;
2337 }
2338
2339 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002340 vport->cfg_nodev_tmo = val;
2341 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002342 return 0;
2343 }
James Smarte8b62012007-08-02 11:10:09 -04002344 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2345 "0400 lpfc_nodev_tmo attribute cannot be set to"
2346 " %d, allowed range is [%d, %d]\n",
2347 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002348 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002349 return -EINVAL;
2350}
2351
James Smarte59058c2008-08-24 21:49:00 -04002352/**
James Smart3621a712009-04-06 18:47:14 -04002353 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002354 * @vport: lpfc vport structure pointer.
2355 *
2356 * Description:
2357 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2358 **/
James Smart7054a602007-04-25 09:52:34 -04002359static void
James Smart3de2a652007-08-02 11:09:59 -04002360lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002361{
James Smart858c9f62007-06-17 19:56:39 -05002362 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002363 struct lpfc_nodelist *ndlp;
2364
James Smart51ef4c22007-08-02 11:10:31 -04002365 shost = lpfc_shost_from_vport(vport);
2366 spin_lock_irq(shost->host_lock);
2367 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002368 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002369 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2370 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002371}
2372
James Smarte59058c2008-08-24 21:49:00 -04002373/**
James Smart3621a712009-04-06 18:47:14 -04002374 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002375 * @vport: lpfc vport structure pointer.
2376 * @val: contains the tmo value.
2377 *
2378 * Description:
2379 * If the devloss tmo is already set or the vport dev loss tmo has changed
2380 * then a kernel error message is printed and zero is returned.
2381 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2382 * Otherwise nodev tmo is set to the default value.
2383 *
2384 * Returns:
2385 * zero if already set or if val is in range
2386 * -EINVAL val out of range
2387 **/
James Smartc01f3202006-08-18 17:47:08 -04002388static int
James Smart3de2a652007-08-02 11:09:59 -04002389lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002390{
James Smart3de2a652007-08-02 11:09:59 -04002391 if (vport->dev_loss_tmo_changed ||
2392 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002393 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2394 "0401 Ignoring change to nodev_tmo "
2395 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002396 return 0;
2397 }
James Smartc01f3202006-08-18 17:47:08 -04002398 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002399 vport->cfg_nodev_tmo = val;
2400 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002401 /*
2402 * For compat: set the fc_host dev loss so new rports
2403 * will get the value.
2404 */
2405 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002406 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002407 return 0;
2408 }
James Smarte8b62012007-08-02 11:10:09 -04002409 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2410 "0403 lpfc_nodev_tmo attribute cannot be set to"
2411 "%d, allowed range is [%d, %d]\n",
2412 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002413 return -EINVAL;
2414}
2415
James Smart3de2a652007-08-02 11:09:59 -04002416lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002417
Tony Jonesee959b02008-02-22 00:13:36 +01002418static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2419 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002420
2421/*
2422# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2423# disappear until the timer expires. Value range is [0,255]. Default
2424# value is 30.
2425*/
James Smartab56dc22011-02-16 12:39:57 -05002426module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002427MODULE_PARM_DESC(lpfc_devloss_tmo,
2428 "Seconds driver will hold I/O waiting "
2429 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002430lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2431 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2432lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002433
2434/**
James Smart3621a712009-04-06 18:47:14 -04002435 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002436 * @vport: lpfc vport structure pointer.
2437 * @val: contains the tmo value.
2438 *
2439 * Description:
2440 * If val is in a valid range then set the vport nodev tmo,
2441 * devloss tmo, also set the vport dev loss tmo changed flag.
2442 * Else a kernel error message is printed.
2443 *
2444 * Returns:
2445 * zero if val is in range
2446 * -EINVAL val out of range
2447 **/
James Smartc01f3202006-08-18 17:47:08 -04002448static int
James Smart3de2a652007-08-02 11:09:59 -04002449lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002450{
2451 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002452 vport->cfg_nodev_tmo = val;
2453 vport->cfg_devloss_tmo = val;
2454 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002455 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002456 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002457 return 0;
2458 }
2459
James Smarte8b62012007-08-02 11:10:09 -04002460 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2461 "0404 lpfc_devloss_tmo attribute cannot be set to"
2462 " %d, allowed range is [%d, %d]\n",
2463 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002464 return -EINVAL;
2465}
2466
James Smart3de2a652007-08-02 11:09:59 -04002467lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002468static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2469 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002470
2471/*
dea31012005-04-17 16:05:31 -05002472# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2473# deluged with LOTS of information.
2474# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002475# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002476*/
James Smartf4b4c682009-05-22 14:53:12 -04002477LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002478 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002479
2480/*
James Smart7ee5d432007-10-27 13:37:17 -04002481# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2482# objects that have been registered with the nameserver after login.
2483*/
2484LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2485 "Deregister nameserver objects before LOGO");
2486
2487/*
dea31012005-04-17 16:05:31 -05002488# lun_queue_depth: This parameter is used to limit the number of outstanding
2489# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2490*/
James Smart3de2a652007-08-02 11:09:59 -04002491LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2492 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002493
2494/*
James Smart7dc517d2010-07-14 15:32:10 -04002495# tgt_queue_depth: This parameter is used to limit the number of outstanding
2496# commands per target port. Value range is [10,65535]. Default value is 65535.
2497*/
2498LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2499 "Max number of FCP commands we can queue to a specific target port");
2500
2501/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002502# hba_queue_depth: This parameter is used to limit the number of outstanding
2503# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2504# value is greater than the maximum number of exchanges supported by the HBA,
2505# then maximum number of exchanges supported by the HBA is used to determine
2506# the hba_queue_depth.
2507*/
2508LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2509 "Max number of FCP commands we can queue to a lpfc HBA");
2510
2511/*
James Smart92d7f7b2007-06-17 19:56:38 -05002512# peer_port_login: This parameter allows/prevents logins
2513# between peer ports hosted on the same physical port.
2514# When this parameter is set 0 peer ports of same physical port
2515# are not allowed to login to each other.
2516# When this parameter is set 1 peer ports of same physical port
2517# are allowed to login to each other.
2518# Default value of this parameter is 0.
2519*/
James Smart3de2a652007-08-02 11:09:59 -04002520LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2521 "Allow peer ports on the same physical port to login to each "
2522 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002523
2524/*
James Smart3de2a652007-08-02 11:09:59 -04002525# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002526# between Virtual Ports and remote initiators.
2527# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2528# other initiators and will attempt to PLOGI all remote ports.
2529# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2530# remote ports and will not attempt to PLOGI to other initiators.
2531# This parameter does not restrict to the physical port.
2532# This parameter does not restrict logins to Fabric resident remote ports.
2533# Default value of this parameter is 1.
2534*/
James Smart3de2a652007-08-02 11:09:59 -04002535static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002536module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002537MODULE_PARM_DESC(lpfc_restrict_login,
2538 "Restrict virtual ports login to remote initiators.");
2539lpfc_vport_param_show(restrict_login);
2540
James Smarte59058c2008-08-24 21:49:00 -04002541/**
James Smart3621a712009-04-06 18:47:14 -04002542 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002543 * @vport: lpfc vport structure pointer.
2544 * @val: contains the restrict login value.
2545 *
2546 * Description:
2547 * If val is not in a valid range then log a kernel error message and set
2548 * the vport restrict login to one.
2549 * If the port type is physical clear the restrict login flag and return.
2550 * Else set the restrict login flag to val.
2551 *
2552 * Returns:
2553 * zero if val is in range
2554 * -EINVAL val out of range
2555 **/
James Smart3de2a652007-08-02 11:09:59 -04002556static int
2557lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2558{
2559 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002560 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002561 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002562 "be set to %d, allowed range is [0, 1]\n",
2563 val);
James Smart3de2a652007-08-02 11:09:59 -04002564 vport->cfg_restrict_login = 1;
2565 return -EINVAL;
2566 }
2567 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2568 vport->cfg_restrict_login = 0;
2569 return 0;
2570 }
2571 vport->cfg_restrict_login = val;
2572 return 0;
2573}
2574
James Smarte59058c2008-08-24 21:49:00 -04002575/**
James Smart3621a712009-04-06 18:47:14 -04002576 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002577 * @vport: lpfc vport structure pointer.
2578 * @val: contains the restrict login value.
2579 *
2580 * Description:
2581 * If val is not in a valid range then log a kernel error message and set
2582 * the vport restrict login to one.
2583 * If the port type is physical and the val is not zero log a kernel
2584 * error message, clear the restrict login flag and return zero.
2585 * Else set the restrict login flag to val.
2586 *
2587 * Returns:
2588 * zero if val is in range
2589 * -EINVAL val out of range
2590 **/
James Smart3de2a652007-08-02 11:09:59 -04002591static int
2592lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2593{
2594 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002595 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002596 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002597 "be set to %d, allowed range is [0, 1]\n",
2598 val);
James Smart3de2a652007-08-02 11:09:59 -04002599 vport->cfg_restrict_login = 1;
2600 return -EINVAL;
2601 }
2602 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002603 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2604 "0468 lpfc_restrict_login must be 0 for "
2605 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002606 vport->cfg_restrict_login = 0;
2607 return 0;
2608 }
2609 vport->cfg_restrict_login = val;
2610 return 0;
2611}
2612lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002613static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2614 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002615
2616/*
dea31012005-04-17 16:05:31 -05002617# Some disk devices have a "select ID" or "select Target" capability.
2618# From a protocol standpoint "select ID" usually means select the
2619# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2620# annex" which contains a table that maps a "select ID" (a number
2621# between 0 and 7F) to an ALPA. By default, for compatibility with
2622# older drivers, the lpfc driver scans this table from low ALPA to high
2623# ALPA.
2624#
2625# Turning on the scan-down variable (on = 1, off = 0) will
2626# cause the lpfc driver to use an inverted table, effectively
2627# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2628#
2629# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2630# and will not work across a fabric. Also this parameter will take
2631# effect only in the case when ALPA map is not available.)
2632*/
James Smart3de2a652007-08-02 11:09:59 -04002633LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2634 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002635
2636/*
dea31012005-04-17 16:05:31 -05002637# lpfc_topology: link topology for init link
2638# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002639# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002640# 0x02 = attempt point-to-point mode only
2641# 0x04 = attempt loop mode only
2642# 0x06 = attempt point-to-point mode then loop
2643# Set point-to-point mode if you want to run as an N_Port.
2644# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2645# Default value is 0.
2646*/
James Smarte59058c2008-08-24 21:49:00 -04002647
2648/**
James Smart3621a712009-04-06 18:47:14 -04002649 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002650 * @phba: lpfc_hba pointer.
2651 * @val: topology value.
2652 *
2653 * Description:
2654 * If val is in a valid range then set the adapter's topology field and
2655 * issue a lip; if the lip fails reset the topology to the old value.
2656 *
2657 * If the value is not in range log a kernel error message and return an error.
2658 *
2659 * Returns:
2660 * zero if val is in range and lip okay
2661 * non-zero return value from lpfc_issue_lip()
2662 * -EINVAL val out of range
2663 **/
James Smarta257bf92009-04-06 18:48:10 -04002664static ssize_t
2665lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2666 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002667{
James Smarta257bf92009-04-06 18:48:10 -04002668 struct Scsi_Host *shost = class_to_shost(dev);
2669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2670 struct lpfc_hba *phba = vport->phba;
2671 int val = 0;
2672 int nolip = 0;
2673 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002674 int err;
2675 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002676
2677 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2678 nolip = 1;
2679 val_buf = &buf[strlen("nolip ")];
2680 }
2681
2682 if (!isdigit(val_buf[0]))
2683 return -EINVAL;
2684 if (sscanf(val_buf, "%i", &val) != 1)
2685 return -EINVAL;
2686
James Smart83108bd2008-01-11 01:53:09 -05002687 if (val >= 0 && val <= 6) {
2688 prev_val = phba->cfg_topology;
2689 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002690 if (nolip)
2691 return strlen(buf);
2692
James Smart88a2cfb2011-07-22 18:36:33 -04002693 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2694 "3054 lpfc_topology changed from %d to %d\n",
2695 prev_val, val);
James Smart83108bd2008-01-11 01:53:09 -05002696 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002697 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002698 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002699 return -EINVAL;
2700 } else
2701 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002702 }
2703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2704 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2705 "allowed range is [0, 6]\n",
2706 phba->brd_no, val);
2707 return -EINVAL;
2708}
2709static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002710module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002711MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2712lpfc_param_show(topology)
2713lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002714static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002715 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002716
James Smart21e9a0a2009-05-22 14:53:21 -04002717/**
2718 * lpfc_static_vport_show: Read callback function for
2719 * lpfc_static_vport sysfs file.
2720 * @dev: Pointer to class device object.
2721 * @attr: device attribute structure.
2722 * @buf: Data buffer.
2723 *
2724 * This function is the read call back function for
2725 * lpfc_static_vport sysfs file. The lpfc_static_vport
2726 * sysfs file report the mageability of the vport.
2727 **/
2728static ssize_t
2729lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2730 char *buf)
2731{
2732 struct Scsi_Host *shost = class_to_shost(dev);
2733 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2734 if (vport->vport_flag & STATIC_VPORT)
2735 sprintf(buf, "1\n");
2736 else
2737 sprintf(buf, "0\n");
2738
2739 return strlen(buf);
2740}
2741
2742/*
2743 * Sysfs attribute to control the statistical data collection.
2744 */
2745static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2746 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002747
2748/**
James Smart3621a712009-04-06 18:47:14 -04002749 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002750 * @dev: Pointer to class device.
2751 * @buf: Data buffer.
2752 * @count: Size of the data buffer.
2753 *
2754 * This function get called when an user write to the lpfc_stat_data_ctrl
2755 * sysfs file. This function parse the command written to the sysfs file
2756 * and take appropriate action. These commands are used for controlling
2757 * driver statistical data collection.
2758 * Following are the command this function handles.
2759 *
2760 * setbucket <bucket_type> <base> <step>
2761 * = Set the latency buckets.
2762 * destroybucket = destroy all the buckets.
2763 * start = start data collection
2764 * stop = stop data collection
2765 * reset = reset the collected data
2766 **/
2767static ssize_t
2768lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2769 const char *buf, size_t count)
2770{
2771 struct Scsi_Host *shost = class_to_shost(dev);
2772 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2773 struct lpfc_hba *phba = vport->phba;
2774#define LPFC_MAX_DATA_CTRL_LEN 1024
2775 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2776 unsigned long i;
2777 char *str_ptr, *token;
2778 struct lpfc_vport **vports;
2779 struct Scsi_Host *v_shost;
2780 char *bucket_type_str, *base_str, *step_str;
2781 unsigned long base, step, bucket_type;
2782
2783 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002784 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002785 return -EINVAL;
2786
2787 strcpy(bucket_data, buf);
2788 str_ptr = &bucket_data[0];
2789 /* Ignore this token - this is command token */
2790 token = strsep(&str_ptr, "\t ");
2791 if (!token)
2792 return -EINVAL;
2793
2794 bucket_type_str = strsep(&str_ptr, "\t ");
2795 if (!bucket_type_str)
2796 return -EINVAL;
2797
2798 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2799 bucket_type = LPFC_LINEAR_BUCKET;
2800 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2801 bucket_type = LPFC_POWER2_BUCKET;
2802 else
2803 return -EINVAL;
2804
2805 base_str = strsep(&str_ptr, "\t ");
2806 if (!base_str)
2807 return -EINVAL;
2808 base = simple_strtoul(base_str, NULL, 0);
2809
2810 step_str = strsep(&str_ptr, "\t ");
2811 if (!step_str)
2812 return -EINVAL;
2813 step = simple_strtoul(step_str, NULL, 0);
2814 if (!step)
2815 return -EINVAL;
2816
2817 /* Block the data collection for every vport */
2818 vports = lpfc_create_vport_work_array(phba);
2819 if (vports == NULL)
2820 return -ENOMEM;
2821
James Smartf4b4c682009-05-22 14:53:12 -04002822 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002823 v_shost = lpfc_shost_from_vport(vports[i]);
2824 spin_lock_irq(v_shost->host_lock);
2825 /* Block and reset data collection */
2826 vports[i]->stat_data_blocked = 1;
2827 if (vports[i]->stat_data_enabled)
2828 lpfc_vport_reset_stat_data(vports[i]);
2829 spin_unlock_irq(v_shost->host_lock);
2830 }
2831
2832 /* Set the bucket attributes */
2833 phba->bucket_type = bucket_type;
2834 phba->bucket_base = base;
2835 phba->bucket_step = step;
2836
James Smartf4b4c682009-05-22 14:53:12 -04002837 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002838 v_shost = lpfc_shost_from_vport(vports[i]);
2839
2840 /* Unblock data collection */
2841 spin_lock_irq(v_shost->host_lock);
2842 vports[i]->stat_data_blocked = 0;
2843 spin_unlock_irq(v_shost->host_lock);
2844 }
2845 lpfc_destroy_vport_work_array(phba, vports);
2846 return strlen(buf);
2847 }
2848
2849 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2850 vports = lpfc_create_vport_work_array(phba);
2851 if (vports == NULL)
2852 return -ENOMEM;
2853
James Smartf4b4c682009-05-22 14:53:12 -04002854 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002855 v_shost = lpfc_shost_from_vport(vports[i]);
2856 spin_lock_irq(shost->host_lock);
2857 vports[i]->stat_data_blocked = 1;
2858 lpfc_free_bucket(vport);
2859 vport->stat_data_enabled = 0;
2860 vports[i]->stat_data_blocked = 0;
2861 spin_unlock_irq(shost->host_lock);
2862 }
2863 lpfc_destroy_vport_work_array(phba, vports);
2864 phba->bucket_type = LPFC_NO_BUCKET;
2865 phba->bucket_base = 0;
2866 phba->bucket_step = 0;
2867 return strlen(buf);
2868 }
2869
2870 if (!strncmp(buf, "start", strlen("start"))) {
2871 /* If no buckets configured return error */
2872 if (phba->bucket_type == LPFC_NO_BUCKET)
2873 return -EINVAL;
2874 spin_lock_irq(shost->host_lock);
2875 if (vport->stat_data_enabled) {
2876 spin_unlock_irq(shost->host_lock);
2877 return strlen(buf);
2878 }
2879 lpfc_alloc_bucket(vport);
2880 vport->stat_data_enabled = 1;
2881 spin_unlock_irq(shost->host_lock);
2882 return strlen(buf);
2883 }
2884
2885 if (!strncmp(buf, "stop", strlen("stop"))) {
2886 spin_lock_irq(shost->host_lock);
2887 if (vport->stat_data_enabled == 0) {
2888 spin_unlock_irq(shost->host_lock);
2889 return strlen(buf);
2890 }
2891 lpfc_free_bucket(vport);
2892 vport->stat_data_enabled = 0;
2893 spin_unlock_irq(shost->host_lock);
2894 return strlen(buf);
2895 }
2896
2897 if (!strncmp(buf, "reset", strlen("reset"))) {
2898 if ((phba->bucket_type == LPFC_NO_BUCKET)
2899 || !vport->stat_data_enabled)
2900 return strlen(buf);
2901 spin_lock_irq(shost->host_lock);
2902 vport->stat_data_blocked = 1;
2903 lpfc_vport_reset_stat_data(vport);
2904 vport->stat_data_blocked = 0;
2905 spin_unlock_irq(shost->host_lock);
2906 return strlen(buf);
2907 }
2908 return -EINVAL;
2909}
2910
2911
2912/**
James Smart3621a712009-04-06 18:47:14 -04002913 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002914 * @dev: Pointer to class device object.
2915 * @buf: Data buffer.
2916 *
2917 * This function is the read call back function for
2918 * lpfc_stat_data_ctrl sysfs file. This function report the
2919 * current statistical data collection state.
2920 **/
2921static ssize_t
2922lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2923 char *buf)
2924{
2925 struct Scsi_Host *shost = class_to_shost(dev);
2926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2927 struct lpfc_hba *phba = vport->phba;
2928 int index = 0;
2929 int i;
2930 char *bucket_type;
2931 unsigned long bucket_value;
2932
2933 switch (phba->bucket_type) {
2934 case LPFC_LINEAR_BUCKET:
2935 bucket_type = "linear";
2936 break;
2937 case LPFC_POWER2_BUCKET:
2938 bucket_type = "power2";
2939 break;
2940 default:
2941 bucket_type = "No Bucket";
2942 break;
2943 }
2944
2945 sprintf(&buf[index], "Statistical Data enabled :%d, "
2946 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2947 " Bucket step :%d\nLatency Ranges :",
2948 vport->stat_data_enabled, vport->stat_data_blocked,
2949 bucket_type, phba->bucket_base, phba->bucket_step);
2950 index = strlen(buf);
2951 if (phba->bucket_type != LPFC_NO_BUCKET) {
2952 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2953 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2954 bucket_value = phba->bucket_base +
2955 phba->bucket_step * i;
2956 else
2957 bucket_value = phba->bucket_base +
2958 (1 << i) * phba->bucket_step;
2959
2960 if (index + 10 > PAGE_SIZE)
2961 break;
2962 sprintf(&buf[index], "%08ld ", bucket_value);
2963 index = strlen(buf);
2964 }
2965 }
2966 sprintf(&buf[index], "\n");
2967 return strlen(buf);
2968}
2969
2970/*
2971 * Sysfs attribute to control the statistical data collection.
2972 */
2973static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2974 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2975
2976/*
2977 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2978 */
2979
2980/*
2981 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2982 * for each target.
2983 */
2984#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2985#define MAX_STAT_DATA_SIZE_PER_TARGET \
2986 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2987
2988
2989/**
James Smart3621a712009-04-06 18:47:14 -04002990 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002991 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002992 * @kobj: Pointer to the kernel object
2993 * @bin_attr: Attribute object
2994 * @buff: Buffer pointer
2995 * @off: File offset
2996 * @count: Buffer size
2997 *
2998 * This function is the read call back function for lpfc_drvr_stat_data
2999 * sysfs file. This function export the statistical data to user
3000 * applications.
3001 **/
3002static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003003sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3004 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003005 char *buf, loff_t off, size_t count)
3006{
3007 struct device *dev = container_of(kobj, struct device,
3008 kobj);
3009 struct Scsi_Host *shost = class_to_shost(dev);
3010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3011 struct lpfc_hba *phba = vport->phba;
3012 int i = 0, index = 0;
3013 unsigned long nport_index;
3014 struct lpfc_nodelist *ndlp = NULL;
3015 nport_index = (unsigned long)off /
3016 MAX_STAT_DATA_SIZE_PER_TARGET;
3017
3018 if (!vport->stat_data_enabled || vport->stat_data_blocked
3019 || (phba->bucket_type == LPFC_NO_BUCKET))
3020 return 0;
3021
3022 spin_lock_irq(shost->host_lock);
3023 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3024 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3025 continue;
3026
3027 if (nport_index > 0) {
3028 nport_index--;
3029 continue;
3030 }
3031
3032 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3033 > count)
3034 break;
3035
3036 if (!ndlp->lat_data)
3037 continue;
3038
3039 /* Print the WWN */
3040 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3041 ndlp->nlp_portname.u.wwn[0],
3042 ndlp->nlp_portname.u.wwn[1],
3043 ndlp->nlp_portname.u.wwn[2],
3044 ndlp->nlp_portname.u.wwn[3],
3045 ndlp->nlp_portname.u.wwn[4],
3046 ndlp->nlp_portname.u.wwn[5],
3047 ndlp->nlp_portname.u.wwn[6],
3048 ndlp->nlp_portname.u.wwn[7]);
3049
3050 index = strlen(buf);
3051
3052 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3053 sprintf(&buf[index], "%010u,",
3054 ndlp->lat_data[i].cmd_count);
3055 index = strlen(buf);
3056 }
3057 sprintf(&buf[index], "\n");
3058 index = strlen(buf);
3059 }
3060 spin_unlock_irq(shost->host_lock);
3061 return index;
3062}
3063
3064static struct bin_attribute sysfs_drvr_stat_data_attr = {
3065 .attr = {
3066 .name = "lpfc_drvr_stat_data",
3067 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003068 },
3069 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3070 .read = sysfs_drvr_stat_data_read,
3071 .write = NULL,
3072};
3073
dea31012005-04-17 16:05:31 -05003074/*
3075# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3076# connection.
James Smart76a95d72010-11-20 23:11:48 -05003077# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003078*/
James Smarte59058c2008-08-24 21:49:00 -04003079/**
James Smart3621a712009-04-06 18:47:14 -04003080 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003081 * @phba: lpfc_hba pointer.
3082 * @val: link speed value.
3083 *
3084 * Description:
3085 * If val is in a valid range then set the adapter's link speed field and
3086 * issue a lip; if the lip fails reset the link speed to the old value.
3087 *
3088 * Notes:
3089 * If the value is not in range log a kernel error message and return an error.
3090 *
3091 * Returns:
3092 * zero if val is in range and lip okay.
3093 * non-zero return value from lpfc_issue_lip()
3094 * -EINVAL val out of range
3095 **/
James Smarta257bf92009-04-06 18:48:10 -04003096static ssize_t
3097lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3098 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003099{
James Smarta257bf92009-04-06 18:48:10 -04003100 struct Scsi_Host *shost = class_to_shost(dev);
3101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3102 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003103 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003104 int nolip = 0;
3105 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003106 int err;
3107 uint32_t prev_val;
3108
James Smarta257bf92009-04-06 18:48:10 -04003109 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3110 nolip = 1;
3111 val_buf = &buf[strlen("nolip ")];
3112 }
3113
3114 if (!isdigit(val_buf[0]))
3115 return -EINVAL;
3116 if (sscanf(val_buf, "%i", &val) != 1)
3117 return -EINVAL;
3118
James Smart88a2cfb2011-07-22 18:36:33 -04003119 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3120 "3055 lpfc_link_speed changed from %d to %d %s\n",
3121 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3122
James Smart76a95d72010-11-20 23:11:48 -05003123 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3124 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3125 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3126 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3127 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3128 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3130 "2879 lpfc_link_speed attribute cannot be set "
3131 "to %d. Speed is not supported by this port.\n",
3132 val);
James Smart83108bd2008-01-11 01:53:09 -05003133 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003134 }
3135 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3136 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003137 prev_val = phba->cfg_link_speed;
3138 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003139 if (nolip)
3140 return strlen(buf);
3141
James Smart83108bd2008-01-11 01:53:09 -05003142 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003143 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003144 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003145 return -EINVAL;
3146 } else
3147 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003148 }
James Smart83108bd2008-01-11 01:53:09 -05003149 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003150 "0469 lpfc_link_speed attribute cannot be set to %d, "
3151 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003152 return -EINVAL;
3153}
3154
3155static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003156module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003157MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3158lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003159
3160/**
James Smart3621a712009-04-06 18:47:14 -04003161 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003162 * @phba: lpfc_hba pointer.
3163 * @val: link speed value.
3164 *
3165 * Description:
3166 * If val is in a valid range then set the adapter's link speed field.
3167 *
3168 * Notes:
3169 * If the value is not in range log a kernel error message, clear the link
3170 * speed and return an error.
3171 *
3172 * Returns:
3173 * zero if val saved.
3174 * -EINVAL val out of range
3175 **/
James Smart83108bd2008-01-11 01:53:09 -05003176static int
3177lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3178{
James Smart76a95d72010-11-20 23:11:48 -05003179 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3180 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003181 phba->cfg_link_speed = val;
3182 return 0;
3183 }
3184 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003185 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003186 "be set to %d, allowed values are "
3187 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003188 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003189 return -EINVAL;
3190}
3191
Tony Jonesee959b02008-02-22 00:13:36 +01003192static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003193 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003194
3195/*
James Smart0d878412009-10-02 15:16:56 -04003196# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3197# 0 = aer disabled or not supported
3198# 1 = aer supported and enabled (default)
3199# Value range is [0,1]. Default value is 1.
3200*/
3201
3202/**
3203 * lpfc_aer_support_store - Set the adapter for aer support
3204 *
3205 * @dev: class device that is converted into a Scsi_host.
3206 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003207 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003208 * @count: unused variable.
3209 *
3210 * Description:
3211 * If the val is 1 and currently the device's AER capability was not
3212 * enabled, invoke the kernel's enable AER helper routine, trying to
3213 * enable the device's AER capability. If the helper routine enabling
3214 * AER returns success, update the device's cfg_aer_support flag to
3215 * indicate AER is supported by the device; otherwise, if the device
3216 * AER capability is already enabled to support AER, then do nothing.
3217 *
3218 * If the val is 0 and currently the device's AER support was enabled,
3219 * invoke the kernel's disable AER helper routine. After that, update
3220 * the device's cfg_aer_support flag to indicate AER is not supported
3221 * by the device; otherwise, if the device AER capability is already
3222 * disabled from supporting AER, then do nothing.
3223 *
3224 * Returns:
3225 * length of the buf on success if val is in range the intended mode
3226 * is supported.
3227 * -EINVAL if val out of range or intended mode is not supported.
3228 **/
3229static ssize_t
3230lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3231 const char *buf, size_t count)
3232{
3233 struct Scsi_Host *shost = class_to_shost(dev);
3234 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3235 struct lpfc_hba *phba = vport->phba;
3236 int val = 0, rc = -EINVAL;
3237
3238 if (!isdigit(buf[0]))
3239 return -EINVAL;
3240 if (sscanf(buf, "%i", &val) != 1)
3241 return -EINVAL;
3242
3243 switch (val) {
3244 case 0:
3245 if (phba->hba_flag & HBA_AER_ENABLED) {
3246 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3247 if (!rc) {
3248 spin_lock_irq(&phba->hbalock);
3249 phba->hba_flag &= ~HBA_AER_ENABLED;
3250 spin_unlock_irq(&phba->hbalock);
3251 phba->cfg_aer_support = 0;
3252 rc = strlen(buf);
3253 } else
James Smart891478a2009-11-18 15:40:23 -05003254 rc = -EPERM;
3255 } else {
James Smart0d878412009-10-02 15:16:56 -04003256 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003257 rc = strlen(buf);
3258 }
James Smart0d878412009-10-02 15:16:56 -04003259 break;
3260 case 1:
3261 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3262 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3263 if (!rc) {
3264 spin_lock_irq(&phba->hbalock);
3265 phba->hba_flag |= HBA_AER_ENABLED;
3266 spin_unlock_irq(&phba->hbalock);
3267 phba->cfg_aer_support = 1;
3268 rc = strlen(buf);
3269 } else
James Smart891478a2009-11-18 15:40:23 -05003270 rc = -EPERM;
3271 } else {
James Smart0d878412009-10-02 15:16:56 -04003272 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003273 rc = strlen(buf);
3274 }
James Smart0d878412009-10-02 15:16:56 -04003275 break;
3276 default:
3277 rc = -EINVAL;
3278 break;
3279 }
3280 return rc;
3281}
3282
3283static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003284module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003285MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3286lpfc_param_show(aer_support)
3287
3288/**
3289 * lpfc_aer_support_init - Set the initial adapters aer support flag
3290 * @phba: lpfc_hba pointer.
James Smart912e3ac2011-05-24 11:42:11 -04003291 * @val: enable aer or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003292 *
3293 * Description:
3294 * If val is in a valid range [0,1], then set the adapter's initial
3295 * cfg_aer_support field. It will be up to the driver's probe_one
3296 * routine to determine whether the device's AER support can be set
3297 * or not.
3298 *
3299 * Notes:
3300 * If the value is not in range log a kernel error message, and
3301 * choose the default value of setting AER support and return.
3302 *
3303 * Returns:
3304 * zero if val saved.
3305 * -EINVAL val out of range
3306 **/
3307static int
3308lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3309{
3310 if (val == 0 || val == 1) {
3311 phba->cfg_aer_support = val;
3312 return 0;
3313 }
3314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3315 "2712 lpfc_aer_support attribute value %d out "
3316 "of range, allowed values are 0|1, setting it "
3317 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003318 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003319 phba->cfg_aer_support = 1;
3320 return -EINVAL;
3321}
3322
3323static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3324 lpfc_aer_support_show, lpfc_aer_support_store);
3325
3326/**
3327 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3328 * @dev: class device that is converted into a Scsi_host.
3329 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003330 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04003331 * @count: unused variable.
3332 *
3333 * Description:
3334 * If the @buf contains 1 and the device currently has the AER support
3335 * enabled, then invokes the kernel AER helper routine
3336 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3337 * error status register.
3338 *
3339 * Notes:
3340 *
3341 * Returns:
3342 * -EINVAL if the buf does not contain the 1 or the device is not currently
3343 * enabled with the AER support.
3344 **/
3345static ssize_t
3346lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3347 const char *buf, size_t count)
3348{
3349 struct Scsi_Host *shost = class_to_shost(dev);
3350 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3351 struct lpfc_hba *phba = vport->phba;
3352 int val, rc = -1;
3353
3354 if (!isdigit(buf[0]))
3355 return -EINVAL;
3356 if (sscanf(buf, "%i", &val) != 1)
3357 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003358 if (val != 1)
3359 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003360
James Smart891478a2009-11-18 15:40:23 -05003361 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003362 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3363
3364 if (rc == 0)
3365 return strlen(buf);
3366 else
James Smart891478a2009-11-18 15:40:23 -05003367 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003368}
3369
3370static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3371 lpfc_aer_cleanup_state);
3372
James Smart912e3ac2011-05-24 11:42:11 -04003373/**
3374 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3375 *
3376 * @dev: class device that is converted into a Scsi_host.
3377 * @attr: device attribute, not used.
3378 * @buf: containing the string the number of vfs to be enabled.
3379 * @count: unused variable.
3380 *
3381 * Description:
3382 * When this api is called either through user sysfs, the driver shall
3383 * try to enable or disable SR-IOV virtual functions according to the
3384 * following:
3385 *
3386 * If zero virtual function has been enabled to the physical function,
3387 * the driver shall invoke the pci enable virtual function api trying
3388 * to enable the virtual functions. If the nr_vfn provided is greater
3389 * than the maximum supported, the maximum virtual function number will
3390 * be used for invoking the api; otherwise, the nr_vfn provided shall
3391 * be used for invoking the api. If the api call returned success, the
3392 * actual number of virtual functions enabled will be set to the driver
3393 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3394 * cfg_sriov_nr_virtfn remains zero.
3395 *
3396 * If none-zero virtual functions have already been enabled to the
3397 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3398 * -EINVAL will be returned and the driver does nothing;
3399 *
3400 * If the nr_vfn provided is zero and none-zero virtual functions have
3401 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3402 * disabling virtual function api shall be invoded to disable all the
3403 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3404 * zero. Otherwise, if zero virtual function has been enabled, do
3405 * nothing.
3406 *
3407 * Returns:
3408 * length of the buf on success if val is in range the intended mode
3409 * is supported.
3410 * -EINVAL if val out of range or intended mode is not supported.
3411 **/
3412static ssize_t
3413lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3414 const char *buf, size_t count)
3415{
3416 struct Scsi_Host *shost = class_to_shost(dev);
3417 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3418 struct lpfc_hba *phba = vport->phba;
3419 struct pci_dev *pdev = phba->pcidev;
3420 int val = 0, rc = -EINVAL;
3421
3422 /* Sanity check on user data */
3423 if (!isdigit(buf[0]))
3424 return -EINVAL;
3425 if (sscanf(buf, "%i", &val) != 1)
3426 return -EINVAL;
3427 if (val < 0)
3428 return -EINVAL;
3429
3430 /* Request disabling virtual functions */
3431 if (val == 0) {
3432 if (phba->cfg_sriov_nr_virtfn > 0) {
3433 pci_disable_sriov(pdev);
3434 phba->cfg_sriov_nr_virtfn = 0;
3435 }
3436 return strlen(buf);
3437 }
3438
3439 /* Request enabling virtual functions */
3440 if (phba->cfg_sriov_nr_virtfn > 0) {
3441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3442 "3018 There are %d virtual functions "
3443 "enabled on physical function.\n",
3444 phba->cfg_sriov_nr_virtfn);
3445 return -EEXIST;
3446 }
3447
3448 if (val <= LPFC_MAX_VFN_PER_PFN)
3449 phba->cfg_sriov_nr_virtfn = val;
3450 else {
3451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3452 "3019 Enabling %d virtual functions is not "
3453 "allowed.\n", val);
3454 return -EINVAL;
3455 }
3456
3457 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3458 if (rc) {
3459 phba->cfg_sriov_nr_virtfn = 0;
3460 rc = -EPERM;
3461 } else
3462 rc = strlen(buf);
3463
3464 return rc;
3465}
3466
3467static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3468module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3469MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3470lpfc_param_show(sriov_nr_virtfn)
3471
3472/**
3473 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3474 * @phba: lpfc_hba pointer.
3475 * @val: link speed value.
3476 *
3477 * Description:
3478 * If val is in a valid range [0,255], then set the adapter's initial
3479 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3480 * number shall be used instead. It will be up to the driver's probe_one
3481 * routine to determine whether the device's SR-IOV is supported or not.
3482 *
3483 * Returns:
3484 * zero if val saved.
3485 * -EINVAL val out of range
3486 **/
3487static int
3488lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3489{
3490 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3491 phba->cfg_sriov_nr_virtfn = val;
3492 return 0;
3493 }
3494
3495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3496 "3017 Enabling %d virtual functions is not "
3497 "allowed.\n", val);
3498 return -EINVAL;
3499}
3500static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3501 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3502
James Smart0d878412009-10-02 15:16:56 -04003503/*
dea31012005-04-17 16:05:31 -05003504# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3505# Value range is [2,3]. Default value is 3.
3506*/
James Smart3de2a652007-08-02 11:09:59 -04003507LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3508 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003509
3510/*
3511# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3512# is [0,1]. Default value is 0.
3513*/
James Smart3de2a652007-08-02 11:09:59 -04003514LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3515 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003516
3517/*
James Smart977b5a02008-09-07 11:52:04 -04003518# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3519# depth. Default value is 0. When the value of this parameter is zero the
3520# SCSI command completion time is not used for controlling I/O queue depth. When
3521# the parameter is set to a non-zero value, the I/O queue depth is controlled
3522# to limit the I/O completion time to the parameter value.
3523# The value is set in milliseconds.
3524*/
3525static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003526module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003527MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3528 "Use command completion time to control queue depth");
3529lpfc_vport_param_show(max_scsicmpl_time);
3530lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3531static int
3532lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3533{
3534 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3535 struct lpfc_nodelist *ndlp, *next_ndlp;
3536
3537 if (val == vport->cfg_max_scsicmpl_time)
3538 return 0;
3539 if ((val < 0) || (val > 60000))
3540 return -EINVAL;
3541 vport->cfg_max_scsicmpl_time = val;
3542
3543 spin_lock_irq(shost->host_lock);
3544 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3545 if (!NLP_CHK_NODE_ACT(ndlp))
3546 continue;
3547 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3548 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003549 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003550 }
3551 spin_unlock_irq(shost->host_lock);
3552 return 0;
3553}
3554lpfc_vport_param_store(max_scsicmpl_time);
3555static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3556 lpfc_max_scsicmpl_time_show,
3557 lpfc_max_scsicmpl_time_store);
3558
3559/*
dea31012005-04-17 16:05:31 -05003560# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3561# range is [0,1]. Default value is 0.
3562*/
3563LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3564
3565/*
3566# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3567# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003568# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003569# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3570# cr_delay is set to 0.
3571*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003572LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003573 "interrupt response is generated");
3574
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003575LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003576 "interrupt response is generated");
3577
3578/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003579# lpfc_multi_ring_support: Determines how many rings to spread available
3580# cmd/rsp IOCB entries across.
3581# Value range is [1,2]. Default value is 1.
3582*/
3583LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3584 "SLI rings to spread IOCB entries across");
3585
3586/*
James Smarta4bc3372006-12-02 13:34:16 -05003587# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3588# identifies what rctl value to configure the additional ring for.
3589# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3590*/
James Smart6a9c52c2009-10-02 15:16:51 -04003591LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003592 255, "Identifies RCTL for additional ring configuration");
3593
3594/*
3595# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3596# identifies what type value to configure the additional ring for.
3597# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3598*/
James Smart6a9c52c2009-10-02 15:16:51 -04003599LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003600 255, "Identifies TYPE for additional ring configuration");
3601
3602/*
dea31012005-04-17 16:05:31 -05003603# lpfc_fdmi_on: controls FDMI support.
3604# 0 = no FDMI support
3605# 1 = support FDMI without attribute of hostname
3606# 2 = support FDMI with attribute of hostname
3607# Value range [0,2]. Default value is 0.
3608*/
James Smart3de2a652007-08-02 11:09:59 -04003609LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003610
3611/*
3612# Specifies the maximum number of ELS cmds we can have outstanding (for
3613# discovery). Value range is [1,64]. Default value = 32.
3614*/
James Smart3de2a652007-08-02 11:09:59 -04003615LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003616 "during discovery");
3617
3618/*
James Smart65a29c12006-07-06 15:50:50 -04003619# lpfc_max_luns: maximum allowed LUN.
3620# Value range is [0,65535]. Default value is 255.
3621# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003622*/
James Smart3de2a652007-08-02 11:09:59 -04003623LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003624
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003625/*
3626# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3627# Value range is [1,255], default value is 10.
3628*/
3629LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3630 "Milliseconds driver will wait between polling FCP ring");
3631
James Smart4ff43242006-12-02 13:34:56 -05003632/*
3633# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3634# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003635# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003636# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003637# 2 = MSI-X enabled (default)
3638# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003639*/
George Kadianakis8605c462010-01-17 21:19:31 +02003640LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003641 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003642
James Smart13815c82008-01-11 01:52:48 -05003643/*
James Smartda0436e2009-05-22 14:51:39 -04003644# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3645#
3646# Value range is [636,651042]. Default value is 10000.
3647*/
3648LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3649 "Set the maximum number of fast-path FCP interrupts per second");
3650
3651/*
3652# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3653#
3654# Value range is [1,31]. Default value is 4.
3655*/
3656LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3657 "Set the number of fast-path FCP work queues, if possible");
3658
3659/*
3660# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3661#
3662# Value range is [1,7]. Default value is 1.
3663*/
3664LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3665 "Set the number of fast-path FCP event queues, if possible");
3666
3667/*
James Smart13815c82008-01-11 01:52:48 -05003668# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3669# 0 = HBA resets disabled
3670# 1 = HBA resets enabled (default)
3671# Value range is [0,1]. Default value is 1.
3672*/
3673LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003674
James Smart13815c82008-01-11 01:52:48 -05003675/*
James Smarteb7a3392010-11-20 23:12:02 -05003676# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003677# 0 = HBA Heartbeat disabled
3678# 1 = HBA Heartbeat enabled (default)
3679# Value range is [0,1]. Default value is 1.
3680*/
James Smarteb7a3392010-11-20 23:12:02 -05003681LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003682
James Smart83108bd2008-01-11 01:53:09 -05003683/*
James Smart81301a92008-12-04 22:39:46 -05003684# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3685# 0 = BlockGuard disabled (default)
3686# 1 = BlockGuard enabled
3687# Value range is [0,1]. Default value is 0.
3688*/
3689LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3690
James Smart6fb120a2009-05-22 14:52:59 -04003691/*
James Smart81301a92008-12-04 22:39:46 -05003692# lpfc_prot_mask: i
3693# - Bit mask of host protection capabilities used to register with the
3694# SCSI mid-layer
3695# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3696# - Allows you to ultimately specify which profiles to use
3697# - Default will result in registering capabilities for all profiles.
3698#
3699*/
James Smart7c56b9f2011-07-22 18:36:25 -04003700unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3701 SHOST_DIX_TYPE0_PROTECTION |
3702 SHOST_DIX_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003703
James Smartab56dc22011-02-16 12:39:57 -05003704module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003705MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3706
3707/*
3708# lpfc_prot_guard: i
3709# - Bit mask of protection guard types to register with the SCSI mid-layer
3710# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3711# - Allows you to ultimately specify which profiles to use
3712# - Default will result in registering capabilities for all guard types
3713#
3714*/
3715unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003716module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003717MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3718
James Smart92494142011-02-16 12:39:44 -05003719/*
3720 * Delay initial NPort discovery when Clean Address bit is cleared in
3721 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3722 * This parameter can have value 0 or 1.
3723 * When this parameter is set to 0, no delay is added to the initial
3724 * discovery.
3725 * When this parameter is set to non-zero value, initial Nport discovery is
3726 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3727 * accept and FCID/Fabric name/Fabric portname is changed.
3728 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3729 * when Clean Address bit is cleared in FLOGI/FDISC
3730 * accept and FCID/Fabric name/Fabric portname is changed.
3731 * Default value is 0.
3732 */
3733int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003734module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003735MODULE_PARM_DESC(lpfc_delay_discovery,
3736 "Delay NPort discovery when Clean Address bit is cleared. "
3737 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003738
3739/*
James Smart3621a712009-04-06 18:47:14 -04003740 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003741 * This value can be set to values between 64 and 256. The default value is
3742 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3743 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3744 */
3745LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3746 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3747
James Smart81301a92008-12-04 22:39:46 -05003748LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3749 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3750 "Max Protection Scatter Gather Segment Count");
3751
Tony Jonesee959b02008-02-22 00:13:36 +01003752struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003753 &dev_attr_bg_info,
3754 &dev_attr_bg_guard_err,
3755 &dev_attr_bg_apptag_err,
3756 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003757 &dev_attr_info,
3758 &dev_attr_serialnum,
3759 &dev_attr_modeldesc,
3760 &dev_attr_modelname,
3761 &dev_attr_programtype,
3762 &dev_attr_portnum,
3763 &dev_attr_fwrev,
3764 &dev_attr_hdw,
3765 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003766 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003767 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003768 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003769 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003770 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003771 &dev_attr_lpfc_temp_sensor,
3772 &dev_attr_lpfc_log_verbose,
3773 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003774 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003775 &dev_attr_lpfc_hba_queue_depth,
3776 &dev_attr_lpfc_peer_port_login,
3777 &dev_attr_lpfc_nodev_tmo,
3778 &dev_attr_lpfc_devloss_tmo,
3779 &dev_attr_lpfc_fcp_class,
3780 &dev_attr_lpfc_use_adisc,
3781 &dev_attr_lpfc_ack0,
3782 &dev_attr_lpfc_topology,
3783 &dev_attr_lpfc_scan_down,
3784 &dev_attr_lpfc_link_speed,
3785 &dev_attr_lpfc_cr_delay,
3786 &dev_attr_lpfc_cr_count,
3787 &dev_attr_lpfc_multi_ring_support,
3788 &dev_attr_lpfc_multi_ring_rctl,
3789 &dev_attr_lpfc_multi_ring_type,
3790 &dev_attr_lpfc_fdmi_on,
3791 &dev_attr_lpfc_max_luns,
3792 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04003793 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05003794 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003795 &dev_attr_nport_evt_cnt,
3796 &dev_attr_board_mode,
3797 &dev_attr_max_vpi,
3798 &dev_attr_used_vpi,
3799 &dev_attr_max_rpi,
3800 &dev_attr_used_rpi,
3801 &dev_attr_max_xri,
3802 &dev_attr_used_xri,
3803 &dev_attr_npiv_info,
3804 &dev_attr_issue_reset,
3805 &dev_attr_lpfc_poll,
3806 &dev_attr_lpfc_poll_tmo,
3807 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003808 &dev_attr_lpfc_fcp_imax,
3809 &dev_attr_lpfc_fcp_wq_count,
3810 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003811 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003812 &dev_attr_lpfc_soft_wwnn,
3813 &dev_attr_lpfc_soft_wwpn,
3814 &dev_attr_lpfc_soft_wwn_enable,
3815 &dev_attr_lpfc_enable_hba_reset,
3816 &dev_attr_lpfc_enable_hba_heartbeat,
3817 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003818 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003819 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003820 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003821 &dev_attr_lpfc_aer_support,
3822 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04003823 &dev_attr_lpfc_sriov_nr_virtfn,
James Smart84d1b002010-02-12 14:42:33 -05003824 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003825 &dev_attr_lpfc_iocb_cnt,
3826 &dev_attr_iocb_hw,
3827 &dev_attr_txq_hw,
3828 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003829 &dev_attr_lpfc_fips_level,
3830 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003831 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04003832 &dev_attr_lpfc_sriov_hw_max_virtfn,
dea31012005-04-17 16:05:31 -05003833 NULL,
3834};
3835
Tony Jonesee959b02008-02-22 00:13:36 +01003836struct device_attribute *lpfc_vport_attrs[] = {
3837 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003838 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003839 &dev_attr_num_discovered_ports,
3840 &dev_attr_lpfc_drvr_version,
3841 &dev_attr_lpfc_log_verbose,
3842 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003843 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003844 &dev_attr_lpfc_nodev_tmo,
3845 &dev_attr_lpfc_devloss_tmo,
3846 &dev_attr_lpfc_hba_queue_depth,
3847 &dev_attr_lpfc_peer_port_login,
3848 &dev_attr_lpfc_restrict_login,
3849 &dev_attr_lpfc_fcp_class,
3850 &dev_attr_lpfc_use_adisc,
3851 &dev_attr_lpfc_fdmi_on,
3852 &dev_attr_lpfc_max_luns,
3853 &dev_attr_nport_evt_cnt,
3854 &dev_attr_npiv_info,
3855 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003856 &dev_attr_lpfc_max_scsicmpl_time,
3857 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003858 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003859 &dev_attr_lpfc_fips_level,
3860 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003861 NULL,
3862};
3863
James Smarte59058c2008-08-24 21:49:00 -04003864/**
James Smart3621a712009-04-06 18:47:14 -04003865 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003866 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003867 * @kobj: kernel kobject that contains the kernel class device.
3868 * @bin_attr: kernel attributes passed to us.
3869 * @buf: contains the data to be written to the adapter IOREG space.
3870 * @off: offset into buffer to beginning of data.
3871 * @count: bytes to transfer.
3872 *
3873 * Description:
3874 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3875 * Uses the adapter io control registers to send buf contents to the adapter.
3876 *
3877 * Returns:
3878 * -ERANGE off and count combo out of range
3879 * -EINVAL off, count or buff address invalid
3880 * -EPERM adapter is offline
3881 * value of count, buf contents written
3882 **/
dea31012005-04-17 16:05:31 -05003883static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003884sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3885 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003886 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003887{
3888 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003889 struct device *dev = container_of(kobj, struct device, kobj);
3890 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003891 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3892 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003893
James Smartf1126682009-06-10 17:22:44 -04003894 if (phba->sli_rev >= LPFC_SLI_REV4)
3895 return -EPERM;
3896
dea31012005-04-17 16:05:31 -05003897 if ((off + count) > FF_REG_AREA_SIZE)
3898 return -ERANGE;
3899
James Smartf7a919b2011-08-21 21:49:16 -04003900 if (count <= LPFC_REG_WRITE_KEY_SIZE)
3901 return 0;
dea31012005-04-17 16:05:31 -05003902
3903 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3904 return -EINVAL;
3905
James Smartf7a919b2011-08-21 21:49:16 -04003906 /* This is to protect HBA registers from accidental writes. */
3907 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3908 return -EINVAL;
3909
3910 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003911 return -EPERM;
dea31012005-04-17 16:05:31 -05003912
James Smart2e0fef82007-06-17 19:56:36 -05003913 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04003914 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
3915 buf_off += sizeof(uint32_t))
3916 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05003917 phba->ctrl_regs_memmap_p + off + buf_off);
3918
James Smart2e0fef82007-06-17 19:56:36 -05003919 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003920
3921 return count;
3922}
3923
James Smarte59058c2008-08-24 21:49:00 -04003924/**
James Smart3621a712009-04-06 18:47:14 -04003925 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003926 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003927 * @kobj: kernel kobject that contains the kernel class device.
3928 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003929 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003930 * @off: offset into buffer to beginning of data.
3931 * @count: bytes to transfer.
3932 *
3933 * Description:
3934 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3935 * Uses the adapter io control registers to read data into buf.
3936 *
3937 * Returns:
3938 * -ERANGE off and count combo out of range
3939 * -EINVAL off, count or buff address invalid
3940 * value of count, buf contents read
3941 **/
dea31012005-04-17 16:05:31 -05003942static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003943sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3944 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003945 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003946{
3947 size_t buf_off;
3948 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003949 struct device *dev = container_of(kobj, struct device, kobj);
3950 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003951 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3952 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003953
James Smartf1126682009-06-10 17:22:44 -04003954 if (phba->sli_rev >= LPFC_SLI_REV4)
3955 return -EPERM;
3956
dea31012005-04-17 16:05:31 -05003957 if (off > FF_REG_AREA_SIZE)
3958 return -ERANGE;
3959
3960 if ((off + count) > FF_REG_AREA_SIZE)
3961 count = FF_REG_AREA_SIZE - off;
3962
3963 if (count == 0) return 0;
3964
3965 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3966 return -EINVAL;
3967
James Smart2e0fef82007-06-17 19:56:36 -05003968 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003969
3970 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3971 tmp_ptr = (uint32_t *)(buf + buf_off);
3972 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3973 }
3974
James Smart2e0fef82007-06-17 19:56:36 -05003975 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003976
3977 return count;
3978}
3979
3980static struct bin_attribute sysfs_ctlreg_attr = {
3981 .attr = {
3982 .name = "ctlreg",
3983 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003984 },
3985 .size = 256,
3986 .read = sysfs_ctlreg_read,
3987 .write = sysfs_ctlreg_write,
3988};
3989
James Smarte59058c2008-08-24 21:49:00 -04003990/**
James Smart3621a712009-04-06 18:47:14 -04003991 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003992 * @phba: lpfc_hba pointer
3993 **/
dea31012005-04-17 16:05:31 -05003994static void
James Smart2e0fef82007-06-17 19:56:36 -05003995sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003996{
3997 phba->sysfs_mbox.state = SMBOX_IDLE;
3998 phba->sysfs_mbox.offset = 0;
3999
4000 if (phba->sysfs_mbox.mbox) {
4001 mempool_free(phba->sysfs_mbox.mbox,
4002 phba->mbox_mem_pool);
4003 phba->sysfs_mbox.mbox = NULL;
4004 }
4005}
4006
James Smarte59058c2008-08-24 21:49:00 -04004007/**
James Smart3621a712009-04-06 18:47:14 -04004008 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004009 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004010 * @kobj: kernel kobject that contains the kernel class device.
4011 * @bin_attr: kernel attributes passed to us.
4012 * @buf: contains the data to be written to sysfs mbox.
4013 * @off: offset into buffer to beginning of data.
4014 * @count: bytes to transfer.
4015 *
4016 * Description:
4017 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4018 * Uses the sysfs mbox to send buf contents to the adapter.
4019 *
4020 * Returns:
4021 * -ERANGE off and count combo out of range
4022 * -EINVAL off, count or buff address invalid
4023 * zero if count is zero
4024 * -EPERM adapter is offline
4025 * -ENOMEM failed to allocate memory for the mail box
4026 * -EAGAIN offset, state or mbox is NULL
4027 * count number of bytes transferred
4028 **/
dea31012005-04-17 16:05:31 -05004029static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004030sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4031 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004032 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004033{
Tony Jonesee959b02008-02-22 00:13:36 +01004034 struct device *dev = container_of(kobj, struct device, kobj);
4035 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004036 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4037 struct lpfc_hba *phba = vport->phba;
4038 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05004039
4040 if ((count + off) > MAILBOX_CMD_SIZE)
4041 return -ERANGE;
4042
4043 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4044 return -EINVAL;
4045
4046 if (count == 0)
4047 return 0;
4048
4049 if (off == 0) {
4050 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4051 if (!mbox)
4052 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05004053 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004054 }
4055
James Smart2e0fef82007-06-17 19:56:36 -05004056 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004057
4058 if (off == 0) {
4059 if (phba->sysfs_mbox.mbox)
4060 mempool_free(mbox, phba->mbox_mem_pool);
4061 else
4062 phba->sysfs_mbox.mbox = mbox;
4063 phba->sysfs_mbox.state = SMBOX_WRITING;
4064 } else {
4065 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4066 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05004067 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05004068 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004069 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004070 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004071 }
4072 }
4073
James Smart04c68492009-05-22 14:52:52 -04004074 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05004075 buf, count);
4076
4077 phba->sysfs_mbox.offset = off + count;
4078
James Smart2e0fef82007-06-17 19:56:36 -05004079 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004080
4081 return count;
4082}
4083
James Smarte59058c2008-08-24 21:49:00 -04004084/**
James Smart3621a712009-04-06 18:47:14 -04004085 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07004086 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04004087 * @kobj: kernel kobject that contains the kernel class device.
4088 * @bin_attr: kernel attributes passed to us.
4089 * @buf: contains the data to be read from sysfs mbox.
4090 * @off: offset into buffer to beginning of data.
4091 * @count: bytes to transfer.
4092 *
4093 * Description:
4094 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4095 * Uses the sysfs mbox to receive data from to the adapter.
4096 *
4097 * Returns:
4098 * -ERANGE off greater than mailbox command size
4099 * -EINVAL off, count or buff address invalid
4100 * zero if off and count are zero
4101 * -EACCES adapter over temp
4102 * -EPERM garbage can value to catch a multitude of errors
4103 * -EAGAIN management IO not permitted, state or off error
4104 * -ETIME mailbox timeout
4105 * -ENODEV mailbox error
4106 * count number of bytes transferred
4107 **/
dea31012005-04-17 16:05:31 -05004108static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004109sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4110 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08004111 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05004112{
Tony Jonesee959b02008-02-22 00:13:36 +01004113 struct device *dev = container_of(kobj, struct device, kobj);
4114 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05004115 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4116 struct lpfc_hba *phba = vport->phba;
James Smarta183a152011-10-10 21:32:43 -04004117 LPFC_MBOXQ_t *mboxq;
James Smart04c68492009-05-22 14:52:52 -04004118 MAILBOX_t *pmb;
James Smarta183a152011-10-10 21:32:43 -04004119 uint32_t mbox_tmo;
4120 int rc;
dea31012005-04-17 16:05:31 -05004121
James Smart1dcb58e2007-04-25 09:51:30 -04004122 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004123 return -ERANGE;
4124
James Smart1dcb58e2007-04-25 09:51:30 -04004125 if ((count + off) > MAILBOX_CMD_SIZE)
4126 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05004127
4128 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4129 return -EINVAL;
4130
4131 if (off && count == 0)
4132 return 0;
4133
James Smart2e0fef82007-06-17 19:56:36 -05004134 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004135
James Smart7af67052007-10-27 13:38:11 -04004136 if (phba->over_temp_state == HBA_OVER_TEMP) {
4137 sysfs_mbox_idle(phba);
4138 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05004139 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04004140 }
4141
dea31012005-04-17 16:05:31 -05004142 if (off == 0 &&
4143 phba->sysfs_mbox.state == SMBOX_WRITING &&
4144 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smarta183a152011-10-10 21:32:43 -04004145 mboxq = (LPFC_MBOXQ_t *)&phba->sysfs_mbox.mbox;
4146 pmb = &mboxq->u.mb;
James Smart04c68492009-05-22 14:52:52 -04004147 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05004148 /* Offline only */
dea31012005-04-17 16:05:31 -05004149 case MBX_INIT_LINK:
4150 case MBX_DOWN_LINK:
4151 case MBX_CONFIG_LINK:
4152 case MBX_CONFIG_RING:
4153 case MBX_RESET_RING:
4154 case MBX_UNREG_LOGIN:
4155 case MBX_CLEAR_LA:
4156 case MBX_DUMP_CONTEXT:
4157 case MBX_RUN_DIAGS:
4158 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05004159 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05004160 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05004161 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05004162 printk(KERN_WARNING "mbox_read:Command 0x%x "
4163 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04004164 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004165 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004166 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004167 return -EPERM;
4168 }
James Smarta8adb832007-10-27 13:37:53 -04004169 case MBX_WRITE_NV:
4170 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05004171 case MBX_LOAD_SM:
4172 case MBX_READ_NV:
4173 case MBX_READ_CONFIG:
4174 case MBX_READ_RCONFIG:
4175 case MBX_READ_STATUS:
4176 case MBX_READ_XRI:
4177 case MBX_READ_REV:
4178 case MBX_READ_LNK_STAT:
4179 case MBX_DUMP_MEMORY:
4180 case MBX_DOWN_LOAD:
4181 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004182 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05004183 case MBX_LOAD_AREA:
4184 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05004185 case MBX_BEACON:
4186 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05004187 case MBX_SET_VARIABLE:
4188 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04004189 case MBX_PORT_CAPABILITIES:
4190 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05004191 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04004192 case MBX_SECURITY_MGMT:
4193 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04004194 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4195 printk(KERN_WARNING "mbox_read:Command 0x%x "
4196 "is not permitted\n", pmb->mbxCommand);
4197 sysfs_mbox_idle(phba);
4198 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04004199 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04004200 }
James Smartdcf2a4e2010-09-29 11:18:53 -04004201 break;
dea31012005-04-17 16:05:31 -05004202 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05004203 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05004204 case MBX_REG_LOGIN:
4205 case MBX_REG_LOGIN64:
4206 case MBX_CONFIG_PORT:
4207 case MBX_RUN_BIU_DIAG:
4208 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004209 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004210 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004211 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004212 return -EPERM;
4213 default:
4214 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004215 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05004216 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004217 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004218 return -EPERM;
4219 }
4220
James Smart09372822008-01-11 01:52:54 -05004221 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05004222 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05004223 */
James Smartd7c255b2008-08-24 21:50:00 -04004224 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04004225 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4226 pmb->mbxCommand != MBX_RESTART &&
4227 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4228 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04004229 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4230 "1259 mbox: Issued mailbox cmd "
4231 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04004232 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05004233
James Smart92d7f7b2007-06-17 19:56:38 -05004234 phba->sysfs_mbox.mbox->vport = vport;
4235
James Smart58da1ff2008-04-07 10:15:56 -04004236 /* Don't allow mailbox commands to be sent when blocked
4237 * or when in the middle of discovery
4238 */
James Smart495a7142008-06-14 22:52:59 -04004239 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04004240 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004241 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04004242 return -EAGAIN;
4243 }
4244
James Smart2e0fef82007-06-17 19:56:36 -05004245 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004246 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05004247
James Smart2e0fef82007-06-17 19:56:36 -05004248 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004249 rc = lpfc_sli_issue_mbox (phba,
4250 phba->sysfs_mbox.mbox,
4251 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05004252 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004253
4254 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004255 spin_unlock_irq(&phba->hbalock);
James Smarta183a152011-10-10 21:32:43 -04004256 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
4257 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
James Smart2e0fef82007-06-17 19:56:36 -05004258 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004259 }
4260
4261 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04004262 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04004263 phba->sysfs_mbox.mbox = NULL;
4264 }
dea31012005-04-17 16:05:31 -05004265 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004266 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004267 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05004268 }
4269 phba->sysfs_mbox.state = SMBOX_READING;
4270 }
4271 else if (phba->sysfs_mbox.offset != off ||
4272 phba->sysfs_mbox.state != SMBOX_READING) {
4273 printk(KERN_WARNING "mbox_read: Bad State\n");
4274 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004275 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004276 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004277 }
4278
James Smart04c68492009-05-22 14:52:52 -04004279 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05004280
4281 phba->sysfs_mbox.offset = off + count;
4282
James Smart1dcb58e2007-04-25 09:51:30 -04004283 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004284 sysfs_mbox_idle(phba);
4285
James Smart2e0fef82007-06-17 19:56:36 -05004286 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004287
4288 return count;
4289}
4290
4291static struct bin_attribute sysfs_mbox_attr = {
4292 .attr = {
4293 .name = "mbox",
4294 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004295 },
James Smartc0c11512011-05-24 11:41:34 -04004296 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004297 .read = sysfs_mbox_read,
4298 .write = sysfs_mbox_write,
4299};
4300
James Smarte59058c2008-08-24 21:49:00 -04004301/**
James Smart3621a712009-04-06 18:47:14 -04004302 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004303 * @vport: address of lpfc vport structure.
4304 *
4305 * Return codes:
4306 * zero on success
4307 * error return code from sysfs_create_bin_file()
4308 **/
dea31012005-04-17 16:05:31 -05004309int
James Smart2e0fef82007-06-17 19:56:36 -05004310lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004311{
James Smart2e0fef82007-06-17 19:56:36 -05004312 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004313 int error;
4314
Tony Jonesee959b02008-02-22 00:13:36 +01004315 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004316 &sysfs_drvr_stat_data_attr);
4317
4318 /* Virtual ports do not need ctrl_reg and mbox */
4319 if (error || vport->port_type == LPFC_NPIV_PORT)
4320 goto out;
4321
4322 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004323 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004324 if (error)
James Smarteada2722008-12-04 22:39:13 -05004325 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004326
Tony Jonesee959b02008-02-22 00:13:36 +01004327 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004328 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004329 if (error)
4330 goto out_remove_ctlreg_attr;
4331
4332 return 0;
4333out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004334 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004335out_remove_stat_attr:
4336 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4337 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004338out:
4339 return error;
4340}
4341
James Smarte59058c2008-08-24 21:49:00 -04004342/**
James Smart3621a712009-04-06 18:47:14 -04004343 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004344 * @vport: address of lpfc vport structure.
4345 **/
dea31012005-04-17 16:05:31 -05004346void
James Smart2e0fef82007-06-17 19:56:36 -05004347lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004348{
James Smart2e0fef82007-06-17 19:56:36 -05004349 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004350 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4351 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004352 /* Virtual ports do not need ctrl_reg and mbox */
4353 if (vport->port_type == LPFC_NPIV_PORT)
4354 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004355 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4356 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004357}
4358
4359
4360/*
4361 * Dynamic FC Host Attributes Support
4362 */
4363
James Smarte59058c2008-08-24 21:49:00 -04004364/**
James Smart3621a712009-04-06 18:47:14 -04004365 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004366 * @shost: kernel scsi host pointer.
4367 **/
dea31012005-04-17 16:05:31 -05004368static void
4369lpfc_get_host_port_id(struct Scsi_Host *shost)
4370{
James Smart2e0fef82007-06-17 19:56:36 -05004371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4372
dea31012005-04-17 16:05:31 -05004373 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004374 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004375}
4376
James Smarte59058c2008-08-24 21:49:00 -04004377/**
James Smart3621a712009-04-06 18:47:14 -04004378 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004379 * @shost: kernel scsi host pointer.
4380 **/
dea31012005-04-17 16:05:31 -05004381static void
4382lpfc_get_host_port_type(struct Scsi_Host *shost)
4383{
James Smart2e0fef82007-06-17 19:56:36 -05004384 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4385 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004386
4387 spin_lock_irq(shost->host_lock);
4388
James Smart92d7f7b2007-06-17 19:56:38 -05004389 if (vport->port_type == LPFC_NPIV_PORT) {
4390 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4391 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004392 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004393 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004394 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4395 else
4396 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4397 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004398 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004399 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4400 else
4401 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4402 }
4403 } else
4404 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4405
4406 spin_unlock_irq(shost->host_lock);
4407}
4408
James Smarte59058c2008-08-24 21:49:00 -04004409/**
James Smart3621a712009-04-06 18:47:14 -04004410 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004411 * @shost: kernel scsi host pointer.
4412 **/
dea31012005-04-17 16:05:31 -05004413static void
4414lpfc_get_host_port_state(struct Scsi_Host *shost)
4415{
James Smart2e0fef82007-06-17 19:56:36 -05004416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4417 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004418
4419 spin_lock_irq(shost->host_lock);
4420
James Smart2e0fef82007-06-17 19:56:36 -05004421 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004422 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4423 else {
James Smart2e0fef82007-06-17 19:56:36 -05004424 switch (phba->link_state) {
4425 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004426 case LPFC_LINK_DOWN:
4427 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4428 break;
4429 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004430 case LPFC_CLEAR_LA:
4431 case LPFC_HBA_READY:
4432 /* Links up, beyond this port_type reports state */
4433 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4434 break;
4435 case LPFC_HBA_ERROR:
4436 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4437 break;
4438 default:
4439 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4440 break;
4441 }
4442 }
4443
4444 spin_unlock_irq(shost->host_lock);
4445}
4446
James Smarte59058c2008-08-24 21:49:00 -04004447/**
James Smart3621a712009-04-06 18:47:14 -04004448 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004449 * @shost: kernel scsi host pointer.
4450 **/
dea31012005-04-17 16:05:31 -05004451static void
4452lpfc_get_host_speed(struct Scsi_Host *shost)
4453{
James Smart2e0fef82007-06-17 19:56:36 -05004454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4455 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004456
4457 spin_lock_irq(shost->host_lock);
4458
James Smart2e0fef82007-06-17 19:56:36 -05004459 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004460 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004461 case LPFC_LINK_SPEED_1GHZ:
4462 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004463 break;
James Smart76a95d72010-11-20 23:11:48 -05004464 case LPFC_LINK_SPEED_2GHZ:
4465 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004466 break;
James Smart76a95d72010-11-20 23:11:48 -05004467 case LPFC_LINK_SPEED_4GHZ:
4468 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004469 break;
James Smart76a95d72010-11-20 23:11:48 -05004470 case LPFC_LINK_SPEED_8GHZ:
4471 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004472 break;
James Smart76a95d72010-11-20 23:11:48 -05004473 case LPFC_LINK_SPEED_10GHZ:
4474 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004475 break;
James Smart76a95d72010-11-20 23:11:48 -05004476 case LPFC_LINK_SPEED_16GHZ:
4477 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4478 break;
4479 default:
4480 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004481 break;
4482 }
James Smart09372822008-01-11 01:52:54 -05004483 } else
4484 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004485
4486 spin_unlock_irq(shost->host_lock);
4487}
4488
James Smarte59058c2008-08-24 21:49:00 -04004489/**
James Smart3621a712009-04-06 18:47:14 -04004490 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004491 * @shost: kernel scsi host pointer.
4492 **/
dea31012005-04-17 16:05:31 -05004493static void
4494lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4495{
James Smart2e0fef82007-06-17 19:56:36 -05004496 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4497 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004498 u64 node_name;
dea31012005-04-17 16:05:31 -05004499
4500 spin_lock_irq(shost->host_lock);
4501
James Smart73d91e52011-10-10 21:32:10 -04004502 if ((vport->port_state > LPFC_FLOGI) &&
4503 ((vport->fc_flag & FC_FABRIC) ||
4504 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4505 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004506 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004507 else
4508 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004509 node_name = 0;
dea31012005-04-17 16:05:31 -05004510
4511 spin_unlock_irq(shost->host_lock);
4512
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004513 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004514}
4515
James Smarte59058c2008-08-24 21:49:00 -04004516/**
James Smart3621a712009-04-06 18:47:14 -04004517 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004518 * @shost: kernel scsi host pointer.
4519 *
4520 * Notes:
4521 * NULL on error for link down, no mbox pool, sli2 active,
4522 * management not allowed, memory allocation error, or mbox error.
4523 *
4524 * Returns:
4525 * NULL for error
4526 * address of the adapter host statistics
4527 **/
dea31012005-04-17 16:05:31 -05004528static struct fc_host_statistics *
4529lpfc_get_stats(struct Scsi_Host *shost)
4530{
James Smart2e0fef82007-06-17 19:56:36 -05004531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4532 struct lpfc_hba *phba = vport->phba;
4533 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004534 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004535 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004536 LPFC_MBOXQ_t *pmboxq;
4537 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004538 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004539 int rc = 0;
dea31012005-04-17 16:05:31 -05004540
James Smart92d7f7b2007-06-17 19:56:38 -05004541 /*
4542 * prevent udev from issuing mailbox commands until the port is
4543 * configured.
4544 */
James Smart2e0fef82007-06-17 19:56:36 -05004545 if (phba->link_state < LPFC_LINK_DOWN ||
4546 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004547 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004548 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004549
4550 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004551 return NULL;
4552
dea31012005-04-17 16:05:31 -05004553 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4554 if (!pmboxq)
4555 return NULL;
4556 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4557
James Smart04c68492009-05-22 14:52:52 -04004558 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004559 pmb->mbxCommand = MBX_READ_STATUS;
4560 pmb->mbxOwner = OWN_HOST;
4561 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004562 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004563
James Smart75baf692010-06-08 18:31:21 -04004564 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004565 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004566 else
dea31012005-04-17 16:05:31 -05004567 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4568
4569 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004570 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004571 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004572 return NULL;
4573 }
4574
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004575 memset(hs, 0, sizeof (struct fc_host_statistics));
4576
dea31012005-04-17 16:05:31 -05004577 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004578 /*
4579 * The MBX_READ_STATUS returns tx_k_bytes which has to
4580 * converted to words
4581 */
4582 hs->tx_words = (uint64_t)
4583 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4584 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004585 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04004586 hs->rx_words = (uint64_t)
4587 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4588 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05004589
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004590 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004591 pmb->mbxCommand = MBX_READ_LNK_STAT;
4592 pmb->mbxOwner = OWN_HOST;
4593 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004594 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004595
James Smart75baf692010-06-08 18:31:21 -04004596 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004597 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004598 else
dea31012005-04-17 16:05:31 -05004599 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4600
4601 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004602 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004603 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004604 return NULL;
4605 }
4606
4607 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4608 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4609 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4610 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4611 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4612 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4613 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4614
James Smart64ba8812006-08-02 15:24:34 -04004615 hs->link_failure_count -= lso->link_failure_count;
4616 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4617 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4618 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4619 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4620 hs->invalid_crc_count -= lso->invalid_crc_count;
4621 hs->error_frames -= lso->error_frames;
4622
James Smart76a95d72010-11-20 23:11:48 -05004623 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004624 hs->lip_count = -1;
4625 hs->nos_count = (phba->link_events >> 1);
4626 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004627 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004628 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004629 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004630 hs->nos_count = -1;
4631 } else {
4632 hs->lip_count = -1;
4633 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004634 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004635 }
4636
4637 hs->dumped_frames = -1;
4638
James Smart64ba8812006-08-02 15:24:34 -04004639 seconds = get_seconds();
4640 if (seconds < psli->stats_start)
4641 hs->seconds_since_last_reset = seconds +
4642 ((unsigned long)-1 - psli->stats_start);
4643 else
4644 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004645
James Smart1dcb58e2007-04-25 09:51:30 -04004646 mempool_free(pmboxq, phba->mbox_mem_pool);
4647
dea31012005-04-17 16:05:31 -05004648 return hs;
4649}
4650
James Smarte59058c2008-08-24 21:49:00 -04004651/**
James Smart3621a712009-04-06 18:47:14 -04004652 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004653 * @shost: kernel scsi host pointer.
4654 **/
James Smart64ba8812006-08-02 15:24:34 -04004655static void
4656lpfc_reset_stats(struct Scsi_Host *shost)
4657{
James Smart2e0fef82007-06-17 19:56:36 -05004658 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4659 struct lpfc_hba *phba = vport->phba;
4660 struct lpfc_sli *psli = &phba->sli;
4661 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004662 LPFC_MBOXQ_t *pmboxq;
4663 MAILBOX_t *pmb;
4664 int rc = 0;
4665
James Smart2e0fef82007-06-17 19:56:36 -05004666 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004667 return;
4668
James Smart64ba8812006-08-02 15:24:34 -04004669 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4670 if (!pmboxq)
4671 return;
4672 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4673
James Smart04c68492009-05-22 14:52:52 -04004674 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004675 pmb->mbxCommand = MBX_READ_STATUS;
4676 pmb->mbxOwner = OWN_HOST;
4677 pmb->un.varWords[0] = 0x1; /* reset request */
4678 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004679 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004680
James Smart2e0fef82007-06-17 19:56:36 -05004681 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004682 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004683 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4684 else
4685 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4686
4687 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004688 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004689 mempool_free(pmboxq, phba->mbox_mem_pool);
4690 return;
4691 }
4692
4693 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4694 pmb->mbxCommand = MBX_READ_LNK_STAT;
4695 pmb->mbxOwner = OWN_HOST;
4696 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004697 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004698
James Smart2e0fef82007-06-17 19:56:36 -05004699 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004700 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004701 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4702 else
4703 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4704
4705 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004706 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004707 mempool_free( pmboxq, phba->mbox_mem_pool);
4708 return;
4709 }
4710
4711 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4712 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4713 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4714 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4715 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4716 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4717 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004718 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004719 lso->link_events = (phba->link_events >> 1);
4720 else
4721 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004722
4723 psli->stats_start = get_seconds();
4724
James Smart1dcb58e2007-04-25 09:51:30 -04004725 mempool_free(pmboxq, phba->mbox_mem_pool);
4726
James Smart64ba8812006-08-02 15:24:34 -04004727 return;
4728}
dea31012005-04-17 16:05:31 -05004729
4730/*
4731 * The LPFC driver treats linkdown handling as target loss events so there
4732 * are no sysfs handlers for link_down_tmo.
4733 */
James Smart685f0bf2007-04-25 09:53:08 -04004734
James Smarte59058c2008-08-24 21:49:00 -04004735/**
James Smart3621a712009-04-06 18:47:14 -04004736 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004737 * @starget: kernel scsi target pointer.
4738 *
4739 * Returns:
4740 * address of the node list if found
4741 * NULL target not found
4742 **/
James Smart685f0bf2007-04-25 09:53:08 -04004743static struct lpfc_nodelist *
4744lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004745{
James Smart2e0fef82007-06-17 19:56:36 -05004746 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4747 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004748 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004749
4750 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004751 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004752 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004753 if (NLP_CHK_NODE_ACT(ndlp) &&
4754 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004755 starget->id == ndlp->nlp_sid) {
4756 spin_unlock_irq(shost->host_lock);
4757 return ndlp;
dea31012005-04-17 16:05:31 -05004758 }
4759 }
4760 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004761 return NULL;
4762}
dea31012005-04-17 16:05:31 -05004763
James Smarte59058c2008-08-24 21:49:00 -04004764/**
James Smart3621a712009-04-06 18:47:14 -04004765 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004766 * @starget: kernel scsi target pointer.
4767 **/
James Smart685f0bf2007-04-25 09:53:08 -04004768static void
4769lpfc_get_starget_port_id(struct scsi_target *starget)
4770{
4771 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4772
4773 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004774}
4775
James Smarte59058c2008-08-24 21:49:00 -04004776/**
James Smart3621a712009-04-06 18:47:14 -04004777 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004778 * @starget: kernel scsi target pointer.
4779 *
4780 * Description: Set the target node name to the ndlp node name wwn or zero.
4781 **/
dea31012005-04-17 16:05:31 -05004782static void
4783lpfc_get_starget_node_name(struct scsi_target *starget)
4784{
James Smart685f0bf2007-04-25 09:53:08 -04004785 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004786
James Smart685f0bf2007-04-25 09:53:08 -04004787 fc_starget_node_name(starget) =
4788 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004789}
4790
James Smarte59058c2008-08-24 21:49:00 -04004791/**
James Smart3621a712009-04-06 18:47:14 -04004792 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004793 * @starget: kernel scsi target pointer.
4794 *
4795 * Description: set the target port name to the ndlp port name wwn or zero.
4796 **/
dea31012005-04-17 16:05:31 -05004797static void
4798lpfc_get_starget_port_name(struct scsi_target *starget)
4799{
James Smart685f0bf2007-04-25 09:53:08 -04004800 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004801
James Smart685f0bf2007-04-25 09:53:08 -04004802 fc_starget_port_name(starget) =
4803 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004804}
4805
James Smarte59058c2008-08-24 21:49:00 -04004806/**
James Smart3621a712009-04-06 18:47:14 -04004807 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004808 * @rport: fc rport address.
4809 * @timeout: new value for dev loss tmo.
4810 *
4811 * Description:
4812 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4813 * dev_loss_tmo to one.
4814 **/
dea31012005-04-17 16:05:31 -05004815static void
dea31012005-04-17 16:05:31 -05004816lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4817{
dea31012005-04-17 16:05:31 -05004818 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004819 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004820 else
James Smartc01f3202006-08-18 17:47:08 -04004821 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004822}
4823
James Smarte59058c2008-08-24 21:49:00 -04004824/**
James Smart3621a712009-04-06 18:47:14 -04004825 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004826 *
4827 * Description:
4828 * Macro that uses field to generate a function with the name lpfc_show_rport_
4829 *
4830 * lpfc_show_rport_##field: returns the bytes formatted in buf
4831 * @cdev: class converted to an fc_rport.
4832 * @buf: on return contains the target_field or zero.
4833 *
4834 * Returns: size of formatted string.
4835 **/
dea31012005-04-17 16:05:31 -05004836#define lpfc_rport_show_function(field, format_string, sz, cast) \
4837static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004838lpfc_show_rport_##field (struct device *dev, \
4839 struct device_attribute *attr, \
4840 char *buf) \
dea31012005-04-17 16:05:31 -05004841{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004842 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004843 struct lpfc_rport_data *rdata = rport->hostdata; \
4844 return snprintf(buf, sz, format_string, \
4845 (rdata->target) ? cast rdata->target->field : 0); \
4846}
4847
4848#define lpfc_rport_rd_attr(field, format_string, sz) \
4849 lpfc_rport_show_function(field, format_string, sz, ) \
4850static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4851
James Smarteada2722008-12-04 22:39:13 -05004852/**
James Smart3621a712009-04-06 18:47:14 -04004853 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004854 * @fc_vport: The fc_vport who's symbolic name has been changed.
4855 *
4856 * Description:
4857 * This function is called by the transport after the @fc_vport's symbolic name
4858 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004859 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004860 **/
4861static void
4862lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4863{
4864 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4865
4866 if (vport->port_state == LPFC_VPORT_READY)
4867 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4868}
dea31012005-04-17 16:05:31 -05004869
James Smartf4b4c682009-05-22 14:53:12 -04004870/**
4871 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4872 * @phba: Pointer to lpfc_hba struct.
4873 *
4874 * This function is called by the lpfc_get_cfgparam() routine to set the
4875 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004876 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004877 * before hba port or vport created.
4878 **/
4879static void
4880lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4881{
4882 phba->cfg_log_verbose = verbose;
4883}
4884
dea31012005-04-17 16:05:31 -05004885struct fc_function_template lpfc_transport_functions = {
4886 /* fixed attributes the driver supports */
4887 .show_host_node_name = 1,
4888 .show_host_port_name = 1,
4889 .show_host_supported_classes = 1,
4890 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004891 .show_host_supported_speeds = 1,
4892 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004893 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004894
4895 /* dynamic attributes the driver supports */
4896 .get_host_port_id = lpfc_get_host_port_id,
4897 .show_host_port_id = 1,
4898
4899 .get_host_port_type = lpfc_get_host_port_type,
4900 .show_host_port_type = 1,
4901
4902 .get_host_port_state = lpfc_get_host_port_state,
4903 .show_host_port_state = 1,
4904
4905 /* active_fc4s is shown but doesn't change (thus no get function) */
4906 .show_host_active_fc4s = 1,
4907
4908 .get_host_speed = lpfc_get_host_speed,
4909 .show_host_speed = 1,
4910
4911 .get_host_fabric_name = lpfc_get_host_fabric_name,
4912 .show_host_fabric_name = 1,
4913
4914 /*
4915 * The LPFC driver treats linkdown handling as target loss events
4916 * so there are no sysfs handlers for link_down_tmo.
4917 */
4918
4919 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004920 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004921
4922 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4923 .show_rport_maxframe_size = 1,
4924 .show_rport_supported_classes = 1,
4925
dea31012005-04-17 16:05:31 -05004926 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4927 .show_rport_dev_loss_tmo = 1,
4928
4929 .get_starget_port_id = lpfc_get_starget_port_id,
4930 .show_starget_port_id = 1,
4931
4932 .get_starget_node_name = lpfc_get_starget_node_name,
4933 .show_starget_node_name = 1,
4934
4935 .get_starget_port_name = lpfc_get_starget_port_name,
4936 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004937
4938 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004939 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4940 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004941
James Smart92d7f7b2007-06-17 19:56:38 -05004942 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004943
4944 .vport_disable = lpfc_vport_disable,
4945
4946 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004947
4948 .bsg_request = lpfc_bsg_request,
4949 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004950};
4951
James Smart98c9ea52007-10-27 13:37:33 -04004952struct fc_function_template lpfc_vport_transport_functions = {
4953 /* fixed attributes the driver supports */
4954 .show_host_node_name = 1,
4955 .show_host_port_name = 1,
4956 .show_host_supported_classes = 1,
4957 .show_host_supported_fc4s = 1,
4958 .show_host_supported_speeds = 1,
4959 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004960 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004961
4962 /* dynamic attributes the driver supports */
4963 .get_host_port_id = lpfc_get_host_port_id,
4964 .show_host_port_id = 1,
4965
4966 .get_host_port_type = lpfc_get_host_port_type,
4967 .show_host_port_type = 1,
4968
4969 .get_host_port_state = lpfc_get_host_port_state,
4970 .show_host_port_state = 1,
4971
4972 /* active_fc4s is shown but doesn't change (thus no get function) */
4973 .show_host_active_fc4s = 1,
4974
4975 .get_host_speed = lpfc_get_host_speed,
4976 .show_host_speed = 1,
4977
4978 .get_host_fabric_name = lpfc_get_host_fabric_name,
4979 .show_host_fabric_name = 1,
4980
4981 /*
4982 * The LPFC driver treats linkdown handling as target loss events
4983 * so there are no sysfs handlers for link_down_tmo.
4984 */
4985
4986 .get_fc_host_stats = lpfc_get_stats,
4987 .reset_fc_host_stats = lpfc_reset_stats,
4988
4989 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4990 .show_rport_maxframe_size = 1,
4991 .show_rport_supported_classes = 1,
4992
4993 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4994 .show_rport_dev_loss_tmo = 1,
4995
4996 .get_starget_port_id = lpfc_get_starget_port_id,
4997 .show_starget_port_id = 1,
4998
4999 .get_starget_node_name = lpfc_get_starget_node_name,
5000 .show_starget_node_name = 1,
5001
5002 .get_starget_port_name = lpfc_get_starget_port_name,
5003 .show_starget_port_name = 1,
5004
5005 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5006 .terminate_rport_io = lpfc_terminate_rport_io,
5007
5008 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005009
5010 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005011};
5012
James Smarte59058c2008-08-24 21:49:00 -04005013/**
James Smart3621a712009-04-06 18:47:14 -04005014 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005015 * @phba: lpfc_hba pointer.
5016 **/
dea31012005-04-17 16:05:31 -05005017void
5018lpfc_get_cfgparam(struct lpfc_hba *phba)
5019{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005020 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5021 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005022 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005023 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5024 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005025 lpfc_ack0_init(phba, lpfc_ack0);
5026 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005027 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005028 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04005029 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04005030 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05005031 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05005032 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04005033 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5034 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5035 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05005036 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5037 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05005038 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04005039 if (phba->sli_rev == LPFC_SLI_REV4)
5040 phba->cfg_poll = 0;
5041 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005042 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05005043 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04005044 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05005045 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05005046 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04005047 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04005048 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04005049 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04005050 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smart84d1b002010-02-12 14:42:33 -05005051 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04005052 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05005053 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04005054 return;
5055}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05005056
James Smarte59058c2008-08-24 21:49:00 -04005057/**
James Smart3621a712009-04-06 18:47:14 -04005058 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04005059 * @vport: lpfc_vport pointer.
5060 **/
James Smart3de2a652007-08-02 11:09:59 -04005061void
5062lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5063{
James Smarte8b62012007-08-02 11:10:09 -04005064 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04005065 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04005066 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04005067 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5068 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5069 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5070 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5071 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5072 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04005073 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04005074 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5075 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5076 lpfc_max_luns_init(vport, lpfc_max_luns);
5077 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04005078 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05005079 return;
5080}