blob: e058f1018ff22987bce15beab84d360b3cc2a104 [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_tcq.h>
31#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040032#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050033
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050035#include "lpfc_hw.h"
36#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040038#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_disc.h"
40#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_version.h"
44#include "lpfc_compat.h"
45#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050046#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050047
James Smartc01f3202006-08-18 17:47:08 -040048#define LPFC_DEF_DEVLOSS_TMO 30
49#define LPFC_MIN_DEVLOSS_TMO 1
50#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050051
James Smart83108bd2008-01-11 01:53:09 -050052#define LPFC_MAX_LINK_SPEED 8
53#define LPFC_LINK_SPEED_BITMAP 0x00000117
54#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
55
James Smarte59058c2008-08-24 21:49:00 -040056/**
James Smart3621a712009-04-06 18:47:14 -040057 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040058 * @incr: integer to convert.
59 * @hdw: ascii string holding converted integer plus a string terminator.
60 *
61 * Description:
62 * JEDEC Joint Electron Device Engineering Council.
63 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
64 * character string. The string is then terminated with a NULL in byte 9.
65 * Hex 0-9 becomes ascii '0' to '9'.
66 * Hex a-f becomes ascii '=' to 'B' capital B.
67 *
68 * Notes:
69 * Coded for 32 bit integers only.
70 **/
dea31012005-04-17 16:05:31 -050071static void
72lpfc_jedec_to_ascii(int incr, char hdw[])
73{
74 int i, j;
75 for (i = 0; i < 8; i++) {
76 j = (incr & 0xf);
77 if (j <= 9)
78 hdw[7 - i] = 0x30 + j;
79 else
80 hdw[7 - i] = 0x61 + j - 10;
81 incr = (incr >> 4);
82 }
83 hdw[8] = 0;
84 return;
85}
86
James Smarte59058c2008-08-24 21:49:00 -040087/**
James Smart3621a712009-04-06 18:47:14 -040088 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040089 * @dev: class unused variable.
90 * @attr: device attribute, not used.
91 * @buf: on return contains the module description text.
92 *
93 * Returns: size of formatted string.
94 **/
dea31012005-04-17 16:05:31 -050095static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010096lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
97 char *buf)
dea31012005-04-17 16:05:31 -050098{
99 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
100}
101
James Smart81301a92008-12-04 22:39:46 -0500102static ssize_t
103lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
105{
106 struct Scsi_Host *shost = class_to_shost(dev);
107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
108 struct lpfc_hba *phba = vport->phba;
109
110 if (phba->cfg_enable_bg)
111 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
112 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
113 else
114 return snprintf(buf, PAGE_SIZE,
115 "BlockGuard Not Supported\n");
116 else
117 return snprintf(buf, PAGE_SIZE,
118 "BlockGuard Disabled\n");
119}
120
121static ssize_t
122lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
123 char *buf)
124{
125 struct Scsi_Host *shost = class_to_shost(dev);
126 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
127 struct lpfc_hba *phba = vport->phba;
128
James Smart87b5c322008-12-16 10:34:09 -0500129 return snprintf(buf, PAGE_SIZE, "%llu\n",
130 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500131}
132
133static ssize_t
134lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
135 char *buf)
136{
137 struct Scsi_Host *shost = class_to_shost(dev);
138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
139 struct lpfc_hba *phba = vport->phba;
140
James Smart87b5c322008-12-16 10:34:09 -0500141 return snprintf(buf, PAGE_SIZE, "%llu\n",
142 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500143}
144
145static ssize_t
146lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
147 char *buf)
148{
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
152
James Smart87b5c322008-12-16 10:34:09 -0500153 return snprintf(buf, PAGE_SIZE, "%llu\n",
154 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500155}
156
James Smarte59058c2008-08-24 21:49:00 -0400157/**
James Smart3621a712009-04-06 18:47:14 -0400158 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400159 * @dev: class converted to a Scsi_host structure.
160 * @attr: device attribute, not used.
161 * @buf: on return contains the formatted text from lpfc_info().
162 *
163 * Returns: size of formatted string.
164 **/
dea31012005-04-17 16:05:31 -0500165static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100166lpfc_info_show(struct device *dev, struct device_attribute *attr,
167 char *buf)
dea31012005-04-17 16:05:31 -0500168{
Tony Jonesee959b02008-02-22 00:13:36 +0100169 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500170
dea31012005-04-17 16:05:31 -0500171 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
172}
173
James Smarte59058c2008-08-24 21:49:00 -0400174/**
James Smart3621a712009-04-06 18:47:14 -0400175 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400176 * @dev: class converted to a Scsi_host structure.
177 * @attr: device attribute, not used.
178 * @buf: on return contains the formatted text serial number.
179 *
180 * Returns: size of formatted string.
181 **/
dea31012005-04-17 16:05:31 -0500182static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100183lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
184 char *buf)
dea31012005-04-17 16:05:31 -0500185{
Tony Jonesee959b02008-02-22 00:13:36 +0100186 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500187 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
188 struct lpfc_hba *phba = vport->phba;
189
dea31012005-04-17 16:05:31 -0500190 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
191}
192
James Smarte59058c2008-08-24 21:49:00 -0400193/**
James Smart3621a712009-04-06 18:47:14 -0400194 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400195 * @dev: class converted to a Scsi_host structure.
196 * @attr: device attribute, not used.
197 * @buf: on return contains the formatted support level.
198 *
199 * Description:
200 * Returns a number indicating the temperature sensor level currently
201 * supported, zero or one in ascii.
202 *
203 * Returns: size of formatted string.
204 **/
dea31012005-04-17 16:05:31 -0500205static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100206lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
207 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400208{
Tony Jonesee959b02008-02-22 00:13:36 +0100209 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
211 struct lpfc_hba *phba = vport->phba;
212 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
213}
214
James Smarte59058c2008-08-24 21:49:00 -0400215/**
James Smart3621a712009-04-06 18:47:14 -0400216 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400217 * @dev: class converted to a Scsi_host structure.
218 * @attr: device attribute, not used.
219 * @buf: on return contains the scsi vpd model description.
220 *
221 * Returns: size of formatted string.
222 **/
James Smart57127f12007-10-27 13:37:05 -0400223static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100224lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
225 char *buf)
dea31012005-04-17 16:05:31 -0500226{
Tony Jonesee959b02008-02-22 00:13:36 +0100227 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500228 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
229 struct lpfc_hba *phba = vport->phba;
230
dea31012005-04-17 16:05:31 -0500231 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
232}
233
James Smarte59058c2008-08-24 21:49:00 -0400234/**
James Smart3621a712009-04-06 18:47:14 -0400235 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400236 * @dev: class converted to a Scsi_host structure.
237 * @attr: device attribute, not used.
238 * @buf: on return contains the scsi vpd model name.
239 *
240 * Returns: size of formatted string.
241 **/
dea31012005-04-17 16:05:31 -0500242static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100243lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
244 char *buf)
dea31012005-04-17 16:05:31 -0500245{
Tony Jonesee959b02008-02-22 00:13:36 +0100246 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500247 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
248 struct lpfc_hba *phba = vport->phba;
249
dea31012005-04-17 16:05:31 -0500250 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
251}
252
James Smarte59058c2008-08-24 21:49:00 -0400253/**
James Smart3621a712009-04-06 18:47:14 -0400254 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400255 * @dev: class converted to a Scsi_host structure.
256 * @attr: device attribute, not used.
257 * @buf: on return contains the scsi vpd program type.
258 *
259 * Returns: size of formatted string.
260 **/
dea31012005-04-17 16:05:31 -0500261static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100262lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
263 char *buf)
dea31012005-04-17 16:05:31 -0500264{
Tony Jonesee959b02008-02-22 00:13:36 +0100265 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
267 struct lpfc_hba *phba = vport->phba;
268
dea31012005-04-17 16:05:31 -0500269 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
270}
271
James Smarte59058c2008-08-24 21:49:00 -0400272/**
James Smart3621a712009-04-06 18:47:14 -0400273 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400274 * @dev: class converted to a Scsi_host structure.
275 * @attr: device attribute, not used.
276 * @buf: on return contains the Menlo Maintenance sli flag.
277 *
278 * Returns: size of formatted string.
279 **/
280static ssize_t
281lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
282{
283 struct Scsi_Host *shost = class_to_shost(dev);
284 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
285 struct lpfc_hba *phba = vport->phba;
286
287 return snprintf(buf, PAGE_SIZE, "%d\n",
288 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
289}
290
291/**
James Smart3621a712009-04-06 18:47:14 -0400292 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400293 * @dev: class converted to a Scsi_host structure.
294 * @attr: device attribute, not used.
295 * @buf: on return contains scsi vpd program type.
296 *
297 * Returns: size of formatted string.
298 **/
dea31012005-04-17 16:05:31 -0500299static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100300lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
301 char *buf)
dea31012005-04-17 16:05:31 -0500302{
Tony Jonesee959b02008-02-22 00:13:36 +0100303 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500304 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
305 struct lpfc_hba *phba = vport->phba;
306
dea31012005-04-17 16:05:31 -0500307 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
308}
309
James Smarte59058c2008-08-24 21:49:00 -0400310/**
James Smart3621a712009-04-06 18:47:14 -0400311 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400312 * @dev: class converted to a Scsi_host structure.
313 * @attr: device attribute, not used.
314 * @buf: on return contains the scsi vpd program type.
315 *
316 * Returns: size of formatted string.
317 **/
dea31012005-04-17 16:05:31 -0500318static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100319lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
320 char *buf)
dea31012005-04-17 16:05:31 -0500321{
Tony Jonesee959b02008-02-22 00:13:36 +0100322 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
324 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500325 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500326
dea31012005-04-17 16:05:31 -0500327 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500328 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500329}
330
James Smarte59058c2008-08-24 21:49:00 -0400331/**
James Smart3621a712009-04-06 18:47:14 -0400332 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
336 *
337 * Returns: size of formatted string.
338 **/
dea31012005-04-17 16:05:31 -0500339static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100340lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500341{
342 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100343 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500346 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500347
dea31012005-04-17 16:05:31 -0500348 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
349 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
350}
James Smarte59058c2008-08-24 21:49:00 -0400351
352/**
James Smart3621a712009-04-06 18:47:14 -0400353 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the ROM and FCode ascii strings.
357 *
358 * Returns: size of formatted string.
359 **/
dea31012005-04-17 16:05:31 -0500360static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100361lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
362 char *buf)
dea31012005-04-17 16:05:31 -0500363{
Tony Jonesee959b02008-02-22 00:13:36 +0100364 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367
dea31012005-04-17 16:05:31 -0500368 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
369}
James Smarte59058c2008-08-24 21:49:00 -0400370
371/**
James Smart3621a712009-04-06 18:47:14 -0400372 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400373 * @dev: class converted to a Scsi_host structure.
374 * @attr: device attribute, not used.
375 * @buf: on return contains text describing the state of the link.
376 *
377 * Notes:
378 * The switch statement has no default so zero will be returned.
379 *
380 * Returns: size of formatted string.
381 **/
dea31012005-04-17 16:05:31 -0500382static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100383lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
384 char *buf)
dea31012005-04-17 16:05:31 -0500385{
Tony Jonesee959b02008-02-22 00:13:36 +0100386 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
388 struct lpfc_hba *phba = vport->phba;
389 int len = 0;
390
391 switch (phba->link_state) {
392 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500393 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500394 case LPFC_INIT_START:
395 case LPFC_INIT_MBX_CMDS:
396 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500397 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400398 if (phba->hba_flag & LINK_DISABLED)
399 len += snprintf(buf + len, PAGE_SIZE-len,
400 "Link Down - User disabled\n");
401 else
402 len += snprintf(buf + len, PAGE_SIZE-len,
403 "Link Down\n");
dea31012005-04-17 16:05:31 -0500404 break;
405 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500406 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500407 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400408 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500409
410 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500411 case LPFC_LOCAL_CFG_LINK:
412 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500413 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500414 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500415 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500416 case LPFC_FLOGI:
417 case LPFC_FABRIC_CFG_LINK:
418 case LPFC_NS_REG:
419 case LPFC_NS_QRY:
420 case LPFC_BUILD_DISC_LIST:
421 case LPFC_DISC_AUTH:
422 len += snprintf(buf + len, PAGE_SIZE - len,
423 "Discovery\n");
424 break;
425 case LPFC_VPORT_READY:
426 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
427 break;
428
James Smart92d7f7b2007-06-17 19:56:38 -0500429 case LPFC_VPORT_FAILED:
430 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
431 break;
432
433 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500434 len += snprintf(buf + len, PAGE_SIZE - len,
435 "Unknown\n");
436 break;
437 }
James Smart84774a42008-08-24 21:50:06 -0400438 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
439 len += snprintf(buf + len, PAGE_SIZE-len,
440 " Menlo Maint Mode\n");
441 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500442 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500443 len += snprintf(buf + len, PAGE_SIZE-len,
444 " Public Loop\n");
445 else
446 len += snprintf(buf + len, PAGE_SIZE-len,
447 " Private Loop\n");
448 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500449 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500450 len += snprintf(buf + len, PAGE_SIZE-len,
451 " Fabric\n");
452 else
453 len += snprintf(buf + len, PAGE_SIZE-len,
454 " Point-2-Point\n");
455 }
456 }
James Smart2e0fef82007-06-17 19:56:36 -0500457
dea31012005-04-17 16:05:31 -0500458 return len;
459}
460
James Smarte59058c2008-08-24 21:49:00 -0400461/**
James Smart3621a712009-04-06 18:47:14 -0400462 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400463 * @dev: class device that is converted into a Scsi_host.
464 * @attr: device attribute, not used.
465 * @buf: on return contains the sum of fc mapped and unmapped.
466 *
467 * Description:
468 * Returns the ascii text number of the sum of the fc mapped and unmapped
469 * vport counts.
470 *
471 * Returns: size of formatted string.
472 **/
dea31012005-04-17 16:05:31 -0500473static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100474lpfc_num_discovered_ports_show(struct device *dev,
475 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500476{
Tony Jonesee959b02008-02-22 00:13:36 +0100477 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
479
480 return snprintf(buf, PAGE_SIZE, "%d\n",
481 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500482}
483
James Smarte59058c2008-08-24 21:49:00 -0400484/**
James Smart3621a712009-04-06 18:47:14 -0400485 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400486 * @shost: Scsi_Host pointer.
487 *
488 * Description:
489 * Bring the link down gracefully then re-init the link. The firmware will
490 * re-init the fiber channel interface as required. Does not issue a LIP.
491 *
492 * Returns:
493 * -EPERM port offline or management commands are being blocked
494 * -ENOMEM cannot allocate memory for the mailbox command
495 * -EIO error sending the mailbox command
496 * zero for success
497 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700498static int
James Smart2e0fef82007-06-17 19:56:36 -0500499lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500500{
James Smart2e0fef82007-06-17 19:56:36 -0500501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
502 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500503 LPFC_MBOXQ_t *pmboxq;
504 int mbxstatus = MBXERR_ERROR;
505
James Smart2e0fef82007-06-17 19:56:36 -0500506 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500507 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500508 return -EPERM;
509
510 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
511
512 if (!pmboxq)
513 return -ENOMEM;
514
515 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400516 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
517 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400518
James Smart33ccf8d2006-08-17 11:57:58 -0400519 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500520
James Smart04c68492009-05-22 14:52:52 -0400521 if ((mbxstatus == MBX_SUCCESS) &&
522 (pmboxq->u.mb.mbxStatus == 0 ||
523 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400524 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
525 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
526 phba->cfg_link_speed);
527 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
528 phba->fc_ratov * 2);
529 }
530
James Smart5b8bd0c2007-04-25 09:52:49 -0400531 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500532 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c35792005-10-28 20:28:56 -0400533 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500534
535 if (mbxstatus == MBXERR_ERROR)
536 return -EIO;
537
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700538 return 0;
dea31012005-04-17 16:05:31 -0500539}
540
James Smarte59058c2008-08-24 21:49:00 -0400541/**
James Smart3621a712009-04-06 18:47:14 -0400542 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400543 * @phba: lpfc_hba pointer.
544 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
545 *
546 * Notes:
547 * Assumes any error from lpfc_do_offline() will be negative.
548 * Can wait up to 5 seconds for the port ring buffers count
549 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400550 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400551 *
552 * Returns:
553 * -EIO error posting the event
554 * zero for success
555 **/
James Smart40496f02006-07-06 15:50:22 -0400556static int
James Smart46fa3112007-04-25 09:51:45 -0400557lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
558{
559 struct completion online_compl;
560 struct lpfc_sli_ring *pring;
561 struct lpfc_sli *psli;
562 int status = 0;
563 int cnt = 0;
564 int i;
565
566 init_completion(&online_compl);
567 lpfc_workq_post_event(phba, &status, &online_compl,
568 LPFC_EVT_OFFLINE_PREP);
569 wait_for_completion(&online_compl);
570
571 if (status != 0)
572 return -EIO;
573
574 psli = &phba->sli;
575
James Smart09372822008-01-11 01:52:54 -0500576 /* Wait a little for things to settle down, but not
577 * long enough for dev loss timeout to expire.
578 */
James Smart46fa3112007-04-25 09:51:45 -0400579 for (i = 0; i < psli->num_rings; i++) {
580 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400581 while (pring->txcmplq_cnt) {
582 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500583 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400584 lpfc_printf_log(phba,
585 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400586 "0466 Outstanding IO when "
587 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400588 break;
589 }
590 }
591 }
592
593 init_completion(&online_compl);
594 lpfc_workq_post_event(phba, &status, &online_compl, type);
595 wait_for_completion(&online_compl);
596
597 if (status != 0)
598 return -EIO;
599
600 return 0;
601}
602
James Smarte59058c2008-08-24 21:49:00 -0400603/**
James Smart3621a712009-04-06 18:47:14 -0400604 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400605 * @phba: lpfc_hba pointer.
606 *
607 * Description:
608 * If the port is configured to allow a reset then the hba is brought
609 * offline then online.
610 *
611 * Notes:
612 * Assumes any error from lpfc_do_offline() will be negative.
613 *
614 * Returns:
615 * lpfc_do_offline() return code if not zero
616 * -EIO reset not configured or error posting the event
617 * zero for success
618 **/
James Smart46fa3112007-04-25 09:51:45 -0400619static int
James Smart40496f02006-07-06 15:50:22 -0400620lpfc_selective_reset(struct lpfc_hba *phba)
621{
622 struct completion online_compl;
623 int status = 0;
624
James Smart13815c82008-01-11 01:52:48 -0500625 if (!phba->cfg_enable_hba_reset)
626 return -EIO;
627
James Smart46fa3112007-04-25 09:51:45 -0400628 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400629
630 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400631 return status;
James Smart40496f02006-07-06 15:50:22 -0400632
633 init_completion(&online_compl);
634 lpfc_workq_post_event(phba, &status, &online_compl,
635 LPFC_EVT_ONLINE);
636 wait_for_completion(&online_compl);
637
638 if (status != 0)
639 return -EIO;
640
641 return 0;
642}
643
James Smarte59058c2008-08-24 21:49:00 -0400644/**
James Smart3621a712009-04-06 18:47:14 -0400645 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400646 * @dev: class device that is converted into a Scsi_host.
647 * @attr: device attribute, not used.
648 * @buf: containing the string "selective".
649 * @count: unused variable.
650 *
651 * Description:
652 * If the buf contains the string "selective" then lpfc_selective_reset()
653 * is called to perform the reset.
654 *
655 * Notes:
656 * Assumes any error from lpfc_selective_reset() will be negative.
657 * If lpfc_selective_reset() returns zero then the length of the buffer
658 * is returned which indicates succcess
659 *
660 * Returns:
661 * -EINVAL if the buffer does not contain the string "selective"
662 * length of buf if lpfc-selective_reset() if the call succeeds
663 * return value of lpfc_selective_reset() if the call fails
664**/
James Smart40496f02006-07-06 15:50:22 -0400665static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100666lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
667 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400668{
Tony Jonesee959b02008-02-22 00:13:36 +0100669 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
671 struct lpfc_hba *phba = vport->phba;
672
James Smart40496f02006-07-06 15:50:22 -0400673 int status = -EINVAL;
674
675 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
676 status = lpfc_selective_reset(phba);
677
678 if (status == 0)
679 return strlen(buf);
680 else
681 return status;
682}
683
James Smarte59058c2008-08-24 21:49:00 -0400684/**
James Smart3621a712009-04-06 18:47:14 -0400685 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400686 * @dev: class device that is converted into a Scsi_host.
687 * @attr: device attribute, not used.
688 * @buf: on return contains the ascii number of nport events.
689 *
690 * Returns: size of formatted string.
691 **/
dea31012005-04-17 16:05:31 -0500692static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100693lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
694 char *buf)
dea31012005-04-17 16:05:31 -0500695{
Tony Jonesee959b02008-02-22 00:13:36 +0100696 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500697 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
698 struct lpfc_hba *phba = vport->phba;
699
dea31012005-04-17 16:05:31 -0500700 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
701}
702
James Smarte59058c2008-08-24 21:49:00 -0400703/**
James Smart3621a712009-04-06 18:47:14 -0400704 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400705 * @dev: class device that is converted into a Scsi_host.
706 * @attr: device attribute, not used.
707 * @buf: on return contains the state of the adapter.
708 *
709 * Returns: size of formatted string.
710 **/
dea31012005-04-17 16:05:31 -0500711static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100712lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
713 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500714{
Tony Jonesee959b02008-02-22 00:13:36 +0100715 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500716 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
717 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500718 char * state;
719
James Smart2e0fef82007-06-17 19:56:36 -0500720 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500721 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500722 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500723 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500724 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500725 state = "offline";
726 else
727 state = "online";
728
729 return snprintf(buf, PAGE_SIZE, "%s\n", state);
730}
731
James Smarte59058c2008-08-24 21:49:00 -0400732/**
James Smart3621a712009-04-06 18:47:14 -0400733 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400734 * @dev: class device that is converted into a Scsi_host.
735 * @attr: device attribute, not used.
736 * @buf: containing one of the strings "online", "offline", "warm" or "error".
737 * @count: unused variable.
738 *
739 * Returns:
740 * -EACCES if enable hba reset not enabled
741 * -EINVAL if the buffer does not contain a valid string (see above)
742 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
743 * buf length greater than zero indicates success
744 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500745static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100746lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
747 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500748{
Tony Jonesee959b02008-02-22 00:13:36 +0100749 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500750 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
751 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500752 struct completion online_compl;
753 int status=0;
754
James Smart13815c82008-01-11 01:52:48 -0500755 if (!phba->cfg_enable_hba_reset)
756 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500757 init_completion(&online_compl);
758
James Smart46fa3112007-04-25 09:51:45 -0400759 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500760 lpfc_workq_post_event(phba, &status, &online_compl,
761 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400762 wait_for_completion(&online_compl);
763 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
764 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500765 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400766 if (phba->sli_rev == LPFC_SLI_REV4)
767 return -EINVAL;
768 else
769 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400770 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400771 if (phba->sli_rev == LPFC_SLI_REV4)
772 return -EINVAL;
773 else
774 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500775 else
776 return -EINVAL;
777
Jamie Wellnitz41415862006-02-28 19:25:27 -0500778 if (!status)
779 return strlen(buf);
780 else
781 return -EIO;
782}
783
James Smarte59058c2008-08-24 21:49:00 -0400784/**
James Smart3621a712009-04-06 18:47:14 -0400785 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400786 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400787 * @mxri: max xri count.
788 * @axri: available xri count.
789 * @mrpi: max rpi count.
790 * @arpi: available rpi count.
791 * @mvpi: max vpi count.
792 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400793 *
794 * Description:
795 * If an integer pointer for an count is not null then the value for the
796 * count is returned.
797 *
798 * Returns:
799 * zero on error
800 * one for success
801 **/
James Smart311464e2007-08-02 11:10:37 -0400802static int
James Smart858c9f62007-06-17 19:56:39 -0500803lpfc_get_hba_info(struct lpfc_hba *phba,
804 uint32_t *mxri, uint32_t *axri,
805 uint32_t *mrpi, uint32_t *arpi,
806 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500807{
James Smart04c68492009-05-22 14:52:52 -0400808 struct lpfc_sli *psli = &phba->sli;
809 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500810 LPFC_MBOXQ_t *pmboxq;
811 MAILBOX_t *pmb;
812 int rc = 0;
813
814 /*
815 * prevent udev from issuing mailbox commands until the port is
816 * configured.
817 */
818 if (phba->link_state < LPFC_LINK_DOWN ||
819 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400820 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500821 return 0;
822
823 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
824 return 0;
825
826 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
827 if (!pmboxq)
828 return 0;
829 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
830
James Smart04c68492009-05-22 14:52:52 -0400831 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500832 pmb->mbxCommand = MBX_READ_CONFIG;
833 pmb->mbxOwner = OWN_HOST;
834 pmboxq->context1 = NULL;
835
836 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -0400837 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart92d7f7b2007-06-17 19:56:38 -0500838 rc = MBX_NOT_FINISHED;
839 else
840 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
841
842 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500843 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500844 mempool_free(pmboxq, phba->mbox_mem_pool);
845 return 0;
846 }
847
James Smartda0436e2009-05-22 14:51:39 -0400848 if (phba->sli_rev == LPFC_SLI_REV4) {
849 rd_config = &pmboxq->u.mqe.un.rd_config;
850 if (mrpi)
851 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
852 if (arpi)
853 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
854 phba->sli4_hba.max_cfg_param.rpi_used;
855 if (mxri)
856 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
857 if (axri)
858 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
859 phba->sli4_hba.max_cfg_param.xri_used;
860 if (mvpi)
861 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
862 if (avpi)
863 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
864 phba->sli4_hba.max_cfg_param.vpi_used;
865 } else {
866 if (mrpi)
867 *mrpi = pmb->un.varRdConfig.max_rpi;
868 if (arpi)
869 *arpi = pmb->un.varRdConfig.avail_rpi;
870 if (mxri)
871 *mxri = pmb->un.varRdConfig.max_xri;
872 if (axri)
873 *axri = pmb->un.varRdConfig.avail_xri;
874 if (mvpi)
875 *mvpi = pmb->un.varRdConfig.max_vpi;
876 if (avpi)
877 *avpi = pmb->un.varRdConfig.avail_vpi;
878 }
James Smart92d7f7b2007-06-17 19:56:38 -0500879
880 mempool_free(pmboxq, phba->mbox_mem_pool);
881 return 1;
882}
883
James Smarte59058c2008-08-24 21:49:00 -0400884/**
James Smart3621a712009-04-06 18:47:14 -0400885 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400886 * @dev: class device that is converted into a Scsi_host.
887 * @attr: device attribute, not used.
888 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
889 *
890 * Description:
891 * Calls lpfc_get_hba_info() asking for just the mrpi count.
892 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
893 * to "Unknown" and the buffer length is returned, therefore the caller
894 * must check for "Unknown" in the buffer to detect a failure.
895 *
896 * Returns: size of formatted string.
897 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500898static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100899lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
900 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500901{
Tony Jonesee959b02008-02-22 00:13:36 +0100902 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500903 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
904 struct lpfc_hba *phba = vport->phba;
905 uint32_t cnt;
906
James Smart858c9f62007-06-17 19:56:39 -0500907 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500908 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
909 return snprintf(buf, PAGE_SIZE, "Unknown\n");
910}
911
James Smarte59058c2008-08-24 21:49:00 -0400912/**
James Smart3621a712009-04-06 18:47:14 -0400913 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400914 * @dev: class device that is converted into a Scsi_host.
915 * @attr: device attribute, not used.
916 * @buf: containing the used rpi count in decimal or "Unknown".
917 *
918 * Description:
919 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
920 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
921 * to "Unknown" and the buffer length is returned, therefore the caller
922 * must check for "Unknown" in the buffer to detect a failure.
923 *
924 * Returns: size of formatted string.
925 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500926static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100927lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
928 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500929{
Tony Jonesee959b02008-02-22 00:13:36 +0100930 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500931 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
932 struct lpfc_hba *phba = vport->phba;
933 uint32_t cnt, acnt;
934
James Smart858c9f62007-06-17 19:56:39 -0500935 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500936 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
937 return snprintf(buf, PAGE_SIZE, "Unknown\n");
938}
939
James Smarte59058c2008-08-24 21:49:00 -0400940/**
James Smart3621a712009-04-06 18:47:14 -0400941 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -0400942 * @dev: class device that is converted into a Scsi_host.
943 * @attr: device attribute, not used.
944 * @buf: on return contains the maximum xri count in decimal or "Unknown".
945 *
946 * Description:
947 * Calls lpfc_get_hba_info() asking for just the mrpi count.
948 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
949 * to "Unknown" and the buffer length is returned, therefore the caller
950 * must check for "Unknown" in the buffer to detect a failure.
951 *
952 * Returns: size of formatted string.
953 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500954static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100955lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
956 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500957{
Tony Jonesee959b02008-02-22 00:13:36 +0100958 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500959 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
960 struct lpfc_hba *phba = vport->phba;
961 uint32_t cnt;
962
James Smart858c9f62007-06-17 19:56:39 -0500963 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500964 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
965 return snprintf(buf, PAGE_SIZE, "Unknown\n");
966}
967
James Smarte59058c2008-08-24 21:49:00 -0400968/**
James Smart3621a712009-04-06 18:47:14 -0400969 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -0400970 * @dev: class device that is converted into a Scsi_host.
971 * @attr: device attribute, not used.
972 * @buf: on return contains the used xri count in decimal or "Unknown".
973 *
974 * Description:
975 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
976 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
977 * to "Unknown" and the buffer length is returned, therefore the caller
978 * must check for "Unknown" in the buffer to detect a failure.
979 *
980 * Returns: size of formatted string.
981 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500982static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100983lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
984 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500985{
Tony Jonesee959b02008-02-22 00:13:36 +0100986 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500987 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
988 struct lpfc_hba *phba = vport->phba;
989 uint32_t cnt, acnt;
990
James Smart858c9f62007-06-17 19:56:39 -0500991 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
992 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
993 return snprintf(buf, PAGE_SIZE, "Unknown\n");
994}
995
James Smarte59058c2008-08-24 21:49:00 -0400996/**
James Smart3621a712009-04-06 18:47:14 -0400997 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -0400998 * @dev: class device that is converted into a Scsi_host.
999 * @attr: device attribute, not used.
1000 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1001 *
1002 * Description:
1003 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1004 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1005 * to "Unknown" and the buffer length is returned, therefore the caller
1006 * must check for "Unknown" in the buffer to detect a failure.
1007 *
1008 * Returns: size of formatted string.
1009 **/
James Smart858c9f62007-06-17 19:56:39 -05001010static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001011lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1012 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001013{
Tony Jonesee959b02008-02-22 00:13:36 +01001014 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001015 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1016 struct lpfc_hba *phba = vport->phba;
1017 uint32_t cnt;
1018
1019 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1020 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1021 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1022}
1023
James Smarte59058c2008-08-24 21:49:00 -04001024/**
James Smart3621a712009-04-06 18:47:14 -04001025 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001026 * @dev: class device that is converted into a Scsi_host.
1027 * @attr: device attribute, not used.
1028 * @buf: on return contains the used vpi count in decimal or "Unknown".
1029 *
1030 * Description:
1031 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1032 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1033 * to "Unknown" and the buffer length is returned, therefore the caller
1034 * must check for "Unknown" in the buffer to detect a failure.
1035 *
1036 * Returns: size of formatted string.
1037 **/
James Smart858c9f62007-06-17 19:56:39 -05001038static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001039lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1040 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001041{
Tony Jonesee959b02008-02-22 00:13:36 +01001042 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001043 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1044 struct lpfc_hba *phba = vport->phba;
1045 uint32_t cnt, acnt;
1046
1047 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001048 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1049 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1050}
1051
James Smarte59058c2008-08-24 21:49:00 -04001052/**
James Smart3621a712009-04-06 18:47:14 -04001053 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001054 * @dev: class device that is converted into a Scsi_host.
1055 * @attr: device attribute, not used.
1056 * @buf: text that must be interpreted to determine if npiv is supported.
1057 *
1058 * Description:
1059 * Buffer will contain text indicating npiv is not suppoerted on the port,
1060 * the port is an NPIV physical port, or it is an npiv virtual port with
1061 * the id of the vport.
1062 *
1063 * Returns: size of formatted string.
1064 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001065static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001066lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1067 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001068{
Tony Jonesee959b02008-02-22 00:13:36 +01001069 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001070 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1071 struct lpfc_hba *phba = vport->phba;
1072
1073 if (!(phba->max_vpi))
1074 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1075 if (vport->port_type == LPFC_PHYSICAL_PORT)
1076 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1077 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1078}
1079
James Smarte59058c2008-08-24 21:49:00 -04001080/**
James Smart3621a712009-04-06 18:47:14 -04001081 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001082 * @dev: class device that is converted into a Scsi_host.
1083 * @attr: device attribute, not used.
1084 * @buf: on return contains the cfg_poll in hex.
1085 *
1086 * Notes:
1087 * cfg_poll should be a lpfc_polling_flags type.
1088 *
1089 * Returns: size of formatted string.
1090 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001091static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001092lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1093 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001094{
Tony Jonesee959b02008-02-22 00:13:36 +01001095 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001098
1099 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1100}
1101
James Smarte59058c2008-08-24 21:49:00 -04001102/**
James Smart3621a712009-04-06 18:47:14 -04001103 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001104 * @dev: class device that is converted into a Scsi_host.
1105 * @attr: device attribute, not used.
1106 * @buf: one or more lpfc_polling_flags values.
1107 * @count: not used.
1108 *
1109 * Notes:
1110 * buf contents converted to integer and checked for a valid value.
1111 *
1112 * Returns:
1113 * -EINVAL if the buffer connot be converted or is out of range
1114 * length of the buf on success
1115 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001116static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001117lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1118 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001119{
Tony Jonesee959b02008-02-22 00:13:36 +01001120 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1122 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001123 uint32_t creg_val;
1124 uint32_t old_val;
1125 int val=0;
1126
1127 if (!isdigit(buf[0]))
1128 return -EINVAL;
1129
1130 if (sscanf(buf, "%i", &val) != 1)
1131 return -EINVAL;
1132
1133 if ((val & 0x3) != val)
1134 return -EINVAL;
1135
James Smart2e0fef82007-06-17 19:56:36 -05001136 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001137
1138 old_val = phba->cfg_poll;
1139
1140 if (val & ENABLE_FCP_RING_POLLING) {
1141 if ((val & DISABLE_FCP_RING_INT) &&
1142 !(old_val & DISABLE_FCP_RING_INT)) {
1143 creg_val = readl(phba->HCregaddr);
1144 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1145 writel(creg_val, phba->HCregaddr);
1146 readl(phba->HCregaddr); /* flush */
1147
1148 lpfc_poll_start_timer(phba);
1149 }
1150 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001151 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001152 return -EINVAL;
1153 }
1154
1155 if (!(val & DISABLE_FCP_RING_INT) &&
1156 (old_val & DISABLE_FCP_RING_INT))
1157 {
James Smart2e0fef82007-06-17 19:56:36 -05001158 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001159 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001160 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001161 creg_val = readl(phba->HCregaddr);
1162 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1163 writel(creg_val, phba->HCregaddr);
1164 readl(phba->HCregaddr); /* flush */
1165 }
1166
1167 phba->cfg_poll = val;
1168
James Smart2e0fef82007-06-17 19:56:36 -05001169 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001170
1171 return strlen(buf);
1172}
dea31012005-04-17 16:05:31 -05001173
James Smarte59058c2008-08-24 21:49:00 -04001174/**
James Smart3621a712009-04-06 18:47:14 -04001175 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001176 *
1177 * Description:
1178 * Macro that given an attr e.g. hba_queue_depth expands
1179 * into a function with the name lpfc_hba_queue_depth_show.
1180 *
1181 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1182 * @dev: class device that is converted into a Scsi_host.
1183 * @attr: device attribute, not used.
1184 * @buf: on return contains the attribute value in decimal.
1185 *
1186 * Returns: size of formatted string.
1187 **/
dea31012005-04-17 16:05:31 -05001188#define lpfc_param_show(attr) \
1189static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001190lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1191 char *buf) \
dea31012005-04-17 16:05:31 -05001192{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001193 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001194 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1195 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001196 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001197 val = phba->cfg_##attr;\
1198 return snprintf(buf, PAGE_SIZE, "%d\n",\
1199 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001200}
1201
James Smarte59058c2008-08-24 21:49:00 -04001202/**
James Smart3621a712009-04-06 18:47:14 -04001203 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001204 *
1205 * Description:
1206 * Macro that given an attr e.g. hba_queue_depth expands
1207 * into a function with the name lpfc_hba_queue_depth_show
1208 *
1209 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1210 * @dev: class device that is converted into a Scsi_host.
1211 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001212 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001213 *
1214 * Returns: size of formatted string.
1215 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001216#define lpfc_param_hex_show(attr) \
1217static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001218lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1219 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001220{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001221 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1223 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001224 int val = 0;\
1225 val = phba->cfg_##attr;\
1226 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1227 phba->cfg_##attr);\
1228}
1229
James Smarte59058c2008-08-24 21:49:00 -04001230/**
James Smart3621a712009-04-06 18:47:14 -04001231 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001232 *
1233 * Description:
1234 * Macro that given an attr e.g. hba_queue_depth expands
1235 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1236 * takes a default argument, a minimum and maximum argument.
1237 *
1238 * lpfc_##attr##_init: Initializes an attribute.
1239 * @phba: pointer the the adapter structure.
1240 * @val: integer attribute value.
1241 *
1242 * Validates the min and max values then sets the adapter config field
1243 * accordingly, or uses the default if out of range and prints an error message.
1244 *
1245 * Returns:
1246 * zero on success
1247 * -EINVAL if default used
1248 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001249#define lpfc_param_init(attr, default, minval, maxval) \
1250static int \
1251lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1252{ \
1253 if (val >= minval && val <= maxval) {\
1254 phba->cfg_##attr = val;\
1255 return 0;\
1256 }\
1257 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001258 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1259 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001260 phba->cfg_##attr = default;\
1261 return -EINVAL;\
1262}
1263
James Smarte59058c2008-08-24 21:49:00 -04001264/**
James Smart3621a712009-04-06 18:47:14 -04001265 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001266 *
1267 * Description:
1268 * Macro that given an attr e.g. hba_queue_depth expands
1269 * into a function with the name lpfc_hba_queue_depth_set
1270 *
1271 * lpfc_##attr##_set: Sets an attribute value.
1272 * @phba: pointer the the adapter structure.
1273 * @val: integer attribute value.
1274 *
1275 * Description:
1276 * Validates the min and max values then sets the
1277 * adapter config field if in the valid range. prints error message
1278 * and does not set the parameter if invalid.
1279 *
1280 * Returns:
1281 * zero on success
1282 * -EINVAL if val is invalid
1283 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001284#define lpfc_param_set(attr, default, minval, maxval) \
1285static int \
1286lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1287{ \
1288 if (val >= minval && val <= maxval) {\
1289 phba->cfg_##attr = val;\
1290 return 0;\
1291 }\
1292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001293 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1294 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001295 return -EINVAL;\
1296}
1297
James Smarte59058c2008-08-24 21:49:00 -04001298/**
James Smart3621a712009-04-06 18:47:14 -04001299 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001300 *
1301 * Description:
1302 * Macro that given an attr e.g. hba_queue_depth expands
1303 * into a function with the name lpfc_hba_queue_depth_store.
1304 *
1305 * lpfc_##attr##_store: Set an sttribute value.
1306 * @dev: class device that is converted into a Scsi_host.
1307 * @attr: device attribute, not used.
1308 * @buf: contains the attribute value in ascii.
1309 * @count: not used.
1310 *
1311 * Description:
1312 * Convert the ascii text number to an integer, then
1313 * use the lpfc_##attr##_set function to set the value.
1314 *
1315 * Returns:
1316 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1317 * length of buffer upon success.
1318 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001319#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001320static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001321lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1322 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001323{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001324 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1326 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001327 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001328 if (!isdigit(buf[0]))\
1329 return -EINVAL;\
1330 if (sscanf(buf, "%i", &val) != 1)\
1331 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001332 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001333 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001334 else \
1335 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001336}
1337
James Smarte59058c2008-08-24 21:49:00 -04001338/**
James Smart3621a712009-04-06 18:47:14 -04001339 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001340 *
1341 * Description:
1342 * Macro that given an attr e.g. hba_queue_depth expands
1343 * into a function with the name lpfc_hba_queue_depth_show
1344 *
1345 * lpfc_##attr##_show: prints the attribute value in decimal.
1346 * @dev: class device that is converted into a Scsi_host.
1347 * @attr: device attribute, not used.
1348 * @buf: on return contains the attribute value in decimal.
1349 *
1350 * Returns: length of formatted string.
1351 **/
James Smart3de2a652007-08-02 11:09:59 -04001352#define lpfc_vport_param_show(attr) \
1353static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001354lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1355 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001356{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001357 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001358 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1359 int val = 0;\
1360 val = vport->cfg_##attr;\
1361 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1362}
1363
James Smarte59058c2008-08-24 21:49:00 -04001364/**
James Smart3621a712009-04-06 18:47:14 -04001365 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001366 *
1367 * Description:
1368 * Macro that given an attr e.g.
1369 * hba_queue_depth expands into a function with the name
1370 * lpfc_hba_queue_depth_show
1371 *
James Smart3621a712009-04-06 18:47:14 -04001372 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001373 * @dev: class device that is converted into a Scsi_host.
1374 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001375 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001376 *
1377 * Returns: length of formatted string.
1378 **/
James Smart3de2a652007-08-02 11:09:59 -04001379#define lpfc_vport_param_hex_show(attr) \
1380static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001381lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1382 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001383{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001384 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1386 int val = 0;\
1387 val = vport->cfg_##attr;\
1388 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1389}
1390
James Smarte59058c2008-08-24 21:49:00 -04001391/**
James Smart3621a712009-04-06 18:47:14 -04001392 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001393 *
1394 * Description:
1395 * Macro that given an attr e.g. hba_queue_depth expands
1396 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1397 * takes a default argument, a minimum and maximum argument.
1398 *
1399 * lpfc_##attr##_init: validates the min and max values then sets the
1400 * adapter config field accordingly, or uses the default if out of range
1401 * and prints an error message.
1402 * @phba: pointer the the adapter structure.
1403 * @val: integer attribute value.
1404 *
1405 * Returns:
1406 * zero on success
1407 * -EINVAL if default used
1408 **/
James Smart3de2a652007-08-02 11:09:59 -04001409#define lpfc_vport_param_init(attr, default, minval, maxval) \
1410static int \
1411lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1412{ \
1413 if (val >= minval && val <= maxval) {\
1414 vport->cfg_##attr = val;\
1415 return 0;\
1416 }\
James Smarte8b62012007-08-02 11:10:09 -04001417 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001418 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001419 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001420 vport->cfg_##attr = default;\
1421 return -EINVAL;\
1422}
1423
James Smarte59058c2008-08-24 21:49:00 -04001424/**
James Smart3621a712009-04-06 18:47:14 -04001425 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001426 *
1427 * Description:
1428 * Macro that given an attr e.g. hba_queue_depth expands
1429 * into a function with the name lpfc_hba_queue_depth_set
1430 *
1431 * lpfc_##attr##_set: validates the min and max values then sets the
1432 * adapter config field if in the valid range. prints error message
1433 * and does not set the parameter if invalid.
1434 * @phba: pointer the the adapter structure.
1435 * @val: integer attribute value.
1436 *
1437 * Returns:
1438 * zero on success
1439 * -EINVAL if val is invalid
1440 **/
James Smart3de2a652007-08-02 11:09:59 -04001441#define lpfc_vport_param_set(attr, default, minval, maxval) \
1442static int \
1443lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1444{ \
1445 if (val >= minval && val <= maxval) {\
1446 vport->cfg_##attr = val;\
1447 return 0;\
1448 }\
James Smarte8b62012007-08-02 11:10:09 -04001449 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001450 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001451 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001452 return -EINVAL;\
1453}
1454
James Smarte59058c2008-08-24 21:49:00 -04001455/**
James Smart3621a712009-04-06 18:47:14 -04001456 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001457 *
1458 * Description:
1459 * Macro that given an attr e.g. hba_queue_depth
1460 * expands into a function with the name lpfc_hba_queue_depth_store
1461 *
1462 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1463 * use the lpfc_##attr##_set function to set the value.
1464 * @cdev: class device that is converted into a Scsi_host.
1465 * @buf: contains the attribute value in decimal.
1466 * @count: not used.
1467 *
1468 * Returns:
1469 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1470 * length of buffer upon success.
1471 **/
James Smart3de2a652007-08-02 11:09:59 -04001472#define lpfc_vport_param_store(attr) \
1473static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001474lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1475 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001476{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001477 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1479 int val=0;\
1480 if (!isdigit(buf[0]))\
1481 return -EINVAL;\
1482 if (sscanf(buf, "%i", &val) != 1)\
1483 return -EINVAL;\
1484 if (lpfc_##attr##_set(vport, val) == 0) \
1485 return strlen(buf);\
1486 else \
1487 return -EINVAL;\
1488}
1489
1490
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001491#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1492static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001493module_param(lpfc_##name, int, 0);\
1494MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001495lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001496
1497#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1498static int lpfc_##name = defval;\
1499module_param(lpfc_##name, int, 0);\
1500MODULE_PARM_DESC(lpfc_##name, desc);\
1501lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001502lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001503static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001504
1505#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1506static int lpfc_##name = defval;\
1507module_param(lpfc_##name, int, 0);\
1508MODULE_PARM_DESC(lpfc_##name, desc);\
1509lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001510lpfc_param_init(name, defval, minval, maxval)\
1511lpfc_param_set(name, defval, minval, maxval)\
1512lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001513static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1514 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001515
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001516#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1517static int lpfc_##name = defval;\
1518module_param(lpfc_##name, int, 0);\
1519MODULE_PARM_DESC(lpfc_##name, desc);\
1520lpfc_param_hex_show(name)\
1521lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001522static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001523
1524#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1525static int lpfc_##name = defval;\
1526module_param(lpfc_##name, int, 0);\
1527MODULE_PARM_DESC(lpfc_##name, desc);\
1528lpfc_param_hex_show(name)\
1529lpfc_param_init(name, defval, minval, maxval)\
1530lpfc_param_set(name, defval, minval, maxval)\
1531lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001532static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1533 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001534
James Smart3de2a652007-08-02 11:09:59 -04001535#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1536static int lpfc_##name = defval;\
1537module_param(lpfc_##name, int, 0);\
1538MODULE_PARM_DESC(lpfc_##name, desc);\
1539lpfc_vport_param_init(name, defval, minval, maxval)
1540
1541#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1542static int lpfc_##name = defval;\
1543module_param(lpfc_##name, int, 0);\
1544MODULE_PARM_DESC(lpfc_##name, desc);\
1545lpfc_vport_param_show(name)\
1546lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001547static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001548
1549#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1550static int lpfc_##name = defval;\
1551module_param(lpfc_##name, int, 0);\
1552MODULE_PARM_DESC(lpfc_##name, desc);\
1553lpfc_vport_param_show(name)\
1554lpfc_vport_param_init(name, defval, minval, maxval)\
1555lpfc_vport_param_set(name, defval, minval, maxval)\
1556lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001557static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1558 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001559
1560#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1561static int lpfc_##name = defval;\
1562module_param(lpfc_##name, int, 0);\
1563MODULE_PARM_DESC(lpfc_##name, desc);\
1564lpfc_vport_param_hex_show(name)\
1565lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001566static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001567
1568#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1569static int lpfc_##name = defval;\
1570module_param(lpfc_##name, int, 0);\
1571MODULE_PARM_DESC(lpfc_##name, desc);\
1572lpfc_vport_param_hex_show(name)\
1573lpfc_vport_param_init(name, defval, minval, maxval)\
1574lpfc_vport_param_set(name, defval, minval, maxval)\
1575lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001576static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1577 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001578
James Smart81301a92008-12-04 22:39:46 -05001579static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1580static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1581static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1582static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001583static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1584static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1585static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1586static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1587static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1588static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1589static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1590static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001591static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001592static DEVICE_ATTR(option_rom_version, S_IRUGO,
1593 lpfc_option_rom_version_show, NULL);
1594static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1595 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001596static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001597static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1598static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1599static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1600 lpfc_board_mode_show, lpfc_board_mode_store);
1601static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1602static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1603static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1604static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1605static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1606static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1607static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1608static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1609static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001610
James Smartc3f28af2006-08-18 17:47:18 -04001611
James Smarta12e07b2006-12-02 13:35:30 -05001612static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001613
James Smarte59058c2008-08-24 21:49:00 -04001614/**
James Smart3621a712009-04-06 18:47:14 -04001615 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001616 * @dev: class device that is converted into a Scsi_host.
1617 * @attr: device attribute, not used.
1618 * @buf: containing the string lpfc_soft_wwn_key.
1619 * @count: must be size of lpfc_soft_wwn_key.
1620 *
1621 * Returns:
1622 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1623 * length of buf indicates success
1624 **/
James Smartc3f28af2006-08-18 17:47:18 -04001625static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001626lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1627 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001628{
Tony Jonesee959b02008-02-22 00:13:36 +01001629 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001630 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1631 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001632 unsigned int cnt = count;
1633
1634 /*
1635 * We're doing a simple sanity check for soft_wwpn setting.
1636 * We require that the user write a specific key to enable
1637 * the soft_wwpn attribute to be settable. Once the attribute
1638 * is written, the enable key resets. If further updates are
1639 * desired, the key must be written again to re-enable the
1640 * attribute.
1641 *
1642 * The "key" is not secret - it is a hardcoded string shown
1643 * here. The intent is to protect against the random user or
1644 * application that is just writing attributes.
1645 */
1646
1647 /* count may include a LF at end of string */
1648 if (buf[cnt-1] == '\n')
1649 cnt--;
1650
James Smarta12e07b2006-12-02 13:35:30 -05001651 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1652 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001653 return -EINVAL;
1654
James Smarta12e07b2006-12-02 13:35:30 -05001655 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001656 return count;
1657}
Tony Jonesee959b02008-02-22 00:13:36 +01001658static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1659 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001660
James Smarte59058c2008-08-24 21:49:00 -04001661/**
James Smart3621a712009-04-06 18:47:14 -04001662 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001663 * @dev: class device that is converted into a Scsi_host.
1664 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001665 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001666 *
1667 * Returns: size of formatted string.
1668 **/
James Smartc3f28af2006-08-18 17:47:18 -04001669static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001670lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1671 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001672{
Tony Jonesee959b02008-02-22 00:13:36 +01001673 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001674 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1675 struct lpfc_hba *phba = vport->phba;
1676
Randy Dunlapafc071e2006-10-23 21:47:13 -07001677 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1678 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001679}
1680
James Smarte59058c2008-08-24 21:49:00 -04001681/**
James Smart3621a712009-04-06 18:47:14 -04001682 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001683 * @dev class device that is converted into a Scsi_host.
1684 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001685 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001686 * @count: number of wwpn bytes in buf
1687 *
1688 * Returns:
1689 * -EACCES hba reset not enabled, adapter over temp
1690 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1691 * -EIO error taking adapter offline or online
1692 * value of count on success
1693 **/
James Smartc3f28af2006-08-18 17:47:18 -04001694static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001695lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1696 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001697{
Tony Jonesee959b02008-02-22 00:13:36 +01001698 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1700 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001701 struct completion online_compl;
1702 int stat1=0, stat2=0;
1703 unsigned int i, j, cnt=count;
1704 u8 wwpn[8];
1705
James Smart13815c82008-01-11 01:52:48 -05001706 if (!phba->cfg_enable_hba_reset)
1707 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001708 spin_lock_irq(&phba->hbalock);
1709 if (phba->over_temp_state == HBA_OVER_TEMP) {
1710 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001711 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001712 }
1713 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001714 /* count may include a LF at end of string */
1715 if (buf[cnt-1] == '\n')
1716 cnt--;
1717
James Smarta12e07b2006-12-02 13:35:30 -05001718 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001719 ((cnt == 17) && (*buf++ != 'x')) ||
1720 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1721 return -EINVAL;
1722
James Smarta12e07b2006-12-02 13:35:30 -05001723 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001724
1725 memset(wwpn, 0, sizeof(wwpn));
1726
1727 /* Validate and store the new name */
1728 for (i=0, j=0; i < 16; i++) {
1729 if ((*buf >= 'a') && (*buf <= 'f'))
1730 j = ((j << 4) | ((*buf++ -'a') + 10));
1731 else if ((*buf >= 'A') && (*buf <= 'F'))
1732 j = ((j << 4) | ((*buf++ -'A') + 10));
1733 else if ((*buf >= '0') && (*buf <= '9'))
1734 j = ((j << 4) | (*buf++ -'0'));
1735 else
1736 return -EINVAL;
1737 if (i % 2) {
1738 wwpn[i/2] = j & 0xff;
1739 j = 0;
1740 }
1741 }
1742 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001743 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001744 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001745 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001746
1747 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1748 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1749
James Smart46fa3112007-04-25 09:51:45 -04001750 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001751 if (stat1)
1752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001753 "0463 lpfc_soft_wwpn attribute set failed to "
1754 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001755 init_completion(&online_compl);
1756 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1757 wait_for_completion(&online_compl);
1758 if (stat2)
1759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001760 "0464 lpfc_soft_wwpn attribute set failed to "
1761 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001762 return (stat1 || stat2) ? -EIO : count;
1763}
Tony Jonesee959b02008-02-22 00:13:36 +01001764static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1765 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001766
James Smarte59058c2008-08-24 21:49:00 -04001767/**
James Smart3621a712009-04-06 18:47:14 -04001768 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001769 * @dev: class device that is converted into a Scsi_host.
1770 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001771 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001772 *
1773 * Returns: size of formatted string.
1774 **/
James Smarta12e07b2006-12-02 13:35:30 -05001775static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001776lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1777 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001778{
Tony Jonesee959b02008-02-22 00:13:36 +01001779 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001780 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001781 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1782 (unsigned long long)phba->cfg_soft_wwnn);
1783}
1784
James Smarte59058c2008-08-24 21:49:00 -04001785/**
James Smart3621a712009-04-06 18:47:14 -04001786 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001787 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001788 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001789 * @count: number of wwnn bytes in buf.
1790 *
1791 * Returns:
1792 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1793 * value of count on success
1794 **/
James Smarta12e07b2006-12-02 13:35:30 -05001795static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001796lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1797 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001798{
Tony Jonesee959b02008-02-22 00:13:36 +01001799 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001800 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001801 unsigned int i, j, cnt=count;
1802 u8 wwnn[8];
1803
1804 /* count may include a LF at end of string */
1805 if (buf[cnt-1] == '\n')
1806 cnt--;
1807
1808 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1809 ((cnt == 17) && (*buf++ != 'x')) ||
1810 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1811 return -EINVAL;
1812
1813 /*
1814 * Allow wwnn to be set many times, as long as the enable is set.
1815 * However, once the wwpn is set, everything locks.
1816 */
1817
1818 memset(wwnn, 0, sizeof(wwnn));
1819
1820 /* Validate and store the new name */
1821 for (i=0, j=0; i < 16; i++) {
1822 if ((*buf >= 'a') && (*buf <= 'f'))
1823 j = ((j << 4) | ((*buf++ -'a') + 10));
1824 else if ((*buf >= 'A') && (*buf <= 'F'))
1825 j = ((j << 4) | ((*buf++ -'A') + 10));
1826 else if ((*buf >= '0') && (*buf <= '9'))
1827 j = ((j << 4) | (*buf++ -'0'));
1828 else
1829 return -EINVAL;
1830 if (i % 2) {
1831 wwnn[i/2] = j & 0xff;
1832 j = 0;
1833 }
1834 }
1835 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1836
1837 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1838 "lpfc%d: soft_wwnn set. Value will take effect upon "
1839 "setting of the soft_wwpn\n", phba->brd_no);
1840
1841 return count;
1842}
Tony Jonesee959b02008-02-22 00:13:36 +01001843static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1844 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001845
James Smartc3f28af2006-08-18 17:47:18 -04001846
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001847static int lpfc_poll = 0;
1848module_param(lpfc_poll, int, 0);
1849MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1850 " 0 - none,"
1851 " 1 - poll with interrupts enabled"
1852 " 3 - poll and disable FCP ring interrupts");
1853
Tony Jonesee959b02008-02-22 00:13:36 +01001854static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1855 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001856
James Smart92d7f7b2007-06-17 19:56:38 -05001857int lpfc_sli_mode = 0;
1858module_param(lpfc_sli_mode, int, 0);
1859MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1860 " 0 - auto (SLI-3 if supported),"
1861 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1862 " 3 - select SLI-3");
1863
James Smart7ee5d432007-10-27 13:37:17 -04001864int lpfc_enable_npiv = 0;
1865module_param(lpfc_enable_npiv, int, 0);
1866MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1867lpfc_param_show(enable_npiv);
1868lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001869static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001870 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001871
dea31012005-04-17 16:05:31 -05001872/*
James Smartc01f3202006-08-18 17:47:08 -04001873# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1874# until the timer expires. Value range is [0,255]. Default value is 30.
1875*/
1876static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1877static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1878module_param(lpfc_nodev_tmo, int, 0);
1879MODULE_PARM_DESC(lpfc_nodev_tmo,
1880 "Seconds driver will hold I/O waiting "
1881 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001882
1883/**
James Smart3621a712009-04-06 18:47:14 -04001884 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04001885 * @dev: class converted to a Scsi_host structure.
1886 * @attr: device attribute, not used.
1887 * @buf: on return contains the dev loss timeout in decimal.
1888 *
1889 * Returns: size of formatted string.
1890 **/
James Smartc01f3202006-08-18 17:47:08 -04001891static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001892lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1893 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001894{
Tony Jonesee959b02008-02-22 00:13:36 +01001895 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001896 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001897 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001898 val = vport->cfg_devloss_tmo;
1899 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001900}
1901
James Smarte59058c2008-08-24 21:49:00 -04001902/**
James Smart3621a712009-04-06 18:47:14 -04001903 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04001904 * @vport: lpfc vport structure pointer.
1905 * @val: contains the nodev timeout value.
1906 *
1907 * Description:
1908 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1909 * a kernel error message is printed and zero is returned.
1910 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1911 * Otherwise nodev tmo is set to the default value.
1912 *
1913 * Returns:
1914 * zero if already set or if val is in range
1915 * -EINVAL val out of range
1916 **/
James Smartc01f3202006-08-18 17:47:08 -04001917static int
James Smart3de2a652007-08-02 11:09:59 -04001918lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001919{
James Smart3de2a652007-08-02 11:09:59 -04001920 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1921 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1922 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001923 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001924 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001925 "parameter because devloss_tmo is "
1926 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001927 return 0;
1928 }
1929
1930 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001931 vport->cfg_nodev_tmo = val;
1932 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001933 return 0;
1934 }
James Smarte8b62012007-08-02 11:10:09 -04001935 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1936 "0400 lpfc_nodev_tmo attribute cannot be set to"
1937 " %d, allowed range is [%d, %d]\n",
1938 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001939 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001940 return -EINVAL;
1941}
1942
James Smarte59058c2008-08-24 21:49:00 -04001943/**
James Smart3621a712009-04-06 18:47:14 -04001944 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04001945 * @vport: lpfc vport structure pointer.
1946 *
1947 * Description:
1948 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1949 **/
James Smart7054a602007-04-25 09:52:34 -04001950static void
James Smart3de2a652007-08-02 11:09:59 -04001951lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001952{
James Smart858c9f62007-06-17 19:56:39 -05001953 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001954 struct lpfc_nodelist *ndlp;
1955
James Smart51ef4c22007-08-02 11:10:31 -04001956 shost = lpfc_shost_from_vport(vport);
1957 spin_lock_irq(shost->host_lock);
1958 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001959 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001960 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1961 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001962}
1963
James Smarte59058c2008-08-24 21:49:00 -04001964/**
James Smart3621a712009-04-06 18:47:14 -04001965 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04001966 * @vport: lpfc vport structure pointer.
1967 * @val: contains the tmo value.
1968 *
1969 * Description:
1970 * If the devloss tmo is already set or the vport dev loss tmo has changed
1971 * then a kernel error message is printed and zero is returned.
1972 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1973 * Otherwise nodev tmo is set to the default value.
1974 *
1975 * Returns:
1976 * zero if already set or if val is in range
1977 * -EINVAL val out of range
1978 **/
James Smartc01f3202006-08-18 17:47:08 -04001979static int
James Smart3de2a652007-08-02 11:09:59 -04001980lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001981{
James Smart3de2a652007-08-02 11:09:59 -04001982 if (vport->dev_loss_tmo_changed ||
1983 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001984 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1985 "0401 Ignoring change to nodev_tmo "
1986 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001987 return 0;
1988 }
James Smartc01f3202006-08-18 17:47:08 -04001989 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001990 vport->cfg_nodev_tmo = val;
1991 vport->cfg_devloss_tmo = val;
1992 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001993 return 0;
1994 }
James Smarte8b62012007-08-02 11:10:09 -04001995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1996 "0403 lpfc_nodev_tmo attribute cannot be set to"
1997 "%d, allowed range is [%d, %d]\n",
1998 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001999 return -EINVAL;
2000}
2001
James Smart3de2a652007-08-02 11:09:59 -04002002lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002003
Tony Jonesee959b02008-02-22 00:13:36 +01002004static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2005 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002006
2007/*
2008# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2009# disappear until the timer expires. Value range is [0,255]. Default
2010# value is 30.
2011*/
2012module_param(lpfc_devloss_tmo, int, 0);
2013MODULE_PARM_DESC(lpfc_devloss_tmo,
2014 "Seconds driver will hold I/O waiting "
2015 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002016lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2017 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2018lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002019
2020/**
James Smart3621a712009-04-06 18:47:14 -04002021 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002022 * @vport: lpfc vport structure pointer.
2023 * @val: contains the tmo value.
2024 *
2025 * Description:
2026 * If val is in a valid range then set the vport nodev tmo,
2027 * devloss tmo, also set the vport dev loss tmo changed flag.
2028 * Else a kernel error message is printed.
2029 *
2030 * Returns:
2031 * zero if val is in range
2032 * -EINVAL val out of range
2033 **/
James Smartc01f3202006-08-18 17:47:08 -04002034static int
James Smart3de2a652007-08-02 11:09:59 -04002035lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002036{
2037 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002038 vport->cfg_nodev_tmo = val;
2039 vport->cfg_devloss_tmo = val;
2040 vport->dev_loss_tmo_changed = 1;
2041 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002042 return 0;
2043 }
2044
James Smarte8b62012007-08-02 11:10:09 -04002045 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2046 "0404 lpfc_devloss_tmo attribute cannot be set to"
2047 " %d, allowed range is [%d, %d]\n",
2048 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002049 return -EINVAL;
2050}
2051
James Smart3de2a652007-08-02 11:09:59 -04002052lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002053static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2054 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002055
2056/*
dea31012005-04-17 16:05:31 -05002057# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2058# deluged with LOTS of information.
2059# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002060# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002061*/
James Smartf4b4c682009-05-22 14:53:12 -04002062LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002063 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002064
2065/*
James Smart7ee5d432007-10-27 13:37:17 -04002066# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2067# objects that have been registered with the nameserver after login.
2068*/
2069LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2070 "Deregister nameserver objects before LOGO");
2071
2072/*
dea31012005-04-17 16:05:31 -05002073# lun_queue_depth: This parameter is used to limit the number of outstanding
2074# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2075*/
James Smart3de2a652007-08-02 11:09:59 -04002076LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2077 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002078
2079/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002080# hba_queue_depth: This parameter is used to limit the number of outstanding
2081# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2082# value is greater than the maximum number of exchanges supported by the HBA,
2083# then maximum number of exchanges supported by the HBA is used to determine
2084# the hba_queue_depth.
2085*/
2086LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2087 "Max number of FCP commands we can queue to a lpfc HBA");
2088
2089/*
James Smart92d7f7b2007-06-17 19:56:38 -05002090# peer_port_login: This parameter allows/prevents logins
2091# between peer ports hosted on the same physical port.
2092# When this parameter is set 0 peer ports of same physical port
2093# are not allowed to login to each other.
2094# When this parameter is set 1 peer ports of same physical port
2095# are allowed to login to each other.
2096# Default value of this parameter is 0.
2097*/
James Smart3de2a652007-08-02 11:09:59 -04002098LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2099 "Allow peer ports on the same physical port to login to each "
2100 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002101
2102/*
James Smart3de2a652007-08-02 11:09:59 -04002103# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002104# between Virtual Ports and remote initiators.
2105# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2106# other initiators and will attempt to PLOGI all remote ports.
2107# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2108# remote ports and will not attempt to PLOGI to other initiators.
2109# This parameter does not restrict to the physical port.
2110# This parameter does not restrict logins to Fabric resident remote ports.
2111# Default value of this parameter is 1.
2112*/
James Smart3de2a652007-08-02 11:09:59 -04002113static int lpfc_restrict_login = 1;
2114module_param(lpfc_restrict_login, int, 0);
2115MODULE_PARM_DESC(lpfc_restrict_login,
2116 "Restrict virtual ports login to remote initiators.");
2117lpfc_vport_param_show(restrict_login);
2118
James Smarte59058c2008-08-24 21:49:00 -04002119/**
James Smart3621a712009-04-06 18:47:14 -04002120 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002121 * @vport: lpfc vport structure pointer.
2122 * @val: contains the restrict login value.
2123 *
2124 * Description:
2125 * If val is not in a valid range then log a kernel error message and set
2126 * the vport restrict login to one.
2127 * If the port type is physical clear the restrict login flag and return.
2128 * Else set the restrict login flag to val.
2129 *
2130 * Returns:
2131 * zero if val is in range
2132 * -EINVAL val out of range
2133 **/
James Smart3de2a652007-08-02 11:09:59 -04002134static int
2135lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2136{
2137 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002138 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002139 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002140 "be set to %d, allowed range is [0, 1]\n",
2141 val);
James Smart3de2a652007-08-02 11:09:59 -04002142 vport->cfg_restrict_login = 1;
2143 return -EINVAL;
2144 }
2145 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2146 vport->cfg_restrict_login = 0;
2147 return 0;
2148 }
2149 vport->cfg_restrict_login = val;
2150 return 0;
2151}
2152
James Smarte59058c2008-08-24 21:49:00 -04002153/**
James Smart3621a712009-04-06 18:47:14 -04002154 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002155 * @vport: lpfc vport structure pointer.
2156 * @val: contains the restrict login value.
2157 *
2158 * Description:
2159 * If val is not in a valid range then log a kernel error message and set
2160 * the vport restrict login to one.
2161 * If the port type is physical and the val is not zero log a kernel
2162 * error message, clear the restrict login flag and return zero.
2163 * Else set the restrict login flag to val.
2164 *
2165 * Returns:
2166 * zero if val is in range
2167 * -EINVAL val out of range
2168 **/
James Smart3de2a652007-08-02 11:09:59 -04002169static int
2170lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2171{
2172 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002173 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002174 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002175 "be set to %d, allowed range is [0, 1]\n",
2176 val);
James Smart3de2a652007-08-02 11:09:59 -04002177 vport->cfg_restrict_login = 1;
2178 return -EINVAL;
2179 }
2180 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002181 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2182 "0468 lpfc_restrict_login must be 0 for "
2183 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002184 vport->cfg_restrict_login = 0;
2185 return 0;
2186 }
2187 vport->cfg_restrict_login = val;
2188 return 0;
2189}
2190lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002191static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2192 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002193
2194/*
dea31012005-04-17 16:05:31 -05002195# Some disk devices have a "select ID" or "select Target" capability.
2196# From a protocol standpoint "select ID" usually means select the
2197# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2198# annex" which contains a table that maps a "select ID" (a number
2199# between 0 and 7F) to an ALPA. By default, for compatibility with
2200# older drivers, the lpfc driver scans this table from low ALPA to high
2201# ALPA.
2202#
2203# Turning on the scan-down variable (on = 1, off = 0) will
2204# cause the lpfc driver to use an inverted table, effectively
2205# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2206#
2207# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2208# and will not work across a fabric. Also this parameter will take
2209# effect only in the case when ALPA map is not available.)
2210*/
James Smart3de2a652007-08-02 11:09:59 -04002211LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2212 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002213
2214/*
dea31012005-04-17 16:05:31 -05002215# lpfc_topology: link topology for init link
2216# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002217# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002218# 0x02 = attempt point-to-point mode only
2219# 0x04 = attempt loop mode only
2220# 0x06 = attempt point-to-point mode then loop
2221# Set point-to-point mode if you want to run as an N_Port.
2222# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2223# Default value is 0.
2224*/
James Smarte59058c2008-08-24 21:49:00 -04002225
2226/**
James Smart3621a712009-04-06 18:47:14 -04002227 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002228 * @phba: lpfc_hba pointer.
2229 * @val: topology value.
2230 *
2231 * Description:
2232 * If val is in a valid range then set the adapter's topology field and
2233 * issue a lip; if the lip fails reset the topology to the old value.
2234 *
2235 * If the value is not in range log a kernel error message and return an error.
2236 *
2237 * Returns:
2238 * zero if val is in range and lip okay
2239 * non-zero return value from lpfc_issue_lip()
2240 * -EINVAL val out of range
2241 **/
James Smarta257bf92009-04-06 18:48:10 -04002242static ssize_t
2243lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2244 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002245{
James Smarta257bf92009-04-06 18:48:10 -04002246 struct Scsi_Host *shost = class_to_shost(dev);
2247 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2248 struct lpfc_hba *phba = vport->phba;
2249 int val = 0;
2250 int nolip = 0;
2251 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002252 int err;
2253 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002254
2255 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2256 nolip = 1;
2257 val_buf = &buf[strlen("nolip ")];
2258 }
2259
2260 if (!isdigit(val_buf[0]))
2261 return -EINVAL;
2262 if (sscanf(val_buf, "%i", &val) != 1)
2263 return -EINVAL;
2264
James Smart83108bd2008-01-11 01:53:09 -05002265 if (val >= 0 && val <= 6) {
2266 prev_val = phba->cfg_topology;
2267 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002268 if (nolip)
2269 return strlen(buf);
2270
James Smart83108bd2008-01-11 01:53:09 -05002271 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002272 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002273 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002274 return -EINVAL;
2275 } else
2276 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002277 }
2278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2279 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2280 "allowed range is [0, 6]\n",
2281 phba->brd_no, val);
2282 return -EINVAL;
2283}
2284static int lpfc_topology = 0;
2285module_param(lpfc_topology, int, 0);
2286MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2287lpfc_param_show(topology)
2288lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002289static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002290 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002291
James Smart21e9a0a2009-05-22 14:53:21 -04002292/**
2293 * lpfc_static_vport_show: Read callback function for
2294 * lpfc_static_vport sysfs file.
2295 * @dev: Pointer to class device object.
2296 * @attr: device attribute structure.
2297 * @buf: Data buffer.
2298 *
2299 * This function is the read call back function for
2300 * lpfc_static_vport sysfs file. The lpfc_static_vport
2301 * sysfs file report the mageability of the vport.
2302 **/
2303static ssize_t
2304lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2305 char *buf)
2306{
2307 struct Scsi_Host *shost = class_to_shost(dev);
2308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2309 if (vport->vport_flag & STATIC_VPORT)
2310 sprintf(buf, "1\n");
2311 else
2312 sprintf(buf, "0\n");
2313
2314 return strlen(buf);
2315}
2316
2317/*
2318 * Sysfs attribute to control the statistical data collection.
2319 */
2320static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2321 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002322
2323/**
James Smart3621a712009-04-06 18:47:14 -04002324 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002325 * @dev: Pointer to class device.
2326 * @buf: Data buffer.
2327 * @count: Size of the data buffer.
2328 *
2329 * This function get called when an user write to the lpfc_stat_data_ctrl
2330 * sysfs file. This function parse the command written to the sysfs file
2331 * and take appropriate action. These commands are used for controlling
2332 * driver statistical data collection.
2333 * Following are the command this function handles.
2334 *
2335 * setbucket <bucket_type> <base> <step>
2336 * = Set the latency buckets.
2337 * destroybucket = destroy all the buckets.
2338 * start = start data collection
2339 * stop = stop data collection
2340 * reset = reset the collected data
2341 **/
2342static ssize_t
2343lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2344 const char *buf, size_t count)
2345{
2346 struct Scsi_Host *shost = class_to_shost(dev);
2347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2348 struct lpfc_hba *phba = vport->phba;
2349#define LPFC_MAX_DATA_CTRL_LEN 1024
2350 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2351 unsigned long i;
2352 char *str_ptr, *token;
2353 struct lpfc_vport **vports;
2354 struct Scsi_Host *v_shost;
2355 char *bucket_type_str, *base_str, *step_str;
2356 unsigned long base, step, bucket_type;
2357
2358 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002359 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002360 return -EINVAL;
2361
2362 strcpy(bucket_data, buf);
2363 str_ptr = &bucket_data[0];
2364 /* Ignore this token - this is command token */
2365 token = strsep(&str_ptr, "\t ");
2366 if (!token)
2367 return -EINVAL;
2368
2369 bucket_type_str = strsep(&str_ptr, "\t ");
2370 if (!bucket_type_str)
2371 return -EINVAL;
2372
2373 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2374 bucket_type = LPFC_LINEAR_BUCKET;
2375 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2376 bucket_type = LPFC_POWER2_BUCKET;
2377 else
2378 return -EINVAL;
2379
2380 base_str = strsep(&str_ptr, "\t ");
2381 if (!base_str)
2382 return -EINVAL;
2383 base = simple_strtoul(base_str, NULL, 0);
2384
2385 step_str = strsep(&str_ptr, "\t ");
2386 if (!step_str)
2387 return -EINVAL;
2388 step = simple_strtoul(step_str, NULL, 0);
2389 if (!step)
2390 return -EINVAL;
2391
2392 /* Block the data collection for every vport */
2393 vports = lpfc_create_vport_work_array(phba);
2394 if (vports == NULL)
2395 return -ENOMEM;
2396
James Smartf4b4c682009-05-22 14:53:12 -04002397 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002398 v_shost = lpfc_shost_from_vport(vports[i]);
2399 spin_lock_irq(v_shost->host_lock);
2400 /* Block and reset data collection */
2401 vports[i]->stat_data_blocked = 1;
2402 if (vports[i]->stat_data_enabled)
2403 lpfc_vport_reset_stat_data(vports[i]);
2404 spin_unlock_irq(v_shost->host_lock);
2405 }
2406
2407 /* Set the bucket attributes */
2408 phba->bucket_type = bucket_type;
2409 phba->bucket_base = base;
2410 phba->bucket_step = step;
2411
James Smartf4b4c682009-05-22 14:53:12 -04002412 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002413 v_shost = lpfc_shost_from_vport(vports[i]);
2414
2415 /* Unblock data collection */
2416 spin_lock_irq(v_shost->host_lock);
2417 vports[i]->stat_data_blocked = 0;
2418 spin_unlock_irq(v_shost->host_lock);
2419 }
2420 lpfc_destroy_vport_work_array(phba, vports);
2421 return strlen(buf);
2422 }
2423
2424 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2425 vports = lpfc_create_vport_work_array(phba);
2426 if (vports == NULL)
2427 return -ENOMEM;
2428
James Smartf4b4c682009-05-22 14:53:12 -04002429 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002430 v_shost = lpfc_shost_from_vport(vports[i]);
2431 spin_lock_irq(shost->host_lock);
2432 vports[i]->stat_data_blocked = 1;
2433 lpfc_free_bucket(vport);
2434 vport->stat_data_enabled = 0;
2435 vports[i]->stat_data_blocked = 0;
2436 spin_unlock_irq(shost->host_lock);
2437 }
2438 lpfc_destroy_vport_work_array(phba, vports);
2439 phba->bucket_type = LPFC_NO_BUCKET;
2440 phba->bucket_base = 0;
2441 phba->bucket_step = 0;
2442 return strlen(buf);
2443 }
2444
2445 if (!strncmp(buf, "start", strlen("start"))) {
2446 /* If no buckets configured return error */
2447 if (phba->bucket_type == LPFC_NO_BUCKET)
2448 return -EINVAL;
2449 spin_lock_irq(shost->host_lock);
2450 if (vport->stat_data_enabled) {
2451 spin_unlock_irq(shost->host_lock);
2452 return strlen(buf);
2453 }
2454 lpfc_alloc_bucket(vport);
2455 vport->stat_data_enabled = 1;
2456 spin_unlock_irq(shost->host_lock);
2457 return strlen(buf);
2458 }
2459
2460 if (!strncmp(buf, "stop", strlen("stop"))) {
2461 spin_lock_irq(shost->host_lock);
2462 if (vport->stat_data_enabled == 0) {
2463 spin_unlock_irq(shost->host_lock);
2464 return strlen(buf);
2465 }
2466 lpfc_free_bucket(vport);
2467 vport->stat_data_enabled = 0;
2468 spin_unlock_irq(shost->host_lock);
2469 return strlen(buf);
2470 }
2471
2472 if (!strncmp(buf, "reset", strlen("reset"))) {
2473 if ((phba->bucket_type == LPFC_NO_BUCKET)
2474 || !vport->stat_data_enabled)
2475 return strlen(buf);
2476 spin_lock_irq(shost->host_lock);
2477 vport->stat_data_blocked = 1;
2478 lpfc_vport_reset_stat_data(vport);
2479 vport->stat_data_blocked = 0;
2480 spin_unlock_irq(shost->host_lock);
2481 return strlen(buf);
2482 }
2483 return -EINVAL;
2484}
2485
2486
2487/**
James Smart3621a712009-04-06 18:47:14 -04002488 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002489 * @dev: Pointer to class device object.
2490 * @buf: Data buffer.
2491 *
2492 * This function is the read call back function for
2493 * lpfc_stat_data_ctrl sysfs file. This function report the
2494 * current statistical data collection state.
2495 **/
2496static ssize_t
2497lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2498 char *buf)
2499{
2500 struct Scsi_Host *shost = class_to_shost(dev);
2501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2502 struct lpfc_hba *phba = vport->phba;
2503 int index = 0;
2504 int i;
2505 char *bucket_type;
2506 unsigned long bucket_value;
2507
2508 switch (phba->bucket_type) {
2509 case LPFC_LINEAR_BUCKET:
2510 bucket_type = "linear";
2511 break;
2512 case LPFC_POWER2_BUCKET:
2513 bucket_type = "power2";
2514 break;
2515 default:
2516 bucket_type = "No Bucket";
2517 break;
2518 }
2519
2520 sprintf(&buf[index], "Statistical Data enabled :%d, "
2521 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2522 " Bucket step :%d\nLatency Ranges :",
2523 vport->stat_data_enabled, vport->stat_data_blocked,
2524 bucket_type, phba->bucket_base, phba->bucket_step);
2525 index = strlen(buf);
2526 if (phba->bucket_type != LPFC_NO_BUCKET) {
2527 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2528 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2529 bucket_value = phba->bucket_base +
2530 phba->bucket_step * i;
2531 else
2532 bucket_value = phba->bucket_base +
2533 (1 << i) * phba->bucket_step;
2534
2535 if (index + 10 > PAGE_SIZE)
2536 break;
2537 sprintf(&buf[index], "%08ld ", bucket_value);
2538 index = strlen(buf);
2539 }
2540 }
2541 sprintf(&buf[index], "\n");
2542 return strlen(buf);
2543}
2544
2545/*
2546 * Sysfs attribute to control the statistical data collection.
2547 */
2548static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2549 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2550
2551/*
2552 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2553 */
2554
2555/*
2556 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2557 * for each target.
2558 */
2559#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2560#define MAX_STAT_DATA_SIZE_PER_TARGET \
2561 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2562
2563
2564/**
James Smart3621a712009-04-06 18:47:14 -04002565 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
James Smartea2151b2008-09-07 11:52:10 -04002566 * @kobj: Pointer to the kernel object
2567 * @bin_attr: Attribute object
2568 * @buff: Buffer pointer
2569 * @off: File offset
2570 * @count: Buffer size
2571 *
2572 * This function is the read call back function for lpfc_drvr_stat_data
2573 * sysfs file. This function export the statistical data to user
2574 * applications.
2575 **/
2576static ssize_t
2577sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2578 char *buf, loff_t off, size_t count)
2579{
2580 struct device *dev = container_of(kobj, struct device,
2581 kobj);
2582 struct Scsi_Host *shost = class_to_shost(dev);
2583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2584 struct lpfc_hba *phba = vport->phba;
2585 int i = 0, index = 0;
2586 unsigned long nport_index;
2587 struct lpfc_nodelist *ndlp = NULL;
2588 nport_index = (unsigned long)off /
2589 MAX_STAT_DATA_SIZE_PER_TARGET;
2590
2591 if (!vport->stat_data_enabled || vport->stat_data_blocked
2592 || (phba->bucket_type == LPFC_NO_BUCKET))
2593 return 0;
2594
2595 spin_lock_irq(shost->host_lock);
2596 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2597 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2598 continue;
2599
2600 if (nport_index > 0) {
2601 nport_index--;
2602 continue;
2603 }
2604
2605 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2606 > count)
2607 break;
2608
2609 if (!ndlp->lat_data)
2610 continue;
2611
2612 /* Print the WWN */
2613 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2614 ndlp->nlp_portname.u.wwn[0],
2615 ndlp->nlp_portname.u.wwn[1],
2616 ndlp->nlp_portname.u.wwn[2],
2617 ndlp->nlp_portname.u.wwn[3],
2618 ndlp->nlp_portname.u.wwn[4],
2619 ndlp->nlp_portname.u.wwn[5],
2620 ndlp->nlp_portname.u.wwn[6],
2621 ndlp->nlp_portname.u.wwn[7]);
2622
2623 index = strlen(buf);
2624
2625 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2626 sprintf(&buf[index], "%010u,",
2627 ndlp->lat_data[i].cmd_count);
2628 index = strlen(buf);
2629 }
2630 sprintf(&buf[index], "\n");
2631 index = strlen(buf);
2632 }
2633 spin_unlock_irq(shost->host_lock);
2634 return index;
2635}
2636
2637static struct bin_attribute sysfs_drvr_stat_data_attr = {
2638 .attr = {
2639 .name = "lpfc_drvr_stat_data",
2640 .mode = S_IRUSR,
2641 .owner = THIS_MODULE,
2642 },
2643 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2644 .read = sysfs_drvr_stat_data_read,
2645 .write = NULL,
2646};
2647
dea31012005-04-17 16:05:31 -05002648/*
2649# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2650# connection.
2651# 0 = auto select (default)
2652# 1 = 1 Gigabaud
2653# 2 = 2 Gigabaud
2654# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002655# 8 = 8 Gigabaud
2656# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002657*/
James Smarte59058c2008-08-24 21:49:00 -04002658
2659/**
James Smart3621a712009-04-06 18:47:14 -04002660 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002661 * @phba: lpfc_hba pointer.
2662 * @val: link speed value.
2663 *
2664 * Description:
2665 * If val is in a valid range then set the adapter's link speed field and
2666 * issue a lip; if the lip fails reset the link speed to the old value.
2667 *
2668 * Notes:
2669 * If the value is not in range log a kernel error message and return an error.
2670 *
2671 * Returns:
2672 * zero if val is in range and lip okay.
2673 * non-zero return value from lpfc_issue_lip()
2674 * -EINVAL val out of range
2675 **/
James Smarta257bf92009-04-06 18:48:10 -04002676static ssize_t
2677lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2678 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002679{
James Smarta257bf92009-04-06 18:48:10 -04002680 struct Scsi_Host *shost = class_to_shost(dev);
2681 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2682 struct lpfc_hba *phba = vport->phba;
2683 int val = 0;
2684 int nolip = 0;
2685 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002686 int err;
2687 uint32_t prev_val;
2688
James Smarta257bf92009-04-06 18:48:10 -04002689 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2690 nolip = 1;
2691 val_buf = &buf[strlen("nolip ")];
2692 }
2693
2694 if (!isdigit(val_buf[0]))
2695 return -EINVAL;
2696 if (sscanf(val_buf, "%i", &val) != 1)
2697 return -EINVAL;
2698
James Smart83108bd2008-01-11 01:53:09 -05002699 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2700 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2701 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2702 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2703 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2704 return -EINVAL;
2705
James Smarta257bf92009-04-06 18:48:10 -04002706 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002707 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2708 prev_val = phba->cfg_link_speed;
2709 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002710 if (nolip)
2711 return strlen(buf);
2712
James Smart83108bd2008-01-11 01:53:09 -05002713 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002714 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002715 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002716 return -EINVAL;
2717 } else
2718 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002719 }
2720
2721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2722 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2723 "allowed range is [0, 8]\n",
2724 phba->brd_no, val);
2725 return -EINVAL;
2726}
2727
2728static int lpfc_link_speed = 0;
2729module_param(lpfc_link_speed, int, 0);
2730MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2731lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002732
2733/**
James Smart3621a712009-04-06 18:47:14 -04002734 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002735 * @phba: lpfc_hba pointer.
2736 * @val: link speed value.
2737 *
2738 * Description:
2739 * If val is in a valid range then set the adapter's link speed field.
2740 *
2741 * Notes:
2742 * If the value is not in range log a kernel error message, clear the link
2743 * speed and return an error.
2744 *
2745 * Returns:
2746 * zero if val saved.
2747 * -EINVAL val out of range
2748 **/
James Smart83108bd2008-01-11 01:53:09 -05002749static int
2750lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2751{
2752 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2753 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2754 phba->cfg_link_speed = val;
2755 return 0;
2756 }
2757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002758 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002759 "be set to %d, allowed values are "
2760 "["LPFC_LINK_SPEED_STRING"]\n", val);
2761 phba->cfg_link_speed = 0;
2762 return -EINVAL;
2763}
2764
Tony Jonesee959b02008-02-22 00:13:36 +01002765static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002766 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002767
2768/*
2769# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2770# Value range is [2,3]. Default value is 3.
2771*/
James Smart3de2a652007-08-02 11:09:59 -04002772LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2773 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002774
2775/*
2776# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2777# is [0,1]. Default value is 0.
2778*/
James Smart3de2a652007-08-02 11:09:59 -04002779LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2780 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002781
2782/*
James Smart977b5a02008-09-07 11:52:04 -04002783# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2784# depth. Default value is 0. When the value of this parameter is zero the
2785# SCSI command completion time is not used for controlling I/O queue depth. When
2786# the parameter is set to a non-zero value, the I/O queue depth is controlled
2787# to limit the I/O completion time to the parameter value.
2788# The value is set in milliseconds.
2789*/
2790static int lpfc_max_scsicmpl_time;
2791module_param(lpfc_max_scsicmpl_time, int, 0);
2792MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2793 "Use command completion time to control queue depth");
2794lpfc_vport_param_show(max_scsicmpl_time);
2795lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2796static int
2797lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2798{
2799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2800 struct lpfc_nodelist *ndlp, *next_ndlp;
2801
2802 if (val == vport->cfg_max_scsicmpl_time)
2803 return 0;
2804 if ((val < 0) || (val > 60000))
2805 return -EINVAL;
2806 vport->cfg_max_scsicmpl_time = val;
2807
2808 spin_lock_irq(shost->host_lock);
2809 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2810 if (!NLP_CHK_NODE_ACT(ndlp))
2811 continue;
2812 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2813 continue;
2814 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2815 }
2816 spin_unlock_irq(shost->host_lock);
2817 return 0;
2818}
2819lpfc_vport_param_store(max_scsicmpl_time);
2820static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2821 lpfc_max_scsicmpl_time_show,
2822 lpfc_max_scsicmpl_time_store);
2823
2824/*
dea31012005-04-17 16:05:31 -05002825# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2826# range is [0,1]. Default value is 0.
2827*/
2828LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2829
2830/*
2831# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2832# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04002833# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05002834# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2835# cr_delay is set to 0.
2836*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002837LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05002838 "interrupt response is generated");
2839
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002840LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05002841 "interrupt response is generated");
2842
2843/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002844# lpfc_multi_ring_support: Determines how many rings to spread available
2845# cmd/rsp IOCB entries across.
2846# Value range is [1,2]. Default value is 1.
2847*/
2848LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2849 "SLI rings to spread IOCB entries across");
2850
2851/*
James Smarta4bc3372006-12-02 13:34:16 -05002852# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2853# identifies what rctl value to configure the additional ring for.
2854# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2855*/
James Smart6a9c52c2009-10-02 15:16:51 -04002856LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05002857 255, "Identifies RCTL for additional ring configuration");
2858
2859/*
2860# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2861# identifies what type value to configure the additional ring for.
2862# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2863*/
James Smart6a9c52c2009-10-02 15:16:51 -04002864LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05002865 255, "Identifies TYPE for additional ring configuration");
2866
2867/*
dea31012005-04-17 16:05:31 -05002868# lpfc_fdmi_on: controls FDMI support.
2869# 0 = no FDMI support
2870# 1 = support FDMI without attribute of hostname
2871# 2 = support FDMI with attribute of hostname
2872# Value range [0,2]. Default value is 0.
2873*/
James Smart3de2a652007-08-02 11:09:59 -04002874LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05002875
2876/*
2877# Specifies the maximum number of ELS cmds we can have outstanding (for
2878# discovery). Value range is [1,64]. Default value = 32.
2879*/
James Smart3de2a652007-08-02 11:09:59 -04002880LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05002881 "during discovery");
2882
2883/*
James Smart65a29c12006-07-06 15:50:50 -04002884# lpfc_max_luns: maximum allowed LUN.
2885# Value range is [0,65535]. Default value is 255.
2886# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05002887*/
James Smart3de2a652007-08-02 11:09:59 -04002888LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05002889
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002890/*
2891# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2892# Value range is [1,255], default value is 10.
2893*/
2894LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2895 "Milliseconds driver will wait between polling FCP ring");
2896
James Smart4ff43242006-12-02 13:34:56 -05002897/*
2898# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2899# support this feature
James Smartda0436e2009-05-22 14:51:39 -04002900# 0 = MSI disabled (default)
James Smart4ff43242006-12-02 13:34:56 -05002901# 1 = MSI enabled
James Smartda0436e2009-05-22 14:51:39 -04002902# 2 = MSI-X enabled
2903# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05002904*/
James Smartda0436e2009-05-22 14:51:39 -04002905LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05002906 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05002907
James Smart13815c82008-01-11 01:52:48 -05002908/*
James Smartda0436e2009-05-22 14:51:39 -04002909# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
2910#
2911# Value range is [636,651042]. Default value is 10000.
2912*/
2913LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
2914 "Set the maximum number of fast-path FCP interrupts per second");
2915
2916/*
2917# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
2918#
2919# Value range is [1,31]. Default value is 4.
2920*/
2921LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
2922 "Set the number of fast-path FCP work queues, if possible");
2923
2924/*
2925# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
2926#
2927# Value range is [1,7]. Default value is 1.
2928*/
2929LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
2930 "Set the number of fast-path FCP event queues, if possible");
2931
2932/*
James Smart13815c82008-01-11 01:52:48 -05002933# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2934# 0 = HBA resets disabled
2935# 1 = HBA resets enabled (default)
2936# Value range is [0,1]. Default value is 1.
2937*/
2938LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04002939
James Smart13815c82008-01-11 01:52:48 -05002940/*
2941# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2942# 0 = HBA Heartbeat disabled
2943# 1 = HBA Heartbeat enabled (default)
2944# Value range is [0,1]. Default value is 1.
2945*/
2946LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05002947
James Smart83108bd2008-01-11 01:53:09 -05002948/*
James Smart81301a92008-12-04 22:39:46 -05002949# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
2950# 0 = BlockGuard disabled (default)
2951# 1 = BlockGuard enabled
2952# Value range is [0,1]. Default value is 0.
2953*/
2954LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
2955
James Smart6fb120a2009-05-22 14:52:59 -04002956/*
2957# lpfc_enable_fip: When set, FIP is required to start discovery. If not
2958# set, the driver will add an FCF record manually if the port has no
2959# FCF records available and start discovery.
2960# Value range is [0,1]. Default value is 1 (enabled)
2961*/
2962LPFC_ATTR_RW(enable_fip, 0, 0, 1, "Enable FIP Discovery");
2963
James Smart81301a92008-12-04 22:39:46 -05002964
2965/*
2966# lpfc_prot_mask: i
2967# - Bit mask of host protection capabilities used to register with the
2968# SCSI mid-layer
2969# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
2970# - Allows you to ultimately specify which profiles to use
2971# - Default will result in registering capabilities for all profiles.
2972#
2973*/
2974unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
2975
2976module_param(lpfc_prot_mask, uint, 0);
2977MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
2978
2979/*
2980# lpfc_prot_guard: i
2981# - Bit mask of protection guard types to register with the SCSI mid-layer
2982# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
2983# - Allows you to ultimately specify which profiles to use
2984# - Default will result in registering capabilities for all guard types
2985#
2986*/
2987unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
2988module_param(lpfc_prot_guard, byte, 0);
2989MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
2990
2991
2992/*
James Smart3621a712009-04-06 18:47:14 -04002993 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05002994 * This value can be set to values between 64 and 256. The default value is
2995 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2996 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2997 */
2998LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2999 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3000
James Smart81301a92008-12-04 22:39:46 -05003001LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3002 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3003 "Max Protection Scatter Gather Segment Count");
3004
Tony Jonesee959b02008-02-22 00:13:36 +01003005struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003006 &dev_attr_bg_info,
3007 &dev_attr_bg_guard_err,
3008 &dev_attr_bg_apptag_err,
3009 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003010 &dev_attr_info,
3011 &dev_attr_serialnum,
3012 &dev_attr_modeldesc,
3013 &dev_attr_modelname,
3014 &dev_attr_programtype,
3015 &dev_attr_portnum,
3016 &dev_attr_fwrev,
3017 &dev_attr_hdw,
3018 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003019 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003020 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003021 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003022 &dev_attr_lpfc_drvr_version,
3023 &dev_attr_lpfc_temp_sensor,
3024 &dev_attr_lpfc_log_verbose,
3025 &dev_attr_lpfc_lun_queue_depth,
3026 &dev_attr_lpfc_hba_queue_depth,
3027 &dev_attr_lpfc_peer_port_login,
3028 &dev_attr_lpfc_nodev_tmo,
3029 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04003030 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003031 &dev_attr_lpfc_fcp_class,
3032 &dev_attr_lpfc_use_adisc,
3033 &dev_attr_lpfc_ack0,
3034 &dev_attr_lpfc_topology,
3035 &dev_attr_lpfc_scan_down,
3036 &dev_attr_lpfc_link_speed,
3037 &dev_attr_lpfc_cr_delay,
3038 &dev_attr_lpfc_cr_count,
3039 &dev_attr_lpfc_multi_ring_support,
3040 &dev_attr_lpfc_multi_ring_rctl,
3041 &dev_attr_lpfc_multi_ring_type,
3042 &dev_attr_lpfc_fdmi_on,
3043 &dev_attr_lpfc_max_luns,
3044 &dev_attr_lpfc_enable_npiv,
3045 &dev_attr_nport_evt_cnt,
3046 &dev_attr_board_mode,
3047 &dev_attr_max_vpi,
3048 &dev_attr_used_vpi,
3049 &dev_attr_max_rpi,
3050 &dev_attr_used_rpi,
3051 &dev_attr_max_xri,
3052 &dev_attr_used_xri,
3053 &dev_attr_npiv_info,
3054 &dev_attr_issue_reset,
3055 &dev_attr_lpfc_poll,
3056 &dev_attr_lpfc_poll_tmo,
3057 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003058 &dev_attr_lpfc_fcp_imax,
3059 &dev_attr_lpfc_fcp_wq_count,
3060 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003061 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003062 &dev_attr_lpfc_soft_wwnn,
3063 &dev_attr_lpfc_soft_wwpn,
3064 &dev_attr_lpfc_soft_wwn_enable,
3065 &dev_attr_lpfc_enable_hba_reset,
3066 &dev_attr_lpfc_enable_hba_heartbeat,
3067 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003068 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003069 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003070 &dev_attr_lpfc_prot_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05003071 NULL,
3072};
3073
Tony Jonesee959b02008-02-22 00:13:36 +01003074struct device_attribute *lpfc_vport_attrs[] = {
3075 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003076 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003077 &dev_attr_num_discovered_ports,
3078 &dev_attr_lpfc_drvr_version,
3079 &dev_attr_lpfc_log_verbose,
3080 &dev_attr_lpfc_lun_queue_depth,
3081 &dev_attr_lpfc_nodev_tmo,
3082 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04003083 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003084 &dev_attr_lpfc_hba_queue_depth,
3085 &dev_attr_lpfc_peer_port_login,
3086 &dev_attr_lpfc_restrict_login,
3087 &dev_attr_lpfc_fcp_class,
3088 &dev_attr_lpfc_use_adisc,
3089 &dev_attr_lpfc_fdmi_on,
3090 &dev_attr_lpfc_max_luns,
3091 &dev_attr_nport_evt_cnt,
3092 &dev_attr_npiv_info,
3093 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003094 &dev_attr_lpfc_max_scsicmpl_time,
3095 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003096 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003097 NULL,
3098};
3099
James Smarte59058c2008-08-24 21:49:00 -04003100/**
James Smart3621a712009-04-06 18:47:14 -04003101 * sysfs_ctlreg_write - Write method for writing to ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003102 * @kobj: kernel kobject that contains the kernel class device.
3103 * @bin_attr: kernel attributes passed to us.
3104 * @buf: contains the data to be written to the adapter IOREG space.
3105 * @off: offset into buffer to beginning of data.
3106 * @count: bytes to transfer.
3107 *
3108 * Description:
3109 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3110 * Uses the adapter io control registers to send buf contents to the adapter.
3111 *
3112 * Returns:
3113 * -ERANGE off and count combo out of range
3114 * -EINVAL off, count or buff address invalid
3115 * -EPERM adapter is offline
3116 * value of count, buf contents written
3117 **/
dea31012005-04-17 16:05:31 -05003118static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003119sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3120 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003121{
3122 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003123 struct device *dev = container_of(kobj, struct device, kobj);
3124 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3126 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003127
James Smartf1126682009-06-10 17:22:44 -04003128 if (phba->sli_rev >= LPFC_SLI_REV4)
3129 return -EPERM;
3130
dea31012005-04-17 16:05:31 -05003131 if ((off + count) > FF_REG_AREA_SIZE)
3132 return -ERANGE;
3133
3134 if (count == 0) return 0;
3135
3136 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3137 return -EINVAL;
3138
James Smart2e0fef82007-06-17 19:56:36 -05003139 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003140 return -EPERM;
3141 }
3142
James Smart2e0fef82007-06-17 19:56:36 -05003143 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003144 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3145 writel(*((uint32_t *)(buf + buf_off)),
3146 phba->ctrl_regs_memmap_p + off + buf_off);
3147
James Smart2e0fef82007-06-17 19:56:36 -05003148 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003149
3150 return count;
3151}
3152
James Smarte59058c2008-08-24 21:49:00 -04003153/**
James Smart3621a712009-04-06 18:47:14 -04003154 * sysfs_ctlreg_read - Read method for reading from ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003155 * @kobj: kernel kobject that contains the kernel class device.
3156 * @bin_attr: kernel attributes passed to us.
3157 * @buf: if succesful contains the data from the adapter IOREG space.
3158 * @off: offset into buffer to beginning of data.
3159 * @count: bytes to transfer.
3160 *
3161 * Description:
3162 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3163 * Uses the adapter io control registers to read data into buf.
3164 *
3165 * Returns:
3166 * -ERANGE off and count combo out of range
3167 * -EINVAL off, count or buff address invalid
3168 * value of count, buf contents read
3169 **/
dea31012005-04-17 16:05:31 -05003170static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003171sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3172 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003173{
3174 size_t buf_off;
3175 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003176 struct device *dev = container_of(kobj, struct device, kobj);
3177 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003178 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3179 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003180
James Smartf1126682009-06-10 17:22:44 -04003181 if (phba->sli_rev >= LPFC_SLI_REV4)
3182 return -EPERM;
3183
dea31012005-04-17 16:05:31 -05003184 if (off > FF_REG_AREA_SIZE)
3185 return -ERANGE;
3186
3187 if ((off + count) > FF_REG_AREA_SIZE)
3188 count = FF_REG_AREA_SIZE - off;
3189
3190 if (count == 0) return 0;
3191
3192 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3193 return -EINVAL;
3194
James Smart2e0fef82007-06-17 19:56:36 -05003195 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003196
3197 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3198 tmp_ptr = (uint32_t *)(buf + buf_off);
3199 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3200 }
3201
James Smart2e0fef82007-06-17 19:56:36 -05003202 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003203
3204 return count;
3205}
3206
3207static struct bin_attribute sysfs_ctlreg_attr = {
3208 .attr = {
3209 .name = "ctlreg",
3210 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003211 },
3212 .size = 256,
3213 .read = sysfs_ctlreg_read,
3214 .write = sysfs_ctlreg_write,
3215};
3216
James Smarte59058c2008-08-24 21:49:00 -04003217/**
James Smart3621a712009-04-06 18:47:14 -04003218 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003219 * @phba: lpfc_hba pointer
3220 **/
dea31012005-04-17 16:05:31 -05003221static void
James Smart2e0fef82007-06-17 19:56:36 -05003222sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003223{
3224 phba->sysfs_mbox.state = SMBOX_IDLE;
3225 phba->sysfs_mbox.offset = 0;
3226
3227 if (phba->sysfs_mbox.mbox) {
3228 mempool_free(phba->sysfs_mbox.mbox,
3229 phba->mbox_mem_pool);
3230 phba->sysfs_mbox.mbox = NULL;
3231 }
3232}
3233
James Smarte59058c2008-08-24 21:49:00 -04003234/**
James Smart3621a712009-04-06 18:47:14 -04003235 * sysfs_mbox_write - Write method for writing information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003236 * @kobj: kernel kobject that contains the kernel class device.
3237 * @bin_attr: kernel attributes passed to us.
3238 * @buf: contains the data to be written to sysfs mbox.
3239 * @off: offset into buffer to beginning of data.
3240 * @count: bytes to transfer.
3241 *
3242 * Description:
3243 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3244 * Uses the sysfs mbox to send buf contents to the adapter.
3245 *
3246 * Returns:
3247 * -ERANGE off and count combo out of range
3248 * -EINVAL off, count or buff address invalid
3249 * zero if count is zero
3250 * -EPERM adapter is offline
3251 * -ENOMEM failed to allocate memory for the mail box
3252 * -EAGAIN offset, state or mbox is NULL
3253 * count number of bytes transferred
3254 **/
dea31012005-04-17 16:05:31 -05003255static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003256sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3257 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003258{
Tony Jonesee959b02008-02-22 00:13:36 +01003259 struct device *dev = container_of(kobj, struct device, kobj);
3260 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3262 struct lpfc_hba *phba = vport->phba;
3263 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003264
3265 if ((count + off) > MAILBOX_CMD_SIZE)
3266 return -ERANGE;
3267
3268 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3269 return -EINVAL;
3270
3271 if (count == 0)
3272 return 0;
3273
3274 if (off == 0) {
3275 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3276 if (!mbox)
3277 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003278 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003279 }
3280
James Smart2e0fef82007-06-17 19:56:36 -05003281 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003282
3283 if (off == 0) {
3284 if (phba->sysfs_mbox.mbox)
3285 mempool_free(mbox, phba->mbox_mem_pool);
3286 else
3287 phba->sysfs_mbox.mbox = mbox;
3288 phba->sysfs_mbox.state = SMBOX_WRITING;
3289 } else {
3290 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3291 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003292 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003293 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003294 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003295 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003296 }
3297 }
3298
James Smart04c68492009-05-22 14:52:52 -04003299 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003300 buf, count);
3301
3302 phba->sysfs_mbox.offset = off + count;
3303
James Smart2e0fef82007-06-17 19:56:36 -05003304 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003305
3306 return count;
3307}
3308
James Smarte59058c2008-08-24 21:49:00 -04003309/**
James Smart3621a712009-04-06 18:47:14 -04003310 * sysfs_mbox_read - Read method for reading information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003311 * @kobj: kernel kobject that contains the kernel class device.
3312 * @bin_attr: kernel attributes passed to us.
3313 * @buf: contains the data to be read from sysfs mbox.
3314 * @off: offset into buffer to beginning of data.
3315 * @count: bytes to transfer.
3316 *
3317 * Description:
3318 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3319 * Uses the sysfs mbox to receive data from to the adapter.
3320 *
3321 * Returns:
3322 * -ERANGE off greater than mailbox command size
3323 * -EINVAL off, count or buff address invalid
3324 * zero if off and count are zero
3325 * -EACCES adapter over temp
3326 * -EPERM garbage can value to catch a multitude of errors
3327 * -EAGAIN management IO not permitted, state or off error
3328 * -ETIME mailbox timeout
3329 * -ENODEV mailbox error
3330 * count number of bytes transferred
3331 **/
dea31012005-04-17 16:05:31 -05003332static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003333sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3334 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003335{
Tony Jonesee959b02008-02-22 00:13:36 +01003336 struct device *dev = container_of(kobj, struct device, kobj);
3337 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3339 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003340 int rc;
James Smart04c68492009-05-22 14:52:52 -04003341 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003342
James Smart1dcb58e2007-04-25 09:51:30 -04003343 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003344 return -ERANGE;
3345
James Smart1dcb58e2007-04-25 09:51:30 -04003346 if ((count + off) > MAILBOX_CMD_SIZE)
3347 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003348
3349 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3350 return -EINVAL;
3351
3352 if (off && count == 0)
3353 return 0;
3354
James Smart2e0fef82007-06-17 19:56:36 -05003355 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003356
James Smart7af67052007-10-27 13:38:11 -04003357 if (phba->over_temp_state == HBA_OVER_TEMP) {
3358 sysfs_mbox_idle(phba);
3359 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003360 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003361 }
3362
dea31012005-04-17 16:05:31 -05003363 if (off == 0 &&
3364 phba->sysfs_mbox.state == SMBOX_WRITING &&
3365 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003366 pmb = &phba->sysfs_mbox.mbox->u.mb;
3367 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003368 /* Offline only */
dea31012005-04-17 16:05:31 -05003369 case MBX_INIT_LINK:
3370 case MBX_DOWN_LINK:
3371 case MBX_CONFIG_LINK:
3372 case MBX_CONFIG_RING:
3373 case MBX_RESET_RING:
3374 case MBX_UNREG_LOGIN:
3375 case MBX_CLEAR_LA:
3376 case MBX_DUMP_CONTEXT:
3377 case MBX_RUN_DIAGS:
3378 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003379 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003380 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003381 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003382 printk(KERN_WARNING "mbox_read:Command 0x%x "
3383 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003384 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003385 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003386 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003387 return -EPERM;
3388 }
James Smarta8adb832007-10-27 13:37:53 -04003389 case MBX_WRITE_NV:
3390 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003391 case MBX_LOAD_SM:
3392 case MBX_READ_NV:
3393 case MBX_READ_CONFIG:
3394 case MBX_READ_RCONFIG:
3395 case MBX_READ_STATUS:
3396 case MBX_READ_XRI:
3397 case MBX_READ_REV:
3398 case MBX_READ_LNK_STAT:
3399 case MBX_DUMP_MEMORY:
3400 case MBX_DOWN_LOAD:
3401 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003402 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003403 case MBX_LOAD_AREA:
3404 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003405 case MBX_BEACON:
3406 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003407 case MBX_SET_VARIABLE:
3408 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003409 case MBX_PORT_CAPABILITIES:
3410 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003411 break;
3412 case MBX_READ_SPARM64:
3413 case MBX_READ_LA:
3414 case MBX_READ_LA64:
3415 case MBX_REG_LOGIN:
3416 case MBX_REG_LOGIN64:
3417 case MBX_CONFIG_PORT:
3418 case MBX_RUN_BIU_DIAG:
3419 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003420 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003421 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003422 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003423 return -EPERM;
3424 default:
3425 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003426 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003427 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003428 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003429 return -EPERM;
3430 }
3431
James Smart09372822008-01-11 01:52:54 -05003432 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003433 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003434 */
James Smartd7c255b2008-08-24 21:50:00 -04003435 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003436 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3437 pmb->mbxCommand != MBX_RESTART &&
3438 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3439 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003440 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3441 "1259 mbox: Issued mailbox cmd "
3442 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003443 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003444
James Smart92d7f7b2007-06-17 19:56:38 -05003445 phba->sysfs_mbox.mbox->vport = vport;
3446
James Smart58da1ff2008-04-07 10:15:56 -04003447 /* Don't allow mailbox commands to be sent when blocked
3448 * or when in the middle of discovery
3449 */
James Smart495a7142008-06-14 22:52:59 -04003450 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003451 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003452 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003453 return -EAGAIN;
3454 }
3455
James Smart2e0fef82007-06-17 19:56:36 -05003456 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003457 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003458
James Smart2e0fef82007-06-17 19:56:36 -05003459 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003460 rc = lpfc_sli_issue_mbox (phba,
3461 phba->sysfs_mbox.mbox,
3462 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003463 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003464
3465 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003466 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003467 rc = lpfc_sli_issue_mbox_wait (phba,
3468 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003469 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003470 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003471 }
3472
3473 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003474 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003475 phba->sysfs_mbox.mbox = NULL;
3476 }
dea31012005-04-17 16:05:31 -05003477 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003478 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003479 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003480 }
3481 phba->sysfs_mbox.state = SMBOX_READING;
3482 }
3483 else if (phba->sysfs_mbox.offset != off ||
3484 phba->sysfs_mbox.state != SMBOX_READING) {
3485 printk(KERN_WARNING "mbox_read: Bad State\n");
3486 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003487 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003488 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003489 }
3490
James Smart04c68492009-05-22 14:52:52 -04003491 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003492
3493 phba->sysfs_mbox.offset = off + count;
3494
James Smart1dcb58e2007-04-25 09:51:30 -04003495 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003496 sysfs_mbox_idle(phba);
3497
James Smart2e0fef82007-06-17 19:56:36 -05003498 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003499
3500 return count;
3501}
3502
3503static struct bin_attribute sysfs_mbox_attr = {
3504 .attr = {
3505 .name = "mbox",
3506 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003507 },
James Smart1dcb58e2007-04-25 09:51:30 -04003508 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003509 .read = sysfs_mbox_read,
3510 .write = sysfs_mbox_write,
3511};
3512
James Smarte59058c2008-08-24 21:49:00 -04003513/**
James Smart3621a712009-04-06 18:47:14 -04003514 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003515 * @vport: address of lpfc vport structure.
3516 *
3517 * Return codes:
3518 * zero on success
3519 * error return code from sysfs_create_bin_file()
3520 **/
dea31012005-04-17 16:05:31 -05003521int
James Smart2e0fef82007-06-17 19:56:36 -05003522lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003523{
James Smart2e0fef82007-06-17 19:56:36 -05003524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003525 int error;
3526
Tony Jonesee959b02008-02-22 00:13:36 +01003527 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003528 &sysfs_drvr_stat_data_attr);
3529
3530 /* Virtual ports do not need ctrl_reg and mbox */
3531 if (error || vport->port_type == LPFC_NPIV_PORT)
3532 goto out;
3533
3534 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003535 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003536 if (error)
James Smarteada2722008-12-04 22:39:13 -05003537 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003538
Tony Jonesee959b02008-02-22 00:13:36 +01003539 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003540 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003541 if (error)
3542 goto out_remove_ctlreg_attr;
3543
3544 return 0;
3545out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003546 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003547out_remove_stat_attr:
3548 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3549 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003550out:
3551 return error;
3552}
3553
James Smarte59058c2008-08-24 21:49:00 -04003554/**
James Smart3621a712009-04-06 18:47:14 -04003555 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003556 * @vport: address of lpfc vport structure.
3557 **/
dea31012005-04-17 16:05:31 -05003558void
James Smart2e0fef82007-06-17 19:56:36 -05003559lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003560{
James Smart2e0fef82007-06-17 19:56:36 -05003561 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003562 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3563 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003564 /* Virtual ports do not need ctrl_reg and mbox */
3565 if (vport->port_type == LPFC_NPIV_PORT)
3566 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003567 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3568 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003569}
3570
3571
3572/*
3573 * Dynamic FC Host Attributes Support
3574 */
3575
James Smarte59058c2008-08-24 21:49:00 -04003576/**
James Smart3621a712009-04-06 18:47:14 -04003577 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003578 * @shost: kernel scsi host pointer.
3579 **/
dea31012005-04-17 16:05:31 -05003580static void
3581lpfc_get_host_port_id(struct Scsi_Host *shost)
3582{
James Smart2e0fef82007-06-17 19:56:36 -05003583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3584
dea31012005-04-17 16:05:31 -05003585 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003586 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003587}
3588
James Smarte59058c2008-08-24 21:49:00 -04003589/**
James Smart3621a712009-04-06 18:47:14 -04003590 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003591 * @shost: kernel scsi host pointer.
3592 **/
dea31012005-04-17 16:05:31 -05003593static void
3594lpfc_get_host_port_type(struct Scsi_Host *shost)
3595{
James Smart2e0fef82007-06-17 19:56:36 -05003596 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3597 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003598
3599 spin_lock_irq(shost->host_lock);
3600
James Smart92d7f7b2007-06-17 19:56:38 -05003601 if (vport->port_type == LPFC_NPIV_PORT) {
3602 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3603 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003604 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003605 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003606 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3607 else
3608 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3609 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003610 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003611 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3612 else
3613 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3614 }
3615 } else
3616 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3617
3618 spin_unlock_irq(shost->host_lock);
3619}
3620
James Smarte59058c2008-08-24 21:49:00 -04003621/**
James Smart3621a712009-04-06 18:47:14 -04003622 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003623 * @shost: kernel scsi host pointer.
3624 **/
dea31012005-04-17 16:05:31 -05003625static void
3626lpfc_get_host_port_state(struct Scsi_Host *shost)
3627{
James Smart2e0fef82007-06-17 19:56:36 -05003628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3629 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003630
3631 spin_lock_irq(shost->host_lock);
3632
James Smart2e0fef82007-06-17 19:56:36 -05003633 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003634 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3635 else {
James Smart2e0fef82007-06-17 19:56:36 -05003636 switch (phba->link_state) {
3637 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003638 case LPFC_LINK_DOWN:
3639 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3640 break;
3641 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003642 case LPFC_CLEAR_LA:
3643 case LPFC_HBA_READY:
3644 /* Links up, beyond this port_type reports state */
3645 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3646 break;
3647 case LPFC_HBA_ERROR:
3648 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3649 break;
3650 default:
3651 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3652 break;
3653 }
3654 }
3655
3656 spin_unlock_irq(shost->host_lock);
3657}
3658
James Smarte59058c2008-08-24 21:49:00 -04003659/**
James Smart3621a712009-04-06 18:47:14 -04003660 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003661 * @shost: kernel scsi host pointer.
3662 **/
dea31012005-04-17 16:05:31 -05003663static void
3664lpfc_get_host_speed(struct Scsi_Host *shost)
3665{
James Smart2e0fef82007-06-17 19:56:36 -05003666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3667 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003668
3669 spin_lock_irq(shost->host_lock);
3670
James Smart2e0fef82007-06-17 19:56:36 -05003671 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003672 switch(phba->fc_linkspeed) {
3673 case LA_1GHZ_LINK:
3674 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3675 break;
3676 case LA_2GHZ_LINK:
3677 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3678 break;
3679 case LA_4GHZ_LINK:
3680 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3681 break;
James Smartb87eab32007-04-25 09:53:28 -04003682 case LA_8GHZ_LINK:
3683 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3684 break;
James Smartf4b4c682009-05-22 14:53:12 -04003685 case LA_10GHZ_LINK:
3686 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3687 break;
dea31012005-04-17 16:05:31 -05003688 default:
3689 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3690 break;
3691 }
James Smart09372822008-01-11 01:52:54 -05003692 } else
3693 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003694
3695 spin_unlock_irq(shost->host_lock);
3696}
3697
James Smarte59058c2008-08-24 21:49:00 -04003698/**
James Smart3621a712009-04-06 18:47:14 -04003699 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04003700 * @shost: kernel scsi host pointer.
3701 **/
dea31012005-04-17 16:05:31 -05003702static void
3703lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3704{
James Smart2e0fef82007-06-17 19:56:36 -05003705 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3706 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003707 u64 node_name;
dea31012005-04-17 16:05:31 -05003708
3709 spin_lock_irq(shost->host_lock);
3710
James Smart2e0fef82007-06-17 19:56:36 -05003711 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003712 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003713 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003714 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003715 else
3716 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003717 node_name = 0;
dea31012005-04-17 16:05:31 -05003718
3719 spin_unlock_irq(shost->host_lock);
3720
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003721 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003722}
3723
James Smarte59058c2008-08-24 21:49:00 -04003724/**
James Smart3621a712009-04-06 18:47:14 -04003725 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04003726 * @shost: kernel scsi host pointer.
3727 *
3728 * Notes:
3729 * NULL on error for link down, no mbox pool, sli2 active,
3730 * management not allowed, memory allocation error, or mbox error.
3731 *
3732 * Returns:
3733 * NULL for error
3734 * address of the adapter host statistics
3735 **/
dea31012005-04-17 16:05:31 -05003736static struct fc_host_statistics *
3737lpfc_get_stats(struct Scsi_Host *shost)
3738{
James Smart2e0fef82007-06-17 19:56:36 -05003739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3740 struct lpfc_hba *phba = vport->phba;
3741 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003742 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003743 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003744 LPFC_MBOXQ_t *pmboxq;
3745 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003746 unsigned long seconds;
James.Smart@Emulex.Com433c35792005-10-28 20:28:56 -04003747 int rc = 0;
dea31012005-04-17 16:05:31 -05003748
James Smart92d7f7b2007-06-17 19:56:38 -05003749 /*
3750 * prevent udev from issuing mailbox commands until the port is
3751 * configured.
3752 */
James Smart2e0fef82007-06-17 19:56:36 -05003753 if (phba->link_state < LPFC_LINK_DOWN ||
3754 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04003755 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003756 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003757
3758 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003759 return NULL;
3760
dea31012005-04-17 16:05:31 -05003761 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3762 if (!pmboxq)
3763 return NULL;
3764 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3765
James Smart04c68492009-05-22 14:52:52 -04003766 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05003767 pmb->mbxCommand = MBX_READ_STATUS;
3768 pmb->mbxOwner = OWN_HOST;
3769 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003770 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003771
James Smart2e0fef82007-06-17 19:56:36 -05003772 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart04c68492009-05-22 14:52:52 -04003773 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003774 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c35792005-10-28 20:28:56 -04003775 else
dea31012005-04-17 16:05:31 -05003776 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3777
3778 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003779 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c35792005-10-28 20:28:56 -04003780 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003781 return NULL;
3782 }
3783
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003784 memset(hs, 0, sizeof (struct fc_host_statistics));
3785
dea31012005-04-17 16:05:31 -05003786 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3787 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3788 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3789 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3790
James.Smart@Emulex.Com433c35792005-10-28 20:28:56 -04003791 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003792 pmb->mbxCommand = MBX_READ_LNK_STAT;
3793 pmb->mbxOwner = OWN_HOST;
3794 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003795 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003796
James Smart2e0fef82007-06-17 19:56:36 -05003797 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003798 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003799 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c35792005-10-28 20:28:56 -04003800 else
dea31012005-04-17 16:05:31 -05003801 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3802
3803 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003804 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003805 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003806 return NULL;
3807 }
3808
3809 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3810 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3811 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3812 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3813 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3814 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3815 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3816
James Smart64ba8812006-08-02 15:24:34 -04003817 hs->link_failure_count -= lso->link_failure_count;
3818 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3819 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3820 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3821 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3822 hs->invalid_crc_count -= lso->invalid_crc_count;
3823 hs->error_frames -= lso->error_frames;
3824
James Smart4d9ab992009-10-02 15:16:39 -04003825 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
3826 hs->lip_count = -1;
3827 hs->nos_count = (phba->link_events >> 1);
3828 hs->nos_count -= lso->link_events;
3829 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05003830 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003831 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003832 hs->nos_count = -1;
3833 } else {
3834 hs->lip_count = -1;
3835 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003836 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003837 }
3838
3839 hs->dumped_frames = -1;
3840
James Smart64ba8812006-08-02 15:24:34 -04003841 seconds = get_seconds();
3842 if (seconds < psli->stats_start)
3843 hs->seconds_since_last_reset = seconds +
3844 ((unsigned long)-1 - psli->stats_start);
3845 else
3846 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05003847
James Smart1dcb58e2007-04-25 09:51:30 -04003848 mempool_free(pmboxq, phba->mbox_mem_pool);
3849
dea31012005-04-17 16:05:31 -05003850 return hs;
3851}
3852
James Smarte59058c2008-08-24 21:49:00 -04003853/**
James Smart3621a712009-04-06 18:47:14 -04003854 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04003855 * @shost: kernel scsi host pointer.
3856 **/
James Smart64ba8812006-08-02 15:24:34 -04003857static void
3858lpfc_reset_stats(struct Scsi_Host *shost)
3859{
James Smart2e0fef82007-06-17 19:56:36 -05003860 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3861 struct lpfc_hba *phba = vport->phba;
3862 struct lpfc_sli *psli = &phba->sli;
3863 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04003864 LPFC_MBOXQ_t *pmboxq;
3865 MAILBOX_t *pmb;
3866 int rc = 0;
3867
James Smart2e0fef82007-06-17 19:56:36 -05003868 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003869 return;
3870
James Smart64ba8812006-08-02 15:24:34 -04003871 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3872 if (!pmboxq)
3873 return;
3874 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3875
James Smart04c68492009-05-22 14:52:52 -04003876 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04003877 pmb->mbxCommand = MBX_READ_STATUS;
3878 pmb->mbxOwner = OWN_HOST;
3879 pmb->un.varWords[0] = 0x1; /* reset request */
3880 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003881 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003882
James Smart2e0fef82007-06-17 19:56:36 -05003883 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003884 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04003885 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3886 else
3887 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3888
3889 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003890 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003891 mempool_free(pmboxq, phba->mbox_mem_pool);
3892 return;
3893 }
3894
3895 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3896 pmb->mbxCommand = MBX_READ_LNK_STAT;
3897 pmb->mbxOwner = OWN_HOST;
3898 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003899 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003900
James Smart2e0fef82007-06-17 19:56:36 -05003901 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003902 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04003903 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3904 else
3905 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3906
3907 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003908 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003909 mempool_free( pmboxq, phba->mbox_mem_pool);
3910 return;
3911 }
3912
3913 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3914 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3915 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3916 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3917 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3918 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3919 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04003920 if (phba->hba_flag & HBA_FCOE_SUPPORT)
3921 lso->link_events = (phba->link_events >> 1);
3922 else
3923 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003924
3925 psli->stats_start = get_seconds();
3926
James Smart1dcb58e2007-04-25 09:51:30 -04003927 mempool_free(pmboxq, phba->mbox_mem_pool);
3928
James Smart64ba8812006-08-02 15:24:34 -04003929 return;
3930}
dea31012005-04-17 16:05:31 -05003931
3932/*
3933 * The LPFC driver treats linkdown handling as target loss events so there
3934 * are no sysfs handlers for link_down_tmo.
3935 */
James Smart685f0bf2007-04-25 09:53:08 -04003936
James Smarte59058c2008-08-24 21:49:00 -04003937/**
James Smart3621a712009-04-06 18:47:14 -04003938 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04003939 * @starget: kernel scsi target pointer.
3940 *
3941 * Returns:
3942 * address of the node list if found
3943 * NULL target not found
3944 **/
James Smart685f0bf2007-04-25 09:53:08 -04003945static struct lpfc_nodelist *
3946lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05003947{
James Smart2e0fef82007-06-17 19:56:36 -05003948 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3949 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04003950 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003951
3952 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003953 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05003954 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003955 if (NLP_CHK_NODE_ACT(ndlp) &&
3956 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04003957 starget->id == ndlp->nlp_sid) {
3958 spin_unlock_irq(shost->host_lock);
3959 return ndlp;
dea31012005-04-17 16:05:31 -05003960 }
3961 }
3962 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003963 return NULL;
3964}
dea31012005-04-17 16:05:31 -05003965
James Smarte59058c2008-08-24 21:49:00 -04003966/**
James Smart3621a712009-04-06 18:47:14 -04003967 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04003968 * @starget: kernel scsi target pointer.
3969 **/
James Smart685f0bf2007-04-25 09:53:08 -04003970static void
3971lpfc_get_starget_port_id(struct scsi_target *starget)
3972{
3973 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3974
3975 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05003976}
3977
James Smarte59058c2008-08-24 21:49:00 -04003978/**
James Smart3621a712009-04-06 18:47:14 -04003979 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04003980 * @starget: kernel scsi target pointer.
3981 *
3982 * Description: Set the target node name to the ndlp node name wwn or zero.
3983 **/
dea31012005-04-17 16:05:31 -05003984static void
3985lpfc_get_starget_node_name(struct scsi_target *starget)
3986{
James Smart685f0bf2007-04-25 09:53:08 -04003987 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003988
James Smart685f0bf2007-04-25 09:53:08 -04003989 fc_starget_node_name(starget) =
3990 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003991}
3992
James Smarte59058c2008-08-24 21:49:00 -04003993/**
James Smart3621a712009-04-06 18:47:14 -04003994 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04003995 * @starget: kernel scsi target pointer.
3996 *
3997 * Description: set the target port name to the ndlp port name wwn or zero.
3998 **/
dea31012005-04-17 16:05:31 -05003999static void
4000lpfc_get_starget_port_name(struct scsi_target *starget)
4001{
James Smart685f0bf2007-04-25 09:53:08 -04004002 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004003
James Smart685f0bf2007-04-25 09:53:08 -04004004 fc_starget_port_name(starget) =
4005 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004006}
4007
James Smarte59058c2008-08-24 21:49:00 -04004008/**
James Smart3621a712009-04-06 18:47:14 -04004009 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004010 * @rport: fc rport address.
4011 * @timeout: new value for dev loss tmo.
4012 *
4013 * Description:
4014 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4015 * dev_loss_tmo to one.
4016 **/
dea31012005-04-17 16:05:31 -05004017static void
dea31012005-04-17 16:05:31 -05004018lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4019{
dea31012005-04-17 16:05:31 -05004020 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004021 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004022 else
James Smartc01f3202006-08-18 17:47:08 -04004023 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004024}
4025
James Smarte59058c2008-08-24 21:49:00 -04004026/**
James Smart3621a712009-04-06 18:47:14 -04004027 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004028 *
4029 * Description:
4030 * Macro that uses field to generate a function with the name lpfc_show_rport_
4031 *
4032 * lpfc_show_rport_##field: returns the bytes formatted in buf
4033 * @cdev: class converted to an fc_rport.
4034 * @buf: on return contains the target_field or zero.
4035 *
4036 * Returns: size of formatted string.
4037 **/
dea31012005-04-17 16:05:31 -05004038#define lpfc_rport_show_function(field, format_string, sz, cast) \
4039static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004040lpfc_show_rport_##field (struct device *dev, \
4041 struct device_attribute *attr, \
4042 char *buf) \
dea31012005-04-17 16:05:31 -05004043{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004044 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004045 struct lpfc_rport_data *rdata = rport->hostdata; \
4046 return snprintf(buf, sz, format_string, \
4047 (rdata->target) ? cast rdata->target->field : 0); \
4048}
4049
4050#define lpfc_rport_rd_attr(field, format_string, sz) \
4051 lpfc_rport_show_function(field, format_string, sz, ) \
4052static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4053
James Smarteada2722008-12-04 22:39:13 -05004054/**
James Smart3621a712009-04-06 18:47:14 -04004055 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004056 * @fc_vport: The fc_vport who's symbolic name has been changed.
4057 *
4058 * Description:
4059 * This function is called by the transport after the @fc_vport's symbolic name
4060 * has been changed. This function re-registers the symbolic name with the
4061 * switch to propogate the change into the fabric if the vport is active.
4062 **/
4063static void
4064lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4065{
4066 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4067
4068 if (vport->port_state == LPFC_VPORT_READY)
4069 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4070}
dea31012005-04-17 16:05:31 -05004071
James Smartf4b4c682009-05-22 14:53:12 -04004072/**
4073 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4074 * @phba: Pointer to lpfc_hba struct.
4075 *
4076 * This function is called by the lpfc_get_cfgparam() routine to set the
4077 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4078 * log messsage according to the module's lpfc_log_verbose parameter setting
4079 * before hba port or vport created.
4080 **/
4081static void
4082lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4083{
4084 phba->cfg_log_verbose = verbose;
4085}
4086
dea31012005-04-17 16:05:31 -05004087struct fc_function_template lpfc_transport_functions = {
4088 /* fixed attributes the driver supports */
4089 .show_host_node_name = 1,
4090 .show_host_port_name = 1,
4091 .show_host_supported_classes = 1,
4092 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004093 .show_host_supported_speeds = 1,
4094 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004095 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004096
4097 /* dynamic attributes the driver supports */
4098 .get_host_port_id = lpfc_get_host_port_id,
4099 .show_host_port_id = 1,
4100
4101 .get_host_port_type = lpfc_get_host_port_type,
4102 .show_host_port_type = 1,
4103
4104 .get_host_port_state = lpfc_get_host_port_state,
4105 .show_host_port_state = 1,
4106
4107 /* active_fc4s is shown but doesn't change (thus no get function) */
4108 .show_host_active_fc4s = 1,
4109
4110 .get_host_speed = lpfc_get_host_speed,
4111 .show_host_speed = 1,
4112
4113 .get_host_fabric_name = lpfc_get_host_fabric_name,
4114 .show_host_fabric_name = 1,
4115
4116 /*
4117 * The LPFC driver treats linkdown handling as target loss events
4118 * so there are no sysfs handlers for link_down_tmo.
4119 */
4120
4121 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004122 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004123
4124 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4125 .show_rport_maxframe_size = 1,
4126 .show_rport_supported_classes = 1,
4127
dea31012005-04-17 16:05:31 -05004128 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4129 .show_rport_dev_loss_tmo = 1,
4130
4131 .get_starget_port_id = lpfc_get_starget_port_id,
4132 .show_starget_port_id = 1,
4133
4134 .get_starget_node_name = lpfc_get_starget_node_name,
4135 .show_starget_node_name = 1,
4136
4137 .get_starget_port_name = lpfc_get_starget_port_name,
4138 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004139
4140 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004141 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4142 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004143
James Smart92d7f7b2007-06-17 19:56:38 -05004144 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004145
4146 .vport_disable = lpfc_vport_disable,
4147
4148 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004149
4150 .bsg_request = lpfc_bsg_request,
4151 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004152};
4153
James Smart98c9ea52007-10-27 13:37:33 -04004154struct fc_function_template lpfc_vport_transport_functions = {
4155 /* fixed attributes the driver supports */
4156 .show_host_node_name = 1,
4157 .show_host_port_name = 1,
4158 .show_host_supported_classes = 1,
4159 .show_host_supported_fc4s = 1,
4160 .show_host_supported_speeds = 1,
4161 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004162 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004163
4164 /* dynamic attributes the driver supports */
4165 .get_host_port_id = lpfc_get_host_port_id,
4166 .show_host_port_id = 1,
4167
4168 .get_host_port_type = lpfc_get_host_port_type,
4169 .show_host_port_type = 1,
4170
4171 .get_host_port_state = lpfc_get_host_port_state,
4172 .show_host_port_state = 1,
4173
4174 /* active_fc4s is shown but doesn't change (thus no get function) */
4175 .show_host_active_fc4s = 1,
4176
4177 .get_host_speed = lpfc_get_host_speed,
4178 .show_host_speed = 1,
4179
4180 .get_host_fabric_name = lpfc_get_host_fabric_name,
4181 .show_host_fabric_name = 1,
4182
4183 /*
4184 * The LPFC driver treats linkdown handling as target loss events
4185 * so there are no sysfs handlers for link_down_tmo.
4186 */
4187
4188 .get_fc_host_stats = lpfc_get_stats,
4189 .reset_fc_host_stats = lpfc_reset_stats,
4190
4191 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4192 .show_rport_maxframe_size = 1,
4193 .show_rport_supported_classes = 1,
4194
4195 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4196 .show_rport_dev_loss_tmo = 1,
4197
4198 .get_starget_port_id = lpfc_get_starget_port_id,
4199 .show_starget_port_id = 1,
4200
4201 .get_starget_node_name = lpfc_get_starget_node_name,
4202 .show_starget_node_name = 1,
4203
4204 .get_starget_port_name = lpfc_get_starget_port_name,
4205 .show_starget_port_name = 1,
4206
4207 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4208 .terminate_rport_io = lpfc_terminate_rport_io,
4209
4210 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004211
4212 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004213};
4214
James Smarte59058c2008-08-24 21:49:00 -04004215/**
James Smart3621a712009-04-06 18:47:14 -04004216 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004217 * @phba: lpfc_hba pointer.
4218 **/
dea31012005-04-17 16:05:31 -05004219void
4220lpfc_get_cfgparam(struct lpfc_hba *phba)
4221{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004222 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4223 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004224 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004225 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4226 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004227 lpfc_ack0_init(phba, lpfc_ack0);
4228 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004229 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004230 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004231 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004232 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004233 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4234 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4235 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004236 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4237 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004238 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004239 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004240 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004241 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004242 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004243 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004244 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004245 lpfc_enable_fip_init(phba, lpfc_enable_fip);
4246 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4247
James Smart3de2a652007-08-02 11:09:59 -04004248 return;
4249}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004250
James Smarte59058c2008-08-24 21:49:00 -04004251/**
James Smart3621a712009-04-06 18:47:14 -04004252 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004253 * @vport: lpfc_vport pointer.
4254 **/
James Smart3de2a652007-08-02 11:09:59 -04004255void
4256lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4257{
James Smarte8b62012007-08-02 11:10:09 -04004258 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004259 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4260 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4261 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4262 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4263 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4264 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4265 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004266 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004267 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4268 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4269 lpfc_max_luns_init(vport, lpfc_max_luns);
4270 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004271 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004272 return;
4273}