blob: 46e032aa0bea5aa4b3e1fafd6f26db9c4a13a5b4 [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>
32
James Smartda0436e2009-05-22 14:51:39 -040033#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_hw.h"
35#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040037#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_disc.h"
39#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_version.h"
43#include "lpfc_compat.h"
44#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050045#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050046
James Smartc01f3202006-08-18 17:47:08 -040047#define LPFC_DEF_DEVLOSS_TMO 30
48#define LPFC_MIN_DEVLOSS_TMO 1
49#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050050
James Smart83108bd2008-01-11 01:53:09 -050051#define LPFC_MAX_LINK_SPEED 8
52#define LPFC_LINK_SPEED_BITMAP 0x00000117
53#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
54
James Smarte59058c2008-08-24 21:49:00 -040055/**
James Smart3621a712009-04-06 18:47:14 -040056 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040057 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
dea31012005-04-17 16:05:31 -050070static void
71lpfc_jedec_to_ascii(int incr, char hdw[])
72{
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84}
85
James Smarte59058c2008-08-24 21:49:00 -040086/**
James Smart3621a712009-04-06 18:47:14 -040087 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040088 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
dea31012005-04-17 16:05:31 -050094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010095lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
dea31012005-04-17 16:05:31 -050097{
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99}
100
James Smart81301a92008-12-04 22:39:46 -0500101static ssize_t
102lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
103 char *buf)
104{
105 struct Scsi_Host *shost = class_to_shost(dev);
106 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
107 struct lpfc_hba *phba = vport->phba;
108
109 if (phba->cfg_enable_bg)
110 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
111 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
112 else
113 return snprintf(buf, PAGE_SIZE,
114 "BlockGuard Not Supported\n");
115 else
116 return snprintf(buf, PAGE_SIZE,
117 "BlockGuard Disabled\n");
118}
119
120static ssize_t
121lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
122 char *buf)
123{
124 struct Scsi_Host *shost = class_to_shost(dev);
125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
126 struct lpfc_hba *phba = vport->phba;
127
James Smart87b5c322008-12-16 10:34:09 -0500128 return snprintf(buf, PAGE_SIZE, "%llu\n",
129 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500130}
131
132static ssize_t
133lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
134 char *buf)
135{
136 struct Scsi_Host *shost = class_to_shost(dev);
137 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
138 struct lpfc_hba *phba = vport->phba;
139
James Smart87b5c322008-12-16 10:34:09 -0500140 return snprintf(buf, PAGE_SIZE, "%llu\n",
141 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500142}
143
144static ssize_t
145lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
146 char *buf)
147{
148 struct Scsi_Host *shost = class_to_shost(dev);
149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
150 struct lpfc_hba *phba = vport->phba;
151
James Smart87b5c322008-12-16 10:34:09 -0500152 return snprintf(buf, PAGE_SIZE, "%llu\n",
153 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500154}
155
James Smarte59058c2008-08-24 21:49:00 -0400156/**
James Smart3621a712009-04-06 18:47:14 -0400157 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400158 * @dev: class converted to a Scsi_host structure.
159 * @attr: device attribute, not used.
160 * @buf: on return contains the formatted text from lpfc_info().
161 *
162 * Returns: size of formatted string.
163 **/
dea31012005-04-17 16:05:31 -0500164static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100165lpfc_info_show(struct device *dev, struct device_attribute *attr,
166 char *buf)
dea31012005-04-17 16:05:31 -0500167{
Tony Jonesee959b02008-02-22 00:13:36 +0100168 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500169
dea31012005-04-17 16:05:31 -0500170 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
171}
172
James Smarte59058c2008-08-24 21:49:00 -0400173/**
James Smart3621a712009-04-06 18:47:14 -0400174 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400175 * @dev: class converted to a Scsi_host structure.
176 * @attr: device attribute, not used.
177 * @buf: on return contains the formatted text serial number.
178 *
179 * Returns: size of formatted string.
180 **/
dea31012005-04-17 16:05:31 -0500181static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100182lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
183 char *buf)
dea31012005-04-17 16:05:31 -0500184{
Tony Jonesee959b02008-02-22 00:13:36 +0100185 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
187 struct lpfc_hba *phba = vport->phba;
188
dea31012005-04-17 16:05:31 -0500189 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
190}
191
James Smarte59058c2008-08-24 21:49:00 -0400192/**
James Smart3621a712009-04-06 18:47:14 -0400193 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400194 * @dev: class converted to a Scsi_host structure.
195 * @attr: device attribute, not used.
196 * @buf: on return contains the formatted support level.
197 *
198 * Description:
199 * Returns a number indicating the temperature sensor level currently
200 * supported, zero or one in ascii.
201 *
202 * Returns: size of formatted string.
203 **/
dea31012005-04-17 16:05:31 -0500204static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100205lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
206 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400207{
Tony Jonesee959b02008-02-22 00:13:36 +0100208 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
210 struct lpfc_hba *phba = vport->phba;
211 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
212}
213
James Smarte59058c2008-08-24 21:49:00 -0400214/**
James Smart3621a712009-04-06 18:47:14 -0400215 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the scsi vpd model description.
219 *
220 * Returns: size of formatted string.
221 **/
James Smart57127f12007-10-27 13:37:05 -0400222static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100223lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
224 char *buf)
dea31012005-04-17 16:05:31 -0500225{
Tony Jonesee959b02008-02-22 00:13:36 +0100226 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500227 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
228 struct lpfc_hba *phba = vport->phba;
229
dea31012005-04-17 16:05:31 -0500230 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
231}
232
James Smarte59058c2008-08-24 21:49:00 -0400233/**
James Smart3621a712009-04-06 18:47:14 -0400234 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400235 * @dev: class converted to a Scsi_host structure.
236 * @attr: device attribute, not used.
237 * @buf: on return contains the scsi vpd model name.
238 *
239 * Returns: size of formatted string.
240 **/
dea31012005-04-17 16:05:31 -0500241static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100242lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
243 char *buf)
dea31012005-04-17 16:05:31 -0500244{
Tony Jonesee959b02008-02-22 00:13:36 +0100245 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500246 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
247 struct lpfc_hba *phba = vport->phba;
248
dea31012005-04-17 16:05:31 -0500249 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
250}
251
James Smarte59058c2008-08-24 21:49:00 -0400252/**
James Smart3621a712009-04-06 18:47:14 -0400253 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400254 * @dev: class converted to a Scsi_host structure.
255 * @attr: device attribute, not used.
256 * @buf: on return contains the scsi vpd program type.
257 *
258 * Returns: size of formatted string.
259 **/
dea31012005-04-17 16:05:31 -0500260static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100261lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
262 char *buf)
dea31012005-04-17 16:05:31 -0500263{
Tony Jonesee959b02008-02-22 00:13:36 +0100264 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500265 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
266 struct lpfc_hba *phba = vport->phba;
267
dea31012005-04-17 16:05:31 -0500268 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
269}
270
James Smarte59058c2008-08-24 21:49:00 -0400271/**
James Smart3621a712009-04-06 18:47:14 -0400272 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400273 * @dev: class converted to a Scsi_host structure.
274 * @attr: device attribute, not used.
275 * @buf: on return contains the Menlo Maintenance sli flag.
276 *
277 * Returns: size of formatted string.
278 **/
279static ssize_t
280lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
281{
282 struct Scsi_Host *shost = class_to_shost(dev);
283 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
284 struct lpfc_hba *phba = vport->phba;
285
286 return snprintf(buf, PAGE_SIZE, "%d\n",
287 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
288}
289
290/**
James Smart3621a712009-04-06 18:47:14 -0400291 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400292 * @dev: class converted to a Scsi_host structure.
293 * @attr: device attribute, not used.
294 * @buf: on return contains scsi vpd program type.
295 *
296 * Returns: size of formatted string.
297 **/
dea31012005-04-17 16:05:31 -0500298static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100299lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
300 char *buf)
dea31012005-04-17 16:05:31 -0500301{
Tony Jonesee959b02008-02-22 00:13:36 +0100302 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
304 struct lpfc_hba *phba = vport->phba;
305
dea31012005-04-17 16:05:31 -0500306 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
307}
308
James Smarte59058c2008-08-24 21:49:00 -0400309/**
James Smart3621a712009-04-06 18:47:14 -0400310 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400311 * @dev: class converted to a Scsi_host structure.
312 * @attr: device attribute, not used.
313 * @buf: on return contains the scsi vpd program type.
314 *
315 * Returns: size of formatted string.
316 **/
dea31012005-04-17 16:05:31 -0500317static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100318lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
319 char *buf)
dea31012005-04-17 16:05:31 -0500320{
Tony Jonesee959b02008-02-22 00:13:36 +0100321 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500322 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
323 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500324 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500325
dea31012005-04-17 16:05:31 -0500326 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500327 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500328}
329
James Smarte59058c2008-08-24 21:49:00 -0400330/**
James Smart3621a712009-04-06 18:47:14 -0400331 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400332 * @dev: class converted to a Scsi_host structure.
333 * @attr: device attribute, not used.
334 * @buf: on return contains the scsi vpd program type.
335 *
336 * Returns: size of formatted string.
337 **/
dea31012005-04-17 16:05:31 -0500338static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100339lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500340{
341 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100342 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
344 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500345 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500346
dea31012005-04-17 16:05:31 -0500347 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
348 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
349}
James Smarte59058c2008-08-24 21:49:00 -0400350
351/**
James Smart3621a712009-04-06 18:47:14 -0400352 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400353 * @dev: class converted to a Scsi_host structure.
354 * @attr: device attribute, not used.
355 * @buf: on return contains the ROM and FCode ascii strings.
356 *
357 * Returns: size of formatted string.
358 **/
dea31012005-04-17 16:05:31 -0500359static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100360lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
361 char *buf)
dea31012005-04-17 16:05:31 -0500362{
Tony Jonesee959b02008-02-22 00:13:36 +0100363 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500364 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
365 struct lpfc_hba *phba = vport->phba;
366
dea31012005-04-17 16:05:31 -0500367 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
368}
James Smarte59058c2008-08-24 21:49:00 -0400369
370/**
James Smart3621a712009-04-06 18:47:14 -0400371 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400372 * @dev: class converted to a Scsi_host structure.
373 * @attr: device attribute, not used.
374 * @buf: on return contains text describing the state of the link.
375 *
376 * Notes:
377 * The switch statement has no default so zero will be returned.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100382lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
dea31012005-04-17 16:05:31 -0500384{
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388 int len = 0;
389
390 switch (phba->link_state) {
391 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500392 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500393 case LPFC_INIT_START:
394 case LPFC_INIT_MBX_CMDS:
395 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500396 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500397 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
398 break;
399 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500400 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500401 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400402 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500403
404 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500405 case LPFC_LOCAL_CFG_LINK:
406 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500407 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500408 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500409 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500410 case LPFC_FLOGI:
411 case LPFC_FABRIC_CFG_LINK:
412 case LPFC_NS_REG:
413 case LPFC_NS_QRY:
414 case LPFC_BUILD_DISC_LIST:
415 case LPFC_DISC_AUTH:
416 len += snprintf(buf + len, PAGE_SIZE - len,
417 "Discovery\n");
418 break;
419 case LPFC_VPORT_READY:
420 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
421 break;
422
James Smart92d7f7b2007-06-17 19:56:38 -0500423 case LPFC_VPORT_FAILED:
424 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
425 break;
426
427 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500428 len += snprintf(buf + len, PAGE_SIZE - len,
429 "Unknown\n");
430 break;
431 }
James Smart84774a42008-08-24 21:50:06 -0400432 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
433 len += snprintf(buf + len, PAGE_SIZE-len,
434 " Menlo Maint Mode\n");
435 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500436 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500437 len += snprintf(buf + len, PAGE_SIZE-len,
438 " Public Loop\n");
439 else
440 len += snprintf(buf + len, PAGE_SIZE-len,
441 " Private Loop\n");
442 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500443 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500444 len += snprintf(buf + len, PAGE_SIZE-len,
445 " Fabric\n");
446 else
447 len += snprintf(buf + len, PAGE_SIZE-len,
448 " Point-2-Point\n");
449 }
450 }
James Smart2e0fef82007-06-17 19:56:36 -0500451
dea31012005-04-17 16:05:31 -0500452 return len;
453}
454
James Smarte59058c2008-08-24 21:49:00 -0400455/**
James Smart3621a712009-04-06 18:47:14 -0400456 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400457 * @dev: class device that is converted into a Scsi_host.
458 * @attr: device attribute, not used.
459 * @buf: on return contains the sum of fc mapped and unmapped.
460 *
461 * Description:
462 * Returns the ascii text number of the sum of the fc mapped and unmapped
463 * vport counts.
464 *
465 * Returns: size of formatted string.
466 **/
dea31012005-04-17 16:05:31 -0500467static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100468lpfc_num_discovered_ports_show(struct device *dev,
469 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500470{
Tony Jonesee959b02008-02-22 00:13:36 +0100471 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500472 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
473
474 return snprintf(buf, PAGE_SIZE, "%d\n",
475 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500476}
477
James Smarte59058c2008-08-24 21:49:00 -0400478/**
James Smart3621a712009-04-06 18:47:14 -0400479 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400480 * @shost: Scsi_Host pointer.
481 *
482 * Description:
483 * Bring the link down gracefully then re-init the link. The firmware will
484 * re-init the fiber channel interface as required. Does not issue a LIP.
485 *
486 * Returns:
487 * -EPERM port offline or management commands are being blocked
488 * -ENOMEM cannot allocate memory for the mailbox command
489 * -EIO error sending the mailbox command
490 * zero for success
491 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700492static int
James Smart2e0fef82007-06-17 19:56:36 -0500493lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500494{
James Smart2e0fef82007-06-17 19:56:36 -0500495 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
496 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500497 LPFC_MBOXQ_t *pmboxq;
498 int mbxstatus = MBXERR_ERROR;
499
James Smart2e0fef82007-06-17 19:56:36 -0500500 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500501 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500502 return -EPERM;
503
504 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
505
506 if (!pmboxq)
507 return -ENOMEM;
508
509 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400510 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
511 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400512
James Smart33ccf8d2006-08-17 11:57:58 -0400513 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500514
James Smart04c68492009-05-22 14:52:52 -0400515 if ((mbxstatus == MBX_SUCCESS) &&
516 (pmboxq->u.mb.mbxStatus == 0 ||
517 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400518 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
519 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
520 phba->cfg_link_speed);
521 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
522 phba->fc_ratov * 2);
523 }
524
James Smart5b8bd0c2007-04-25 09:52:49 -0400525 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500526 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400527 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500528
529 if (mbxstatus == MBXERR_ERROR)
530 return -EIO;
531
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700532 return 0;
dea31012005-04-17 16:05:31 -0500533}
534
James Smarte59058c2008-08-24 21:49:00 -0400535/**
James Smart3621a712009-04-06 18:47:14 -0400536 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400537 * @phba: lpfc_hba pointer.
538 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
539 *
540 * Notes:
541 * Assumes any error from lpfc_do_offline() will be negative.
542 * Can wait up to 5 seconds for the port ring buffers count
543 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400544 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400545 *
546 * Returns:
547 * -EIO error posting the event
548 * zero for success
549 **/
James Smart40496f02006-07-06 15:50:22 -0400550static int
James Smart46fa3112007-04-25 09:51:45 -0400551lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
552{
553 struct completion online_compl;
554 struct lpfc_sli_ring *pring;
555 struct lpfc_sli *psli;
556 int status = 0;
557 int cnt = 0;
558 int i;
559
560 init_completion(&online_compl);
561 lpfc_workq_post_event(phba, &status, &online_compl,
562 LPFC_EVT_OFFLINE_PREP);
563 wait_for_completion(&online_compl);
564
565 if (status != 0)
566 return -EIO;
567
568 psli = &phba->sli;
569
James Smart09372822008-01-11 01:52:54 -0500570 /* Wait a little for things to settle down, but not
571 * long enough for dev loss timeout to expire.
572 */
James Smart46fa3112007-04-25 09:51:45 -0400573 for (i = 0; i < psli->num_rings; i++) {
574 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400575 while (pring->txcmplq_cnt) {
576 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500577 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400578 lpfc_printf_log(phba,
579 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400580 "0466 Outstanding IO when "
581 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400582 break;
583 }
584 }
585 }
586
587 init_completion(&online_compl);
588 lpfc_workq_post_event(phba, &status, &online_compl, type);
589 wait_for_completion(&online_compl);
590
591 if (status != 0)
592 return -EIO;
593
594 return 0;
595}
596
James Smarte59058c2008-08-24 21:49:00 -0400597/**
James Smart3621a712009-04-06 18:47:14 -0400598 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400599 * @phba: lpfc_hba pointer.
600 *
601 * Description:
602 * If the port is configured to allow a reset then the hba is brought
603 * offline then online.
604 *
605 * Notes:
606 * Assumes any error from lpfc_do_offline() will be negative.
607 *
608 * Returns:
609 * lpfc_do_offline() return code if not zero
610 * -EIO reset not configured or error posting the event
611 * zero for success
612 **/
James Smart46fa3112007-04-25 09:51:45 -0400613static int
James Smart40496f02006-07-06 15:50:22 -0400614lpfc_selective_reset(struct lpfc_hba *phba)
615{
616 struct completion online_compl;
617 int status = 0;
618
James Smart13815c82008-01-11 01:52:48 -0500619 if (!phba->cfg_enable_hba_reset)
620 return -EIO;
621
James Smart46fa3112007-04-25 09:51:45 -0400622 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400623
624 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400625 return status;
James Smart40496f02006-07-06 15:50:22 -0400626
627 init_completion(&online_compl);
628 lpfc_workq_post_event(phba, &status, &online_compl,
629 LPFC_EVT_ONLINE);
630 wait_for_completion(&online_compl);
631
632 if (status != 0)
633 return -EIO;
634
635 return 0;
636}
637
James Smarte59058c2008-08-24 21:49:00 -0400638/**
James Smart3621a712009-04-06 18:47:14 -0400639 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400640 * @dev: class device that is converted into a Scsi_host.
641 * @attr: device attribute, not used.
642 * @buf: containing the string "selective".
643 * @count: unused variable.
644 *
645 * Description:
646 * If the buf contains the string "selective" then lpfc_selective_reset()
647 * is called to perform the reset.
648 *
649 * Notes:
650 * Assumes any error from lpfc_selective_reset() will be negative.
651 * If lpfc_selective_reset() returns zero then the length of the buffer
652 * is returned which indicates succcess
653 *
654 * Returns:
655 * -EINVAL if the buffer does not contain the string "selective"
656 * length of buf if lpfc-selective_reset() if the call succeeds
657 * return value of lpfc_selective_reset() if the call fails
658**/
James Smart40496f02006-07-06 15:50:22 -0400659static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100660lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
661 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400662{
Tony Jonesee959b02008-02-22 00:13:36 +0100663 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500664 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
665 struct lpfc_hba *phba = vport->phba;
666
James Smart40496f02006-07-06 15:50:22 -0400667 int status = -EINVAL;
668
669 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
670 status = lpfc_selective_reset(phba);
671
672 if (status == 0)
673 return strlen(buf);
674 else
675 return status;
676}
677
James Smarte59058c2008-08-24 21:49:00 -0400678/**
James Smart3621a712009-04-06 18:47:14 -0400679 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400680 * @dev: class device that is converted into a Scsi_host.
681 * @attr: device attribute, not used.
682 * @buf: on return contains the ascii number of nport events.
683 *
684 * Returns: size of formatted string.
685 **/
dea31012005-04-17 16:05:31 -0500686static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100687lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
688 char *buf)
dea31012005-04-17 16:05:31 -0500689{
Tony Jonesee959b02008-02-22 00:13:36 +0100690 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500691 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
692 struct lpfc_hba *phba = vport->phba;
693
dea31012005-04-17 16:05:31 -0500694 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
695}
696
James Smarte59058c2008-08-24 21:49:00 -0400697/**
James Smart3621a712009-04-06 18:47:14 -0400698 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400699 * @dev: class device that is converted into a Scsi_host.
700 * @attr: device attribute, not used.
701 * @buf: on return contains the state of the adapter.
702 *
703 * Returns: size of formatted string.
704 **/
dea31012005-04-17 16:05:31 -0500705static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100706lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
707 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500708{
Tony Jonesee959b02008-02-22 00:13:36 +0100709 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500710 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
711 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500712 char * state;
713
James Smart2e0fef82007-06-17 19:56:36 -0500714 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500715 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500716 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500717 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500718 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500719 state = "offline";
720 else
721 state = "online";
722
723 return snprintf(buf, PAGE_SIZE, "%s\n", state);
724}
725
James Smarte59058c2008-08-24 21:49:00 -0400726/**
James Smart3621a712009-04-06 18:47:14 -0400727 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400728 * @dev: class device that is converted into a Scsi_host.
729 * @attr: device attribute, not used.
730 * @buf: containing one of the strings "online", "offline", "warm" or "error".
731 * @count: unused variable.
732 *
733 * Returns:
734 * -EACCES if enable hba reset not enabled
735 * -EINVAL if the buffer does not contain a valid string (see above)
736 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
737 * buf length greater than zero indicates success
738 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500739static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100740lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
741 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500742{
Tony Jonesee959b02008-02-22 00:13:36 +0100743 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500744 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
745 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500746 struct completion online_compl;
747 int status=0;
748
James Smart13815c82008-01-11 01:52:48 -0500749 if (!phba->cfg_enable_hba_reset)
750 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500751 init_completion(&online_compl);
752
James Smart46fa3112007-04-25 09:51:45 -0400753 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500754 lpfc_workq_post_event(phba, &status, &online_compl,
755 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400756 wait_for_completion(&online_compl);
757 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
758 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500759 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400760 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
761 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
762 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500763 else
764 return -EINVAL;
765
Jamie Wellnitz41415862006-02-28 19:25:27 -0500766 if (!status)
767 return strlen(buf);
768 else
769 return -EIO;
770}
771
James Smarte59058c2008-08-24 21:49:00 -0400772/**
James Smart3621a712009-04-06 18:47:14 -0400773 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400774 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400775 * @mxri: max xri count.
776 * @axri: available xri count.
777 * @mrpi: max rpi count.
778 * @arpi: available rpi count.
779 * @mvpi: max vpi count.
780 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400781 *
782 * Description:
783 * If an integer pointer for an count is not null then the value for the
784 * count is returned.
785 *
786 * Returns:
787 * zero on error
788 * one for success
789 **/
James Smart311464e2007-08-02 11:10:37 -0400790static int
James Smart858c9f62007-06-17 19:56:39 -0500791lpfc_get_hba_info(struct lpfc_hba *phba,
792 uint32_t *mxri, uint32_t *axri,
793 uint32_t *mrpi, uint32_t *arpi,
794 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500795{
James Smart04c68492009-05-22 14:52:52 -0400796 struct lpfc_sli *psli = &phba->sli;
797 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500798 LPFC_MBOXQ_t *pmboxq;
799 MAILBOX_t *pmb;
800 int rc = 0;
801
802 /*
803 * prevent udev from issuing mailbox commands until the port is
804 * configured.
805 */
806 if (phba->link_state < LPFC_LINK_DOWN ||
807 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400808 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500809 return 0;
810
811 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
812 return 0;
813
814 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
815 if (!pmboxq)
816 return 0;
817 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
818
James Smart04c68492009-05-22 14:52:52 -0400819 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500820 pmb->mbxCommand = MBX_READ_CONFIG;
821 pmb->mbxOwner = OWN_HOST;
822 pmboxq->context1 = NULL;
823
824 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -0400825 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart92d7f7b2007-06-17 19:56:38 -0500826 rc = MBX_NOT_FINISHED;
827 else
828 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
829
830 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500831 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500832 mempool_free(pmboxq, phba->mbox_mem_pool);
833 return 0;
834 }
835
James Smartda0436e2009-05-22 14:51:39 -0400836 if (phba->sli_rev == LPFC_SLI_REV4) {
837 rd_config = &pmboxq->u.mqe.un.rd_config;
838 if (mrpi)
839 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
840 if (arpi)
841 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
842 phba->sli4_hba.max_cfg_param.rpi_used;
843 if (mxri)
844 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
845 if (axri)
846 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
847 phba->sli4_hba.max_cfg_param.xri_used;
848 if (mvpi)
849 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
850 if (avpi)
851 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
852 phba->sli4_hba.max_cfg_param.vpi_used;
853 } else {
854 if (mrpi)
855 *mrpi = pmb->un.varRdConfig.max_rpi;
856 if (arpi)
857 *arpi = pmb->un.varRdConfig.avail_rpi;
858 if (mxri)
859 *mxri = pmb->un.varRdConfig.max_xri;
860 if (axri)
861 *axri = pmb->un.varRdConfig.avail_xri;
862 if (mvpi)
863 *mvpi = pmb->un.varRdConfig.max_vpi;
864 if (avpi)
865 *avpi = pmb->un.varRdConfig.avail_vpi;
866 }
James Smart92d7f7b2007-06-17 19:56:38 -0500867
868 mempool_free(pmboxq, phba->mbox_mem_pool);
869 return 1;
870}
871
James Smarte59058c2008-08-24 21:49:00 -0400872/**
James Smart3621a712009-04-06 18:47:14 -0400873 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400874 * @dev: class device that is converted into a Scsi_host.
875 * @attr: device attribute, not used.
876 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
877 *
878 * Description:
879 * Calls lpfc_get_hba_info() asking for just the mrpi count.
880 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
881 * to "Unknown" and the buffer length is returned, therefore the caller
882 * must check for "Unknown" in the buffer to detect a failure.
883 *
884 * Returns: size of formatted string.
885 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500886static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100887lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
888 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500889{
Tony Jonesee959b02008-02-22 00:13:36 +0100890 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500891 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
892 struct lpfc_hba *phba = vport->phba;
893 uint32_t cnt;
894
James Smart858c9f62007-06-17 19:56:39 -0500895 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500896 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
897 return snprintf(buf, PAGE_SIZE, "Unknown\n");
898}
899
James Smarte59058c2008-08-24 21:49:00 -0400900/**
James Smart3621a712009-04-06 18:47:14 -0400901 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400902 * @dev: class device that is converted into a Scsi_host.
903 * @attr: device attribute, not used.
904 * @buf: containing the used rpi count in decimal or "Unknown".
905 *
906 * Description:
907 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
908 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
909 * to "Unknown" and the buffer length is returned, therefore the caller
910 * must check for "Unknown" in the buffer to detect a failure.
911 *
912 * Returns: size of formatted string.
913 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500914static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100915lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
916 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500917{
Tony Jonesee959b02008-02-22 00:13:36 +0100918 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500919 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
920 struct lpfc_hba *phba = vport->phba;
921 uint32_t cnt, acnt;
922
James Smart858c9f62007-06-17 19:56:39 -0500923 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500924 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
925 return snprintf(buf, PAGE_SIZE, "Unknown\n");
926}
927
James Smarte59058c2008-08-24 21:49:00 -0400928/**
James Smart3621a712009-04-06 18:47:14 -0400929 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -0400930 * @dev: class device that is converted into a Scsi_host.
931 * @attr: device attribute, not used.
932 * @buf: on return contains the maximum xri count in decimal or "Unknown".
933 *
934 * Description:
935 * Calls lpfc_get_hba_info() asking for just the mrpi count.
936 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
937 * to "Unknown" and the buffer length is returned, therefore the caller
938 * must check for "Unknown" in the buffer to detect a failure.
939 *
940 * Returns: size of formatted string.
941 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500942static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100943lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
944 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500945{
Tony Jonesee959b02008-02-22 00:13:36 +0100946 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500947 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
948 struct lpfc_hba *phba = vport->phba;
949 uint32_t cnt;
950
James Smart858c9f62007-06-17 19:56:39 -0500951 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500952 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
953 return snprintf(buf, PAGE_SIZE, "Unknown\n");
954}
955
James Smarte59058c2008-08-24 21:49:00 -0400956/**
James Smart3621a712009-04-06 18:47:14 -0400957 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -0400958 * @dev: class device that is converted into a Scsi_host.
959 * @attr: device attribute, not used.
960 * @buf: on return contains the used xri count in decimal or "Unknown".
961 *
962 * Description:
963 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
964 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
965 * to "Unknown" and the buffer length is returned, therefore the caller
966 * must check for "Unknown" in the buffer to detect a failure.
967 *
968 * Returns: size of formatted string.
969 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500970static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100971lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
972 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500973{
Tony Jonesee959b02008-02-22 00:13:36 +0100974 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500975 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
976 struct lpfc_hba *phba = vport->phba;
977 uint32_t cnt, acnt;
978
James Smart858c9f62007-06-17 19:56:39 -0500979 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
980 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
981 return snprintf(buf, PAGE_SIZE, "Unknown\n");
982}
983
James Smarte59058c2008-08-24 21:49:00 -0400984/**
James Smart3621a712009-04-06 18:47:14 -0400985 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -0400986 * @dev: class device that is converted into a Scsi_host.
987 * @attr: device attribute, not used.
988 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
989 *
990 * Description:
991 * Calls lpfc_get_hba_info() asking for just the mvpi count.
992 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
993 * to "Unknown" and the buffer length is returned, therefore the caller
994 * must check for "Unknown" in the buffer to detect a failure.
995 *
996 * Returns: size of formatted string.
997 **/
James Smart858c9f62007-06-17 19:56:39 -0500998static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100999lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1000 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001001{
Tony Jonesee959b02008-02-22 00:13:36 +01001002 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001003 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1004 struct lpfc_hba *phba = vport->phba;
1005 uint32_t cnt;
1006
1007 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1008 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1009 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1010}
1011
James Smarte59058c2008-08-24 21:49:00 -04001012/**
James Smart3621a712009-04-06 18:47:14 -04001013 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001014 * @dev: class device that is converted into a Scsi_host.
1015 * @attr: device attribute, not used.
1016 * @buf: on return contains the used vpi count in decimal or "Unknown".
1017 *
1018 * Description:
1019 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1020 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1021 * to "Unknown" and the buffer length is returned, therefore the caller
1022 * must check for "Unknown" in the buffer to detect a failure.
1023 *
1024 * Returns: size of formatted string.
1025 **/
James Smart858c9f62007-06-17 19:56:39 -05001026static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001027lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1028 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001029{
Tony Jonesee959b02008-02-22 00:13:36 +01001030 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001031 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1032 struct lpfc_hba *phba = vport->phba;
1033 uint32_t cnt, acnt;
1034
1035 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001036 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1037 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1038}
1039
James Smarte59058c2008-08-24 21:49:00 -04001040/**
James Smart3621a712009-04-06 18:47:14 -04001041 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001042 * @dev: class device that is converted into a Scsi_host.
1043 * @attr: device attribute, not used.
1044 * @buf: text that must be interpreted to determine if npiv is supported.
1045 *
1046 * Description:
1047 * Buffer will contain text indicating npiv is not suppoerted on the port,
1048 * the port is an NPIV physical port, or it is an npiv virtual port with
1049 * the id of the vport.
1050 *
1051 * Returns: size of formatted string.
1052 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001053static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001054lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1055 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001056{
Tony Jonesee959b02008-02-22 00:13:36 +01001057 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001058 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1059 struct lpfc_hba *phba = vport->phba;
1060
1061 if (!(phba->max_vpi))
1062 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1063 if (vport->port_type == LPFC_PHYSICAL_PORT)
1064 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1065 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1066}
1067
James Smarte59058c2008-08-24 21:49:00 -04001068/**
James Smart3621a712009-04-06 18:47:14 -04001069 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001070 * @dev: class device that is converted into a Scsi_host.
1071 * @attr: device attribute, not used.
1072 * @buf: on return contains the cfg_poll in hex.
1073 *
1074 * Notes:
1075 * cfg_poll should be a lpfc_polling_flags type.
1076 *
1077 * Returns: size of formatted string.
1078 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001079static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001080lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1081 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001082{
Tony Jonesee959b02008-02-22 00:13:36 +01001083 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001084 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1085 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001086
1087 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1088}
1089
James Smarte59058c2008-08-24 21:49:00 -04001090/**
James Smart3621a712009-04-06 18:47:14 -04001091 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001092 * @dev: class device that is converted into a Scsi_host.
1093 * @attr: device attribute, not used.
1094 * @buf: one or more lpfc_polling_flags values.
1095 * @count: not used.
1096 *
1097 * Notes:
1098 * buf contents converted to integer and checked for a valid value.
1099 *
1100 * Returns:
1101 * -EINVAL if the buffer connot be converted or is out of range
1102 * length of the buf on success
1103 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001104static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001105lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1106 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001107{
Tony Jonesee959b02008-02-22 00:13:36 +01001108 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1110 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001111 uint32_t creg_val;
1112 uint32_t old_val;
1113 int val=0;
1114
1115 if (!isdigit(buf[0]))
1116 return -EINVAL;
1117
1118 if (sscanf(buf, "%i", &val) != 1)
1119 return -EINVAL;
1120
1121 if ((val & 0x3) != val)
1122 return -EINVAL;
1123
James Smart2e0fef82007-06-17 19:56:36 -05001124 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001125
1126 old_val = phba->cfg_poll;
1127
1128 if (val & ENABLE_FCP_RING_POLLING) {
1129 if ((val & DISABLE_FCP_RING_INT) &&
1130 !(old_val & DISABLE_FCP_RING_INT)) {
1131 creg_val = readl(phba->HCregaddr);
1132 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1133 writel(creg_val, phba->HCregaddr);
1134 readl(phba->HCregaddr); /* flush */
1135
1136 lpfc_poll_start_timer(phba);
1137 }
1138 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001139 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001140 return -EINVAL;
1141 }
1142
1143 if (!(val & DISABLE_FCP_RING_INT) &&
1144 (old_val & DISABLE_FCP_RING_INT))
1145 {
James Smart2e0fef82007-06-17 19:56:36 -05001146 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001147 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001148 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001149 creg_val = readl(phba->HCregaddr);
1150 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1151 writel(creg_val, phba->HCregaddr);
1152 readl(phba->HCregaddr); /* flush */
1153 }
1154
1155 phba->cfg_poll = val;
1156
James Smart2e0fef82007-06-17 19:56:36 -05001157 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001158
1159 return strlen(buf);
1160}
dea31012005-04-17 16:05:31 -05001161
James Smarte59058c2008-08-24 21:49:00 -04001162/**
James Smart3621a712009-04-06 18:47:14 -04001163 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001164 *
1165 * Description:
1166 * Macro that given an attr e.g. hba_queue_depth expands
1167 * into a function with the name lpfc_hba_queue_depth_show.
1168 *
1169 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1170 * @dev: class device that is converted into a Scsi_host.
1171 * @attr: device attribute, not used.
1172 * @buf: on return contains the attribute value in decimal.
1173 *
1174 * Returns: size of formatted string.
1175 **/
dea31012005-04-17 16:05:31 -05001176#define lpfc_param_show(attr) \
1177static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001178lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1179 char *buf) \
dea31012005-04-17 16:05:31 -05001180{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001181 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001182 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1183 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001184 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001185 val = phba->cfg_##attr;\
1186 return snprintf(buf, PAGE_SIZE, "%d\n",\
1187 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001188}
1189
James Smarte59058c2008-08-24 21:49:00 -04001190/**
James Smart3621a712009-04-06 18:47:14 -04001191 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001192 *
1193 * Description:
1194 * Macro that given an attr e.g. hba_queue_depth expands
1195 * into a function with the name lpfc_hba_queue_depth_show
1196 *
1197 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1198 * @dev: class device that is converted into a Scsi_host.
1199 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001200 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001201 *
1202 * Returns: size of formatted string.
1203 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001204#define lpfc_param_hex_show(attr) \
1205static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001206lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1207 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001208{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001209 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1211 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001212 int val = 0;\
1213 val = phba->cfg_##attr;\
1214 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1215 phba->cfg_##attr);\
1216}
1217
James Smarte59058c2008-08-24 21:49:00 -04001218/**
James Smart3621a712009-04-06 18:47:14 -04001219 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001220 *
1221 * Description:
1222 * Macro that given an attr e.g. hba_queue_depth expands
1223 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1224 * takes a default argument, a minimum and maximum argument.
1225 *
1226 * lpfc_##attr##_init: Initializes an attribute.
1227 * @phba: pointer the the adapter structure.
1228 * @val: integer attribute value.
1229 *
1230 * Validates the min and max values then sets the adapter config field
1231 * accordingly, or uses the default if out of range and prints an error message.
1232 *
1233 * Returns:
1234 * zero on success
1235 * -EINVAL if default used
1236 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001237#define lpfc_param_init(attr, default, minval, maxval) \
1238static int \
1239lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1240{ \
1241 if (val >= minval && val <= maxval) {\
1242 phba->cfg_##attr = val;\
1243 return 0;\
1244 }\
1245 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001246 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1247 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001248 phba->cfg_##attr = default;\
1249 return -EINVAL;\
1250}
1251
James Smarte59058c2008-08-24 21:49:00 -04001252/**
James Smart3621a712009-04-06 18:47:14 -04001253 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001254 *
1255 * Description:
1256 * Macro that given an attr e.g. hba_queue_depth expands
1257 * into a function with the name lpfc_hba_queue_depth_set
1258 *
1259 * lpfc_##attr##_set: Sets an attribute value.
1260 * @phba: pointer the the adapter structure.
1261 * @val: integer attribute value.
1262 *
1263 * Description:
1264 * Validates the min and max values then sets the
1265 * adapter config field if in the valid range. prints error message
1266 * and does not set the parameter if invalid.
1267 *
1268 * Returns:
1269 * zero on success
1270 * -EINVAL if val is invalid
1271 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001272#define lpfc_param_set(attr, default, minval, maxval) \
1273static int \
1274lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1275{ \
1276 if (val >= minval && val <= maxval) {\
1277 phba->cfg_##attr = val;\
1278 return 0;\
1279 }\
1280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001281 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1282 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001283 return -EINVAL;\
1284}
1285
James Smarte59058c2008-08-24 21:49:00 -04001286/**
James Smart3621a712009-04-06 18:47:14 -04001287 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001288 *
1289 * Description:
1290 * Macro that given an attr e.g. hba_queue_depth expands
1291 * into a function with the name lpfc_hba_queue_depth_store.
1292 *
1293 * lpfc_##attr##_store: Set an sttribute value.
1294 * @dev: class device that is converted into a Scsi_host.
1295 * @attr: device attribute, not used.
1296 * @buf: contains the attribute value in ascii.
1297 * @count: not used.
1298 *
1299 * Description:
1300 * Convert the ascii text number to an integer, then
1301 * use the lpfc_##attr##_set function to set the value.
1302 *
1303 * Returns:
1304 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1305 * length of buffer upon success.
1306 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001307#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001308static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001309lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1310 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001311{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001312 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001313 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1314 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001315 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001316 if (!isdigit(buf[0]))\
1317 return -EINVAL;\
1318 if (sscanf(buf, "%i", &val) != 1)\
1319 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001320 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001321 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001322 else \
1323 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001324}
1325
James Smarte59058c2008-08-24 21:49:00 -04001326/**
James Smart3621a712009-04-06 18:47:14 -04001327 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001328 *
1329 * Description:
1330 * Macro that given an attr e.g. hba_queue_depth expands
1331 * into a function with the name lpfc_hba_queue_depth_show
1332 *
1333 * lpfc_##attr##_show: prints the attribute value in decimal.
1334 * @dev: class device that is converted into a Scsi_host.
1335 * @attr: device attribute, not used.
1336 * @buf: on return contains the attribute value in decimal.
1337 *
1338 * Returns: length of formatted string.
1339 **/
James Smart3de2a652007-08-02 11:09:59 -04001340#define lpfc_vport_param_show(attr) \
1341static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001342lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1343 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001344{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001345 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001346 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1347 int val = 0;\
1348 val = vport->cfg_##attr;\
1349 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1350}
1351
James Smarte59058c2008-08-24 21:49:00 -04001352/**
James Smart3621a712009-04-06 18:47:14 -04001353 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001354 *
1355 * Description:
1356 * Macro that given an attr e.g.
1357 * hba_queue_depth expands into a function with the name
1358 * lpfc_hba_queue_depth_show
1359 *
James Smart3621a712009-04-06 18:47:14 -04001360 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001361 * @dev: class device that is converted into a Scsi_host.
1362 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001363 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001364 *
1365 * Returns: length of formatted string.
1366 **/
James Smart3de2a652007-08-02 11:09:59 -04001367#define lpfc_vport_param_hex_show(attr) \
1368static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001369lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1370 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001371{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001372 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1374 int val = 0;\
1375 val = vport->cfg_##attr;\
1376 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1377}
1378
James Smarte59058c2008-08-24 21:49:00 -04001379/**
James Smart3621a712009-04-06 18:47:14 -04001380 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001381 *
1382 * Description:
1383 * Macro that given an attr e.g. hba_queue_depth expands
1384 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1385 * takes a default argument, a minimum and maximum argument.
1386 *
1387 * lpfc_##attr##_init: validates the min and max values then sets the
1388 * adapter config field accordingly, or uses the default if out of range
1389 * and prints an error message.
1390 * @phba: pointer the the adapter structure.
1391 * @val: integer attribute value.
1392 *
1393 * Returns:
1394 * zero on success
1395 * -EINVAL if default used
1396 **/
James Smart3de2a652007-08-02 11:09:59 -04001397#define lpfc_vport_param_init(attr, default, minval, maxval) \
1398static int \
1399lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1400{ \
1401 if (val >= minval && val <= maxval) {\
1402 vport->cfg_##attr = val;\
1403 return 0;\
1404 }\
James Smarte8b62012007-08-02 11:10:09 -04001405 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001406 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001407 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001408 vport->cfg_##attr = default;\
1409 return -EINVAL;\
1410}
1411
James Smarte59058c2008-08-24 21:49:00 -04001412/**
James Smart3621a712009-04-06 18:47:14 -04001413 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001414 *
1415 * Description:
1416 * Macro that given an attr e.g. hba_queue_depth expands
1417 * into a function with the name lpfc_hba_queue_depth_set
1418 *
1419 * lpfc_##attr##_set: validates the min and max values then sets the
1420 * adapter config field if in the valid range. prints error message
1421 * and does not set the parameter if invalid.
1422 * @phba: pointer the the adapter structure.
1423 * @val: integer attribute value.
1424 *
1425 * Returns:
1426 * zero on success
1427 * -EINVAL if val is invalid
1428 **/
James Smart3de2a652007-08-02 11:09:59 -04001429#define lpfc_vport_param_set(attr, default, minval, maxval) \
1430static int \
1431lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1432{ \
1433 if (val >= minval && val <= maxval) {\
1434 vport->cfg_##attr = val;\
1435 return 0;\
1436 }\
James Smarte8b62012007-08-02 11:10:09 -04001437 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001438 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001439 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001440 return -EINVAL;\
1441}
1442
James Smarte59058c2008-08-24 21:49:00 -04001443/**
James Smart3621a712009-04-06 18:47:14 -04001444 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001445 *
1446 * Description:
1447 * Macro that given an attr e.g. hba_queue_depth
1448 * expands into a function with the name lpfc_hba_queue_depth_store
1449 *
1450 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1451 * use the lpfc_##attr##_set function to set the value.
1452 * @cdev: class device that is converted into a Scsi_host.
1453 * @buf: contains the attribute value in decimal.
1454 * @count: not used.
1455 *
1456 * Returns:
1457 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1458 * length of buffer upon success.
1459 **/
James Smart3de2a652007-08-02 11:09:59 -04001460#define lpfc_vport_param_store(attr) \
1461static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001462lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1463 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001464{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001465 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001466 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1467 int val=0;\
1468 if (!isdigit(buf[0]))\
1469 return -EINVAL;\
1470 if (sscanf(buf, "%i", &val) != 1)\
1471 return -EINVAL;\
1472 if (lpfc_##attr##_set(vport, val) == 0) \
1473 return strlen(buf);\
1474 else \
1475 return -EINVAL;\
1476}
1477
1478
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001479#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1480static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001481module_param(lpfc_##name, int, 0);\
1482MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001483lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001484
1485#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1486static int lpfc_##name = defval;\
1487module_param(lpfc_##name, int, 0);\
1488MODULE_PARM_DESC(lpfc_##name, desc);\
1489lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001490lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001491static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001492
1493#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1494static int lpfc_##name = defval;\
1495module_param(lpfc_##name, int, 0);\
1496MODULE_PARM_DESC(lpfc_##name, desc);\
1497lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001498lpfc_param_init(name, defval, minval, maxval)\
1499lpfc_param_set(name, defval, minval, maxval)\
1500lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001501static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1502 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001503
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001504#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1505static int lpfc_##name = defval;\
1506module_param(lpfc_##name, int, 0);\
1507MODULE_PARM_DESC(lpfc_##name, desc);\
1508lpfc_param_hex_show(name)\
1509lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001510static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001511
1512#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1513static int lpfc_##name = defval;\
1514module_param(lpfc_##name, int, 0);\
1515MODULE_PARM_DESC(lpfc_##name, desc);\
1516lpfc_param_hex_show(name)\
1517lpfc_param_init(name, defval, minval, maxval)\
1518lpfc_param_set(name, defval, minval, maxval)\
1519lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001520static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1521 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001522
James Smart3de2a652007-08-02 11:09:59 -04001523#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1524static int lpfc_##name = defval;\
1525module_param(lpfc_##name, int, 0);\
1526MODULE_PARM_DESC(lpfc_##name, desc);\
1527lpfc_vport_param_init(name, defval, minval, maxval)
1528
1529#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1530static int lpfc_##name = defval;\
1531module_param(lpfc_##name, int, 0);\
1532MODULE_PARM_DESC(lpfc_##name, desc);\
1533lpfc_vport_param_show(name)\
1534lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001535static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001536
1537#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1538static int lpfc_##name = defval;\
1539module_param(lpfc_##name, int, 0);\
1540MODULE_PARM_DESC(lpfc_##name, desc);\
1541lpfc_vport_param_show(name)\
1542lpfc_vport_param_init(name, defval, minval, maxval)\
1543lpfc_vport_param_set(name, defval, minval, maxval)\
1544lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001545static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1546 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001547
1548#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1549static int lpfc_##name = defval;\
1550module_param(lpfc_##name, int, 0);\
1551MODULE_PARM_DESC(lpfc_##name, desc);\
1552lpfc_vport_param_hex_show(name)\
1553lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001554static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001555
1556#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1557static int lpfc_##name = defval;\
1558module_param(lpfc_##name, int, 0);\
1559MODULE_PARM_DESC(lpfc_##name, desc);\
1560lpfc_vport_param_hex_show(name)\
1561lpfc_vport_param_init(name, defval, minval, maxval)\
1562lpfc_vport_param_set(name, defval, minval, maxval)\
1563lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001564static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1565 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001566
James Smart81301a92008-12-04 22:39:46 -05001567static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1568static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1569static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1570static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001571static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1572static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1573static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1574static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1575static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1576static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1577static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1578static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001579static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001580static DEVICE_ATTR(option_rom_version, S_IRUGO,
1581 lpfc_option_rom_version_show, NULL);
1582static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1583 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001584static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001585static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1586static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1587static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1588 lpfc_board_mode_show, lpfc_board_mode_store);
1589static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1590static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1591static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1592static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1593static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1594static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1595static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1596static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1597static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001598
James Smartc3f28af2006-08-18 17:47:18 -04001599
James Smarta12e07b2006-12-02 13:35:30 -05001600static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001601
James Smarte59058c2008-08-24 21:49:00 -04001602/**
James Smart3621a712009-04-06 18:47:14 -04001603 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001604 * @dev: class device that is converted into a Scsi_host.
1605 * @attr: device attribute, not used.
1606 * @buf: containing the string lpfc_soft_wwn_key.
1607 * @count: must be size of lpfc_soft_wwn_key.
1608 *
1609 * Returns:
1610 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1611 * length of buf indicates success
1612 **/
James Smartc3f28af2006-08-18 17:47:18 -04001613static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001614lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1615 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001616{
Tony Jonesee959b02008-02-22 00:13:36 +01001617 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001618 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1619 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001620 unsigned int cnt = count;
1621
1622 /*
1623 * We're doing a simple sanity check for soft_wwpn setting.
1624 * We require that the user write a specific key to enable
1625 * the soft_wwpn attribute to be settable. Once the attribute
1626 * is written, the enable key resets. If further updates are
1627 * desired, the key must be written again to re-enable the
1628 * attribute.
1629 *
1630 * The "key" is not secret - it is a hardcoded string shown
1631 * here. The intent is to protect against the random user or
1632 * application that is just writing attributes.
1633 */
1634
1635 /* count may include a LF at end of string */
1636 if (buf[cnt-1] == '\n')
1637 cnt--;
1638
James Smarta12e07b2006-12-02 13:35:30 -05001639 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1640 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001641 return -EINVAL;
1642
James Smarta12e07b2006-12-02 13:35:30 -05001643 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001644 return count;
1645}
Tony Jonesee959b02008-02-22 00:13:36 +01001646static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1647 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001648
James Smarte59058c2008-08-24 21:49:00 -04001649/**
James Smart3621a712009-04-06 18:47:14 -04001650 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001651 * @dev: class device that is converted into a Scsi_host.
1652 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001653 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001654 *
1655 * Returns: size of formatted string.
1656 **/
James Smartc3f28af2006-08-18 17:47:18 -04001657static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001658lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1659 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001660{
Tony Jonesee959b02008-02-22 00:13:36 +01001661 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1663 struct lpfc_hba *phba = vport->phba;
1664
Randy Dunlapafc071e2006-10-23 21:47:13 -07001665 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1666 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001667}
1668
James Smarte59058c2008-08-24 21:49:00 -04001669/**
James Smart3621a712009-04-06 18:47:14 -04001670 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001671 * @dev class device that is converted into a Scsi_host.
1672 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001673 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001674 * @count: number of wwpn bytes in buf
1675 *
1676 * Returns:
1677 * -EACCES hba reset not enabled, adapter over temp
1678 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1679 * -EIO error taking adapter offline or online
1680 * value of count on success
1681 **/
James Smartc3f28af2006-08-18 17:47:18 -04001682static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001683lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1684 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001685{
Tony Jonesee959b02008-02-22 00:13:36 +01001686 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1688 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001689 struct completion online_compl;
1690 int stat1=0, stat2=0;
1691 unsigned int i, j, cnt=count;
1692 u8 wwpn[8];
1693
James Smart13815c82008-01-11 01:52:48 -05001694 if (!phba->cfg_enable_hba_reset)
1695 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001696 spin_lock_irq(&phba->hbalock);
1697 if (phba->over_temp_state == HBA_OVER_TEMP) {
1698 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001699 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001700 }
1701 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001702 /* count may include a LF at end of string */
1703 if (buf[cnt-1] == '\n')
1704 cnt--;
1705
James Smarta12e07b2006-12-02 13:35:30 -05001706 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001707 ((cnt == 17) && (*buf++ != 'x')) ||
1708 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1709 return -EINVAL;
1710
James Smarta12e07b2006-12-02 13:35:30 -05001711 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001712
1713 memset(wwpn, 0, sizeof(wwpn));
1714
1715 /* Validate and store the new name */
1716 for (i=0, j=0; i < 16; i++) {
1717 if ((*buf >= 'a') && (*buf <= 'f'))
1718 j = ((j << 4) | ((*buf++ -'a') + 10));
1719 else if ((*buf >= 'A') && (*buf <= 'F'))
1720 j = ((j << 4) | ((*buf++ -'A') + 10));
1721 else if ((*buf >= '0') && (*buf <= '9'))
1722 j = ((j << 4) | (*buf++ -'0'));
1723 else
1724 return -EINVAL;
1725 if (i % 2) {
1726 wwpn[i/2] = j & 0xff;
1727 j = 0;
1728 }
1729 }
1730 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001731 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001732 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001733 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001734
1735 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1736 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1737
James Smart46fa3112007-04-25 09:51:45 -04001738 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001739 if (stat1)
1740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001741 "0463 lpfc_soft_wwpn attribute set failed to "
1742 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001743 init_completion(&online_compl);
1744 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1745 wait_for_completion(&online_compl);
1746 if (stat2)
1747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001748 "0464 lpfc_soft_wwpn attribute set failed to "
1749 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001750 return (stat1 || stat2) ? -EIO : count;
1751}
Tony Jonesee959b02008-02-22 00:13:36 +01001752static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1753 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001754
James Smarte59058c2008-08-24 21:49:00 -04001755/**
James Smart3621a712009-04-06 18:47:14 -04001756 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001757 * @dev: class device that is converted into a Scsi_host.
1758 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001759 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001760 *
1761 * Returns: size of formatted string.
1762 **/
James Smarta12e07b2006-12-02 13:35:30 -05001763static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001764lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1765 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001766{
Tony Jonesee959b02008-02-22 00:13:36 +01001767 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001768 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001769 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1770 (unsigned long long)phba->cfg_soft_wwnn);
1771}
1772
James Smarte59058c2008-08-24 21:49:00 -04001773/**
James Smart3621a712009-04-06 18:47:14 -04001774 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001775 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001776 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001777 * @count: number of wwnn bytes in buf.
1778 *
1779 * Returns:
1780 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1781 * value of count on success
1782 **/
James Smarta12e07b2006-12-02 13:35:30 -05001783static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001784lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1785 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001786{
Tony Jonesee959b02008-02-22 00:13:36 +01001787 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001788 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001789 unsigned int i, j, cnt=count;
1790 u8 wwnn[8];
1791
1792 /* count may include a LF at end of string */
1793 if (buf[cnt-1] == '\n')
1794 cnt--;
1795
1796 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1797 ((cnt == 17) && (*buf++ != 'x')) ||
1798 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1799 return -EINVAL;
1800
1801 /*
1802 * Allow wwnn to be set many times, as long as the enable is set.
1803 * However, once the wwpn is set, everything locks.
1804 */
1805
1806 memset(wwnn, 0, sizeof(wwnn));
1807
1808 /* Validate and store the new name */
1809 for (i=0, j=0; i < 16; i++) {
1810 if ((*buf >= 'a') && (*buf <= 'f'))
1811 j = ((j << 4) | ((*buf++ -'a') + 10));
1812 else if ((*buf >= 'A') && (*buf <= 'F'))
1813 j = ((j << 4) | ((*buf++ -'A') + 10));
1814 else if ((*buf >= '0') && (*buf <= '9'))
1815 j = ((j << 4) | (*buf++ -'0'));
1816 else
1817 return -EINVAL;
1818 if (i % 2) {
1819 wwnn[i/2] = j & 0xff;
1820 j = 0;
1821 }
1822 }
1823 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1824
1825 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1826 "lpfc%d: soft_wwnn set. Value will take effect upon "
1827 "setting of the soft_wwpn\n", phba->brd_no);
1828
1829 return count;
1830}
Tony Jonesee959b02008-02-22 00:13:36 +01001831static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1832 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001833
James Smartc3f28af2006-08-18 17:47:18 -04001834
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001835static int lpfc_poll = 0;
1836module_param(lpfc_poll, int, 0);
1837MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1838 " 0 - none,"
1839 " 1 - poll with interrupts enabled"
1840 " 3 - poll and disable FCP ring interrupts");
1841
Tony Jonesee959b02008-02-22 00:13:36 +01001842static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1843 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001844
James Smart92d7f7b2007-06-17 19:56:38 -05001845int lpfc_sli_mode = 0;
1846module_param(lpfc_sli_mode, int, 0);
1847MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1848 " 0 - auto (SLI-3 if supported),"
1849 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1850 " 3 - select SLI-3");
1851
James Smart7ee5d432007-10-27 13:37:17 -04001852int lpfc_enable_npiv = 0;
1853module_param(lpfc_enable_npiv, int, 0);
1854MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1855lpfc_param_show(enable_npiv);
1856lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001857static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001858 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001859
dea31012005-04-17 16:05:31 -05001860/*
James Smartc01f3202006-08-18 17:47:08 -04001861# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1862# until the timer expires. Value range is [0,255]. Default value is 30.
1863*/
1864static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1865static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1866module_param(lpfc_nodev_tmo, int, 0);
1867MODULE_PARM_DESC(lpfc_nodev_tmo,
1868 "Seconds driver will hold I/O waiting "
1869 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001870
1871/**
James Smart3621a712009-04-06 18:47:14 -04001872 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04001873 * @dev: class converted to a Scsi_host structure.
1874 * @attr: device attribute, not used.
1875 * @buf: on return contains the dev loss timeout in decimal.
1876 *
1877 * Returns: size of formatted string.
1878 **/
James Smartc01f3202006-08-18 17:47:08 -04001879static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001880lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1881 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001882{
Tony Jonesee959b02008-02-22 00:13:36 +01001883 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001884 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001885 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001886 val = vport->cfg_devloss_tmo;
1887 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001888}
1889
James Smarte59058c2008-08-24 21:49:00 -04001890/**
James Smart3621a712009-04-06 18:47:14 -04001891 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04001892 * @vport: lpfc vport structure pointer.
1893 * @val: contains the nodev timeout value.
1894 *
1895 * Description:
1896 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1897 * a kernel error message is printed and zero is returned.
1898 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1899 * Otherwise nodev tmo is set to the default value.
1900 *
1901 * Returns:
1902 * zero if already set or if val is in range
1903 * -EINVAL val out of range
1904 **/
James Smartc01f3202006-08-18 17:47:08 -04001905static int
James Smart3de2a652007-08-02 11:09:59 -04001906lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001907{
James Smart3de2a652007-08-02 11:09:59 -04001908 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1909 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1910 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001911 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001912 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001913 "parameter because devloss_tmo is "
1914 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001915 return 0;
1916 }
1917
1918 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001919 vport->cfg_nodev_tmo = val;
1920 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001921 return 0;
1922 }
James Smarte8b62012007-08-02 11:10:09 -04001923 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1924 "0400 lpfc_nodev_tmo attribute cannot be set to"
1925 " %d, allowed range is [%d, %d]\n",
1926 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001927 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001928 return -EINVAL;
1929}
1930
James Smarte59058c2008-08-24 21:49:00 -04001931/**
James Smart3621a712009-04-06 18:47:14 -04001932 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04001933 * @vport: lpfc vport structure pointer.
1934 *
1935 * Description:
1936 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1937 **/
James Smart7054a602007-04-25 09:52:34 -04001938static void
James Smart3de2a652007-08-02 11:09:59 -04001939lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001940{
James Smart858c9f62007-06-17 19:56:39 -05001941 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001942 struct lpfc_nodelist *ndlp;
1943
James Smart51ef4c22007-08-02 11:10:31 -04001944 shost = lpfc_shost_from_vport(vport);
1945 spin_lock_irq(shost->host_lock);
1946 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001947 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001948 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1949 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001950}
1951
James Smarte59058c2008-08-24 21:49:00 -04001952/**
James Smart3621a712009-04-06 18:47:14 -04001953 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04001954 * @vport: lpfc vport structure pointer.
1955 * @val: contains the tmo value.
1956 *
1957 * Description:
1958 * If the devloss tmo is already set or the vport dev loss tmo has changed
1959 * then a kernel error message is printed and zero is returned.
1960 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1961 * Otherwise nodev tmo is set to the default value.
1962 *
1963 * Returns:
1964 * zero if already set or if val is in range
1965 * -EINVAL val out of range
1966 **/
James Smartc01f3202006-08-18 17:47:08 -04001967static int
James Smart3de2a652007-08-02 11:09:59 -04001968lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001969{
James Smart3de2a652007-08-02 11:09:59 -04001970 if (vport->dev_loss_tmo_changed ||
1971 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001972 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1973 "0401 Ignoring change to nodev_tmo "
1974 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001975 return 0;
1976 }
James Smartc01f3202006-08-18 17:47:08 -04001977 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001978 vport->cfg_nodev_tmo = val;
1979 vport->cfg_devloss_tmo = val;
1980 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001981 return 0;
1982 }
James Smarte8b62012007-08-02 11:10:09 -04001983 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1984 "0403 lpfc_nodev_tmo attribute cannot be set to"
1985 "%d, allowed range is [%d, %d]\n",
1986 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001987 return -EINVAL;
1988}
1989
James Smart3de2a652007-08-02 11:09:59 -04001990lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001991
Tony Jonesee959b02008-02-22 00:13:36 +01001992static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1993 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001994
1995/*
1996# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1997# disappear until the timer expires. Value range is [0,255]. Default
1998# value is 30.
1999*/
2000module_param(lpfc_devloss_tmo, int, 0);
2001MODULE_PARM_DESC(lpfc_devloss_tmo,
2002 "Seconds driver will hold I/O waiting "
2003 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002004lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2005 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2006lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002007
2008/**
James Smart3621a712009-04-06 18:47:14 -04002009 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002010 * @vport: lpfc vport structure pointer.
2011 * @val: contains the tmo value.
2012 *
2013 * Description:
2014 * If val is in a valid range then set the vport nodev tmo,
2015 * devloss tmo, also set the vport dev loss tmo changed flag.
2016 * Else a kernel error message is printed.
2017 *
2018 * Returns:
2019 * zero if val is in range
2020 * -EINVAL val out of range
2021 **/
James Smartc01f3202006-08-18 17:47:08 -04002022static int
James Smart3de2a652007-08-02 11:09:59 -04002023lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002024{
2025 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002026 vport->cfg_nodev_tmo = val;
2027 vport->cfg_devloss_tmo = val;
2028 vport->dev_loss_tmo_changed = 1;
2029 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002030 return 0;
2031 }
2032
James Smarte8b62012007-08-02 11:10:09 -04002033 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2034 "0404 lpfc_devloss_tmo attribute cannot be set to"
2035 " %d, allowed range is [%d, %d]\n",
2036 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002037 return -EINVAL;
2038}
2039
James Smart3de2a652007-08-02 11:09:59 -04002040lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002041static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2042 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002043
2044/*
dea31012005-04-17 16:05:31 -05002045# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2046# deluged with LOTS of information.
2047# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002048# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002049*/
James Smartf4b4c682009-05-22 14:53:12 -04002050LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002051 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002052
2053/*
James Smart7ee5d432007-10-27 13:37:17 -04002054# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2055# objects that have been registered with the nameserver after login.
2056*/
2057LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2058 "Deregister nameserver objects before LOGO");
2059
2060/*
dea31012005-04-17 16:05:31 -05002061# lun_queue_depth: This parameter is used to limit the number of outstanding
2062# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2063*/
James Smart3de2a652007-08-02 11:09:59 -04002064LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2065 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002066
2067/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002068# hba_queue_depth: This parameter is used to limit the number of outstanding
2069# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2070# value is greater than the maximum number of exchanges supported by the HBA,
2071# then maximum number of exchanges supported by the HBA is used to determine
2072# the hba_queue_depth.
2073*/
2074LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2075 "Max number of FCP commands we can queue to a lpfc HBA");
2076
2077/*
James Smart92d7f7b2007-06-17 19:56:38 -05002078# peer_port_login: This parameter allows/prevents logins
2079# between peer ports hosted on the same physical port.
2080# When this parameter is set 0 peer ports of same physical port
2081# are not allowed to login to each other.
2082# When this parameter is set 1 peer ports of same physical port
2083# are allowed to login to each other.
2084# Default value of this parameter is 0.
2085*/
James Smart3de2a652007-08-02 11:09:59 -04002086LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2087 "Allow peer ports on the same physical port to login to each "
2088 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002089
2090/*
James Smart3de2a652007-08-02 11:09:59 -04002091# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002092# between Virtual Ports and remote initiators.
2093# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2094# other initiators and will attempt to PLOGI all remote ports.
2095# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2096# remote ports and will not attempt to PLOGI to other initiators.
2097# This parameter does not restrict to the physical port.
2098# This parameter does not restrict logins to Fabric resident remote ports.
2099# Default value of this parameter is 1.
2100*/
James Smart3de2a652007-08-02 11:09:59 -04002101static int lpfc_restrict_login = 1;
2102module_param(lpfc_restrict_login, int, 0);
2103MODULE_PARM_DESC(lpfc_restrict_login,
2104 "Restrict virtual ports login to remote initiators.");
2105lpfc_vport_param_show(restrict_login);
2106
James Smarte59058c2008-08-24 21:49:00 -04002107/**
James Smart3621a712009-04-06 18:47:14 -04002108 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002109 * @vport: lpfc vport structure pointer.
2110 * @val: contains the restrict login value.
2111 *
2112 * Description:
2113 * If val is not in a valid range then log a kernel error message and set
2114 * the vport restrict login to one.
2115 * If the port type is physical clear the restrict login flag and return.
2116 * Else set the restrict login flag to val.
2117 *
2118 * Returns:
2119 * zero if val is in range
2120 * -EINVAL val out of range
2121 **/
James Smart3de2a652007-08-02 11:09:59 -04002122static int
2123lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2124{
2125 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002126 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002127 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002128 "be set to %d, allowed range is [0, 1]\n",
2129 val);
James Smart3de2a652007-08-02 11:09:59 -04002130 vport->cfg_restrict_login = 1;
2131 return -EINVAL;
2132 }
2133 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2134 vport->cfg_restrict_login = 0;
2135 return 0;
2136 }
2137 vport->cfg_restrict_login = val;
2138 return 0;
2139}
2140
James Smarte59058c2008-08-24 21:49:00 -04002141/**
James Smart3621a712009-04-06 18:47:14 -04002142 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002143 * @vport: lpfc vport structure pointer.
2144 * @val: contains the restrict login value.
2145 *
2146 * Description:
2147 * If val is not in a valid range then log a kernel error message and set
2148 * the vport restrict login to one.
2149 * If the port type is physical and the val is not zero log a kernel
2150 * error message, clear the restrict login flag and return zero.
2151 * Else set the restrict login flag to val.
2152 *
2153 * Returns:
2154 * zero if val is in range
2155 * -EINVAL val out of range
2156 **/
James Smart3de2a652007-08-02 11:09:59 -04002157static int
2158lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2159{
2160 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002161 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002162 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002163 "be set to %d, allowed range is [0, 1]\n",
2164 val);
James Smart3de2a652007-08-02 11:09:59 -04002165 vport->cfg_restrict_login = 1;
2166 return -EINVAL;
2167 }
2168 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002169 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2170 "0468 lpfc_restrict_login must be 0 for "
2171 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002172 vport->cfg_restrict_login = 0;
2173 return 0;
2174 }
2175 vport->cfg_restrict_login = val;
2176 return 0;
2177}
2178lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002179static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2180 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002181
2182/*
dea31012005-04-17 16:05:31 -05002183# Some disk devices have a "select ID" or "select Target" capability.
2184# From a protocol standpoint "select ID" usually means select the
2185# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2186# annex" which contains a table that maps a "select ID" (a number
2187# between 0 and 7F) to an ALPA. By default, for compatibility with
2188# older drivers, the lpfc driver scans this table from low ALPA to high
2189# ALPA.
2190#
2191# Turning on the scan-down variable (on = 1, off = 0) will
2192# cause the lpfc driver to use an inverted table, effectively
2193# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2194#
2195# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2196# and will not work across a fabric. Also this parameter will take
2197# effect only in the case when ALPA map is not available.)
2198*/
James Smart3de2a652007-08-02 11:09:59 -04002199LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2200 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002201
2202/*
dea31012005-04-17 16:05:31 -05002203# lpfc_topology: link topology for init link
2204# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002205# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002206# 0x02 = attempt point-to-point mode only
2207# 0x04 = attempt loop mode only
2208# 0x06 = attempt point-to-point mode then loop
2209# Set point-to-point mode if you want to run as an N_Port.
2210# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2211# Default value is 0.
2212*/
James Smarte59058c2008-08-24 21:49:00 -04002213
2214/**
James Smart3621a712009-04-06 18:47:14 -04002215 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002216 * @phba: lpfc_hba pointer.
2217 * @val: topology value.
2218 *
2219 * Description:
2220 * If val is in a valid range then set the adapter's topology field and
2221 * issue a lip; if the lip fails reset the topology to the old value.
2222 *
2223 * If the value is not in range log a kernel error message and return an error.
2224 *
2225 * Returns:
2226 * zero if val is in range and lip okay
2227 * non-zero return value from lpfc_issue_lip()
2228 * -EINVAL val out of range
2229 **/
James Smarta257bf92009-04-06 18:48:10 -04002230static ssize_t
2231lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2232 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002233{
James Smarta257bf92009-04-06 18:48:10 -04002234 struct Scsi_Host *shost = class_to_shost(dev);
2235 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2236 struct lpfc_hba *phba = vport->phba;
2237 int val = 0;
2238 int nolip = 0;
2239 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002240 int err;
2241 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002242
2243 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2244 nolip = 1;
2245 val_buf = &buf[strlen("nolip ")];
2246 }
2247
2248 if (!isdigit(val_buf[0]))
2249 return -EINVAL;
2250 if (sscanf(val_buf, "%i", &val) != 1)
2251 return -EINVAL;
2252
James Smart83108bd2008-01-11 01:53:09 -05002253 if (val >= 0 && val <= 6) {
2254 prev_val = phba->cfg_topology;
2255 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002256 if (nolip)
2257 return strlen(buf);
2258
James Smart83108bd2008-01-11 01:53:09 -05002259 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002260 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002261 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002262 return -EINVAL;
2263 } else
2264 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002265 }
2266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2267 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2268 "allowed range is [0, 6]\n",
2269 phba->brd_no, val);
2270 return -EINVAL;
2271}
2272static int lpfc_topology = 0;
2273module_param(lpfc_topology, int, 0);
2274MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2275lpfc_param_show(topology)
2276lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002277static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002278 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002279
James Smartea2151b2008-09-07 11:52:10 -04002280
2281/**
James Smart3621a712009-04-06 18:47:14 -04002282 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002283 * @dev: Pointer to class device.
2284 * @buf: Data buffer.
2285 * @count: Size of the data buffer.
2286 *
2287 * This function get called when an user write to the lpfc_stat_data_ctrl
2288 * sysfs file. This function parse the command written to the sysfs file
2289 * and take appropriate action. These commands are used for controlling
2290 * driver statistical data collection.
2291 * Following are the command this function handles.
2292 *
2293 * setbucket <bucket_type> <base> <step>
2294 * = Set the latency buckets.
2295 * destroybucket = destroy all the buckets.
2296 * start = start data collection
2297 * stop = stop data collection
2298 * reset = reset the collected data
2299 **/
2300static ssize_t
2301lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2302 const char *buf, size_t count)
2303{
2304 struct Scsi_Host *shost = class_to_shost(dev);
2305 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2306 struct lpfc_hba *phba = vport->phba;
2307#define LPFC_MAX_DATA_CTRL_LEN 1024
2308 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2309 unsigned long i;
2310 char *str_ptr, *token;
2311 struct lpfc_vport **vports;
2312 struct Scsi_Host *v_shost;
2313 char *bucket_type_str, *base_str, *step_str;
2314 unsigned long base, step, bucket_type;
2315
2316 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002317 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002318 return -EINVAL;
2319
2320 strcpy(bucket_data, buf);
2321 str_ptr = &bucket_data[0];
2322 /* Ignore this token - this is command token */
2323 token = strsep(&str_ptr, "\t ");
2324 if (!token)
2325 return -EINVAL;
2326
2327 bucket_type_str = strsep(&str_ptr, "\t ");
2328 if (!bucket_type_str)
2329 return -EINVAL;
2330
2331 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2332 bucket_type = LPFC_LINEAR_BUCKET;
2333 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2334 bucket_type = LPFC_POWER2_BUCKET;
2335 else
2336 return -EINVAL;
2337
2338 base_str = strsep(&str_ptr, "\t ");
2339 if (!base_str)
2340 return -EINVAL;
2341 base = simple_strtoul(base_str, NULL, 0);
2342
2343 step_str = strsep(&str_ptr, "\t ");
2344 if (!step_str)
2345 return -EINVAL;
2346 step = simple_strtoul(step_str, NULL, 0);
2347 if (!step)
2348 return -EINVAL;
2349
2350 /* Block the data collection for every vport */
2351 vports = lpfc_create_vport_work_array(phba);
2352 if (vports == NULL)
2353 return -ENOMEM;
2354
James Smartf4b4c682009-05-22 14:53:12 -04002355 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002356 v_shost = lpfc_shost_from_vport(vports[i]);
2357 spin_lock_irq(v_shost->host_lock);
2358 /* Block and reset data collection */
2359 vports[i]->stat_data_blocked = 1;
2360 if (vports[i]->stat_data_enabled)
2361 lpfc_vport_reset_stat_data(vports[i]);
2362 spin_unlock_irq(v_shost->host_lock);
2363 }
2364
2365 /* Set the bucket attributes */
2366 phba->bucket_type = bucket_type;
2367 phba->bucket_base = base;
2368 phba->bucket_step = step;
2369
James Smartf4b4c682009-05-22 14:53:12 -04002370 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002371 v_shost = lpfc_shost_from_vport(vports[i]);
2372
2373 /* Unblock data collection */
2374 spin_lock_irq(v_shost->host_lock);
2375 vports[i]->stat_data_blocked = 0;
2376 spin_unlock_irq(v_shost->host_lock);
2377 }
2378 lpfc_destroy_vport_work_array(phba, vports);
2379 return strlen(buf);
2380 }
2381
2382 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2383 vports = lpfc_create_vport_work_array(phba);
2384 if (vports == NULL)
2385 return -ENOMEM;
2386
James Smartf4b4c682009-05-22 14:53:12 -04002387 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002388 v_shost = lpfc_shost_from_vport(vports[i]);
2389 spin_lock_irq(shost->host_lock);
2390 vports[i]->stat_data_blocked = 1;
2391 lpfc_free_bucket(vport);
2392 vport->stat_data_enabled = 0;
2393 vports[i]->stat_data_blocked = 0;
2394 spin_unlock_irq(shost->host_lock);
2395 }
2396 lpfc_destroy_vport_work_array(phba, vports);
2397 phba->bucket_type = LPFC_NO_BUCKET;
2398 phba->bucket_base = 0;
2399 phba->bucket_step = 0;
2400 return strlen(buf);
2401 }
2402
2403 if (!strncmp(buf, "start", strlen("start"))) {
2404 /* If no buckets configured return error */
2405 if (phba->bucket_type == LPFC_NO_BUCKET)
2406 return -EINVAL;
2407 spin_lock_irq(shost->host_lock);
2408 if (vport->stat_data_enabled) {
2409 spin_unlock_irq(shost->host_lock);
2410 return strlen(buf);
2411 }
2412 lpfc_alloc_bucket(vport);
2413 vport->stat_data_enabled = 1;
2414 spin_unlock_irq(shost->host_lock);
2415 return strlen(buf);
2416 }
2417
2418 if (!strncmp(buf, "stop", strlen("stop"))) {
2419 spin_lock_irq(shost->host_lock);
2420 if (vport->stat_data_enabled == 0) {
2421 spin_unlock_irq(shost->host_lock);
2422 return strlen(buf);
2423 }
2424 lpfc_free_bucket(vport);
2425 vport->stat_data_enabled = 0;
2426 spin_unlock_irq(shost->host_lock);
2427 return strlen(buf);
2428 }
2429
2430 if (!strncmp(buf, "reset", strlen("reset"))) {
2431 if ((phba->bucket_type == LPFC_NO_BUCKET)
2432 || !vport->stat_data_enabled)
2433 return strlen(buf);
2434 spin_lock_irq(shost->host_lock);
2435 vport->stat_data_blocked = 1;
2436 lpfc_vport_reset_stat_data(vport);
2437 vport->stat_data_blocked = 0;
2438 spin_unlock_irq(shost->host_lock);
2439 return strlen(buf);
2440 }
2441 return -EINVAL;
2442}
2443
2444
2445/**
James Smart3621a712009-04-06 18:47:14 -04002446 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002447 * @dev: Pointer to class device object.
2448 * @buf: Data buffer.
2449 *
2450 * This function is the read call back function for
2451 * lpfc_stat_data_ctrl sysfs file. This function report the
2452 * current statistical data collection state.
2453 **/
2454static ssize_t
2455lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2456 char *buf)
2457{
2458 struct Scsi_Host *shost = class_to_shost(dev);
2459 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2460 struct lpfc_hba *phba = vport->phba;
2461 int index = 0;
2462 int i;
2463 char *bucket_type;
2464 unsigned long bucket_value;
2465
2466 switch (phba->bucket_type) {
2467 case LPFC_LINEAR_BUCKET:
2468 bucket_type = "linear";
2469 break;
2470 case LPFC_POWER2_BUCKET:
2471 bucket_type = "power2";
2472 break;
2473 default:
2474 bucket_type = "No Bucket";
2475 break;
2476 }
2477
2478 sprintf(&buf[index], "Statistical Data enabled :%d, "
2479 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2480 " Bucket step :%d\nLatency Ranges :",
2481 vport->stat_data_enabled, vport->stat_data_blocked,
2482 bucket_type, phba->bucket_base, phba->bucket_step);
2483 index = strlen(buf);
2484 if (phba->bucket_type != LPFC_NO_BUCKET) {
2485 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2486 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2487 bucket_value = phba->bucket_base +
2488 phba->bucket_step * i;
2489 else
2490 bucket_value = phba->bucket_base +
2491 (1 << i) * phba->bucket_step;
2492
2493 if (index + 10 > PAGE_SIZE)
2494 break;
2495 sprintf(&buf[index], "%08ld ", bucket_value);
2496 index = strlen(buf);
2497 }
2498 }
2499 sprintf(&buf[index], "\n");
2500 return strlen(buf);
2501}
2502
2503/*
2504 * Sysfs attribute to control the statistical data collection.
2505 */
2506static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2507 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2508
2509/*
2510 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2511 */
2512
2513/*
2514 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2515 * for each target.
2516 */
2517#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2518#define MAX_STAT_DATA_SIZE_PER_TARGET \
2519 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2520
2521
2522/**
James Smart3621a712009-04-06 18:47:14 -04002523 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
James Smartea2151b2008-09-07 11:52:10 -04002524 * @kobj: Pointer to the kernel object
2525 * @bin_attr: Attribute object
2526 * @buff: Buffer pointer
2527 * @off: File offset
2528 * @count: Buffer size
2529 *
2530 * This function is the read call back function for lpfc_drvr_stat_data
2531 * sysfs file. This function export the statistical data to user
2532 * applications.
2533 **/
2534static ssize_t
2535sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2536 char *buf, loff_t off, size_t count)
2537{
2538 struct device *dev = container_of(kobj, struct device,
2539 kobj);
2540 struct Scsi_Host *shost = class_to_shost(dev);
2541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2542 struct lpfc_hba *phba = vport->phba;
2543 int i = 0, index = 0;
2544 unsigned long nport_index;
2545 struct lpfc_nodelist *ndlp = NULL;
2546 nport_index = (unsigned long)off /
2547 MAX_STAT_DATA_SIZE_PER_TARGET;
2548
2549 if (!vport->stat_data_enabled || vport->stat_data_blocked
2550 || (phba->bucket_type == LPFC_NO_BUCKET))
2551 return 0;
2552
2553 spin_lock_irq(shost->host_lock);
2554 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2555 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2556 continue;
2557
2558 if (nport_index > 0) {
2559 nport_index--;
2560 continue;
2561 }
2562
2563 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2564 > count)
2565 break;
2566
2567 if (!ndlp->lat_data)
2568 continue;
2569
2570 /* Print the WWN */
2571 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2572 ndlp->nlp_portname.u.wwn[0],
2573 ndlp->nlp_portname.u.wwn[1],
2574 ndlp->nlp_portname.u.wwn[2],
2575 ndlp->nlp_portname.u.wwn[3],
2576 ndlp->nlp_portname.u.wwn[4],
2577 ndlp->nlp_portname.u.wwn[5],
2578 ndlp->nlp_portname.u.wwn[6],
2579 ndlp->nlp_portname.u.wwn[7]);
2580
2581 index = strlen(buf);
2582
2583 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2584 sprintf(&buf[index], "%010u,",
2585 ndlp->lat_data[i].cmd_count);
2586 index = strlen(buf);
2587 }
2588 sprintf(&buf[index], "\n");
2589 index = strlen(buf);
2590 }
2591 spin_unlock_irq(shost->host_lock);
2592 return index;
2593}
2594
2595static struct bin_attribute sysfs_drvr_stat_data_attr = {
2596 .attr = {
2597 .name = "lpfc_drvr_stat_data",
2598 .mode = S_IRUSR,
2599 .owner = THIS_MODULE,
2600 },
2601 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2602 .read = sysfs_drvr_stat_data_read,
2603 .write = NULL,
2604};
2605
dea31012005-04-17 16:05:31 -05002606/*
2607# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2608# connection.
2609# 0 = auto select (default)
2610# 1 = 1 Gigabaud
2611# 2 = 2 Gigabaud
2612# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002613# 8 = 8 Gigabaud
2614# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002615*/
James Smarte59058c2008-08-24 21:49:00 -04002616
2617/**
James Smart3621a712009-04-06 18:47:14 -04002618 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002619 * @phba: lpfc_hba pointer.
2620 * @val: link speed value.
2621 *
2622 * Description:
2623 * If val is in a valid range then set the adapter's link speed field and
2624 * issue a lip; if the lip fails reset the link speed to the old value.
2625 *
2626 * Notes:
2627 * If the value is not in range log a kernel error message and return an error.
2628 *
2629 * Returns:
2630 * zero if val is in range and lip okay.
2631 * non-zero return value from lpfc_issue_lip()
2632 * -EINVAL val out of range
2633 **/
James Smarta257bf92009-04-06 18:48:10 -04002634static ssize_t
2635lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2636 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002637{
James Smarta257bf92009-04-06 18:48:10 -04002638 struct Scsi_Host *shost = class_to_shost(dev);
2639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2640 struct lpfc_hba *phba = vport->phba;
2641 int val = 0;
2642 int nolip = 0;
2643 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002644 int err;
2645 uint32_t prev_val;
2646
James Smarta257bf92009-04-06 18:48:10 -04002647 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2648 nolip = 1;
2649 val_buf = &buf[strlen("nolip ")];
2650 }
2651
2652 if (!isdigit(val_buf[0]))
2653 return -EINVAL;
2654 if (sscanf(val_buf, "%i", &val) != 1)
2655 return -EINVAL;
2656
James Smart83108bd2008-01-11 01:53:09 -05002657 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2658 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2659 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2660 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2661 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2662 return -EINVAL;
2663
James Smarta257bf92009-04-06 18:48:10 -04002664 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002665 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2666 prev_val = phba->cfg_link_speed;
2667 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002668 if (nolip)
2669 return strlen(buf);
2670
James Smart83108bd2008-01-11 01:53:09 -05002671 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002672 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002673 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002674 return -EINVAL;
2675 } else
2676 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002677 }
2678
2679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2680 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2681 "allowed range is [0, 8]\n",
2682 phba->brd_no, val);
2683 return -EINVAL;
2684}
2685
2686static int lpfc_link_speed = 0;
2687module_param(lpfc_link_speed, int, 0);
2688MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2689lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002690
2691/**
James Smart3621a712009-04-06 18:47:14 -04002692 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002693 * @phba: lpfc_hba pointer.
2694 * @val: link speed value.
2695 *
2696 * Description:
2697 * If val is in a valid range then set the adapter's link speed field.
2698 *
2699 * Notes:
2700 * If the value is not in range log a kernel error message, clear the link
2701 * speed and return an error.
2702 *
2703 * Returns:
2704 * zero if val saved.
2705 * -EINVAL val out of range
2706 **/
James Smart83108bd2008-01-11 01:53:09 -05002707static int
2708lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2709{
2710 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2711 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2712 phba->cfg_link_speed = val;
2713 return 0;
2714 }
2715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002716 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002717 "be set to %d, allowed values are "
2718 "["LPFC_LINK_SPEED_STRING"]\n", val);
2719 phba->cfg_link_speed = 0;
2720 return -EINVAL;
2721}
2722
Tony Jonesee959b02008-02-22 00:13:36 +01002723static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002724 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002725
2726/*
2727# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2728# Value range is [2,3]. Default value is 3.
2729*/
James Smart3de2a652007-08-02 11:09:59 -04002730LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2731 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002732
2733/*
2734# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2735# is [0,1]. Default value is 0.
2736*/
James Smart3de2a652007-08-02 11:09:59 -04002737LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2738 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002739
2740/*
James Smart977b5a02008-09-07 11:52:04 -04002741# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2742# depth. Default value is 0. When the value of this parameter is zero the
2743# SCSI command completion time is not used for controlling I/O queue depth. When
2744# the parameter is set to a non-zero value, the I/O queue depth is controlled
2745# to limit the I/O completion time to the parameter value.
2746# The value is set in milliseconds.
2747*/
2748static int lpfc_max_scsicmpl_time;
2749module_param(lpfc_max_scsicmpl_time, int, 0);
2750MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2751 "Use command completion time to control queue depth");
2752lpfc_vport_param_show(max_scsicmpl_time);
2753lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2754static int
2755lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2756{
2757 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2758 struct lpfc_nodelist *ndlp, *next_ndlp;
2759
2760 if (val == vport->cfg_max_scsicmpl_time)
2761 return 0;
2762 if ((val < 0) || (val > 60000))
2763 return -EINVAL;
2764 vport->cfg_max_scsicmpl_time = val;
2765
2766 spin_lock_irq(shost->host_lock);
2767 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2768 if (!NLP_CHK_NODE_ACT(ndlp))
2769 continue;
2770 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2771 continue;
2772 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2773 }
2774 spin_unlock_irq(shost->host_lock);
2775 return 0;
2776}
2777lpfc_vport_param_store(max_scsicmpl_time);
2778static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2779 lpfc_max_scsicmpl_time_show,
2780 lpfc_max_scsicmpl_time_store);
2781
2782/*
dea31012005-04-17 16:05:31 -05002783# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2784# range is [0,1]. Default value is 0.
2785*/
2786LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2787
2788/*
2789# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2790# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04002791# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05002792# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2793# cr_delay is set to 0.
2794*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002795LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05002796 "interrupt response is generated");
2797
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002798LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05002799 "interrupt response is generated");
2800
2801/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002802# lpfc_multi_ring_support: Determines how many rings to spread available
2803# cmd/rsp IOCB entries across.
2804# Value range is [1,2]. Default value is 1.
2805*/
2806LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2807 "SLI rings to spread IOCB entries across");
2808
2809/*
James Smarta4bc3372006-12-02 13:34:16 -05002810# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2811# identifies what rctl value to configure the additional ring for.
2812# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2813*/
2814LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2815 255, "Identifies RCTL for additional ring configuration");
2816
2817/*
2818# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2819# identifies what type value to configure the additional ring for.
2820# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2821*/
2822LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2823 255, "Identifies TYPE for additional ring configuration");
2824
2825/*
dea31012005-04-17 16:05:31 -05002826# lpfc_fdmi_on: controls FDMI support.
2827# 0 = no FDMI support
2828# 1 = support FDMI without attribute of hostname
2829# 2 = support FDMI with attribute of hostname
2830# Value range [0,2]. Default value is 0.
2831*/
James Smart3de2a652007-08-02 11:09:59 -04002832LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05002833
2834/*
2835# Specifies the maximum number of ELS cmds we can have outstanding (for
2836# discovery). Value range is [1,64]. Default value = 32.
2837*/
James Smart3de2a652007-08-02 11:09:59 -04002838LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05002839 "during discovery");
2840
2841/*
James Smart65a29c12006-07-06 15:50:50 -04002842# lpfc_max_luns: maximum allowed LUN.
2843# Value range is [0,65535]. Default value is 255.
2844# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05002845*/
James Smart3de2a652007-08-02 11:09:59 -04002846LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05002847
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002848/*
2849# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2850# Value range is [1,255], default value is 10.
2851*/
2852LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2853 "Milliseconds driver will wait between polling FCP ring");
2854
James Smart4ff43242006-12-02 13:34:56 -05002855/*
2856# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2857# support this feature
James Smartda0436e2009-05-22 14:51:39 -04002858# 0 = MSI disabled (default)
James Smart4ff43242006-12-02 13:34:56 -05002859# 1 = MSI enabled
James Smartda0436e2009-05-22 14:51:39 -04002860# 2 = MSI-X enabled
2861# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05002862*/
James Smartda0436e2009-05-22 14:51:39 -04002863LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05002864 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05002865
James Smart13815c82008-01-11 01:52:48 -05002866/*
James Smartda0436e2009-05-22 14:51:39 -04002867# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
2868#
2869# Value range is [636,651042]. Default value is 10000.
2870*/
2871LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
2872 "Set the maximum number of fast-path FCP interrupts per second");
2873
2874/*
2875# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
2876#
2877# Value range is [1,31]. Default value is 4.
2878*/
2879LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
2880 "Set the number of fast-path FCP work queues, if possible");
2881
2882/*
2883# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
2884#
2885# Value range is [1,7]. Default value is 1.
2886*/
2887LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
2888 "Set the number of fast-path FCP event queues, if possible");
2889
2890/*
James Smart13815c82008-01-11 01:52:48 -05002891# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2892# 0 = HBA resets disabled
2893# 1 = HBA resets enabled (default)
2894# Value range is [0,1]. Default value is 1.
2895*/
2896LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04002897
James Smart13815c82008-01-11 01:52:48 -05002898/*
2899# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2900# 0 = HBA Heartbeat disabled
2901# 1 = HBA Heartbeat enabled (default)
2902# Value range is [0,1]. Default value is 1.
2903*/
2904LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05002905
James Smart83108bd2008-01-11 01:53:09 -05002906/*
James Smart81301a92008-12-04 22:39:46 -05002907# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
2908# 0 = BlockGuard disabled (default)
2909# 1 = BlockGuard enabled
2910# Value range is [0,1]. Default value is 0.
2911*/
2912LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
2913
James Smart6fb120a2009-05-22 14:52:59 -04002914/*
2915# lpfc_enable_fip: When set, FIP is required to start discovery. If not
2916# set, the driver will add an FCF record manually if the port has no
2917# FCF records available and start discovery.
2918# Value range is [0,1]. Default value is 1 (enabled)
2919*/
2920LPFC_ATTR_RW(enable_fip, 0, 0, 1, "Enable FIP Discovery");
2921
James Smart81301a92008-12-04 22:39:46 -05002922
2923/*
2924# lpfc_prot_mask: i
2925# - Bit mask of host protection capabilities used to register with the
2926# SCSI mid-layer
2927# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
2928# - Allows you to ultimately specify which profiles to use
2929# - Default will result in registering capabilities for all profiles.
2930#
2931*/
2932unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
2933
2934module_param(lpfc_prot_mask, uint, 0);
2935MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
2936
2937/*
2938# lpfc_prot_guard: i
2939# - Bit mask of protection guard types to register with the SCSI mid-layer
2940# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
2941# - Allows you to ultimately specify which profiles to use
2942# - Default will result in registering capabilities for all guard types
2943#
2944*/
2945unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
2946module_param(lpfc_prot_guard, byte, 0);
2947MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
2948
2949
2950/*
James Smart3621a712009-04-06 18:47:14 -04002951 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05002952 * This value can be set to values between 64 and 256. The default value is
2953 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2954 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2955 */
2956LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2957 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2958
James Smart81301a92008-12-04 22:39:46 -05002959LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
2960 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
2961 "Max Protection Scatter Gather Segment Count");
2962
Tony Jonesee959b02008-02-22 00:13:36 +01002963struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05002964 &dev_attr_bg_info,
2965 &dev_attr_bg_guard_err,
2966 &dev_attr_bg_apptag_err,
2967 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01002968 &dev_attr_info,
2969 &dev_attr_serialnum,
2970 &dev_attr_modeldesc,
2971 &dev_attr_modelname,
2972 &dev_attr_programtype,
2973 &dev_attr_portnum,
2974 &dev_attr_fwrev,
2975 &dev_attr_hdw,
2976 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002977 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002978 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04002979 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01002980 &dev_attr_lpfc_drvr_version,
2981 &dev_attr_lpfc_temp_sensor,
2982 &dev_attr_lpfc_log_verbose,
2983 &dev_attr_lpfc_lun_queue_depth,
2984 &dev_attr_lpfc_hba_queue_depth,
2985 &dev_attr_lpfc_peer_port_login,
2986 &dev_attr_lpfc_nodev_tmo,
2987 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04002988 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01002989 &dev_attr_lpfc_fcp_class,
2990 &dev_attr_lpfc_use_adisc,
2991 &dev_attr_lpfc_ack0,
2992 &dev_attr_lpfc_topology,
2993 &dev_attr_lpfc_scan_down,
2994 &dev_attr_lpfc_link_speed,
2995 &dev_attr_lpfc_cr_delay,
2996 &dev_attr_lpfc_cr_count,
2997 &dev_attr_lpfc_multi_ring_support,
2998 &dev_attr_lpfc_multi_ring_rctl,
2999 &dev_attr_lpfc_multi_ring_type,
3000 &dev_attr_lpfc_fdmi_on,
3001 &dev_attr_lpfc_max_luns,
3002 &dev_attr_lpfc_enable_npiv,
3003 &dev_attr_nport_evt_cnt,
3004 &dev_attr_board_mode,
3005 &dev_attr_max_vpi,
3006 &dev_attr_used_vpi,
3007 &dev_attr_max_rpi,
3008 &dev_attr_used_rpi,
3009 &dev_attr_max_xri,
3010 &dev_attr_used_xri,
3011 &dev_attr_npiv_info,
3012 &dev_attr_issue_reset,
3013 &dev_attr_lpfc_poll,
3014 &dev_attr_lpfc_poll_tmo,
3015 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003016 &dev_attr_lpfc_fcp_imax,
3017 &dev_attr_lpfc_fcp_wq_count,
3018 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003019 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003020 &dev_attr_lpfc_soft_wwnn,
3021 &dev_attr_lpfc_soft_wwpn,
3022 &dev_attr_lpfc_soft_wwn_enable,
3023 &dev_attr_lpfc_enable_hba_reset,
3024 &dev_attr_lpfc_enable_hba_heartbeat,
3025 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003026 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003027 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003028 &dev_attr_lpfc_prot_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05003029 NULL,
3030};
3031
Tony Jonesee959b02008-02-22 00:13:36 +01003032struct device_attribute *lpfc_vport_attrs[] = {
3033 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003034 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003035 &dev_attr_num_discovered_ports,
3036 &dev_attr_lpfc_drvr_version,
3037 &dev_attr_lpfc_log_verbose,
3038 &dev_attr_lpfc_lun_queue_depth,
3039 &dev_attr_lpfc_nodev_tmo,
3040 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04003041 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003042 &dev_attr_lpfc_hba_queue_depth,
3043 &dev_attr_lpfc_peer_port_login,
3044 &dev_attr_lpfc_restrict_login,
3045 &dev_attr_lpfc_fcp_class,
3046 &dev_attr_lpfc_use_adisc,
3047 &dev_attr_lpfc_fdmi_on,
3048 &dev_attr_lpfc_max_luns,
3049 &dev_attr_nport_evt_cnt,
3050 &dev_attr_npiv_info,
3051 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003052 &dev_attr_lpfc_max_scsicmpl_time,
3053 &dev_attr_lpfc_stat_data_ctrl,
James Smart3de2a652007-08-02 11:09:59 -04003054 NULL,
3055};
3056
James Smarte59058c2008-08-24 21:49:00 -04003057/**
James Smart3621a712009-04-06 18:47:14 -04003058 * sysfs_ctlreg_write - Write method for writing to ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003059 * @kobj: kernel kobject that contains the kernel class device.
3060 * @bin_attr: kernel attributes passed to us.
3061 * @buf: contains the data to be written to the adapter IOREG space.
3062 * @off: offset into buffer to beginning of data.
3063 * @count: bytes to transfer.
3064 *
3065 * Description:
3066 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3067 * Uses the adapter io control registers to send buf contents to the adapter.
3068 *
3069 * Returns:
3070 * -ERANGE off and count combo out of range
3071 * -EINVAL off, count or buff address invalid
3072 * -EPERM adapter is offline
3073 * value of count, buf contents written
3074 **/
dea31012005-04-17 16:05:31 -05003075static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003076sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3077 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003078{
3079 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003080 struct device *dev = container_of(kobj, struct device, kobj);
3081 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003082 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3083 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003084
3085 if ((off + count) > FF_REG_AREA_SIZE)
3086 return -ERANGE;
3087
3088 if (count == 0) return 0;
3089
3090 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3091 return -EINVAL;
3092
James Smart2e0fef82007-06-17 19:56:36 -05003093 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003094 return -EPERM;
3095 }
3096
James Smart2e0fef82007-06-17 19:56:36 -05003097 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003098 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3099 writel(*((uint32_t *)(buf + buf_off)),
3100 phba->ctrl_regs_memmap_p + off + buf_off);
3101
James Smart2e0fef82007-06-17 19:56:36 -05003102 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003103
3104 return count;
3105}
3106
James Smarte59058c2008-08-24 21:49:00 -04003107/**
James Smart3621a712009-04-06 18:47:14 -04003108 * sysfs_ctlreg_read - Read method for reading from ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003109 * @kobj: kernel kobject that contains the kernel class device.
3110 * @bin_attr: kernel attributes passed to us.
3111 * @buf: if succesful contains the data from the adapter IOREG space.
3112 * @off: offset into buffer to beginning of data.
3113 * @count: bytes to transfer.
3114 *
3115 * Description:
3116 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3117 * Uses the adapter io control registers to read data into buf.
3118 *
3119 * Returns:
3120 * -ERANGE off and count combo out of range
3121 * -EINVAL off, count or buff address invalid
3122 * value of count, buf contents read
3123 **/
dea31012005-04-17 16:05:31 -05003124static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003125sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3126 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003127{
3128 size_t buf_off;
3129 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003130 struct device *dev = container_of(kobj, struct device, kobj);
3131 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3133 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003134
3135 if (off > FF_REG_AREA_SIZE)
3136 return -ERANGE;
3137
3138 if ((off + count) > FF_REG_AREA_SIZE)
3139 count = FF_REG_AREA_SIZE - off;
3140
3141 if (count == 0) return 0;
3142
3143 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3144 return -EINVAL;
3145
James Smart2e0fef82007-06-17 19:56:36 -05003146 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003147
3148 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3149 tmp_ptr = (uint32_t *)(buf + buf_off);
3150 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3151 }
3152
James Smart2e0fef82007-06-17 19:56:36 -05003153 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003154
3155 return count;
3156}
3157
3158static struct bin_attribute sysfs_ctlreg_attr = {
3159 .attr = {
3160 .name = "ctlreg",
3161 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003162 },
3163 .size = 256,
3164 .read = sysfs_ctlreg_read,
3165 .write = sysfs_ctlreg_write,
3166};
3167
James Smarte59058c2008-08-24 21:49:00 -04003168/**
James Smart3621a712009-04-06 18:47:14 -04003169 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003170 * @phba: lpfc_hba pointer
3171 **/
dea31012005-04-17 16:05:31 -05003172static void
James Smart2e0fef82007-06-17 19:56:36 -05003173sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003174{
3175 phba->sysfs_mbox.state = SMBOX_IDLE;
3176 phba->sysfs_mbox.offset = 0;
3177
3178 if (phba->sysfs_mbox.mbox) {
3179 mempool_free(phba->sysfs_mbox.mbox,
3180 phba->mbox_mem_pool);
3181 phba->sysfs_mbox.mbox = NULL;
3182 }
3183}
3184
James Smarte59058c2008-08-24 21:49:00 -04003185/**
James Smart3621a712009-04-06 18:47:14 -04003186 * sysfs_mbox_write - Write method for writing information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003187 * @kobj: kernel kobject that contains the kernel class device.
3188 * @bin_attr: kernel attributes passed to us.
3189 * @buf: contains the data to be written to sysfs mbox.
3190 * @off: offset into buffer to beginning of data.
3191 * @count: bytes to transfer.
3192 *
3193 * Description:
3194 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3195 * Uses the sysfs mbox to send buf contents to the adapter.
3196 *
3197 * Returns:
3198 * -ERANGE off and count combo out of range
3199 * -EINVAL off, count or buff address invalid
3200 * zero if count is zero
3201 * -EPERM adapter is offline
3202 * -ENOMEM failed to allocate memory for the mail box
3203 * -EAGAIN offset, state or mbox is NULL
3204 * count number of bytes transferred
3205 **/
dea31012005-04-17 16:05:31 -05003206static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003207sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3208 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003209{
Tony Jonesee959b02008-02-22 00:13:36 +01003210 struct device *dev = container_of(kobj, struct device, kobj);
3211 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003212 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3213 struct lpfc_hba *phba = vport->phba;
3214 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003215
3216 if ((count + off) > MAILBOX_CMD_SIZE)
3217 return -ERANGE;
3218
3219 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3220 return -EINVAL;
3221
3222 if (count == 0)
3223 return 0;
3224
3225 if (off == 0) {
3226 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3227 if (!mbox)
3228 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003229 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003230 }
3231
James Smart2e0fef82007-06-17 19:56:36 -05003232 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003233
3234 if (off == 0) {
3235 if (phba->sysfs_mbox.mbox)
3236 mempool_free(mbox, phba->mbox_mem_pool);
3237 else
3238 phba->sysfs_mbox.mbox = mbox;
3239 phba->sysfs_mbox.state = SMBOX_WRITING;
3240 } else {
3241 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3242 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003243 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003244 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003245 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003246 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003247 }
3248 }
3249
James Smart04c68492009-05-22 14:52:52 -04003250 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003251 buf, count);
3252
3253 phba->sysfs_mbox.offset = off + count;
3254
James Smart2e0fef82007-06-17 19:56:36 -05003255 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003256
3257 return count;
3258}
3259
James Smarte59058c2008-08-24 21:49:00 -04003260/**
James Smart3621a712009-04-06 18:47:14 -04003261 * sysfs_mbox_read - Read method for reading information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003262 * @kobj: kernel kobject that contains the kernel class device.
3263 * @bin_attr: kernel attributes passed to us.
3264 * @buf: contains the data to be read from sysfs mbox.
3265 * @off: offset into buffer to beginning of data.
3266 * @count: bytes to transfer.
3267 *
3268 * Description:
3269 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3270 * Uses the sysfs mbox to receive data from to the adapter.
3271 *
3272 * Returns:
3273 * -ERANGE off greater than mailbox command size
3274 * -EINVAL off, count or buff address invalid
3275 * zero if off and count are zero
3276 * -EACCES adapter over temp
3277 * -EPERM garbage can value to catch a multitude of errors
3278 * -EAGAIN management IO not permitted, state or off error
3279 * -ETIME mailbox timeout
3280 * -ENODEV mailbox error
3281 * count number of bytes transferred
3282 **/
dea31012005-04-17 16:05:31 -05003283static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003284sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3285 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003286{
Tony Jonesee959b02008-02-22 00:13:36 +01003287 struct device *dev = container_of(kobj, struct device, kobj);
3288 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3290 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003291 int rc;
James Smart04c68492009-05-22 14:52:52 -04003292 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003293
James Smart1dcb58e2007-04-25 09:51:30 -04003294 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003295 return -ERANGE;
3296
James Smart1dcb58e2007-04-25 09:51:30 -04003297 if ((count + off) > MAILBOX_CMD_SIZE)
3298 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003299
3300 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3301 return -EINVAL;
3302
3303 if (off && count == 0)
3304 return 0;
3305
James Smart2e0fef82007-06-17 19:56:36 -05003306 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003307
James Smart7af67052007-10-27 13:38:11 -04003308 if (phba->over_temp_state == HBA_OVER_TEMP) {
3309 sysfs_mbox_idle(phba);
3310 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003311 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003312 }
3313
dea31012005-04-17 16:05:31 -05003314 if (off == 0 &&
3315 phba->sysfs_mbox.state == SMBOX_WRITING &&
3316 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003317 pmb = &phba->sysfs_mbox.mbox->u.mb;
3318 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003319 /* Offline only */
dea31012005-04-17 16:05:31 -05003320 case MBX_INIT_LINK:
3321 case MBX_DOWN_LINK:
3322 case MBX_CONFIG_LINK:
3323 case MBX_CONFIG_RING:
3324 case MBX_RESET_RING:
3325 case MBX_UNREG_LOGIN:
3326 case MBX_CLEAR_LA:
3327 case MBX_DUMP_CONTEXT:
3328 case MBX_RUN_DIAGS:
3329 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003330 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003331 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003332 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003333 printk(KERN_WARNING "mbox_read:Command 0x%x "
3334 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003335 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003336 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003337 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003338 return -EPERM;
3339 }
James Smarta8adb832007-10-27 13:37:53 -04003340 case MBX_WRITE_NV:
3341 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003342 case MBX_LOAD_SM:
3343 case MBX_READ_NV:
3344 case MBX_READ_CONFIG:
3345 case MBX_READ_RCONFIG:
3346 case MBX_READ_STATUS:
3347 case MBX_READ_XRI:
3348 case MBX_READ_REV:
3349 case MBX_READ_LNK_STAT:
3350 case MBX_DUMP_MEMORY:
3351 case MBX_DOWN_LOAD:
3352 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003353 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003354 case MBX_LOAD_AREA:
3355 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003356 case MBX_BEACON:
3357 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003358 case MBX_SET_VARIABLE:
3359 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003360 case MBX_PORT_CAPABILITIES:
3361 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003362 break;
3363 case MBX_READ_SPARM64:
3364 case MBX_READ_LA:
3365 case MBX_READ_LA64:
3366 case MBX_REG_LOGIN:
3367 case MBX_REG_LOGIN64:
3368 case MBX_CONFIG_PORT:
3369 case MBX_RUN_BIU_DIAG:
3370 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003371 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003372 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003373 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003374 return -EPERM;
3375 default:
3376 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003377 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003378 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003379 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003380 return -EPERM;
3381 }
3382
James Smart09372822008-01-11 01:52:54 -05003383 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003384 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003385 */
James Smartd7c255b2008-08-24 21:50:00 -04003386 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003387 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3388 pmb->mbxCommand != MBX_RESTART &&
3389 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3390 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003391 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3392 "1259 mbox: Issued mailbox cmd "
3393 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003394 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003395
James Smart92d7f7b2007-06-17 19:56:38 -05003396 phba->sysfs_mbox.mbox->vport = vport;
3397
James Smart58da1ff2008-04-07 10:15:56 -04003398 /* Don't allow mailbox commands to be sent when blocked
3399 * or when in the middle of discovery
3400 */
James Smart495a7142008-06-14 22:52:59 -04003401 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003402 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003403 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003404 return -EAGAIN;
3405 }
3406
James Smart2e0fef82007-06-17 19:56:36 -05003407 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003408 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003409
James Smart2e0fef82007-06-17 19:56:36 -05003410 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003411 rc = lpfc_sli_issue_mbox (phba,
3412 phba->sysfs_mbox.mbox,
3413 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003414 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003415
3416 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003417 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003418 rc = lpfc_sli_issue_mbox_wait (phba,
3419 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003420 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003421 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003422 }
3423
3424 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003425 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003426 phba->sysfs_mbox.mbox = NULL;
3427 }
dea31012005-04-17 16:05:31 -05003428 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003429 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003430 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003431 }
3432 phba->sysfs_mbox.state = SMBOX_READING;
3433 }
3434 else if (phba->sysfs_mbox.offset != off ||
3435 phba->sysfs_mbox.state != SMBOX_READING) {
3436 printk(KERN_WARNING "mbox_read: Bad State\n");
3437 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003438 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003439 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003440 }
3441
James Smart04c68492009-05-22 14:52:52 -04003442 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003443
3444 phba->sysfs_mbox.offset = off + count;
3445
James Smart1dcb58e2007-04-25 09:51:30 -04003446 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003447 sysfs_mbox_idle(phba);
3448
James Smart2e0fef82007-06-17 19:56:36 -05003449 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003450
3451 return count;
3452}
3453
3454static struct bin_attribute sysfs_mbox_attr = {
3455 .attr = {
3456 .name = "mbox",
3457 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003458 },
James Smart1dcb58e2007-04-25 09:51:30 -04003459 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003460 .read = sysfs_mbox_read,
3461 .write = sysfs_mbox_write,
3462};
3463
James Smarte59058c2008-08-24 21:49:00 -04003464/**
James Smart3621a712009-04-06 18:47:14 -04003465 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003466 * @vport: address of lpfc vport structure.
3467 *
3468 * Return codes:
3469 * zero on success
3470 * error return code from sysfs_create_bin_file()
3471 **/
dea31012005-04-17 16:05:31 -05003472int
James Smart2e0fef82007-06-17 19:56:36 -05003473lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003474{
James Smart2e0fef82007-06-17 19:56:36 -05003475 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003476 int error;
3477
Tony Jonesee959b02008-02-22 00:13:36 +01003478 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003479 &sysfs_drvr_stat_data_attr);
3480
3481 /* Virtual ports do not need ctrl_reg and mbox */
3482 if (error || vport->port_type == LPFC_NPIV_PORT)
3483 goto out;
3484
3485 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003486 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003487 if (error)
James Smarteada2722008-12-04 22:39:13 -05003488 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003489
Tony Jonesee959b02008-02-22 00:13:36 +01003490 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003491 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003492 if (error)
3493 goto out_remove_ctlreg_attr;
3494
3495 return 0;
3496out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003497 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003498out_remove_stat_attr:
3499 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3500 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003501out:
3502 return error;
3503}
3504
James Smarte59058c2008-08-24 21:49:00 -04003505/**
James Smart3621a712009-04-06 18:47:14 -04003506 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003507 * @vport: address of lpfc vport structure.
3508 **/
dea31012005-04-17 16:05:31 -05003509void
James Smart2e0fef82007-06-17 19:56:36 -05003510lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003511{
James Smart2e0fef82007-06-17 19:56:36 -05003512 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003513 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3514 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003515 /* Virtual ports do not need ctrl_reg and mbox */
3516 if (vport->port_type == LPFC_NPIV_PORT)
3517 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003518 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3519 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003520}
3521
3522
3523/*
3524 * Dynamic FC Host Attributes Support
3525 */
3526
James Smarte59058c2008-08-24 21:49:00 -04003527/**
James Smart3621a712009-04-06 18:47:14 -04003528 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003529 * @shost: kernel scsi host pointer.
3530 **/
dea31012005-04-17 16:05:31 -05003531static void
3532lpfc_get_host_port_id(struct Scsi_Host *shost)
3533{
James Smart2e0fef82007-06-17 19:56:36 -05003534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3535
dea31012005-04-17 16:05:31 -05003536 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003537 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003538}
3539
James Smarte59058c2008-08-24 21:49:00 -04003540/**
James Smart3621a712009-04-06 18:47:14 -04003541 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003542 * @shost: kernel scsi host pointer.
3543 **/
dea31012005-04-17 16:05:31 -05003544static void
3545lpfc_get_host_port_type(struct Scsi_Host *shost)
3546{
James Smart2e0fef82007-06-17 19:56:36 -05003547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3548 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003549
3550 spin_lock_irq(shost->host_lock);
3551
James Smart92d7f7b2007-06-17 19:56:38 -05003552 if (vport->port_type == LPFC_NPIV_PORT) {
3553 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3554 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003555 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003556 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003557 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3558 else
3559 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3560 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003561 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003562 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3563 else
3564 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3565 }
3566 } else
3567 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3568
3569 spin_unlock_irq(shost->host_lock);
3570}
3571
James Smarte59058c2008-08-24 21:49:00 -04003572/**
James Smart3621a712009-04-06 18:47:14 -04003573 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003574 * @shost: kernel scsi host pointer.
3575 **/
dea31012005-04-17 16:05:31 -05003576static void
3577lpfc_get_host_port_state(struct Scsi_Host *shost)
3578{
James Smart2e0fef82007-06-17 19:56:36 -05003579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003581
3582 spin_lock_irq(shost->host_lock);
3583
James Smart2e0fef82007-06-17 19:56:36 -05003584 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003585 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3586 else {
James Smart2e0fef82007-06-17 19:56:36 -05003587 switch (phba->link_state) {
3588 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003589 case LPFC_LINK_DOWN:
3590 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3591 break;
3592 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003593 case LPFC_CLEAR_LA:
3594 case LPFC_HBA_READY:
3595 /* Links up, beyond this port_type reports state */
3596 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3597 break;
3598 case LPFC_HBA_ERROR:
3599 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3600 break;
3601 default:
3602 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3603 break;
3604 }
3605 }
3606
3607 spin_unlock_irq(shost->host_lock);
3608}
3609
James Smarte59058c2008-08-24 21:49:00 -04003610/**
James Smart3621a712009-04-06 18:47:14 -04003611 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003612 * @shost: kernel scsi host pointer.
3613 **/
dea31012005-04-17 16:05:31 -05003614static void
3615lpfc_get_host_speed(struct Scsi_Host *shost)
3616{
James Smart2e0fef82007-06-17 19:56:36 -05003617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3618 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003619
3620 spin_lock_irq(shost->host_lock);
3621
James Smart2e0fef82007-06-17 19:56:36 -05003622 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003623 switch(phba->fc_linkspeed) {
3624 case LA_1GHZ_LINK:
3625 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3626 break;
3627 case LA_2GHZ_LINK:
3628 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3629 break;
3630 case LA_4GHZ_LINK:
3631 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3632 break;
James Smartb87eab32007-04-25 09:53:28 -04003633 case LA_8GHZ_LINK:
3634 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3635 break;
James Smartf4b4c682009-05-22 14:53:12 -04003636 case LA_10GHZ_LINK:
3637 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3638 break;
dea31012005-04-17 16:05:31 -05003639 default:
3640 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3641 break;
3642 }
James Smart09372822008-01-11 01:52:54 -05003643 } else
3644 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003645
3646 spin_unlock_irq(shost->host_lock);
3647}
3648
James Smarte59058c2008-08-24 21:49:00 -04003649/**
James Smart3621a712009-04-06 18:47:14 -04003650 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04003651 * @shost: kernel scsi host pointer.
3652 **/
dea31012005-04-17 16:05:31 -05003653static void
3654lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3655{
James Smart2e0fef82007-06-17 19:56:36 -05003656 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3657 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003658 u64 node_name;
dea31012005-04-17 16:05:31 -05003659
3660 spin_lock_irq(shost->host_lock);
3661
James Smart2e0fef82007-06-17 19:56:36 -05003662 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003663 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003664 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003665 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003666 else
3667 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003668 node_name = 0;
dea31012005-04-17 16:05:31 -05003669
3670 spin_unlock_irq(shost->host_lock);
3671
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003672 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003673}
3674
James Smarte59058c2008-08-24 21:49:00 -04003675/**
James Smart3621a712009-04-06 18:47:14 -04003676 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04003677 * @shost: kernel scsi host pointer.
3678 *
3679 * Notes:
3680 * NULL on error for link down, no mbox pool, sli2 active,
3681 * management not allowed, memory allocation error, or mbox error.
3682 *
3683 * Returns:
3684 * NULL for error
3685 * address of the adapter host statistics
3686 **/
dea31012005-04-17 16:05:31 -05003687static struct fc_host_statistics *
3688lpfc_get_stats(struct Scsi_Host *shost)
3689{
James Smart2e0fef82007-06-17 19:56:36 -05003690 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3691 struct lpfc_hba *phba = vport->phba;
3692 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003693 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003694 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003695 LPFC_MBOXQ_t *pmboxq;
3696 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003697 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003698 int rc = 0;
dea31012005-04-17 16:05:31 -05003699
James Smart92d7f7b2007-06-17 19:56:38 -05003700 /*
3701 * prevent udev from issuing mailbox commands until the port is
3702 * configured.
3703 */
James Smart2e0fef82007-06-17 19:56:36 -05003704 if (phba->link_state < LPFC_LINK_DOWN ||
3705 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04003706 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003707 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003708
3709 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003710 return NULL;
3711
dea31012005-04-17 16:05:31 -05003712 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3713 if (!pmboxq)
3714 return NULL;
3715 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3716
James Smart04c68492009-05-22 14:52:52 -04003717 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05003718 pmb->mbxCommand = MBX_READ_STATUS;
3719 pmb->mbxOwner = OWN_HOST;
3720 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003721 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003722
James Smart2e0fef82007-06-17 19:56:36 -05003723 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart04c68492009-05-22 14:52:52 -04003724 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003725 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003726 else
dea31012005-04-17 16:05:31 -05003727 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3728
3729 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003730 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003731 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003732 return NULL;
3733 }
3734
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003735 memset(hs, 0, sizeof (struct fc_host_statistics));
3736
dea31012005-04-17 16:05:31 -05003737 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3738 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3739 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3740 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3741
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003742 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003743 pmb->mbxCommand = MBX_READ_LNK_STAT;
3744 pmb->mbxOwner = OWN_HOST;
3745 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003746 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003747
James Smart2e0fef82007-06-17 19:56:36 -05003748 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003749 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003750 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003751 else
dea31012005-04-17 16:05:31 -05003752 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3753
3754 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003755 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003756 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003757 return NULL;
3758 }
3759
3760 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3761 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3762 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3763 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3764 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3765 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3766 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3767
James Smart64ba8812006-08-02 15:24:34 -04003768 hs->link_failure_count -= lso->link_failure_count;
3769 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3770 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3771 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3772 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3773 hs->invalid_crc_count -= lso->invalid_crc_count;
3774 hs->error_frames -= lso->error_frames;
3775
dea31012005-04-17 16:05:31 -05003776 if (phba->fc_topology == TOPOLOGY_LOOP) {
3777 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003778 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003779 hs->nos_count = -1;
3780 } else {
3781 hs->lip_count = -1;
3782 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003783 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003784 }
3785
3786 hs->dumped_frames = -1;
3787
James Smart64ba8812006-08-02 15:24:34 -04003788 seconds = get_seconds();
3789 if (seconds < psli->stats_start)
3790 hs->seconds_since_last_reset = seconds +
3791 ((unsigned long)-1 - psli->stats_start);
3792 else
3793 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05003794
James Smart1dcb58e2007-04-25 09:51:30 -04003795 mempool_free(pmboxq, phba->mbox_mem_pool);
3796
dea31012005-04-17 16:05:31 -05003797 return hs;
3798}
3799
James Smarte59058c2008-08-24 21:49:00 -04003800/**
James Smart3621a712009-04-06 18:47:14 -04003801 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04003802 * @shost: kernel scsi host pointer.
3803 **/
James Smart64ba8812006-08-02 15:24:34 -04003804static void
3805lpfc_reset_stats(struct Scsi_Host *shost)
3806{
James Smart2e0fef82007-06-17 19:56:36 -05003807 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3808 struct lpfc_hba *phba = vport->phba;
3809 struct lpfc_sli *psli = &phba->sli;
3810 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04003811 LPFC_MBOXQ_t *pmboxq;
3812 MAILBOX_t *pmb;
3813 int rc = 0;
3814
James Smart2e0fef82007-06-17 19:56:36 -05003815 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003816 return;
3817
James Smart64ba8812006-08-02 15:24:34 -04003818 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3819 if (!pmboxq)
3820 return;
3821 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3822
James Smart04c68492009-05-22 14:52:52 -04003823 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04003824 pmb->mbxCommand = MBX_READ_STATUS;
3825 pmb->mbxOwner = OWN_HOST;
3826 pmb->un.varWords[0] = 0x1; /* reset request */
3827 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003828 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003829
James Smart2e0fef82007-06-17 19:56:36 -05003830 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003831 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04003832 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3833 else
3834 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3835
3836 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003837 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003838 mempool_free(pmboxq, phba->mbox_mem_pool);
3839 return;
3840 }
3841
3842 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3843 pmb->mbxCommand = MBX_READ_LNK_STAT;
3844 pmb->mbxOwner = OWN_HOST;
3845 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003846 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003847
James Smart2e0fef82007-06-17 19:56:36 -05003848 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003849 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04003850 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3851 else
3852 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3853
3854 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003855 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003856 mempool_free( pmboxq, phba->mbox_mem_pool);
3857 return;
3858 }
3859
3860 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3861 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3862 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3863 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3864 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3865 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3866 lso->error_frames = pmb->un.varRdLnk.crcCnt;
3867 lso->link_events = (phba->fc_eventTag >> 1);
3868
3869 psli->stats_start = get_seconds();
3870
James Smart1dcb58e2007-04-25 09:51:30 -04003871 mempool_free(pmboxq, phba->mbox_mem_pool);
3872
James Smart64ba8812006-08-02 15:24:34 -04003873 return;
3874}
dea31012005-04-17 16:05:31 -05003875
3876/*
3877 * The LPFC driver treats linkdown handling as target loss events so there
3878 * are no sysfs handlers for link_down_tmo.
3879 */
James Smart685f0bf2007-04-25 09:53:08 -04003880
James Smarte59058c2008-08-24 21:49:00 -04003881/**
James Smart3621a712009-04-06 18:47:14 -04003882 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04003883 * @starget: kernel scsi target pointer.
3884 *
3885 * Returns:
3886 * address of the node list if found
3887 * NULL target not found
3888 **/
James Smart685f0bf2007-04-25 09:53:08 -04003889static struct lpfc_nodelist *
3890lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05003891{
James Smart2e0fef82007-06-17 19:56:36 -05003892 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3893 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04003894 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003895
3896 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003897 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05003898 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003899 if (NLP_CHK_NODE_ACT(ndlp) &&
3900 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04003901 starget->id == ndlp->nlp_sid) {
3902 spin_unlock_irq(shost->host_lock);
3903 return ndlp;
dea31012005-04-17 16:05:31 -05003904 }
3905 }
3906 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003907 return NULL;
3908}
dea31012005-04-17 16:05:31 -05003909
James Smarte59058c2008-08-24 21:49:00 -04003910/**
James Smart3621a712009-04-06 18:47:14 -04003911 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04003912 * @starget: kernel scsi target pointer.
3913 **/
James Smart685f0bf2007-04-25 09:53:08 -04003914static void
3915lpfc_get_starget_port_id(struct scsi_target *starget)
3916{
3917 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3918
3919 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05003920}
3921
James Smarte59058c2008-08-24 21:49:00 -04003922/**
James Smart3621a712009-04-06 18:47:14 -04003923 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04003924 * @starget: kernel scsi target pointer.
3925 *
3926 * Description: Set the target node name to the ndlp node name wwn or zero.
3927 **/
dea31012005-04-17 16:05:31 -05003928static void
3929lpfc_get_starget_node_name(struct scsi_target *starget)
3930{
James Smart685f0bf2007-04-25 09:53:08 -04003931 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003932
James Smart685f0bf2007-04-25 09:53:08 -04003933 fc_starget_node_name(starget) =
3934 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003935}
3936
James Smarte59058c2008-08-24 21:49:00 -04003937/**
James Smart3621a712009-04-06 18:47:14 -04003938 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04003939 * @starget: kernel scsi target pointer.
3940 *
3941 * Description: set the target port name to the ndlp port name wwn or zero.
3942 **/
dea31012005-04-17 16:05:31 -05003943static void
3944lpfc_get_starget_port_name(struct scsi_target *starget)
3945{
James Smart685f0bf2007-04-25 09:53:08 -04003946 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003947
James Smart685f0bf2007-04-25 09:53:08 -04003948 fc_starget_port_name(starget) =
3949 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003950}
3951
James Smarte59058c2008-08-24 21:49:00 -04003952/**
James Smart3621a712009-04-06 18:47:14 -04003953 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04003954 * @rport: fc rport address.
3955 * @timeout: new value for dev loss tmo.
3956 *
3957 * Description:
3958 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3959 * dev_loss_tmo to one.
3960 **/
dea31012005-04-17 16:05:31 -05003961static void
dea31012005-04-17 16:05:31 -05003962lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
3963{
dea31012005-04-17 16:05:31 -05003964 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04003965 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05003966 else
James Smartc01f3202006-08-18 17:47:08 -04003967 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05003968}
3969
James Smarte59058c2008-08-24 21:49:00 -04003970/**
James Smart3621a712009-04-06 18:47:14 -04003971 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04003972 *
3973 * Description:
3974 * Macro that uses field to generate a function with the name lpfc_show_rport_
3975 *
3976 * lpfc_show_rport_##field: returns the bytes formatted in buf
3977 * @cdev: class converted to an fc_rport.
3978 * @buf: on return contains the target_field or zero.
3979 *
3980 * Returns: size of formatted string.
3981 **/
dea31012005-04-17 16:05:31 -05003982#define lpfc_rport_show_function(field, format_string, sz, cast) \
3983static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01003984lpfc_show_rport_##field (struct device *dev, \
3985 struct device_attribute *attr, \
3986 char *buf) \
dea31012005-04-17 16:05:31 -05003987{ \
Tony Jonesee959b02008-02-22 00:13:36 +01003988 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05003989 struct lpfc_rport_data *rdata = rport->hostdata; \
3990 return snprintf(buf, sz, format_string, \
3991 (rdata->target) ? cast rdata->target->field : 0); \
3992}
3993
3994#define lpfc_rport_rd_attr(field, format_string, sz) \
3995 lpfc_rport_show_function(field, format_string, sz, ) \
3996static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3997
James Smarteada2722008-12-04 22:39:13 -05003998/**
James Smart3621a712009-04-06 18:47:14 -04003999 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004000 * @fc_vport: The fc_vport who's symbolic name has been changed.
4001 *
4002 * Description:
4003 * This function is called by the transport after the @fc_vport's symbolic name
4004 * has been changed. This function re-registers the symbolic name with the
4005 * switch to propogate the change into the fabric if the vport is active.
4006 **/
4007static void
4008lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4009{
4010 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4011
4012 if (vport->port_state == LPFC_VPORT_READY)
4013 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4014}
dea31012005-04-17 16:05:31 -05004015
James Smartf4b4c682009-05-22 14:53:12 -04004016/**
4017 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4018 * @phba: Pointer to lpfc_hba struct.
4019 *
4020 * This function is called by the lpfc_get_cfgparam() routine to set the
4021 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4022 * log messsage according to the module's lpfc_log_verbose parameter setting
4023 * before hba port or vport created.
4024 **/
4025static void
4026lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4027{
4028 phba->cfg_log_verbose = verbose;
4029}
4030
dea31012005-04-17 16:05:31 -05004031struct fc_function_template lpfc_transport_functions = {
4032 /* fixed attributes the driver supports */
4033 .show_host_node_name = 1,
4034 .show_host_port_name = 1,
4035 .show_host_supported_classes = 1,
4036 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004037 .show_host_supported_speeds = 1,
4038 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004039 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004040
4041 /* dynamic attributes the driver supports */
4042 .get_host_port_id = lpfc_get_host_port_id,
4043 .show_host_port_id = 1,
4044
4045 .get_host_port_type = lpfc_get_host_port_type,
4046 .show_host_port_type = 1,
4047
4048 .get_host_port_state = lpfc_get_host_port_state,
4049 .show_host_port_state = 1,
4050
4051 /* active_fc4s is shown but doesn't change (thus no get function) */
4052 .show_host_active_fc4s = 1,
4053
4054 .get_host_speed = lpfc_get_host_speed,
4055 .show_host_speed = 1,
4056
4057 .get_host_fabric_name = lpfc_get_host_fabric_name,
4058 .show_host_fabric_name = 1,
4059
4060 /*
4061 * The LPFC driver treats linkdown handling as target loss events
4062 * so there are no sysfs handlers for link_down_tmo.
4063 */
4064
4065 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004066 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004067
4068 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4069 .show_rport_maxframe_size = 1,
4070 .show_rport_supported_classes = 1,
4071
dea31012005-04-17 16:05:31 -05004072 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4073 .show_rport_dev_loss_tmo = 1,
4074
4075 .get_starget_port_id = lpfc_get_starget_port_id,
4076 .show_starget_port_id = 1,
4077
4078 .get_starget_node_name = lpfc_get_starget_node_name,
4079 .show_starget_node_name = 1,
4080
4081 .get_starget_port_name = lpfc_get_starget_port_name,
4082 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004083
4084 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004085 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4086 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004087
James Smart92d7f7b2007-06-17 19:56:38 -05004088 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004089
4090 .vport_disable = lpfc_vport_disable,
4091
4092 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart92d7f7b2007-06-17 19:56:38 -05004093};
4094
James Smart98c9ea52007-10-27 13:37:33 -04004095struct fc_function_template lpfc_vport_transport_functions = {
4096 /* fixed attributes the driver supports */
4097 .show_host_node_name = 1,
4098 .show_host_port_name = 1,
4099 .show_host_supported_classes = 1,
4100 .show_host_supported_fc4s = 1,
4101 .show_host_supported_speeds = 1,
4102 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004103 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004104
4105 /* dynamic attributes the driver supports */
4106 .get_host_port_id = lpfc_get_host_port_id,
4107 .show_host_port_id = 1,
4108
4109 .get_host_port_type = lpfc_get_host_port_type,
4110 .show_host_port_type = 1,
4111
4112 .get_host_port_state = lpfc_get_host_port_state,
4113 .show_host_port_state = 1,
4114
4115 /* active_fc4s is shown but doesn't change (thus no get function) */
4116 .show_host_active_fc4s = 1,
4117
4118 .get_host_speed = lpfc_get_host_speed,
4119 .show_host_speed = 1,
4120
4121 .get_host_fabric_name = lpfc_get_host_fabric_name,
4122 .show_host_fabric_name = 1,
4123
4124 /*
4125 * The LPFC driver treats linkdown handling as target loss events
4126 * so there are no sysfs handlers for link_down_tmo.
4127 */
4128
4129 .get_fc_host_stats = lpfc_get_stats,
4130 .reset_fc_host_stats = lpfc_reset_stats,
4131
4132 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4133 .show_rport_maxframe_size = 1,
4134 .show_rport_supported_classes = 1,
4135
4136 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4137 .show_rport_dev_loss_tmo = 1,
4138
4139 .get_starget_port_id = lpfc_get_starget_port_id,
4140 .show_starget_port_id = 1,
4141
4142 .get_starget_node_name = lpfc_get_starget_node_name,
4143 .show_starget_node_name = 1,
4144
4145 .get_starget_port_name = lpfc_get_starget_port_name,
4146 .show_starget_port_name = 1,
4147
4148 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4149 .terminate_rport_io = lpfc_terminate_rport_io,
4150
4151 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004152
4153 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004154};
4155
James Smarte59058c2008-08-24 21:49:00 -04004156/**
James Smart3621a712009-04-06 18:47:14 -04004157 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004158 * @phba: lpfc_hba pointer.
4159 **/
dea31012005-04-17 16:05:31 -05004160void
4161lpfc_get_cfgparam(struct lpfc_hba *phba)
4162{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004163 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4164 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004165 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004166 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4167 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004168 lpfc_ack0_init(phba, lpfc_ack0);
4169 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004170 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004171 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004172 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004173 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004174 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4175 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4176 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004177 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4178 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004179 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004180 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004181 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004182 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004183 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004184 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004185 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004186 lpfc_enable_fip_init(phba, lpfc_enable_fip);
4187 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4188
James Smart3de2a652007-08-02 11:09:59 -04004189 return;
4190}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004191
James Smarte59058c2008-08-24 21:49:00 -04004192/**
James Smart3621a712009-04-06 18:47:14 -04004193 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004194 * @vport: lpfc_vport pointer.
4195 **/
James Smart3de2a652007-08-02 11:09:59 -04004196void
4197lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4198{
James Smarte8b62012007-08-02 11:10:09 -04004199 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004200 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4201 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4202 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4203 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4204 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4205 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4206 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004207 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004208 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4209 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4210 lpfc_max_luns_init(vport, lpfc_max_luns);
4211 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004212 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004213 return;
4214}