blob: 82016fc672b1c39ea6215fb0f80351061b37f87d [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 Smart09372822008-01-11 01:52:54 -05004 * Copyright (C) 2004-2008 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 Smart4db621e2006-07-06 15:49:49 -0400510 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
511 pmboxq->mb.mbxOwner = OWN_HOST;
512
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 Smart4db621e2006-07-06 15:49:49 -0400515 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
516 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
517 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
518 phba->cfg_link_speed);
519 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
520 phba->fc_ratov * 2);
521 }
522
James Smart5b8bd0c2007-04-25 09:52:49 -0400523 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500524 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400525 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500526
527 if (mbxstatus == MBXERR_ERROR)
528 return -EIO;
529
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700530 return 0;
dea31012005-04-17 16:05:31 -0500531}
532
James Smarte59058c2008-08-24 21:49:00 -0400533/**
James Smart3621a712009-04-06 18:47:14 -0400534 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400535 * @phba: lpfc_hba pointer.
536 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
537 *
538 * Notes:
539 * Assumes any error from lpfc_do_offline() will be negative.
540 * Can wait up to 5 seconds for the port ring buffers count
541 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400542 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400543 *
544 * Returns:
545 * -EIO error posting the event
546 * zero for success
547 **/
James Smart40496f02006-07-06 15:50:22 -0400548static int
James Smart46fa3112007-04-25 09:51:45 -0400549lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
550{
551 struct completion online_compl;
552 struct lpfc_sli_ring *pring;
553 struct lpfc_sli *psli;
554 int status = 0;
555 int cnt = 0;
556 int i;
557
558 init_completion(&online_compl);
559 lpfc_workq_post_event(phba, &status, &online_compl,
560 LPFC_EVT_OFFLINE_PREP);
561 wait_for_completion(&online_compl);
562
563 if (status != 0)
564 return -EIO;
565
566 psli = &phba->sli;
567
James Smart09372822008-01-11 01:52:54 -0500568 /* Wait a little for things to settle down, but not
569 * long enough for dev loss timeout to expire.
570 */
James Smart46fa3112007-04-25 09:51:45 -0400571 for (i = 0; i < psli->num_rings; i++) {
572 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400573 while (pring->txcmplq_cnt) {
574 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500575 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400576 lpfc_printf_log(phba,
577 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400578 "0466 Outstanding IO when "
579 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400580 break;
581 }
582 }
583 }
584
585 init_completion(&online_compl);
586 lpfc_workq_post_event(phba, &status, &online_compl, type);
587 wait_for_completion(&online_compl);
588
589 if (status != 0)
590 return -EIO;
591
592 return 0;
593}
594
James Smarte59058c2008-08-24 21:49:00 -0400595/**
James Smart3621a712009-04-06 18:47:14 -0400596 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400597 * @phba: lpfc_hba pointer.
598 *
599 * Description:
600 * If the port is configured to allow a reset then the hba is brought
601 * offline then online.
602 *
603 * Notes:
604 * Assumes any error from lpfc_do_offline() will be negative.
605 *
606 * Returns:
607 * lpfc_do_offline() return code if not zero
608 * -EIO reset not configured or error posting the event
609 * zero for success
610 **/
James Smart46fa3112007-04-25 09:51:45 -0400611static int
James Smart40496f02006-07-06 15:50:22 -0400612lpfc_selective_reset(struct lpfc_hba *phba)
613{
614 struct completion online_compl;
615 int status = 0;
616
James Smart13815c82008-01-11 01:52:48 -0500617 if (!phba->cfg_enable_hba_reset)
618 return -EIO;
619
James Smart46fa3112007-04-25 09:51:45 -0400620 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400621
622 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400623 return status;
James Smart40496f02006-07-06 15:50:22 -0400624
625 init_completion(&online_compl);
626 lpfc_workq_post_event(phba, &status, &online_compl,
627 LPFC_EVT_ONLINE);
628 wait_for_completion(&online_compl);
629
630 if (status != 0)
631 return -EIO;
632
633 return 0;
634}
635
James Smarte59058c2008-08-24 21:49:00 -0400636/**
James Smart3621a712009-04-06 18:47:14 -0400637 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400638 * @dev: class device that is converted into a Scsi_host.
639 * @attr: device attribute, not used.
640 * @buf: containing the string "selective".
641 * @count: unused variable.
642 *
643 * Description:
644 * If the buf contains the string "selective" then lpfc_selective_reset()
645 * is called to perform the reset.
646 *
647 * Notes:
648 * Assumes any error from lpfc_selective_reset() will be negative.
649 * If lpfc_selective_reset() returns zero then the length of the buffer
650 * is returned which indicates succcess
651 *
652 * Returns:
653 * -EINVAL if the buffer does not contain the string "selective"
654 * length of buf if lpfc-selective_reset() if the call succeeds
655 * return value of lpfc_selective_reset() if the call fails
656**/
James Smart40496f02006-07-06 15:50:22 -0400657static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100658lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
659 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400660{
Tony Jonesee959b02008-02-22 00:13:36 +0100661 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
663 struct lpfc_hba *phba = vport->phba;
664
James Smart40496f02006-07-06 15:50:22 -0400665 int status = -EINVAL;
666
667 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
668 status = lpfc_selective_reset(phba);
669
670 if (status == 0)
671 return strlen(buf);
672 else
673 return status;
674}
675
James Smarte59058c2008-08-24 21:49:00 -0400676/**
James Smart3621a712009-04-06 18:47:14 -0400677 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400678 * @dev: class device that is converted into a Scsi_host.
679 * @attr: device attribute, not used.
680 * @buf: on return contains the ascii number of nport events.
681 *
682 * Returns: size of formatted string.
683 **/
dea31012005-04-17 16:05:31 -0500684static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100685lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
686 char *buf)
dea31012005-04-17 16:05:31 -0500687{
Tony Jonesee959b02008-02-22 00:13:36 +0100688 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500689 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
690 struct lpfc_hba *phba = vport->phba;
691
dea31012005-04-17 16:05:31 -0500692 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
693}
694
James Smarte59058c2008-08-24 21:49:00 -0400695/**
James Smart3621a712009-04-06 18:47:14 -0400696 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400697 * @dev: class device that is converted into a Scsi_host.
698 * @attr: device attribute, not used.
699 * @buf: on return contains the state of the adapter.
700 *
701 * Returns: size of formatted string.
702 **/
dea31012005-04-17 16:05:31 -0500703static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100704lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
705 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500706{
Tony Jonesee959b02008-02-22 00:13:36 +0100707 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500708 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
709 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500710 char * state;
711
James Smart2e0fef82007-06-17 19:56:36 -0500712 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500713 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500714 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500715 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500716 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500717 state = "offline";
718 else
719 state = "online";
720
721 return snprintf(buf, PAGE_SIZE, "%s\n", state);
722}
723
James Smarte59058c2008-08-24 21:49:00 -0400724/**
James Smart3621a712009-04-06 18:47:14 -0400725 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400726 * @dev: class device that is converted into a Scsi_host.
727 * @attr: device attribute, not used.
728 * @buf: containing one of the strings "online", "offline", "warm" or "error".
729 * @count: unused variable.
730 *
731 * Returns:
732 * -EACCES if enable hba reset not enabled
733 * -EINVAL if the buffer does not contain a valid string (see above)
734 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
735 * buf length greater than zero indicates success
736 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500737static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100738lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
739 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500740{
Tony Jonesee959b02008-02-22 00:13:36 +0100741 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500742 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
743 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500744 struct completion online_compl;
745 int status=0;
746
James Smart13815c82008-01-11 01:52:48 -0500747 if (!phba->cfg_enable_hba_reset)
748 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500749 init_completion(&online_compl);
750
James Smart46fa3112007-04-25 09:51:45 -0400751 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500752 lpfc_workq_post_event(phba, &status, &online_compl,
753 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400754 wait_for_completion(&online_compl);
755 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
756 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500757 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400758 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
759 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
760 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500761 else
762 return -EINVAL;
763
Jamie Wellnitz41415862006-02-28 19:25:27 -0500764 if (!status)
765 return strlen(buf);
766 else
767 return -EIO;
768}
769
James Smarte59058c2008-08-24 21:49:00 -0400770/**
James Smart3621a712009-04-06 18:47:14 -0400771 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400772 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400773 * @mxri: max xri count.
774 * @axri: available xri count.
775 * @mrpi: max rpi count.
776 * @arpi: available rpi count.
777 * @mvpi: max vpi count.
778 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400779 *
780 * Description:
781 * If an integer pointer for an count is not null then the value for the
782 * count is returned.
783 *
784 * Returns:
785 * zero on error
786 * one for success
787 **/
James Smart311464e2007-08-02 11:10:37 -0400788static int
James Smart858c9f62007-06-17 19:56:39 -0500789lpfc_get_hba_info(struct lpfc_hba *phba,
790 uint32_t *mxri, uint32_t *axri,
791 uint32_t *mrpi, uint32_t *arpi,
792 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500793{
794 struct lpfc_sli *psli = &phba->sli;
795 LPFC_MBOXQ_t *pmboxq;
796 MAILBOX_t *pmb;
797 int rc = 0;
798
799 /*
800 * prevent udev from issuing mailbox commands until the port is
801 * configured.
802 */
803 if (phba->link_state < LPFC_LINK_DOWN ||
804 !phba->mbox_mem_pool ||
805 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
806 return 0;
807
808 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
809 return 0;
810
811 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
812 if (!pmboxq)
813 return 0;
814 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
815
816 pmb = &pmboxq->mb;
817 pmb->mbxCommand = MBX_READ_CONFIG;
818 pmb->mbxOwner = OWN_HOST;
819 pmboxq->context1 = NULL;
820
821 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
822 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
823 rc = MBX_NOT_FINISHED;
824 else
825 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
826
827 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500828 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500829 mempool_free(pmboxq, phba->mbox_mem_pool);
830 return 0;
831 }
832
James Smartda0436e2009-05-22 14:51:39 -0400833 if (phba->sli_rev == LPFC_SLI_REV4) {
834 rd_config = &pmboxq->u.mqe.un.rd_config;
835 if (mrpi)
836 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
837 if (arpi)
838 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
839 phba->sli4_hba.max_cfg_param.rpi_used;
840 if (mxri)
841 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
842 if (axri)
843 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
844 phba->sli4_hba.max_cfg_param.xri_used;
845 if (mvpi)
846 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
847 if (avpi)
848 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
849 phba->sli4_hba.max_cfg_param.vpi_used;
850 } else {
851 if (mrpi)
852 *mrpi = pmb->un.varRdConfig.max_rpi;
853 if (arpi)
854 *arpi = pmb->un.varRdConfig.avail_rpi;
855 if (mxri)
856 *mxri = pmb->un.varRdConfig.max_xri;
857 if (axri)
858 *axri = pmb->un.varRdConfig.avail_xri;
859 if (mvpi)
860 *mvpi = pmb->un.varRdConfig.max_vpi;
861 if (avpi)
862 *avpi = pmb->un.varRdConfig.avail_vpi;
863 }
James Smart92d7f7b2007-06-17 19:56:38 -0500864
865 mempool_free(pmboxq, phba->mbox_mem_pool);
866 return 1;
867}
868
James Smarte59058c2008-08-24 21:49:00 -0400869/**
James Smart3621a712009-04-06 18:47:14 -0400870 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400871 * @dev: class device that is converted into a Scsi_host.
872 * @attr: device attribute, not used.
873 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
874 *
875 * Description:
876 * Calls lpfc_get_hba_info() asking for just the mrpi count.
877 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
878 * to "Unknown" and the buffer length is returned, therefore the caller
879 * must check for "Unknown" in the buffer to detect a failure.
880 *
881 * Returns: size of formatted string.
882 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500883static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100884lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
885 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500886{
Tony Jonesee959b02008-02-22 00:13:36 +0100887 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500888 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
889 struct lpfc_hba *phba = vport->phba;
890 uint32_t cnt;
891
James Smart858c9f62007-06-17 19:56:39 -0500892 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500893 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
894 return snprintf(buf, PAGE_SIZE, "Unknown\n");
895}
896
James Smarte59058c2008-08-24 21:49:00 -0400897/**
James Smart3621a712009-04-06 18:47:14 -0400898 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400899 * @dev: class device that is converted into a Scsi_host.
900 * @attr: device attribute, not used.
901 * @buf: containing the used rpi count in decimal or "Unknown".
902 *
903 * Description:
904 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
905 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
906 * to "Unknown" and the buffer length is returned, therefore the caller
907 * must check for "Unknown" in the buffer to detect a failure.
908 *
909 * Returns: size of formatted string.
910 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500911static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100912lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
913 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500914{
Tony Jonesee959b02008-02-22 00:13:36 +0100915 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500916 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
917 struct lpfc_hba *phba = vport->phba;
918 uint32_t cnt, acnt;
919
James Smart858c9f62007-06-17 19:56:39 -0500920 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500921 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
922 return snprintf(buf, PAGE_SIZE, "Unknown\n");
923}
924
James Smarte59058c2008-08-24 21:49:00 -0400925/**
James Smart3621a712009-04-06 18:47:14 -0400926 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -0400927 * @dev: class device that is converted into a Scsi_host.
928 * @attr: device attribute, not used.
929 * @buf: on return contains the maximum xri count in decimal or "Unknown".
930 *
931 * Description:
932 * Calls lpfc_get_hba_info() asking for just the mrpi count.
933 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
934 * to "Unknown" and the buffer length is returned, therefore the caller
935 * must check for "Unknown" in the buffer to detect a failure.
936 *
937 * Returns: size of formatted string.
938 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500939static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100940lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
941 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500942{
Tony Jonesee959b02008-02-22 00:13:36 +0100943 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500944 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
945 struct lpfc_hba *phba = vport->phba;
946 uint32_t cnt;
947
James Smart858c9f62007-06-17 19:56:39 -0500948 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500949 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
950 return snprintf(buf, PAGE_SIZE, "Unknown\n");
951}
952
James Smarte59058c2008-08-24 21:49:00 -0400953/**
James Smart3621a712009-04-06 18:47:14 -0400954 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -0400955 * @dev: class device that is converted into a Scsi_host.
956 * @attr: device attribute, not used.
957 * @buf: on return contains the used xri count in decimal or "Unknown".
958 *
959 * Description:
960 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
961 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
962 * to "Unknown" and the buffer length is returned, therefore the caller
963 * must check for "Unknown" in the buffer to detect a failure.
964 *
965 * Returns: size of formatted string.
966 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500967static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100968lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
969 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500970{
Tony Jonesee959b02008-02-22 00:13:36 +0100971 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500972 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
973 struct lpfc_hba *phba = vport->phba;
974 uint32_t cnt, acnt;
975
James Smart858c9f62007-06-17 19:56:39 -0500976 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
977 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
978 return snprintf(buf, PAGE_SIZE, "Unknown\n");
979}
980
James Smarte59058c2008-08-24 21:49:00 -0400981/**
James Smart3621a712009-04-06 18:47:14 -0400982 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -0400983 * @dev: class device that is converted into a Scsi_host.
984 * @attr: device attribute, not used.
985 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
986 *
987 * Description:
988 * Calls lpfc_get_hba_info() asking for just the mvpi count.
989 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
990 * to "Unknown" and the buffer length is returned, therefore the caller
991 * must check for "Unknown" in the buffer to detect a failure.
992 *
993 * Returns: size of formatted string.
994 **/
James Smart858c9f62007-06-17 19:56:39 -0500995static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100996lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
997 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500998{
Tony Jonesee959b02008-02-22 00:13:36 +0100999 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001000 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1001 struct lpfc_hba *phba = vport->phba;
1002 uint32_t cnt;
1003
1004 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1005 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1006 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1007}
1008
James Smarte59058c2008-08-24 21:49:00 -04001009/**
James Smart3621a712009-04-06 18:47:14 -04001010 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001011 * @dev: class device that is converted into a Scsi_host.
1012 * @attr: device attribute, not used.
1013 * @buf: on return contains the used vpi count in decimal or "Unknown".
1014 *
1015 * Description:
1016 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1017 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1018 * to "Unknown" and the buffer length is returned, therefore the caller
1019 * must check for "Unknown" in the buffer to detect a failure.
1020 *
1021 * Returns: size of formatted string.
1022 **/
James Smart858c9f62007-06-17 19:56:39 -05001023static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001024lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1025 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001026{
Tony Jonesee959b02008-02-22 00:13:36 +01001027 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001028 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1029 struct lpfc_hba *phba = vport->phba;
1030 uint32_t cnt, acnt;
1031
1032 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001033 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1034 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1035}
1036
James Smarte59058c2008-08-24 21:49:00 -04001037/**
James Smart3621a712009-04-06 18:47:14 -04001038 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001039 * @dev: class device that is converted into a Scsi_host.
1040 * @attr: device attribute, not used.
1041 * @buf: text that must be interpreted to determine if npiv is supported.
1042 *
1043 * Description:
1044 * Buffer will contain text indicating npiv is not suppoerted on the port,
1045 * the port is an NPIV physical port, or it is an npiv virtual port with
1046 * the id of the vport.
1047 *
1048 * Returns: size of formatted string.
1049 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001050static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001051lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1052 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001053{
Tony Jonesee959b02008-02-22 00:13:36 +01001054 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001055 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1056 struct lpfc_hba *phba = vport->phba;
1057
1058 if (!(phba->max_vpi))
1059 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1060 if (vport->port_type == LPFC_PHYSICAL_PORT)
1061 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1062 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1063}
1064
James Smarte59058c2008-08-24 21:49:00 -04001065/**
James Smart3621a712009-04-06 18:47:14 -04001066 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001067 * @dev: class device that is converted into a Scsi_host.
1068 * @attr: device attribute, not used.
1069 * @buf: on return contains the cfg_poll in hex.
1070 *
1071 * Notes:
1072 * cfg_poll should be a lpfc_polling_flags type.
1073 *
1074 * Returns: size of formatted string.
1075 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001076static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001077lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1078 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001079{
Tony Jonesee959b02008-02-22 00:13:36 +01001080 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1082 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001083
1084 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1085}
1086
James Smarte59058c2008-08-24 21:49:00 -04001087/**
James Smart3621a712009-04-06 18:47:14 -04001088 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001089 * @dev: class device that is converted into a Scsi_host.
1090 * @attr: device attribute, not used.
1091 * @buf: one or more lpfc_polling_flags values.
1092 * @count: not used.
1093 *
1094 * Notes:
1095 * buf contents converted to integer and checked for a valid value.
1096 *
1097 * Returns:
1098 * -EINVAL if the buffer connot be converted or is out of range
1099 * length of the buf on success
1100 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001101static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001102lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1103 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001104{
Tony Jonesee959b02008-02-22 00:13:36 +01001105 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001106 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1107 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001108 uint32_t creg_val;
1109 uint32_t old_val;
1110 int val=0;
1111
1112 if (!isdigit(buf[0]))
1113 return -EINVAL;
1114
1115 if (sscanf(buf, "%i", &val) != 1)
1116 return -EINVAL;
1117
1118 if ((val & 0x3) != val)
1119 return -EINVAL;
1120
James Smart2e0fef82007-06-17 19:56:36 -05001121 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001122
1123 old_val = phba->cfg_poll;
1124
1125 if (val & ENABLE_FCP_RING_POLLING) {
1126 if ((val & DISABLE_FCP_RING_INT) &&
1127 !(old_val & DISABLE_FCP_RING_INT)) {
1128 creg_val = readl(phba->HCregaddr);
1129 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1130 writel(creg_val, phba->HCregaddr);
1131 readl(phba->HCregaddr); /* flush */
1132
1133 lpfc_poll_start_timer(phba);
1134 }
1135 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001136 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001137 return -EINVAL;
1138 }
1139
1140 if (!(val & DISABLE_FCP_RING_INT) &&
1141 (old_val & DISABLE_FCP_RING_INT))
1142 {
James Smart2e0fef82007-06-17 19:56:36 -05001143 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001144 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001145 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001146 creg_val = readl(phba->HCregaddr);
1147 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1148 writel(creg_val, phba->HCregaddr);
1149 readl(phba->HCregaddr); /* flush */
1150 }
1151
1152 phba->cfg_poll = val;
1153
James Smart2e0fef82007-06-17 19:56:36 -05001154 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001155
1156 return strlen(buf);
1157}
dea31012005-04-17 16:05:31 -05001158
James Smarte59058c2008-08-24 21:49:00 -04001159/**
James Smart3621a712009-04-06 18:47:14 -04001160 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001161 *
1162 * Description:
1163 * Macro that given an attr e.g. hba_queue_depth expands
1164 * into a function with the name lpfc_hba_queue_depth_show.
1165 *
1166 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1167 * @dev: class device that is converted into a Scsi_host.
1168 * @attr: device attribute, not used.
1169 * @buf: on return contains the attribute value in decimal.
1170 *
1171 * Returns: size of formatted string.
1172 **/
dea31012005-04-17 16:05:31 -05001173#define lpfc_param_show(attr) \
1174static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001175lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1176 char *buf) \
dea31012005-04-17 16:05:31 -05001177{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001178 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1180 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001181 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001182 val = phba->cfg_##attr;\
1183 return snprintf(buf, PAGE_SIZE, "%d\n",\
1184 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001185}
1186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001189 *
1190 * Description:
1191 * Macro that given an attr e.g. hba_queue_depth expands
1192 * into a function with the name lpfc_hba_queue_depth_show
1193 *
1194 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1195 * @dev: class device that is converted into a Scsi_host.
1196 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001197 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001198 *
1199 * Returns: size of formatted string.
1200 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001201#define lpfc_param_hex_show(attr) \
1202static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001203lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1204 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001205{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001206 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001207 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1208 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001209 int val = 0;\
1210 val = phba->cfg_##attr;\
1211 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1212 phba->cfg_##attr);\
1213}
1214
James Smarte59058c2008-08-24 21:49:00 -04001215/**
James Smart3621a712009-04-06 18:47:14 -04001216 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001217 *
1218 * Description:
1219 * Macro that given an attr e.g. hba_queue_depth expands
1220 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1221 * takes a default argument, a minimum and maximum argument.
1222 *
1223 * lpfc_##attr##_init: Initializes an attribute.
1224 * @phba: pointer the the adapter structure.
1225 * @val: integer attribute value.
1226 *
1227 * Validates the min and max values then sets the adapter config field
1228 * accordingly, or uses the default if out of range and prints an error message.
1229 *
1230 * Returns:
1231 * zero on success
1232 * -EINVAL if default used
1233 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001234#define lpfc_param_init(attr, default, minval, maxval) \
1235static int \
1236lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1237{ \
1238 if (val >= minval && val <= maxval) {\
1239 phba->cfg_##attr = val;\
1240 return 0;\
1241 }\
1242 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001243 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1244 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001245 phba->cfg_##attr = default;\
1246 return -EINVAL;\
1247}
1248
James Smarte59058c2008-08-24 21:49:00 -04001249/**
James Smart3621a712009-04-06 18:47:14 -04001250 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001251 *
1252 * Description:
1253 * Macro that given an attr e.g. hba_queue_depth expands
1254 * into a function with the name lpfc_hba_queue_depth_set
1255 *
1256 * lpfc_##attr##_set: Sets an attribute value.
1257 * @phba: pointer the the adapter structure.
1258 * @val: integer attribute value.
1259 *
1260 * Description:
1261 * Validates the min and max values then sets the
1262 * adapter config field if in the valid range. prints error message
1263 * and does not set the parameter if invalid.
1264 *
1265 * Returns:
1266 * zero on success
1267 * -EINVAL if val is invalid
1268 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001269#define lpfc_param_set(attr, default, minval, maxval) \
1270static int \
1271lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1272{ \
1273 if (val >= minval && val <= maxval) {\
1274 phba->cfg_##attr = val;\
1275 return 0;\
1276 }\
1277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001278 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1279 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001280 return -EINVAL;\
1281}
1282
James Smarte59058c2008-08-24 21:49:00 -04001283/**
James Smart3621a712009-04-06 18:47:14 -04001284 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001285 *
1286 * Description:
1287 * Macro that given an attr e.g. hba_queue_depth expands
1288 * into a function with the name lpfc_hba_queue_depth_store.
1289 *
1290 * lpfc_##attr##_store: Set an sttribute value.
1291 * @dev: class device that is converted into a Scsi_host.
1292 * @attr: device attribute, not used.
1293 * @buf: contains the attribute value in ascii.
1294 * @count: not used.
1295 *
1296 * Description:
1297 * Convert the ascii text number to an integer, then
1298 * use the lpfc_##attr##_set function to set the value.
1299 *
1300 * Returns:
1301 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1302 * length of buffer upon success.
1303 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001304#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001305static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001306lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1307 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001308{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001309 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001310 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1311 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001312 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001313 if (!isdigit(buf[0]))\
1314 return -EINVAL;\
1315 if (sscanf(buf, "%i", &val) != 1)\
1316 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001317 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001318 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001319 else \
1320 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001321}
1322
James Smarte59058c2008-08-24 21:49:00 -04001323/**
James Smart3621a712009-04-06 18:47:14 -04001324 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001325 *
1326 * Description:
1327 * Macro that given an attr e.g. hba_queue_depth expands
1328 * into a function with the name lpfc_hba_queue_depth_show
1329 *
1330 * lpfc_##attr##_show: prints the attribute value in decimal.
1331 * @dev: class device that is converted into a Scsi_host.
1332 * @attr: device attribute, not used.
1333 * @buf: on return contains the attribute value in decimal.
1334 *
1335 * Returns: length of formatted string.
1336 **/
James Smart3de2a652007-08-02 11:09:59 -04001337#define lpfc_vport_param_show(attr) \
1338static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001339lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1340 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001341{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001342 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1344 int val = 0;\
1345 val = vport->cfg_##attr;\
1346 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1347}
1348
James Smarte59058c2008-08-24 21:49:00 -04001349/**
James Smart3621a712009-04-06 18:47:14 -04001350 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001351 *
1352 * Description:
1353 * Macro that given an attr e.g.
1354 * hba_queue_depth expands into a function with the name
1355 * lpfc_hba_queue_depth_show
1356 *
James Smart3621a712009-04-06 18:47:14 -04001357 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001358 * @dev: class device that is converted into a Scsi_host.
1359 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001360 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001361 *
1362 * Returns: length of formatted string.
1363 **/
James Smart3de2a652007-08-02 11:09:59 -04001364#define lpfc_vport_param_hex_show(attr) \
1365static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001366lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1367 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001368{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001369 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001370 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1371 int val = 0;\
1372 val = vport->cfg_##attr;\
1373 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1374}
1375
James Smarte59058c2008-08-24 21:49:00 -04001376/**
James Smart3621a712009-04-06 18:47:14 -04001377 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001378 *
1379 * Description:
1380 * Macro that given an attr e.g. hba_queue_depth expands
1381 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1382 * takes a default argument, a minimum and maximum argument.
1383 *
1384 * lpfc_##attr##_init: validates the min and max values then sets the
1385 * adapter config field accordingly, or uses the default if out of range
1386 * and prints an error message.
1387 * @phba: pointer the the adapter structure.
1388 * @val: integer attribute value.
1389 *
1390 * Returns:
1391 * zero on success
1392 * -EINVAL if default used
1393 **/
James Smart3de2a652007-08-02 11:09:59 -04001394#define lpfc_vport_param_init(attr, default, minval, maxval) \
1395static int \
1396lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1397{ \
1398 if (val >= minval && val <= maxval) {\
1399 vport->cfg_##attr = val;\
1400 return 0;\
1401 }\
James Smarte8b62012007-08-02 11:10:09 -04001402 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001403 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001404 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001405 vport->cfg_##attr = default;\
1406 return -EINVAL;\
1407}
1408
James Smarte59058c2008-08-24 21:49:00 -04001409/**
James Smart3621a712009-04-06 18:47:14 -04001410 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001411 *
1412 * Description:
1413 * Macro that given an attr e.g. hba_queue_depth expands
1414 * into a function with the name lpfc_hba_queue_depth_set
1415 *
1416 * lpfc_##attr##_set: validates the min and max values then sets the
1417 * adapter config field if in the valid range. prints error message
1418 * and does not set the parameter if invalid.
1419 * @phba: pointer the the adapter structure.
1420 * @val: integer attribute value.
1421 *
1422 * Returns:
1423 * zero on success
1424 * -EINVAL if val is invalid
1425 **/
James Smart3de2a652007-08-02 11:09:59 -04001426#define lpfc_vport_param_set(attr, default, minval, maxval) \
1427static int \
1428lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1429{ \
1430 if (val >= minval && val <= maxval) {\
1431 vport->cfg_##attr = val;\
1432 return 0;\
1433 }\
James Smarte8b62012007-08-02 11:10:09 -04001434 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001435 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001436 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001437 return -EINVAL;\
1438}
1439
James Smarte59058c2008-08-24 21:49:00 -04001440/**
James Smart3621a712009-04-06 18:47:14 -04001441 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001442 *
1443 * Description:
1444 * Macro that given an attr e.g. hba_queue_depth
1445 * expands into a function with the name lpfc_hba_queue_depth_store
1446 *
1447 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1448 * use the lpfc_##attr##_set function to set the value.
1449 * @cdev: class device that is converted into a Scsi_host.
1450 * @buf: contains the attribute value in decimal.
1451 * @count: not used.
1452 *
1453 * Returns:
1454 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1455 * length of buffer upon success.
1456 **/
James Smart3de2a652007-08-02 11:09:59 -04001457#define lpfc_vport_param_store(attr) \
1458static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001459lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1460 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001461{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001462 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001463 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1464 int val=0;\
1465 if (!isdigit(buf[0]))\
1466 return -EINVAL;\
1467 if (sscanf(buf, "%i", &val) != 1)\
1468 return -EINVAL;\
1469 if (lpfc_##attr##_set(vport, val) == 0) \
1470 return strlen(buf);\
1471 else \
1472 return -EINVAL;\
1473}
1474
1475
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001476#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1477static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001478module_param(lpfc_##name, int, 0);\
1479MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001480lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001481
1482#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1483static int lpfc_##name = defval;\
1484module_param(lpfc_##name, int, 0);\
1485MODULE_PARM_DESC(lpfc_##name, desc);\
1486lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001487lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001488static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001489
1490#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1491static int lpfc_##name = defval;\
1492module_param(lpfc_##name, int, 0);\
1493MODULE_PARM_DESC(lpfc_##name, desc);\
1494lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001495lpfc_param_init(name, defval, minval, maxval)\
1496lpfc_param_set(name, defval, minval, maxval)\
1497lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001498static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1499 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001500
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001501#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1502static int lpfc_##name = defval;\
1503module_param(lpfc_##name, int, 0);\
1504MODULE_PARM_DESC(lpfc_##name, desc);\
1505lpfc_param_hex_show(name)\
1506lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001507static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001508
1509#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1510static int lpfc_##name = defval;\
1511module_param(lpfc_##name, int, 0);\
1512MODULE_PARM_DESC(lpfc_##name, desc);\
1513lpfc_param_hex_show(name)\
1514lpfc_param_init(name, defval, minval, maxval)\
1515lpfc_param_set(name, defval, minval, maxval)\
1516lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001517static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1518 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001519
James Smart3de2a652007-08-02 11:09:59 -04001520#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1521static int lpfc_##name = defval;\
1522module_param(lpfc_##name, int, 0);\
1523MODULE_PARM_DESC(lpfc_##name, desc);\
1524lpfc_vport_param_init(name, defval, minval, maxval)
1525
1526#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1527static int lpfc_##name = defval;\
1528module_param(lpfc_##name, int, 0);\
1529MODULE_PARM_DESC(lpfc_##name, desc);\
1530lpfc_vport_param_show(name)\
1531lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001532static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001533
1534#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1535static int lpfc_##name = defval;\
1536module_param(lpfc_##name, int, 0);\
1537MODULE_PARM_DESC(lpfc_##name, desc);\
1538lpfc_vport_param_show(name)\
1539lpfc_vport_param_init(name, defval, minval, maxval)\
1540lpfc_vport_param_set(name, defval, minval, maxval)\
1541lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001542static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1543 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001544
1545#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1546static int lpfc_##name = defval;\
1547module_param(lpfc_##name, int, 0);\
1548MODULE_PARM_DESC(lpfc_##name, desc);\
1549lpfc_vport_param_hex_show(name)\
1550lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001551static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001552
1553#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1554static int lpfc_##name = defval;\
1555module_param(lpfc_##name, int, 0);\
1556MODULE_PARM_DESC(lpfc_##name, desc);\
1557lpfc_vport_param_hex_show(name)\
1558lpfc_vport_param_init(name, defval, minval, maxval)\
1559lpfc_vport_param_set(name, defval, minval, maxval)\
1560lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001561static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1562 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001563
James Smart81301a92008-12-04 22:39:46 -05001564static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1565static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1566static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1567static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001568static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1569static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1570static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1571static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1572static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1573static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1574static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1575static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001576static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001577static DEVICE_ATTR(option_rom_version, S_IRUGO,
1578 lpfc_option_rom_version_show, NULL);
1579static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1580 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001581static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001582static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1583static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1584static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1585 lpfc_board_mode_show, lpfc_board_mode_store);
1586static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1587static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1588static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1589static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1590static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1591static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1592static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1593static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1594static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001595
James Smartc3f28af2006-08-18 17:47:18 -04001596
James Smarta12e07b2006-12-02 13:35:30 -05001597static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001598
James Smarte59058c2008-08-24 21:49:00 -04001599/**
James Smart3621a712009-04-06 18:47:14 -04001600 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001601 * @dev: class device that is converted into a Scsi_host.
1602 * @attr: device attribute, not used.
1603 * @buf: containing the string lpfc_soft_wwn_key.
1604 * @count: must be size of lpfc_soft_wwn_key.
1605 *
1606 * Returns:
1607 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1608 * length of buf indicates success
1609 **/
James Smartc3f28af2006-08-18 17:47:18 -04001610static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001611lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1612 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001613{
Tony Jonesee959b02008-02-22 00:13:36 +01001614 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001617 unsigned int cnt = count;
1618
1619 /*
1620 * We're doing a simple sanity check for soft_wwpn setting.
1621 * We require that the user write a specific key to enable
1622 * the soft_wwpn attribute to be settable. Once the attribute
1623 * is written, the enable key resets. If further updates are
1624 * desired, the key must be written again to re-enable the
1625 * attribute.
1626 *
1627 * The "key" is not secret - it is a hardcoded string shown
1628 * here. The intent is to protect against the random user or
1629 * application that is just writing attributes.
1630 */
1631
1632 /* count may include a LF at end of string */
1633 if (buf[cnt-1] == '\n')
1634 cnt--;
1635
James Smarta12e07b2006-12-02 13:35:30 -05001636 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1637 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001638 return -EINVAL;
1639
James Smarta12e07b2006-12-02 13:35:30 -05001640 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001641 return count;
1642}
Tony Jonesee959b02008-02-22 00:13:36 +01001643static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1644 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001645
James Smarte59058c2008-08-24 21:49:00 -04001646/**
James Smart3621a712009-04-06 18:47:14 -04001647 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001648 * @dev: class device that is converted into a Scsi_host.
1649 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001650 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001651 *
1652 * Returns: size of formatted string.
1653 **/
James Smartc3f28af2006-08-18 17:47:18 -04001654static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001655lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1656 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001657{
Tony Jonesee959b02008-02-22 00:13:36 +01001658 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001659 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1660 struct lpfc_hba *phba = vport->phba;
1661
Randy Dunlapafc071e62006-10-23 21:47:13 -07001662 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1663 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001664}
1665
James Smarte59058c2008-08-24 21:49:00 -04001666/**
James Smart3621a712009-04-06 18:47:14 -04001667 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001668 * @dev class device that is converted into a Scsi_host.
1669 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001670 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001671 * @count: number of wwpn bytes in buf
1672 *
1673 * Returns:
1674 * -EACCES hba reset not enabled, adapter over temp
1675 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1676 * -EIO error taking adapter offline or online
1677 * value of count on success
1678 **/
James Smartc3f28af2006-08-18 17:47:18 -04001679static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001680lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1681 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001682{
Tony Jonesee959b02008-02-22 00:13:36 +01001683 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1685 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001686 struct completion online_compl;
1687 int stat1=0, stat2=0;
1688 unsigned int i, j, cnt=count;
1689 u8 wwpn[8];
1690
James Smart13815c82008-01-11 01:52:48 -05001691 if (!phba->cfg_enable_hba_reset)
1692 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001693 spin_lock_irq(&phba->hbalock);
1694 if (phba->over_temp_state == HBA_OVER_TEMP) {
1695 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001696 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001697 }
1698 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001699 /* count may include a LF at end of string */
1700 if (buf[cnt-1] == '\n')
1701 cnt--;
1702
James Smarta12e07b2006-12-02 13:35:30 -05001703 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001704 ((cnt == 17) && (*buf++ != 'x')) ||
1705 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1706 return -EINVAL;
1707
James Smarta12e07b2006-12-02 13:35:30 -05001708 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001709
1710 memset(wwpn, 0, sizeof(wwpn));
1711
1712 /* Validate and store the new name */
1713 for (i=0, j=0; i < 16; i++) {
1714 if ((*buf >= 'a') && (*buf <= 'f'))
1715 j = ((j << 4) | ((*buf++ -'a') + 10));
1716 else if ((*buf >= 'A') && (*buf <= 'F'))
1717 j = ((j << 4) | ((*buf++ -'A') + 10));
1718 else if ((*buf >= '0') && (*buf <= '9'))
1719 j = ((j << 4) | (*buf++ -'0'));
1720 else
1721 return -EINVAL;
1722 if (i % 2) {
1723 wwpn[i/2] = j & 0xff;
1724 j = 0;
1725 }
1726 }
1727 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001728 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001729 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001730 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001731
1732 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1733 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1734
James Smart46fa3112007-04-25 09:51:45 -04001735 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001736 if (stat1)
1737 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001738 "0463 lpfc_soft_wwpn attribute set failed to "
1739 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001740 init_completion(&online_compl);
1741 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1742 wait_for_completion(&online_compl);
1743 if (stat2)
1744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001745 "0464 lpfc_soft_wwpn attribute set failed to "
1746 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001747 return (stat1 || stat2) ? -EIO : count;
1748}
Tony Jonesee959b02008-02-22 00:13:36 +01001749static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1750 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001751
James Smarte59058c2008-08-24 21:49:00 -04001752/**
James Smart3621a712009-04-06 18:47:14 -04001753 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001754 * @dev: class device that is converted into a Scsi_host.
1755 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001756 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001757 *
1758 * Returns: size of formatted string.
1759 **/
James Smarta12e07b2006-12-02 13:35:30 -05001760static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001761lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1762 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001763{
Tony Jonesee959b02008-02-22 00:13:36 +01001764 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001765 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001766 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1767 (unsigned long long)phba->cfg_soft_wwnn);
1768}
1769
James Smarte59058c2008-08-24 21:49:00 -04001770/**
James Smart3621a712009-04-06 18:47:14 -04001771 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001772 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001773 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001774 * @count: number of wwnn bytes in buf.
1775 *
1776 * Returns:
1777 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1778 * value of count on success
1779 **/
James Smarta12e07b2006-12-02 13:35:30 -05001780static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001781lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1782 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001783{
Tony Jonesee959b02008-02-22 00:13:36 +01001784 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001785 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001786 unsigned int i, j, cnt=count;
1787 u8 wwnn[8];
1788
1789 /* count may include a LF at end of string */
1790 if (buf[cnt-1] == '\n')
1791 cnt--;
1792
1793 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1794 ((cnt == 17) && (*buf++ != 'x')) ||
1795 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1796 return -EINVAL;
1797
1798 /*
1799 * Allow wwnn to be set many times, as long as the enable is set.
1800 * However, once the wwpn is set, everything locks.
1801 */
1802
1803 memset(wwnn, 0, sizeof(wwnn));
1804
1805 /* Validate and store the new name */
1806 for (i=0, j=0; i < 16; i++) {
1807 if ((*buf >= 'a') && (*buf <= 'f'))
1808 j = ((j << 4) | ((*buf++ -'a') + 10));
1809 else if ((*buf >= 'A') && (*buf <= 'F'))
1810 j = ((j << 4) | ((*buf++ -'A') + 10));
1811 else if ((*buf >= '0') && (*buf <= '9'))
1812 j = ((j << 4) | (*buf++ -'0'));
1813 else
1814 return -EINVAL;
1815 if (i % 2) {
1816 wwnn[i/2] = j & 0xff;
1817 j = 0;
1818 }
1819 }
1820 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1821
1822 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1823 "lpfc%d: soft_wwnn set. Value will take effect upon "
1824 "setting of the soft_wwpn\n", phba->brd_no);
1825
1826 return count;
1827}
Tony Jonesee959b02008-02-22 00:13:36 +01001828static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1829 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001830
James Smartc3f28af2006-08-18 17:47:18 -04001831
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001832static int lpfc_poll = 0;
1833module_param(lpfc_poll, int, 0);
1834MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1835 " 0 - none,"
1836 " 1 - poll with interrupts enabled"
1837 " 3 - poll and disable FCP ring interrupts");
1838
Tony Jonesee959b02008-02-22 00:13:36 +01001839static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1840 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001841
James Smart92d7f7b2007-06-17 19:56:38 -05001842int lpfc_sli_mode = 0;
1843module_param(lpfc_sli_mode, int, 0);
1844MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1845 " 0 - auto (SLI-3 if supported),"
1846 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1847 " 3 - select SLI-3");
1848
James Smart7ee5d432007-10-27 13:37:17 -04001849int lpfc_enable_npiv = 0;
1850module_param(lpfc_enable_npiv, int, 0);
1851MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1852lpfc_param_show(enable_npiv);
1853lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001854static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001855 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001856
dea31012005-04-17 16:05:31 -05001857/*
James Smartc01f3202006-08-18 17:47:08 -04001858# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1859# until the timer expires. Value range is [0,255]. Default value is 30.
1860*/
1861static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1862static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1863module_param(lpfc_nodev_tmo, int, 0);
1864MODULE_PARM_DESC(lpfc_nodev_tmo,
1865 "Seconds driver will hold I/O waiting "
1866 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001867
1868/**
James Smart3621a712009-04-06 18:47:14 -04001869 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04001870 * @dev: class converted to a Scsi_host structure.
1871 * @attr: device attribute, not used.
1872 * @buf: on return contains the dev loss timeout in decimal.
1873 *
1874 * Returns: size of formatted string.
1875 **/
James Smartc01f3202006-08-18 17:47:08 -04001876static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001877lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1878 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001879{
Tony Jonesee959b02008-02-22 00:13:36 +01001880 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001882 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001883 val = vport->cfg_devloss_tmo;
1884 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001885}
1886
James Smarte59058c2008-08-24 21:49:00 -04001887/**
James Smart3621a712009-04-06 18:47:14 -04001888 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04001889 * @vport: lpfc vport structure pointer.
1890 * @val: contains the nodev timeout value.
1891 *
1892 * Description:
1893 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1894 * a kernel error message is printed and zero is returned.
1895 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1896 * Otherwise nodev tmo is set to the default value.
1897 *
1898 * Returns:
1899 * zero if already set or if val is in range
1900 * -EINVAL val out of range
1901 **/
James Smartc01f3202006-08-18 17:47:08 -04001902static int
James Smart3de2a652007-08-02 11:09:59 -04001903lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001904{
James Smart3de2a652007-08-02 11:09:59 -04001905 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1906 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1907 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001908 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001909 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001910 "parameter because devloss_tmo is "
1911 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001912 return 0;
1913 }
1914
1915 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001916 vport->cfg_nodev_tmo = val;
1917 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001918 return 0;
1919 }
James Smarte8b62012007-08-02 11:10:09 -04001920 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1921 "0400 lpfc_nodev_tmo attribute cannot be set to"
1922 " %d, allowed range is [%d, %d]\n",
1923 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001924 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001925 return -EINVAL;
1926}
1927
James Smarte59058c2008-08-24 21:49:00 -04001928/**
James Smart3621a712009-04-06 18:47:14 -04001929 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04001930 * @vport: lpfc vport structure pointer.
1931 *
1932 * Description:
1933 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1934 **/
James Smart7054a602007-04-25 09:52:34 -04001935static void
James Smart3de2a652007-08-02 11:09:59 -04001936lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001937{
James Smart858c9f62007-06-17 19:56:39 -05001938 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001939 struct lpfc_nodelist *ndlp;
1940
James Smart51ef4c22007-08-02 11:10:31 -04001941 shost = lpfc_shost_from_vport(vport);
1942 spin_lock_irq(shost->host_lock);
1943 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001944 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001945 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1946 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001947}
1948
James Smarte59058c2008-08-24 21:49:00 -04001949/**
James Smart3621a712009-04-06 18:47:14 -04001950 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04001951 * @vport: lpfc vport structure pointer.
1952 * @val: contains the tmo value.
1953 *
1954 * Description:
1955 * If the devloss tmo is already set or the vport dev loss tmo has changed
1956 * then a kernel error message is printed and zero is returned.
1957 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1958 * Otherwise nodev tmo is set to the default value.
1959 *
1960 * Returns:
1961 * zero if already set or if val is in range
1962 * -EINVAL val out of range
1963 **/
James Smartc01f3202006-08-18 17:47:08 -04001964static int
James Smart3de2a652007-08-02 11:09:59 -04001965lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001966{
James Smart3de2a652007-08-02 11:09:59 -04001967 if (vport->dev_loss_tmo_changed ||
1968 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001969 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1970 "0401 Ignoring change to nodev_tmo "
1971 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001972 return 0;
1973 }
James Smartc01f3202006-08-18 17:47:08 -04001974 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001975 vport->cfg_nodev_tmo = val;
1976 vport->cfg_devloss_tmo = val;
1977 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001978 return 0;
1979 }
James Smarte8b62012007-08-02 11:10:09 -04001980 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1981 "0403 lpfc_nodev_tmo attribute cannot be set to"
1982 "%d, allowed range is [%d, %d]\n",
1983 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001984 return -EINVAL;
1985}
1986
James Smart3de2a652007-08-02 11:09:59 -04001987lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001988
Tony Jonesee959b02008-02-22 00:13:36 +01001989static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1990 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001991
1992/*
1993# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1994# disappear until the timer expires. Value range is [0,255]. Default
1995# value is 30.
1996*/
1997module_param(lpfc_devloss_tmo, int, 0);
1998MODULE_PARM_DESC(lpfc_devloss_tmo,
1999 "Seconds driver will hold I/O waiting "
2000 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002001lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2002 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2003lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002004
2005/**
James Smart3621a712009-04-06 18:47:14 -04002006 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002007 * @vport: lpfc vport structure pointer.
2008 * @val: contains the tmo value.
2009 *
2010 * Description:
2011 * If val is in a valid range then set the vport nodev tmo,
2012 * devloss tmo, also set the vport dev loss tmo changed flag.
2013 * Else a kernel error message is printed.
2014 *
2015 * Returns:
2016 * zero if val is in range
2017 * -EINVAL val out of range
2018 **/
James Smartc01f3202006-08-18 17:47:08 -04002019static int
James Smart3de2a652007-08-02 11:09:59 -04002020lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002021{
2022 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002023 vport->cfg_nodev_tmo = val;
2024 vport->cfg_devloss_tmo = val;
2025 vport->dev_loss_tmo_changed = 1;
2026 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002027 return 0;
2028 }
2029
James Smarte8b62012007-08-02 11:10:09 -04002030 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2031 "0404 lpfc_devloss_tmo attribute cannot be set to"
2032 " %d, allowed range is [%d, %d]\n",
2033 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002034 return -EINVAL;
2035}
2036
James Smart3de2a652007-08-02 11:09:59 -04002037lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002038static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2039 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002040
2041/*
dea31012005-04-17 16:05:31 -05002042# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2043# deluged with LOTS of information.
2044# You can set a bit mask to record specific types of verbose messages:
2045#
2046# LOG_ELS 0x1 ELS events
2047# LOG_DISCOVERY 0x2 Link discovery events
2048# LOG_MBOX 0x4 Mailbox events
2049# LOG_INIT 0x8 Initialization events
2050# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05002051# LOG_FCP 0x40 FCP traffic history
2052# LOG_NODE 0x80 Node table events
James Smart81301a92008-12-04 22:39:46 -05002053# LOG_BG 0x200 BlockBuard events
dea31012005-04-17 16:05:31 -05002054# LOG_MISC 0x400 Miscellaneous events
2055# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05002056# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05002057# LOG_LIBDFC 0x2000 LIBDFC events
2058# LOG_ALL_MSG 0xffff LOG all messages
2059*/
James Smarte8b62012007-08-02 11:10:09 -04002060LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
2061 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002062
2063/*
James Smart7ee5d432007-10-27 13:37:17 -04002064# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2065# objects that have been registered with the nameserver after login.
2066*/
2067LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2068 "Deregister nameserver objects before LOGO");
2069
2070/*
dea31012005-04-17 16:05:31 -05002071# lun_queue_depth: This parameter is used to limit the number of outstanding
2072# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2073*/
James Smart3de2a652007-08-02 11:09:59 -04002074LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2075 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002076
2077/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002078# hba_queue_depth: This parameter is used to limit the number of outstanding
2079# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2080# value is greater than the maximum number of exchanges supported by the HBA,
2081# then maximum number of exchanges supported by the HBA is used to determine
2082# the hba_queue_depth.
2083*/
2084LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2085 "Max number of FCP commands we can queue to a lpfc HBA");
2086
2087/*
James Smart92d7f7b2007-06-17 19:56:38 -05002088# peer_port_login: This parameter allows/prevents logins
2089# between peer ports hosted on the same physical port.
2090# When this parameter is set 0 peer ports of same physical port
2091# are not allowed to login to each other.
2092# When this parameter is set 1 peer ports of same physical port
2093# are allowed to login to each other.
2094# Default value of this parameter is 0.
2095*/
James Smart3de2a652007-08-02 11:09:59 -04002096LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2097 "Allow peer ports on the same physical port to login to each "
2098 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002099
2100/*
James Smart3de2a652007-08-02 11:09:59 -04002101# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002102# between Virtual Ports and remote initiators.
2103# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2104# other initiators and will attempt to PLOGI all remote ports.
2105# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2106# remote ports and will not attempt to PLOGI to other initiators.
2107# This parameter does not restrict to the physical port.
2108# This parameter does not restrict logins to Fabric resident remote ports.
2109# Default value of this parameter is 1.
2110*/
James Smart3de2a652007-08-02 11:09:59 -04002111static int lpfc_restrict_login = 1;
2112module_param(lpfc_restrict_login, int, 0);
2113MODULE_PARM_DESC(lpfc_restrict_login,
2114 "Restrict virtual ports login to remote initiators.");
2115lpfc_vport_param_show(restrict_login);
2116
James Smarte59058c2008-08-24 21:49:00 -04002117/**
James Smart3621a712009-04-06 18:47:14 -04002118 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002119 * @vport: lpfc vport structure pointer.
2120 * @val: contains the restrict login value.
2121 *
2122 * Description:
2123 * If val is not in a valid range then log a kernel error message and set
2124 * the vport restrict login to one.
2125 * If the port type is physical clear the restrict login flag and return.
2126 * Else set the restrict login flag to val.
2127 *
2128 * Returns:
2129 * zero if val is in range
2130 * -EINVAL val out of range
2131 **/
James Smart3de2a652007-08-02 11:09:59 -04002132static int
2133lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2134{
2135 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002136 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002137 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002138 "be set to %d, allowed range is [0, 1]\n",
2139 val);
James Smart3de2a652007-08-02 11:09:59 -04002140 vport->cfg_restrict_login = 1;
2141 return -EINVAL;
2142 }
2143 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2144 vport->cfg_restrict_login = 0;
2145 return 0;
2146 }
2147 vport->cfg_restrict_login = val;
2148 return 0;
2149}
2150
James Smarte59058c2008-08-24 21:49:00 -04002151/**
James Smart3621a712009-04-06 18:47:14 -04002152 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002153 * @vport: lpfc vport structure pointer.
2154 * @val: contains the restrict login value.
2155 *
2156 * Description:
2157 * If val is not in a valid range then log a kernel error message and set
2158 * the vport restrict login to one.
2159 * If the port type is physical and the val is not zero log a kernel
2160 * error message, clear the restrict login flag and return zero.
2161 * Else set the restrict login flag to val.
2162 *
2163 * Returns:
2164 * zero if val is in range
2165 * -EINVAL val out of range
2166 **/
James Smart3de2a652007-08-02 11:09:59 -04002167static int
2168lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2169{
2170 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002171 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002172 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002173 "be set to %d, allowed range is [0, 1]\n",
2174 val);
James Smart3de2a652007-08-02 11:09:59 -04002175 vport->cfg_restrict_login = 1;
2176 return -EINVAL;
2177 }
2178 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002179 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2180 "0468 lpfc_restrict_login must be 0 for "
2181 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002182 vport->cfg_restrict_login = 0;
2183 return 0;
2184 }
2185 vport->cfg_restrict_login = val;
2186 return 0;
2187}
2188lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002189static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2190 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002191
2192/*
dea31012005-04-17 16:05:31 -05002193# Some disk devices have a "select ID" or "select Target" capability.
2194# From a protocol standpoint "select ID" usually means select the
2195# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2196# annex" which contains a table that maps a "select ID" (a number
2197# between 0 and 7F) to an ALPA. By default, for compatibility with
2198# older drivers, the lpfc driver scans this table from low ALPA to high
2199# ALPA.
2200#
2201# Turning on the scan-down variable (on = 1, off = 0) will
2202# cause the lpfc driver to use an inverted table, effectively
2203# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2204#
2205# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2206# and will not work across a fabric. Also this parameter will take
2207# effect only in the case when ALPA map is not available.)
2208*/
James Smart3de2a652007-08-02 11:09:59 -04002209LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2210 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002211
2212/*
dea31012005-04-17 16:05:31 -05002213# lpfc_topology: link topology for init link
2214# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002215# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002216# 0x02 = attempt point-to-point mode only
2217# 0x04 = attempt loop mode only
2218# 0x06 = attempt point-to-point mode then loop
2219# Set point-to-point mode if you want to run as an N_Port.
2220# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2221# Default value is 0.
2222*/
James Smarte59058c2008-08-24 21:49:00 -04002223
2224/**
James Smart3621a712009-04-06 18:47:14 -04002225 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002226 * @phba: lpfc_hba pointer.
2227 * @val: topology value.
2228 *
2229 * Description:
2230 * If val is in a valid range then set the adapter's topology field and
2231 * issue a lip; if the lip fails reset the topology to the old value.
2232 *
2233 * If the value is not in range log a kernel error message and return an error.
2234 *
2235 * Returns:
2236 * zero if val is in range and lip okay
2237 * non-zero return value from lpfc_issue_lip()
2238 * -EINVAL val out of range
2239 **/
James Smarta257bf92009-04-06 18:48:10 -04002240static ssize_t
2241lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2242 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002243{
James Smarta257bf92009-04-06 18:48:10 -04002244 struct Scsi_Host *shost = class_to_shost(dev);
2245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2246 struct lpfc_hba *phba = vport->phba;
2247 int val = 0;
2248 int nolip = 0;
2249 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002250 int err;
2251 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002252
2253 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2254 nolip = 1;
2255 val_buf = &buf[strlen("nolip ")];
2256 }
2257
2258 if (!isdigit(val_buf[0]))
2259 return -EINVAL;
2260 if (sscanf(val_buf, "%i", &val) != 1)
2261 return -EINVAL;
2262
James Smart83108bd2008-01-11 01:53:09 -05002263 if (val >= 0 && val <= 6) {
2264 prev_val = phba->cfg_topology;
2265 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002266 if (nolip)
2267 return strlen(buf);
2268
James Smart83108bd2008-01-11 01:53:09 -05002269 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002270 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002271 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002272 return -EINVAL;
2273 } else
2274 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002275 }
2276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2277 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2278 "allowed range is [0, 6]\n",
2279 phba->brd_no, val);
2280 return -EINVAL;
2281}
2282static int lpfc_topology = 0;
2283module_param(lpfc_topology, int, 0);
2284MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2285lpfc_param_show(topology)
2286lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002287static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002288 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002289
James Smartea2151b2008-09-07 11:52:10 -04002290
2291/**
James Smart3621a712009-04-06 18:47:14 -04002292 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002293 * @dev: Pointer to class device.
2294 * @buf: Data buffer.
2295 * @count: Size of the data buffer.
2296 *
2297 * This function get called when an user write to the lpfc_stat_data_ctrl
2298 * sysfs file. This function parse the command written to the sysfs file
2299 * and take appropriate action. These commands are used for controlling
2300 * driver statistical data collection.
2301 * Following are the command this function handles.
2302 *
2303 * setbucket <bucket_type> <base> <step>
2304 * = Set the latency buckets.
2305 * destroybucket = destroy all the buckets.
2306 * start = start data collection
2307 * stop = stop data collection
2308 * reset = reset the collected data
2309 **/
2310static ssize_t
2311lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2312 const char *buf, size_t count)
2313{
2314 struct Scsi_Host *shost = class_to_shost(dev);
2315 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2316 struct lpfc_hba *phba = vport->phba;
2317#define LPFC_MAX_DATA_CTRL_LEN 1024
2318 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2319 unsigned long i;
2320 char *str_ptr, *token;
2321 struct lpfc_vport **vports;
2322 struct Scsi_Host *v_shost;
2323 char *bucket_type_str, *base_str, *step_str;
2324 unsigned long base, step, bucket_type;
2325
2326 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002327 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002328 return -EINVAL;
2329
2330 strcpy(bucket_data, buf);
2331 str_ptr = &bucket_data[0];
2332 /* Ignore this token - this is command token */
2333 token = strsep(&str_ptr, "\t ");
2334 if (!token)
2335 return -EINVAL;
2336
2337 bucket_type_str = strsep(&str_ptr, "\t ");
2338 if (!bucket_type_str)
2339 return -EINVAL;
2340
2341 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2342 bucket_type = LPFC_LINEAR_BUCKET;
2343 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2344 bucket_type = LPFC_POWER2_BUCKET;
2345 else
2346 return -EINVAL;
2347
2348 base_str = strsep(&str_ptr, "\t ");
2349 if (!base_str)
2350 return -EINVAL;
2351 base = simple_strtoul(base_str, NULL, 0);
2352
2353 step_str = strsep(&str_ptr, "\t ");
2354 if (!step_str)
2355 return -EINVAL;
2356 step = simple_strtoul(step_str, NULL, 0);
2357 if (!step)
2358 return -EINVAL;
2359
2360 /* Block the data collection for every vport */
2361 vports = lpfc_create_vport_work_array(phba);
2362 if (vports == NULL)
2363 return -ENOMEM;
2364
2365 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
2366 v_shost = lpfc_shost_from_vport(vports[i]);
2367 spin_lock_irq(v_shost->host_lock);
2368 /* Block and reset data collection */
2369 vports[i]->stat_data_blocked = 1;
2370 if (vports[i]->stat_data_enabled)
2371 lpfc_vport_reset_stat_data(vports[i]);
2372 spin_unlock_irq(v_shost->host_lock);
2373 }
2374
2375 /* Set the bucket attributes */
2376 phba->bucket_type = bucket_type;
2377 phba->bucket_base = base;
2378 phba->bucket_step = step;
2379
2380 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
2381 v_shost = lpfc_shost_from_vport(vports[i]);
2382
2383 /* Unblock data collection */
2384 spin_lock_irq(v_shost->host_lock);
2385 vports[i]->stat_data_blocked = 0;
2386 spin_unlock_irq(v_shost->host_lock);
2387 }
2388 lpfc_destroy_vport_work_array(phba, vports);
2389 return strlen(buf);
2390 }
2391
2392 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2393 vports = lpfc_create_vport_work_array(phba);
2394 if (vports == NULL)
2395 return -ENOMEM;
2396
2397 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
2398 v_shost = lpfc_shost_from_vport(vports[i]);
2399 spin_lock_irq(shost->host_lock);
2400 vports[i]->stat_data_blocked = 1;
2401 lpfc_free_bucket(vport);
2402 vport->stat_data_enabled = 0;
2403 vports[i]->stat_data_blocked = 0;
2404 spin_unlock_irq(shost->host_lock);
2405 }
2406 lpfc_destroy_vport_work_array(phba, vports);
2407 phba->bucket_type = LPFC_NO_BUCKET;
2408 phba->bucket_base = 0;
2409 phba->bucket_step = 0;
2410 return strlen(buf);
2411 }
2412
2413 if (!strncmp(buf, "start", strlen("start"))) {
2414 /* If no buckets configured return error */
2415 if (phba->bucket_type == LPFC_NO_BUCKET)
2416 return -EINVAL;
2417 spin_lock_irq(shost->host_lock);
2418 if (vport->stat_data_enabled) {
2419 spin_unlock_irq(shost->host_lock);
2420 return strlen(buf);
2421 }
2422 lpfc_alloc_bucket(vport);
2423 vport->stat_data_enabled = 1;
2424 spin_unlock_irq(shost->host_lock);
2425 return strlen(buf);
2426 }
2427
2428 if (!strncmp(buf, "stop", strlen("stop"))) {
2429 spin_lock_irq(shost->host_lock);
2430 if (vport->stat_data_enabled == 0) {
2431 spin_unlock_irq(shost->host_lock);
2432 return strlen(buf);
2433 }
2434 lpfc_free_bucket(vport);
2435 vport->stat_data_enabled = 0;
2436 spin_unlock_irq(shost->host_lock);
2437 return strlen(buf);
2438 }
2439
2440 if (!strncmp(buf, "reset", strlen("reset"))) {
2441 if ((phba->bucket_type == LPFC_NO_BUCKET)
2442 || !vport->stat_data_enabled)
2443 return strlen(buf);
2444 spin_lock_irq(shost->host_lock);
2445 vport->stat_data_blocked = 1;
2446 lpfc_vport_reset_stat_data(vport);
2447 vport->stat_data_blocked = 0;
2448 spin_unlock_irq(shost->host_lock);
2449 return strlen(buf);
2450 }
2451 return -EINVAL;
2452}
2453
2454
2455/**
James Smart3621a712009-04-06 18:47:14 -04002456 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002457 * @dev: Pointer to class device object.
2458 * @buf: Data buffer.
2459 *
2460 * This function is the read call back function for
2461 * lpfc_stat_data_ctrl sysfs file. This function report the
2462 * current statistical data collection state.
2463 **/
2464static ssize_t
2465lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2466 char *buf)
2467{
2468 struct Scsi_Host *shost = class_to_shost(dev);
2469 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2470 struct lpfc_hba *phba = vport->phba;
2471 int index = 0;
2472 int i;
2473 char *bucket_type;
2474 unsigned long bucket_value;
2475
2476 switch (phba->bucket_type) {
2477 case LPFC_LINEAR_BUCKET:
2478 bucket_type = "linear";
2479 break;
2480 case LPFC_POWER2_BUCKET:
2481 bucket_type = "power2";
2482 break;
2483 default:
2484 bucket_type = "No Bucket";
2485 break;
2486 }
2487
2488 sprintf(&buf[index], "Statistical Data enabled :%d, "
2489 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2490 " Bucket step :%d\nLatency Ranges :",
2491 vport->stat_data_enabled, vport->stat_data_blocked,
2492 bucket_type, phba->bucket_base, phba->bucket_step);
2493 index = strlen(buf);
2494 if (phba->bucket_type != LPFC_NO_BUCKET) {
2495 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2496 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2497 bucket_value = phba->bucket_base +
2498 phba->bucket_step * i;
2499 else
2500 bucket_value = phba->bucket_base +
2501 (1 << i) * phba->bucket_step;
2502
2503 if (index + 10 > PAGE_SIZE)
2504 break;
2505 sprintf(&buf[index], "%08ld ", bucket_value);
2506 index = strlen(buf);
2507 }
2508 }
2509 sprintf(&buf[index], "\n");
2510 return strlen(buf);
2511}
2512
2513/*
2514 * Sysfs attribute to control the statistical data collection.
2515 */
2516static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2517 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2518
2519/*
2520 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2521 */
2522
2523/*
2524 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2525 * for each target.
2526 */
2527#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2528#define MAX_STAT_DATA_SIZE_PER_TARGET \
2529 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2530
2531
2532/**
James Smart3621a712009-04-06 18:47:14 -04002533 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
James Smartea2151b2008-09-07 11:52:10 -04002534 * @kobj: Pointer to the kernel object
2535 * @bin_attr: Attribute object
2536 * @buff: Buffer pointer
2537 * @off: File offset
2538 * @count: Buffer size
2539 *
2540 * This function is the read call back function for lpfc_drvr_stat_data
2541 * sysfs file. This function export the statistical data to user
2542 * applications.
2543 **/
2544static ssize_t
2545sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2546 char *buf, loff_t off, size_t count)
2547{
2548 struct device *dev = container_of(kobj, struct device,
2549 kobj);
2550 struct Scsi_Host *shost = class_to_shost(dev);
2551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2552 struct lpfc_hba *phba = vport->phba;
2553 int i = 0, index = 0;
2554 unsigned long nport_index;
2555 struct lpfc_nodelist *ndlp = NULL;
2556 nport_index = (unsigned long)off /
2557 MAX_STAT_DATA_SIZE_PER_TARGET;
2558
2559 if (!vport->stat_data_enabled || vport->stat_data_blocked
2560 || (phba->bucket_type == LPFC_NO_BUCKET))
2561 return 0;
2562
2563 spin_lock_irq(shost->host_lock);
2564 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2565 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2566 continue;
2567
2568 if (nport_index > 0) {
2569 nport_index--;
2570 continue;
2571 }
2572
2573 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2574 > count)
2575 break;
2576
2577 if (!ndlp->lat_data)
2578 continue;
2579
2580 /* Print the WWN */
2581 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2582 ndlp->nlp_portname.u.wwn[0],
2583 ndlp->nlp_portname.u.wwn[1],
2584 ndlp->nlp_portname.u.wwn[2],
2585 ndlp->nlp_portname.u.wwn[3],
2586 ndlp->nlp_portname.u.wwn[4],
2587 ndlp->nlp_portname.u.wwn[5],
2588 ndlp->nlp_portname.u.wwn[6],
2589 ndlp->nlp_portname.u.wwn[7]);
2590
2591 index = strlen(buf);
2592
2593 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2594 sprintf(&buf[index], "%010u,",
2595 ndlp->lat_data[i].cmd_count);
2596 index = strlen(buf);
2597 }
2598 sprintf(&buf[index], "\n");
2599 index = strlen(buf);
2600 }
2601 spin_unlock_irq(shost->host_lock);
2602 return index;
2603}
2604
2605static struct bin_attribute sysfs_drvr_stat_data_attr = {
2606 .attr = {
2607 .name = "lpfc_drvr_stat_data",
2608 .mode = S_IRUSR,
2609 .owner = THIS_MODULE,
2610 },
2611 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2612 .read = sysfs_drvr_stat_data_read,
2613 .write = NULL,
2614};
2615
dea31012005-04-17 16:05:31 -05002616/*
2617# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2618# connection.
2619# 0 = auto select (default)
2620# 1 = 1 Gigabaud
2621# 2 = 2 Gigabaud
2622# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002623# 8 = 8 Gigabaud
2624# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002625*/
James Smarte59058c2008-08-24 21:49:00 -04002626
2627/**
James Smart3621a712009-04-06 18:47:14 -04002628 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002629 * @phba: lpfc_hba pointer.
2630 * @val: link speed value.
2631 *
2632 * Description:
2633 * If val is in a valid range then set the adapter's link speed field and
2634 * issue a lip; if the lip fails reset the link speed to the old value.
2635 *
2636 * Notes:
2637 * If the value is not in range log a kernel error message and return an error.
2638 *
2639 * Returns:
2640 * zero if val is in range and lip okay.
2641 * non-zero return value from lpfc_issue_lip()
2642 * -EINVAL val out of range
2643 **/
James Smarta257bf92009-04-06 18:48:10 -04002644static ssize_t
2645lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2646 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002647{
James Smarta257bf92009-04-06 18:48:10 -04002648 struct Scsi_Host *shost = class_to_shost(dev);
2649 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2650 struct lpfc_hba *phba = vport->phba;
2651 int val = 0;
2652 int nolip = 0;
2653 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002654 int err;
2655 uint32_t prev_val;
2656
James Smarta257bf92009-04-06 18:48:10 -04002657 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2658 nolip = 1;
2659 val_buf = &buf[strlen("nolip ")];
2660 }
2661
2662 if (!isdigit(val_buf[0]))
2663 return -EINVAL;
2664 if (sscanf(val_buf, "%i", &val) != 1)
2665 return -EINVAL;
2666
James Smart83108bd2008-01-11 01:53:09 -05002667 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2668 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2669 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2670 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2671 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2672 return -EINVAL;
2673
James Smarta257bf92009-04-06 18:48:10 -04002674 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002675 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2676 prev_val = phba->cfg_link_speed;
2677 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002678 if (nolip)
2679 return strlen(buf);
2680
James Smart83108bd2008-01-11 01:53:09 -05002681 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002682 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002683 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002684 return -EINVAL;
2685 } else
2686 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002687 }
2688
2689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2690 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2691 "allowed range is [0, 8]\n",
2692 phba->brd_no, val);
2693 return -EINVAL;
2694}
2695
2696static int lpfc_link_speed = 0;
2697module_param(lpfc_link_speed, int, 0);
2698MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2699lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002700
2701/**
James Smart3621a712009-04-06 18:47:14 -04002702 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002703 * @phba: lpfc_hba pointer.
2704 * @val: link speed value.
2705 *
2706 * Description:
2707 * If val is in a valid range then set the adapter's link speed field.
2708 *
2709 * Notes:
2710 * If the value is not in range log a kernel error message, clear the link
2711 * speed and return an error.
2712 *
2713 * Returns:
2714 * zero if val saved.
2715 * -EINVAL val out of range
2716 **/
James Smart83108bd2008-01-11 01:53:09 -05002717static int
2718lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2719{
2720 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2721 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2722 phba->cfg_link_speed = val;
2723 return 0;
2724 }
2725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002726 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002727 "be set to %d, allowed values are "
2728 "["LPFC_LINK_SPEED_STRING"]\n", val);
2729 phba->cfg_link_speed = 0;
2730 return -EINVAL;
2731}
2732
Tony Jonesee959b02008-02-22 00:13:36 +01002733static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002734 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002735
2736/*
2737# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2738# Value range is [2,3]. Default value is 3.
2739*/
James Smart3de2a652007-08-02 11:09:59 -04002740LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2741 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002742
2743/*
2744# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2745# is [0,1]. Default value is 0.
2746*/
James Smart3de2a652007-08-02 11:09:59 -04002747LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2748 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002749
2750/*
James Smart977b5a02008-09-07 11:52:04 -04002751# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2752# depth. Default value is 0. When the value of this parameter is zero the
2753# SCSI command completion time is not used for controlling I/O queue depth. When
2754# the parameter is set to a non-zero value, the I/O queue depth is controlled
2755# to limit the I/O completion time to the parameter value.
2756# The value is set in milliseconds.
2757*/
2758static int lpfc_max_scsicmpl_time;
2759module_param(lpfc_max_scsicmpl_time, int, 0);
2760MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2761 "Use command completion time to control queue depth");
2762lpfc_vport_param_show(max_scsicmpl_time);
2763lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2764static int
2765lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2766{
2767 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2768 struct lpfc_nodelist *ndlp, *next_ndlp;
2769
2770 if (val == vport->cfg_max_scsicmpl_time)
2771 return 0;
2772 if ((val < 0) || (val > 60000))
2773 return -EINVAL;
2774 vport->cfg_max_scsicmpl_time = val;
2775
2776 spin_lock_irq(shost->host_lock);
2777 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2778 if (!NLP_CHK_NODE_ACT(ndlp))
2779 continue;
2780 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2781 continue;
2782 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2783 }
2784 spin_unlock_irq(shost->host_lock);
2785 return 0;
2786}
2787lpfc_vport_param_store(max_scsicmpl_time);
2788static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2789 lpfc_max_scsicmpl_time_show,
2790 lpfc_max_scsicmpl_time_store);
2791
2792/*
dea31012005-04-17 16:05:31 -05002793# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2794# range is [0,1]. Default value is 0.
2795*/
2796LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2797
2798/*
2799# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2800# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04002801# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05002802# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2803# cr_delay is set to 0.
2804*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002805LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05002806 "interrupt response is generated");
2807
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002808LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05002809 "interrupt response is generated");
2810
2811/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002812# lpfc_multi_ring_support: Determines how many rings to spread available
2813# cmd/rsp IOCB entries across.
2814# Value range is [1,2]. Default value is 1.
2815*/
2816LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2817 "SLI rings to spread IOCB entries across");
2818
2819/*
James Smarta4bc3372006-12-02 13:34:16 -05002820# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2821# identifies what rctl value to configure the additional ring for.
2822# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2823*/
2824LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2825 255, "Identifies RCTL for additional ring configuration");
2826
2827/*
2828# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2829# identifies what type value to configure the additional ring for.
2830# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2831*/
2832LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2833 255, "Identifies TYPE for additional ring configuration");
2834
2835/*
dea31012005-04-17 16:05:31 -05002836# lpfc_fdmi_on: controls FDMI support.
2837# 0 = no FDMI support
2838# 1 = support FDMI without attribute of hostname
2839# 2 = support FDMI with attribute of hostname
2840# Value range [0,2]. Default value is 0.
2841*/
James Smart3de2a652007-08-02 11:09:59 -04002842LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05002843
2844/*
2845# Specifies the maximum number of ELS cmds we can have outstanding (for
2846# discovery). Value range is [1,64]. Default value = 32.
2847*/
James Smart3de2a652007-08-02 11:09:59 -04002848LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05002849 "during discovery");
2850
2851/*
James Smart65a29c12006-07-06 15:50:50 -04002852# lpfc_max_luns: maximum allowed LUN.
2853# Value range is [0,65535]. Default value is 255.
2854# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05002855*/
James Smart3de2a652007-08-02 11:09:59 -04002856LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05002857
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002858/*
2859# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2860# Value range is [1,255], default value is 10.
2861*/
2862LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2863 "Milliseconds driver will wait between polling FCP ring");
2864
James Smart4ff43242006-12-02 13:34:56 -05002865/*
2866# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2867# support this feature
James Smartda0436e2009-05-22 14:51:39 -04002868# 0 = MSI disabled (default)
James Smart4ff43242006-12-02 13:34:56 -05002869# 1 = MSI enabled
James Smartda0436e2009-05-22 14:51:39 -04002870# 2 = MSI-X enabled
2871# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05002872*/
James Smartda0436e2009-05-22 14:51:39 -04002873LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05002874 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05002875
James Smart13815c82008-01-11 01:52:48 -05002876/*
James Smartda0436e2009-05-22 14:51:39 -04002877# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
2878#
2879# Value range is [636,651042]. Default value is 10000.
2880*/
2881LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
2882 "Set the maximum number of fast-path FCP interrupts per second");
2883
2884/*
2885# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
2886#
2887# Value range is [1,31]. Default value is 4.
2888*/
2889LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
2890 "Set the number of fast-path FCP work queues, if possible");
2891
2892/*
2893# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
2894#
2895# Value range is [1,7]. Default value is 1.
2896*/
2897LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
2898 "Set the number of fast-path FCP event queues, if possible");
2899
2900/*
James Smart13815c82008-01-11 01:52:48 -05002901# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2902# 0 = HBA resets disabled
2903# 1 = HBA resets enabled (default)
2904# Value range is [0,1]. Default value is 1.
2905*/
2906LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04002907
James Smart13815c82008-01-11 01:52:48 -05002908/*
2909# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2910# 0 = HBA Heartbeat disabled
2911# 1 = HBA Heartbeat enabled (default)
2912# Value range is [0,1]. Default value is 1.
2913*/
2914LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05002915
James Smart83108bd2008-01-11 01:53:09 -05002916/*
James Smart81301a92008-12-04 22:39:46 -05002917# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
2918# 0 = BlockGuard disabled (default)
2919# 1 = BlockGuard enabled
2920# Value range is [0,1]. Default value is 0.
2921*/
2922LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
2923
2924
2925/*
2926# lpfc_prot_mask: i
2927# - Bit mask of host protection capabilities used to register with the
2928# SCSI mid-layer
2929# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
2930# - Allows you to ultimately specify which profiles to use
2931# - Default will result in registering capabilities for all profiles.
2932#
2933*/
2934unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
2935
2936module_param(lpfc_prot_mask, uint, 0);
2937MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
2938
2939/*
2940# lpfc_prot_guard: i
2941# - Bit mask of protection guard types to register with the SCSI mid-layer
2942# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
2943# - Allows you to ultimately specify which profiles to use
2944# - Default will result in registering capabilities for all guard types
2945#
2946*/
2947unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
2948module_param(lpfc_prot_guard, byte, 0);
2949MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
2950
2951
2952/*
James Smart3621a712009-04-06 18:47:14 -04002953 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05002954 * This value can be set to values between 64 and 256. The default value is
2955 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2956 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2957 */
2958LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2959 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2960
James Smart81301a92008-12-04 22:39:46 -05002961LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
2962 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
2963 "Max Protection Scatter Gather Segment Count");
2964
Tony Jonesee959b02008-02-22 00:13:36 +01002965struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05002966 &dev_attr_bg_info,
2967 &dev_attr_bg_guard_err,
2968 &dev_attr_bg_apptag_err,
2969 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01002970 &dev_attr_info,
2971 &dev_attr_serialnum,
2972 &dev_attr_modeldesc,
2973 &dev_attr_modelname,
2974 &dev_attr_programtype,
2975 &dev_attr_portnum,
2976 &dev_attr_fwrev,
2977 &dev_attr_hdw,
2978 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002979 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002980 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04002981 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01002982 &dev_attr_lpfc_drvr_version,
2983 &dev_attr_lpfc_temp_sensor,
2984 &dev_attr_lpfc_log_verbose,
2985 &dev_attr_lpfc_lun_queue_depth,
2986 &dev_attr_lpfc_hba_queue_depth,
2987 &dev_attr_lpfc_peer_port_login,
2988 &dev_attr_lpfc_nodev_tmo,
2989 &dev_attr_lpfc_devloss_tmo,
2990 &dev_attr_lpfc_fcp_class,
2991 &dev_attr_lpfc_use_adisc,
2992 &dev_attr_lpfc_ack0,
2993 &dev_attr_lpfc_topology,
2994 &dev_attr_lpfc_scan_down,
2995 &dev_attr_lpfc_link_speed,
2996 &dev_attr_lpfc_cr_delay,
2997 &dev_attr_lpfc_cr_count,
2998 &dev_attr_lpfc_multi_ring_support,
2999 &dev_attr_lpfc_multi_ring_rctl,
3000 &dev_attr_lpfc_multi_ring_type,
3001 &dev_attr_lpfc_fdmi_on,
3002 &dev_attr_lpfc_max_luns,
3003 &dev_attr_lpfc_enable_npiv,
3004 &dev_attr_nport_evt_cnt,
3005 &dev_attr_board_mode,
3006 &dev_attr_max_vpi,
3007 &dev_attr_used_vpi,
3008 &dev_attr_max_rpi,
3009 &dev_attr_used_rpi,
3010 &dev_attr_max_xri,
3011 &dev_attr_used_xri,
3012 &dev_attr_npiv_info,
3013 &dev_attr_issue_reset,
3014 &dev_attr_lpfc_poll,
3015 &dev_attr_lpfc_poll_tmo,
3016 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003017 &dev_attr_lpfc_fcp_imax,
3018 &dev_attr_lpfc_fcp_wq_count,
3019 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003020 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003021 &dev_attr_lpfc_soft_wwnn,
3022 &dev_attr_lpfc_soft_wwpn,
3023 &dev_attr_lpfc_soft_wwn_enable,
3024 &dev_attr_lpfc_enable_hba_reset,
3025 &dev_attr_lpfc_enable_hba_heartbeat,
3026 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003027 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003028 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003029 &dev_attr_lpfc_prot_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05003030 NULL,
3031};
3032
Tony Jonesee959b02008-02-22 00:13:36 +01003033struct device_attribute *lpfc_vport_attrs[] = {
3034 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003035 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003036 &dev_attr_num_discovered_ports,
3037 &dev_attr_lpfc_drvr_version,
3038 &dev_attr_lpfc_log_verbose,
3039 &dev_attr_lpfc_lun_queue_depth,
3040 &dev_attr_lpfc_nodev_tmo,
3041 &dev_attr_lpfc_devloss_tmo,
3042 &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
3250 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
3251 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;
3292
James Smart1dcb58e2007-04-25 09:51:30 -04003293 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003294 return -ERANGE;
3295
James Smart1dcb58e2007-04-25 09:51:30 -04003296 if ((count + off) > MAILBOX_CMD_SIZE)
3297 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003298
3299 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3300 return -EINVAL;
3301
3302 if (off && count == 0)
3303 return 0;
3304
James Smart2e0fef82007-06-17 19:56:36 -05003305 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003306
James Smart7af67052007-10-27 13:38:11 -04003307 if (phba->over_temp_state == HBA_OVER_TEMP) {
3308 sysfs_mbox_idle(phba);
3309 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003310 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003311 }
3312
dea31012005-04-17 16:05:31 -05003313 if (off == 0 &&
3314 phba->sysfs_mbox.state == SMBOX_WRITING &&
3315 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3316
3317 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
3318 /* Offline only */
dea31012005-04-17 16:05:31 -05003319 case MBX_INIT_LINK:
3320 case MBX_DOWN_LINK:
3321 case MBX_CONFIG_LINK:
3322 case MBX_CONFIG_RING:
3323 case MBX_RESET_RING:
3324 case MBX_UNREG_LOGIN:
3325 case MBX_CLEAR_LA:
3326 case MBX_DUMP_CONTEXT:
3327 case MBX_RUN_DIAGS:
3328 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003329 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003330 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003331 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003332 printk(KERN_WARNING "mbox_read:Command 0x%x "
3333 "is illegal in on-line state\n",
3334 phba->sysfs_mbox.mbox->mb.mbxCommand);
3335 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003336 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003337 return -EPERM;
3338 }
James Smarta8adb832007-10-27 13:37:53 -04003339 case MBX_WRITE_NV:
3340 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003341 case MBX_LOAD_SM:
3342 case MBX_READ_NV:
3343 case MBX_READ_CONFIG:
3344 case MBX_READ_RCONFIG:
3345 case MBX_READ_STATUS:
3346 case MBX_READ_XRI:
3347 case MBX_READ_REV:
3348 case MBX_READ_LNK_STAT:
3349 case MBX_DUMP_MEMORY:
3350 case MBX_DOWN_LOAD:
3351 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003352 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003353 case MBX_LOAD_AREA:
3354 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003355 case MBX_BEACON:
3356 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003357 case MBX_SET_VARIABLE:
3358 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003359 case MBX_PORT_CAPABILITIES:
3360 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003361 break;
3362 case MBX_READ_SPARM64:
3363 case MBX_READ_LA:
3364 case MBX_READ_LA64:
3365 case MBX_REG_LOGIN:
3366 case MBX_REG_LOGIN64:
3367 case MBX_CONFIG_PORT:
3368 case MBX_RUN_BIU_DIAG:
3369 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3370 phba->sysfs_mbox.mbox->mb.mbxCommand);
3371 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003372 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003373 return -EPERM;
3374 default:
3375 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3376 phba->sysfs_mbox.mbox->mb.mbxCommand);
3377 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003378 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003379 return -EPERM;
3380 }
3381
James Smart09372822008-01-11 01:52:54 -05003382 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003383 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003384 */
James Smartd7c255b2008-08-24 21:50:00 -04003385 if (phba->pport->stopped &&
3386 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_DUMP_MEMORY &&
3387 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_RESTART &&
3388 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_VPARMS &&
3389 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_WWN)
3390 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3391 "1259 mbox: Issued mailbox cmd "
3392 "0x%x while in stopped state.\n",
3393 phba->sysfs_mbox.mbox->mb.mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003394
James Smart92d7f7b2007-06-17 19:56:38 -05003395 phba->sysfs_mbox.mbox->vport = vport;
3396
James Smart58da1ff2008-04-07 10:15:56 -04003397 /* Don't allow mailbox commands to be sent when blocked
3398 * or when in the middle of discovery
3399 */
James Smart495a7142008-06-14 22:52:59 -04003400 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003401 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003402 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003403 return -EAGAIN;
3404 }
3405
James Smart2e0fef82007-06-17 19:56:36 -05003406 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05003407 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
3408
James Smart2e0fef82007-06-17 19:56:36 -05003409 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003410 rc = lpfc_sli_issue_mbox (phba,
3411 phba->sysfs_mbox.mbox,
3412 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003413 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003414
3415 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003416 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003417 rc = lpfc_sli_issue_mbox_wait (phba,
3418 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04003419 lpfc_mbox_tmo_val(phba,
3420 phba->sysfs_mbox.mbox->mb.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
3442 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
3443
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;
dea31012005-04-17 16:05:31 -05003636 default:
3637 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3638 break;
3639 }
James Smart09372822008-01-11 01:52:54 -05003640 } else
3641 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003642
3643 spin_unlock_irq(shost->host_lock);
3644}
3645
James Smarte59058c2008-08-24 21:49:00 -04003646/**
James Smart3621a712009-04-06 18:47:14 -04003647 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04003648 * @shost: kernel scsi host pointer.
3649 **/
dea31012005-04-17 16:05:31 -05003650static void
3651lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3652{
James Smart2e0fef82007-06-17 19:56:36 -05003653 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3654 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003655 u64 node_name;
dea31012005-04-17 16:05:31 -05003656
3657 spin_lock_irq(shost->host_lock);
3658
James Smart2e0fef82007-06-17 19:56:36 -05003659 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003660 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003661 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003662 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003663 else
3664 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003665 node_name = 0;
dea31012005-04-17 16:05:31 -05003666
3667 spin_unlock_irq(shost->host_lock);
3668
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003669 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003670}
3671
James Smarte59058c2008-08-24 21:49:00 -04003672/**
James Smart3621a712009-04-06 18:47:14 -04003673 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04003674 * @shost: kernel scsi host pointer.
3675 *
3676 * Notes:
3677 * NULL on error for link down, no mbox pool, sli2 active,
3678 * management not allowed, memory allocation error, or mbox error.
3679 *
3680 * Returns:
3681 * NULL for error
3682 * address of the adapter host statistics
3683 **/
dea31012005-04-17 16:05:31 -05003684static struct fc_host_statistics *
3685lpfc_get_stats(struct Scsi_Host *shost)
3686{
James Smart2e0fef82007-06-17 19:56:36 -05003687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3688 struct lpfc_hba *phba = vport->phba;
3689 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003690 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003691 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003692 LPFC_MBOXQ_t *pmboxq;
3693 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003694 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003695 int rc = 0;
dea31012005-04-17 16:05:31 -05003696
James Smart92d7f7b2007-06-17 19:56:38 -05003697 /*
3698 * prevent udev from issuing mailbox commands until the port is
3699 * configured.
3700 */
James Smart2e0fef82007-06-17 19:56:36 -05003701 if (phba->link_state < LPFC_LINK_DOWN ||
3702 !phba->mbox_mem_pool ||
3703 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003704 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003705
3706 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003707 return NULL;
3708
dea31012005-04-17 16:05:31 -05003709 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3710 if (!pmboxq)
3711 return NULL;
3712 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3713
3714 pmb = &pmboxq->mb;
3715 pmb->mbxCommand = MBX_READ_STATUS;
3716 pmb->mbxOwner = OWN_HOST;
3717 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003718 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003719
James Smart2e0fef82007-06-17 19:56:36 -05003720 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003721 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003722 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003723 else
dea31012005-04-17 16:05:31 -05003724 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3725
3726 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003727 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003728 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003729 return NULL;
3730 }
3731
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003732 memset(hs, 0, sizeof (struct fc_host_statistics));
3733
dea31012005-04-17 16:05:31 -05003734 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3735 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3736 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3737 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3738
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003739 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003740 pmb->mbxCommand = MBX_READ_LNK_STAT;
3741 pmb->mbxOwner = OWN_HOST;
3742 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003743 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003744
James Smart2e0fef82007-06-17 19:56:36 -05003745 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003746 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003747 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003748 else
dea31012005-04-17 16:05:31 -05003749 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3750
3751 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003752 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003753 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003754 return NULL;
3755 }
3756
3757 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3758 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3759 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3760 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3761 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3762 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3763 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3764
James Smart64ba8812006-08-02 15:24:34 -04003765 hs->link_failure_count -= lso->link_failure_count;
3766 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3767 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3768 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3769 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3770 hs->invalid_crc_count -= lso->invalid_crc_count;
3771 hs->error_frames -= lso->error_frames;
3772
dea31012005-04-17 16:05:31 -05003773 if (phba->fc_topology == TOPOLOGY_LOOP) {
3774 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003775 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003776 hs->nos_count = -1;
3777 } else {
3778 hs->lip_count = -1;
3779 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003780 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003781 }
3782
3783 hs->dumped_frames = -1;
3784
James Smart64ba8812006-08-02 15:24:34 -04003785 seconds = get_seconds();
3786 if (seconds < psli->stats_start)
3787 hs->seconds_since_last_reset = seconds +
3788 ((unsigned long)-1 - psli->stats_start);
3789 else
3790 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05003791
James Smart1dcb58e2007-04-25 09:51:30 -04003792 mempool_free(pmboxq, phba->mbox_mem_pool);
3793
dea31012005-04-17 16:05:31 -05003794 return hs;
3795}
3796
James Smarte59058c2008-08-24 21:49:00 -04003797/**
James Smart3621a712009-04-06 18:47:14 -04003798 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04003799 * @shost: kernel scsi host pointer.
3800 **/
James Smart64ba8812006-08-02 15:24:34 -04003801static void
3802lpfc_reset_stats(struct Scsi_Host *shost)
3803{
James Smart2e0fef82007-06-17 19:56:36 -05003804 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3805 struct lpfc_hba *phba = vport->phba;
3806 struct lpfc_sli *psli = &phba->sli;
3807 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04003808 LPFC_MBOXQ_t *pmboxq;
3809 MAILBOX_t *pmb;
3810 int rc = 0;
3811
James Smart2e0fef82007-06-17 19:56:36 -05003812 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003813 return;
3814
James Smart64ba8812006-08-02 15:24:34 -04003815 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3816 if (!pmboxq)
3817 return;
3818 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3819
3820 pmb = &pmboxq->mb;
3821 pmb->mbxCommand = MBX_READ_STATUS;
3822 pmb->mbxOwner = OWN_HOST;
3823 pmb->un.varWords[0] = 0x1; /* reset request */
3824 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003825 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003826
James Smart2e0fef82007-06-17 19:56:36 -05003827 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003828 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3829 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3830 else
3831 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3832
3833 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003834 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003835 mempool_free(pmboxq, phba->mbox_mem_pool);
3836 return;
3837 }
3838
3839 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3840 pmb->mbxCommand = MBX_READ_LNK_STAT;
3841 pmb->mbxOwner = OWN_HOST;
3842 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003843 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003844
James Smart2e0fef82007-06-17 19:56:36 -05003845 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003846 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3847 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3848 else
3849 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3850
3851 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003852 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003853 mempool_free( pmboxq, phba->mbox_mem_pool);
3854 return;
3855 }
3856
3857 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3858 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3859 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3860 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3861 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3862 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3863 lso->error_frames = pmb->un.varRdLnk.crcCnt;
3864 lso->link_events = (phba->fc_eventTag >> 1);
3865
3866 psli->stats_start = get_seconds();
3867
James Smart1dcb58e2007-04-25 09:51:30 -04003868 mempool_free(pmboxq, phba->mbox_mem_pool);
3869
James Smart64ba8812006-08-02 15:24:34 -04003870 return;
3871}
dea31012005-04-17 16:05:31 -05003872
3873/*
3874 * The LPFC driver treats linkdown handling as target loss events so there
3875 * are no sysfs handlers for link_down_tmo.
3876 */
James Smart685f0bf2007-04-25 09:53:08 -04003877
James Smarte59058c2008-08-24 21:49:00 -04003878/**
James Smart3621a712009-04-06 18:47:14 -04003879 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04003880 * @starget: kernel scsi target pointer.
3881 *
3882 * Returns:
3883 * address of the node list if found
3884 * NULL target not found
3885 **/
James Smart685f0bf2007-04-25 09:53:08 -04003886static struct lpfc_nodelist *
3887lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05003888{
James Smart2e0fef82007-06-17 19:56:36 -05003889 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04003891 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003892
3893 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003894 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05003895 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003896 if (NLP_CHK_NODE_ACT(ndlp) &&
3897 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04003898 starget->id == ndlp->nlp_sid) {
3899 spin_unlock_irq(shost->host_lock);
3900 return ndlp;
dea31012005-04-17 16:05:31 -05003901 }
3902 }
3903 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003904 return NULL;
3905}
dea31012005-04-17 16:05:31 -05003906
James Smarte59058c2008-08-24 21:49:00 -04003907/**
James Smart3621a712009-04-06 18:47:14 -04003908 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04003909 * @starget: kernel scsi target pointer.
3910 **/
James Smart685f0bf2007-04-25 09:53:08 -04003911static void
3912lpfc_get_starget_port_id(struct scsi_target *starget)
3913{
3914 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3915
3916 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05003917}
3918
James Smarte59058c2008-08-24 21:49:00 -04003919/**
James Smart3621a712009-04-06 18:47:14 -04003920 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04003921 * @starget: kernel scsi target pointer.
3922 *
3923 * Description: Set the target node name to the ndlp node name wwn or zero.
3924 **/
dea31012005-04-17 16:05:31 -05003925static void
3926lpfc_get_starget_node_name(struct scsi_target *starget)
3927{
James Smart685f0bf2007-04-25 09:53:08 -04003928 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003929
James Smart685f0bf2007-04-25 09:53:08 -04003930 fc_starget_node_name(starget) =
3931 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003932}
3933
James Smarte59058c2008-08-24 21:49:00 -04003934/**
James Smart3621a712009-04-06 18:47:14 -04003935 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04003936 * @starget: kernel scsi target pointer.
3937 *
3938 * Description: set the target port name to the ndlp port name wwn or zero.
3939 **/
dea31012005-04-17 16:05:31 -05003940static void
3941lpfc_get_starget_port_name(struct scsi_target *starget)
3942{
James Smart685f0bf2007-04-25 09:53:08 -04003943 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003944
James Smart685f0bf2007-04-25 09:53:08 -04003945 fc_starget_port_name(starget) =
3946 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003947}
3948
James Smarte59058c2008-08-24 21:49:00 -04003949/**
James Smart3621a712009-04-06 18:47:14 -04003950 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04003951 * @rport: fc rport address.
3952 * @timeout: new value for dev loss tmo.
3953 *
3954 * Description:
3955 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3956 * dev_loss_tmo to one.
3957 **/
dea31012005-04-17 16:05:31 -05003958static void
dea31012005-04-17 16:05:31 -05003959lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
3960{
dea31012005-04-17 16:05:31 -05003961 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04003962 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05003963 else
James Smartc01f3202006-08-18 17:47:08 -04003964 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05003965}
3966
James Smarte59058c2008-08-24 21:49:00 -04003967/**
James Smart3621a712009-04-06 18:47:14 -04003968 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04003969 *
3970 * Description:
3971 * Macro that uses field to generate a function with the name lpfc_show_rport_
3972 *
3973 * lpfc_show_rport_##field: returns the bytes formatted in buf
3974 * @cdev: class converted to an fc_rport.
3975 * @buf: on return contains the target_field or zero.
3976 *
3977 * Returns: size of formatted string.
3978 **/
dea31012005-04-17 16:05:31 -05003979#define lpfc_rport_show_function(field, format_string, sz, cast) \
3980static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01003981lpfc_show_rport_##field (struct device *dev, \
3982 struct device_attribute *attr, \
3983 char *buf) \
dea31012005-04-17 16:05:31 -05003984{ \
Tony Jonesee959b02008-02-22 00:13:36 +01003985 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05003986 struct lpfc_rport_data *rdata = rport->hostdata; \
3987 return snprintf(buf, sz, format_string, \
3988 (rdata->target) ? cast rdata->target->field : 0); \
3989}
3990
3991#define lpfc_rport_rd_attr(field, format_string, sz) \
3992 lpfc_rport_show_function(field, format_string, sz, ) \
3993static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3994
James Smarteada2722008-12-04 22:39:13 -05003995/**
James Smart3621a712009-04-06 18:47:14 -04003996 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05003997 * @fc_vport: The fc_vport who's symbolic name has been changed.
3998 *
3999 * Description:
4000 * This function is called by the transport after the @fc_vport's symbolic name
4001 * has been changed. This function re-registers the symbolic name with the
4002 * switch to propogate the change into the fabric if the vport is active.
4003 **/
4004static void
4005lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4006{
4007 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4008
4009 if (vport->port_state == LPFC_VPORT_READY)
4010 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4011}
dea31012005-04-17 16:05:31 -05004012
4013struct fc_function_template lpfc_transport_functions = {
4014 /* fixed attributes the driver supports */
4015 .show_host_node_name = 1,
4016 .show_host_port_name = 1,
4017 .show_host_supported_classes = 1,
4018 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004019 .show_host_supported_speeds = 1,
4020 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004021 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004022
4023 /* dynamic attributes the driver supports */
4024 .get_host_port_id = lpfc_get_host_port_id,
4025 .show_host_port_id = 1,
4026
4027 .get_host_port_type = lpfc_get_host_port_type,
4028 .show_host_port_type = 1,
4029
4030 .get_host_port_state = lpfc_get_host_port_state,
4031 .show_host_port_state = 1,
4032
4033 /* active_fc4s is shown but doesn't change (thus no get function) */
4034 .show_host_active_fc4s = 1,
4035
4036 .get_host_speed = lpfc_get_host_speed,
4037 .show_host_speed = 1,
4038
4039 .get_host_fabric_name = lpfc_get_host_fabric_name,
4040 .show_host_fabric_name = 1,
4041
4042 /*
4043 * The LPFC driver treats linkdown handling as target loss events
4044 * so there are no sysfs handlers for link_down_tmo.
4045 */
4046
4047 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004048 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004049
4050 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4051 .show_rport_maxframe_size = 1,
4052 .show_rport_supported_classes = 1,
4053
dea31012005-04-17 16:05:31 -05004054 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4055 .show_rport_dev_loss_tmo = 1,
4056
4057 .get_starget_port_id = lpfc_get_starget_port_id,
4058 .show_starget_port_id = 1,
4059
4060 .get_starget_node_name = lpfc_get_starget_node_name,
4061 .show_starget_node_name = 1,
4062
4063 .get_starget_port_name = lpfc_get_starget_port_name,
4064 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004065
4066 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004067 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4068 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004069
James Smart92d7f7b2007-06-17 19:56:38 -05004070 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004071
4072 .vport_disable = lpfc_vport_disable,
4073
4074 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart92d7f7b2007-06-17 19:56:38 -05004075};
4076
James Smart98c9ea52007-10-27 13:37:33 -04004077struct fc_function_template lpfc_vport_transport_functions = {
4078 /* fixed attributes the driver supports */
4079 .show_host_node_name = 1,
4080 .show_host_port_name = 1,
4081 .show_host_supported_classes = 1,
4082 .show_host_supported_fc4s = 1,
4083 .show_host_supported_speeds = 1,
4084 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004085 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004086
4087 /* dynamic attributes the driver supports */
4088 .get_host_port_id = lpfc_get_host_port_id,
4089 .show_host_port_id = 1,
4090
4091 .get_host_port_type = lpfc_get_host_port_type,
4092 .show_host_port_type = 1,
4093
4094 .get_host_port_state = lpfc_get_host_port_state,
4095 .show_host_port_state = 1,
4096
4097 /* active_fc4s is shown but doesn't change (thus no get function) */
4098 .show_host_active_fc4s = 1,
4099
4100 .get_host_speed = lpfc_get_host_speed,
4101 .show_host_speed = 1,
4102
4103 .get_host_fabric_name = lpfc_get_host_fabric_name,
4104 .show_host_fabric_name = 1,
4105
4106 /*
4107 * The LPFC driver treats linkdown handling as target loss events
4108 * so there are no sysfs handlers for link_down_tmo.
4109 */
4110
4111 .get_fc_host_stats = lpfc_get_stats,
4112 .reset_fc_host_stats = lpfc_reset_stats,
4113
4114 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4115 .show_rport_maxframe_size = 1,
4116 .show_rport_supported_classes = 1,
4117
4118 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4119 .show_rport_dev_loss_tmo = 1,
4120
4121 .get_starget_port_id = lpfc_get_starget_port_id,
4122 .show_starget_port_id = 1,
4123
4124 .get_starget_node_name = lpfc_get_starget_node_name,
4125 .show_starget_node_name = 1,
4126
4127 .get_starget_port_name = lpfc_get_starget_port_name,
4128 .show_starget_port_name = 1,
4129
4130 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4131 .terminate_rport_io = lpfc_terminate_rport_io,
4132
4133 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004134
4135 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004136};
4137
James Smarte59058c2008-08-24 21:49:00 -04004138/**
James Smart3621a712009-04-06 18:47:14 -04004139 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004140 * @phba: lpfc_hba pointer.
4141 **/
dea31012005-04-17 16:05:31 -05004142void
4143lpfc_get_cfgparam(struct lpfc_hba *phba)
4144{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004145 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4146 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004147 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004148 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4149 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004150 lpfc_ack0_init(phba, lpfc_ack0);
4151 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004152 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004153 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004154 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004155 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004156 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4157 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4158 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004159 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4160 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004161 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004162 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004163 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004164 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004165 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004166 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
dea31012005-04-17 16:05:31 -05004167 /*
4168 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
James Smart83108bd2008-01-11 01:53:09 -05004169 * used to create the sg_dma_buf_pool must be dynamically calculated.
4170 * 2 segments are added since the IOCB needs a command and response bde.
dea31012005-04-17 16:05:31 -05004171 */
4172 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4173 sizeof(struct fcp_rsp) +
James Smart83108bd2008-01-11 01:53:09 -05004174 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
James Smart81301a92008-12-04 22:39:46 -05004175
4176 if (phba->cfg_enable_bg) {
4177 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4178 phba->cfg_sg_dma_buf_size +=
4179 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
4180 }
4181
4182 /* Also reinitialize the host templates with new values. */
4183 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4184 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4185
James Smart7054a602007-04-25 09:52:34 -04004186 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004187 return;
4188}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004189
James Smarte59058c2008-08-24 21:49:00 -04004190/**
James Smart3621a712009-04-06 18:47:14 -04004191 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004192 * @vport: lpfc_vport pointer.
4193 **/
James Smart3de2a652007-08-02 11:09:59 -04004194void
4195lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4196{
James Smarte8b62012007-08-02 11:10:09 -04004197 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004198 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4199 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4200 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4201 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4202 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4203 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4204 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004205 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004206 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4207 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4208 lpfc_max_luns_init(vport, lpfc_max_luns);
4209 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004210 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004211 return;
4212}