blob: 07f0172674c93596ad9f86cb9537795c8f149bcd [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_tcq.h>
31#include <scsi/scsi_transport_fc.h>
32
James Smartda0436e2009-05-22 14:51:39 -040033#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_hw.h"
35#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040037#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_disc.h"
39#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_version.h"
43#include "lpfc_compat.h"
44#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050045#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050046
James Smartc01f3202006-08-18 17:47:08 -040047#define LPFC_DEF_DEVLOSS_TMO 30
48#define LPFC_MIN_DEVLOSS_TMO 1
49#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050050
James Smart83108bd2008-01-11 01:53:09 -050051#define LPFC_MAX_LINK_SPEED 8
52#define LPFC_LINK_SPEED_BITMAP 0x00000117
53#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
54
James Smarte59058c2008-08-24 21:49:00 -040055/**
James Smart3621a712009-04-06 18:47:14 -040056 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040057 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
dea31012005-04-17 16:05:31 -050070static void
71lpfc_jedec_to_ascii(int incr, char hdw[])
72{
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84}
85
James Smarte59058c2008-08-24 21:49:00 -040086/**
James Smart3621a712009-04-06 18:47:14 -040087 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040088 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
dea31012005-04-17 16:05:31 -050094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010095lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
dea31012005-04-17 16:05:31 -050097{
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99}
100
James Smart81301a92008-12-04 22:39:46 -0500101static ssize_t
102lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
103 char *buf)
104{
105 struct Scsi_Host *shost = class_to_shost(dev);
106 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
107 struct lpfc_hba *phba = vport->phba;
108
109 if (phba->cfg_enable_bg)
110 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
111 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
112 else
113 return snprintf(buf, PAGE_SIZE,
114 "BlockGuard Not Supported\n");
115 else
116 return snprintf(buf, PAGE_SIZE,
117 "BlockGuard Disabled\n");
118}
119
120static ssize_t
121lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
122 char *buf)
123{
124 struct Scsi_Host *shost = class_to_shost(dev);
125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
126 struct lpfc_hba *phba = vport->phba;
127
James Smart87b5c322008-12-16 10:34:09 -0500128 return snprintf(buf, PAGE_SIZE, "%llu\n",
129 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500130}
131
132static ssize_t
133lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
134 char *buf)
135{
136 struct Scsi_Host *shost = class_to_shost(dev);
137 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
138 struct lpfc_hba *phba = vport->phba;
139
James Smart87b5c322008-12-16 10:34:09 -0500140 return snprintf(buf, PAGE_SIZE, "%llu\n",
141 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500142}
143
144static ssize_t
145lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
146 char *buf)
147{
148 struct Scsi_Host *shost = class_to_shost(dev);
149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
150 struct lpfc_hba *phba = vport->phba;
151
James Smart87b5c322008-12-16 10:34:09 -0500152 return snprintf(buf, PAGE_SIZE, "%llu\n",
153 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500154}
155
James Smarte59058c2008-08-24 21:49:00 -0400156/**
James Smart3621a712009-04-06 18:47:14 -0400157 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400158 * @dev: class converted to a Scsi_host structure.
159 * @attr: device attribute, not used.
160 * @buf: on return contains the formatted text from lpfc_info().
161 *
162 * Returns: size of formatted string.
163 **/
dea31012005-04-17 16:05:31 -0500164static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100165lpfc_info_show(struct device *dev, struct device_attribute *attr,
166 char *buf)
dea31012005-04-17 16:05:31 -0500167{
Tony Jonesee959b02008-02-22 00:13:36 +0100168 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500169
dea31012005-04-17 16:05:31 -0500170 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
171}
172
James Smarte59058c2008-08-24 21:49:00 -0400173/**
James Smart3621a712009-04-06 18:47:14 -0400174 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400175 * @dev: class converted to a Scsi_host structure.
176 * @attr: device attribute, not used.
177 * @buf: on return contains the formatted text serial number.
178 *
179 * Returns: size of formatted string.
180 **/
dea31012005-04-17 16:05:31 -0500181static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100182lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
183 char *buf)
dea31012005-04-17 16:05:31 -0500184{
Tony Jonesee959b02008-02-22 00:13:36 +0100185 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
187 struct lpfc_hba *phba = vport->phba;
188
dea31012005-04-17 16:05:31 -0500189 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
190}
191
James Smarte59058c2008-08-24 21:49:00 -0400192/**
James Smart3621a712009-04-06 18:47:14 -0400193 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400194 * @dev: class converted to a Scsi_host structure.
195 * @attr: device attribute, not used.
196 * @buf: on return contains the formatted support level.
197 *
198 * Description:
199 * Returns a number indicating the temperature sensor level currently
200 * supported, zero or one in ascii.
201 *
202 * Returns: size of formatted string.
203 **/
dea31012005-04-17 16:05:31 -0500204static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100205lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
206 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400207{
Tony Jonesee959b02008-02-22 00:13:36 +0100208 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
210 struct lpfc_hba *phba = vport->phba;
211 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
212}
213
James Smarte59058c2008-08-24 21:49:00 -0400214/**
James Smart3621a712009-04-06 18:47:14 -0400215 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the scsi vpd model description.
219 *
220 * Returns: size of formatted string.
221 **/
James Smart57127f12007-10-27 13:37:05 -0400222static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100223lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
224 char *buf)
dea31012005-04-17 16:05:31 -0500225{
Tony Jonesee959b02008-02-22 00:13:36 +0100226 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500227 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
228 struct lpfc_hba *phba = vport->phba;
229
dea31012005-04-17 16:05:31 -0500230 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
231}
232
James Smarte59058c2008-08-24 21:49:00 -0400233/**
James Smart3621a712009-04-06 18:47:14 -0400234 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400235 * @dev: class converted to a Scsi_host structure.
236 * @attr: device attribute, not used.
237 * @buf: on return contains the scsi vpd model name.
238 *
239 * Returns: size of formatted string.
240 **/
dea31012005-04-17 16:05:31 -0500241static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100242lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
243 char *buf)
dea31012005-04-17 16:05:31 -0500244{
Tony Jonesee959b02008-02-22 00:13:36 +0100245 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500246 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
247 struct lpfc_hba *phba = vport->phba;
248
dea31012005-04-17 16:05:31 -0500249 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
250}
251
James Smarte59058c2008-08-24 21:49:00 -0400252/**
James Smart3621a712009-04-06 18:47:14 -0400253 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400254 * @dev: class converted to a Scsi_host structure.
255 * @attr: device attribute, not used.
256 * @buf: on return contains the scsi vpd program type.
257 *
258 * Returns: size of formatted string.
259 **/
dea31012005-04-17 16:05:31 -0500260static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100261lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
262 char *buf)
dea31012005-04-17 16:05:31 -0500263{
Tony Jonesee959b02008-02-22 00:13:36 +0100264 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500265 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
266 struct lpfc_hba *phba = vport->phba;
267
dea31012005-04-17 16:05:31 -0500268 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
269}
270
James Smarte59058c2008-08-24 21:49:00 -0400271/**
James Smart3621a712009-04-06 18:47:14 -0400272 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400273 * @dev: class converted to a Scsi_host structure.
274 * @attr: device attribute, not used.
275 * @buf: on return contains the Menlo Maintenance sli flag.
276 *
277 * Returns: size of formatted string.
278 **/
279static ssize_t
280lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
281{
282 struct Scsi_Host *shost = class_to_shost(dev);
283 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
284 struct lpfc_hba *phba = vport->phba;
285
286 return snprintf(buf, PAGE_SIZE, "%d\n",
287 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
288}
289
290/**
James Smart3621a712009-04-06 18:47:14 -0400291 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400292 * @dev: class converted to a Scsi_host structure.
293 * @attr: device attribute, not used.
294 * @buf: on return contains scsi vpd program type.
295 *
296 * Returns: size of formatted string.
297 **/
dea31012005-04-17 16:05:31 -0500298static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100299lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
300 char *buf)
dea31012005-04-17 16:05:31 -0500301{
Tony Jonesee959b02008-02-22 00:13:36 +0100302 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
304 struct lpfc_hba *phba = vport->phba;
305
dea31012005-04-17 16:05:31 -0500306 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
307}
308
James Smarte59058c2008-08-24 21:49:00 -0400309/**
James Smart3621a712009-04-06 18:47:14 -0400310 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400311 * @dev: class converted to a Scsi_host structure.
312 * @attr: device attribute, not used.
313 * @buf: on return contains the scsi vpd program type.
314 *
315 * Returns: size of formatted string.
316 **/
dea31012005-04-17 16:05:31 -0500317static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100318lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
319 char *buf)
dea31012005-04-17 16:05:31 -0500320{
Tony Jonesee959b02008-02-22 00:13:36 +0100321 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500322 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
323 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500324 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500325
dea31012005-04-17 16:05:31 -0500326 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500327 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500328}
329
James Smarte59058c2008-08-24 21:49:00 -0400330/**
James Smart3621a712009-04-06 18:47:14 -0400331 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400332 * @dev: class converted to a Scsi_host structure.
333 * @attr: device attribute, not used.
334 * @buf: on return contains the scsi vpd program type.
335 *
336 * Returns: size of formatted string.
337 **/
dea31012005-04-17 16:05:31 -0500338static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100339lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500340{
341 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100342 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
344 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500345 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500346
dea31012005-04-17 16:05:31 -0500347 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
348 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
349}
James Smarte59058c2008-08-24 21:49:00 -0400350
351/**
James Smart3621a712009-04-06 18:47:14 -0400352 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400353 * @dev: class converted to a Scsi_host structure.
354 * @attr: device attribute, not used.
355 * @buf: on return contains the ROM and FCode ascii strings.
356 *
357 * Returns: size of formatted string.
358 **/
dea31012005-04-17 16:05:31 -0500359static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100360lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
361 char *buf)
dea31012005-04-17 16:05:31 -0500362{
Tony Jonesee959b02008-02-22 00:13:36 +0100363 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500364 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
365 struct lpfc_hba *phba = vport->phba;
366
dea31012005-04-17 16:05:31 -0500367 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
368}
James Smarte59058c2008-08-24 21:49:00 -0400369
370/**
James Smart3621a712009-04-06 18:47:14 -0400371 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400372 * @dev: class converted to a Scsi_host structure.
373 * @attr: device attribute, not used.
374 * @buf: on return contains text describing the state of the link.
375 *
376 * Notes:
377 * The switch statement has no default so zero will be returned.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100382lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
dea31012005-04-17 16:05:31 -0500384{
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388 int len = 0;
389
390 switch (phba->link_state) {
391 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500392 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500393 case LPFC_INIT_START:
394 case LPFC_INIT_MBX_CMDS:
395 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500396 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400397 if (phba->hba_flag & LINK_DISABLED)
398 len += snprintf(buf + len, PAGE_SIZE-len,
399 "Link Down - User disabled\n");
400 else
401 len += snprintf(buf + len, PAGE_SIZE-len,
402 "Link Down\n");
dea31012005-04-17 16:05:31 -0500403 break;
404 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500405 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500406 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400407 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500408
409 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500410 case LPFC_LOCAL_CFG_LINK:
411 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500412 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500413 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500414 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500415 case LPFC_FLOGI:
416 case LPFC_FABRIC_CFG_LINK:
417 case LPFC_NS_REG:
418 case LPFC_NS_QRY:
419 case LPFC_BUILD_DISC_LIST:
420 case LPFC_DISC_AUTH:
421 len += snprintf(buf + len, PAGE_SIZE - len,
422 "Discovery\n");
423 break;
424 case LPFC_VPORT_READY:
425 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
426 break;
427
James Smart92d7f7b2007-06-17 19:56:38 -0500428 case LPFC_VPORT_FAILED:
429 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
430 break;
431
432 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500433 len += snprintf(buf + len, PAGE_SIZE - len,
434 "Unknown\n");
435 break;
436 }
James Smart84774a42008-08-24 21:50:06 -0400437 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
438 len += snprintf(buf + len, PAGE_SIZE-len,
439 " Menlo Maint Mode\n");
440 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500441 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500442 len += snprintf(buf + len, PAGE_SIZE-len,
443 " Public Loop\n");
444 else
445 len += snprintf(buf + len, PAGE_SIZE-len,
446 " Private Loop\n");
447 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500448 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500449 len += snprintf(buf + len, PAGE_SIZE-len,
450 " Fabric\n");
451 else
452 len += snprintf(buf + len, PAGE_SIZE-len,
453 " Point-2-Point\n");
454 }
455 }
James Smart2e0fef82007-06-17 19:56:36 -0500456
dea31012005-04-17 16:05:31 -0500457 return len;
458}
459
James Smarte59058c2008-08-24 21:49:00 -0400460/**
James Smart3621a712009-04-06 18:47:14 -0400461 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400462 * @dev: class device that is converted into a Scsi_host.
463 * @attr: device attribute, not used.
464 * @buf: on return contains the sum of fc mapped and unmapped.
465 *
466 * Description:
467 * Returns the ascii text number of the sum of the fc mapped and unmapped
468 * vport counts.
469 *
470 * Returns: size of formatted string.
471 **/
dea31012005-04-17 16:05:31 -0500472static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100473lpfc_num_discovered_ports_show(struct device *dev,
474 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500475{
Tony Jonesee959b02008-02-22 00:13:36 +0100476 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500477 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
478
479 return snprintf(buf, PAGE_SIZE, "%d\n",
480 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500481}
482
James Smarte59058c2008-08-24 21:49:00 -0400483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400485 * @shost: Scsi_Host pointer.
486 *
487 * Description:
488 * Bring the link down gracefully then re-init the link. The firmware will
489 * re-init the fiber channel interface as required. Does not issue a LIP.
490 *
491 * Returns:
492 * -EPERM port offline or management commands are being blocked
493 * -ENOMEM cannot allocate memory for the mailbox command
494 * -EIO error sending the mailbox command
495 * zero for success
496 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700497static int
James Smart2e0fef82007-06-17 19:56:36 -0500498lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500499{
James Smart2e0fef82007-06-17 19:56:36 -0500500 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
501 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500502 LPFC_MBOXQ_t *pmboxq;
503 int mbxstatus = MBXERR_ERROR;
504
James Smart2e0fef82007-06-17 19:56:36 -0500505 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500506 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500507 return -EPERM;
508
509 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
510
511 if (!pmboxq)
512 return -ENOMEM;
513
514 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400515 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
516 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400517
James Smart33ccf8d2006-08-17 11:57:58 -0400518 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500519
James Smart04c68492009-05-22 14:52:52 -0400520 if ((mbxstatus == MBX_SUCCESS) &&
521 (pmboxq->u.mb.mbxStatus == 0 ||
522 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400523 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
524 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
525 phba->cfg_link_speed);
526 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
527 phba->fc_ratov * 2);
528 }
529
James Smart5b8bd0c2007-04-25 09:52:49 -0400530 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500531 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400532 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500533
534 if (mbxstatus == MBXERR_ERROR)
535 return -EIO;
536
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700537 return 0;
dea31012005-04-17 16:05:31 -0500538}
539
James Smarte59058c2008-08-24 21:49:00 -0400540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400542 * @phba: lpfc_hba pointer.
543 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
544 *
545 * Notes:
546 * Assumes any error from lpfc_do_offline() will be negative.
547 * Can wait up to 5 seconds for the port ring buffers count
548 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400549 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400550 *
551 * Returns:
552 * -EIO error posting the event
553 * zero for success
554 **/
James Smart40496f02006-07-06 15:50:22 -0400555static int
James Smart46fa3112007-04-25 09:51:45 -0400556lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
557{
558 struct completion online_compl;
559 struct lpfc_sli_ring *pring;
560 struct lpfc_sli *psli;
561 int status = 0;
562 int cnt = 0;
563 int i;
564
565 init_completion(&online_compl);
566 lpfc_workq_post_event(phba, &status, &online_compl,
567 LPFC_EVT_OFFLINE_PREP);
568 wait_for_completion(&online_compl);
569
570 if (status != 0)
571 return -EIO;
572
573 psli = &phba->sli;
574
James Smart09372822008-01-11 01:52:54 -0500575 /* Wait a little for things to settle down, but not
576 * long enough for dev loss timeout to expire.
577 */
James Smart46fa3112007-04-25 09:51:45 -0400578 for (i = 0; i < psli->num_rings; i++) {
579 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400580 while (pring->txcmplq_cnt) {
581 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500582 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400583 lpfc_printf_log(phba,
584 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400585 "0466 Outstanding IO when "
586 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400587 break;
588 }
589 }
590 }
591
592 init_completion(&online_compl);
593 lpfc_workq_post_event(phba, &status, &online_compl, type);
594 wait_for_completion(&online_compl);
595
596 if (status != 0)
597 return -EIO;
598
599 return 0;
600}
601
James Smarte59058c2008-08-24 21:49:00 -0400602/**
James Smart3621a712009-04-06 18:47:14 -0400603 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400604 * @phba: lpfc_hba pointer.
605 *
606 * Description:
607 * If the port is configured to allow a reset then the hba is brought
608 * offline then online.
609 *
610 * Notes:
611 * Assumes any error from lpfc_do_offline() will be negative.
612 *
613 * Returns:
614 * lpfc_do_offline() return code if not zero
615 * -EIO reset not configured or error posting the event
616 * zero for success
617 **/
James Smart46fa3112007-04-25 09:51:45 -0400618static int
James Smart40496f02006-07-06 15:50:22 -0400619lpfc_selective_reset(struct lpfc_hba *phba)
620{
621 struct completion online_compl;
622 int status = 0;
623
James Smart13815c82008-01-11 01:52:48 -0500624 if (!phba->cfg_enable_hba_reset)
625 return -EIO;
626
James Smart46fa3112007-04-25 09:51:45 -0400627 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400628
629 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400630 return status;
James Smart40496f02006-07-06 15:50:22 -0400631
632 init_completion(&online_compl);
633 lpfc_workq_post_event(phba, &status, &online_compl,
634 LPFC_EVT_ONLINE);
635 wait_for_completion(&online_compl);
636
637 if (status != 0)
638 return -EIO;
639
640 return 0;
641}
642
James Smarte59058c2008-08-24 21:49:00 -0400643/**
James Smart3621a712009-04-06 18:47:14 -0400644 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400645 * @dev: class device that is converted into a Scsi_host.
646 * @attr: device attribute, not used.
647 * @buf: containing the string "selective".
648 * @count: unused variable.
649 *
650 * Description:
651 * If the buf contains the string "selective" then lpfc_selective_reset()
652 * is called to perform the reset.
653 *
654 * Notes:
655 * Assumes any error from lpfc_selective_reset() will be negative.
656 * If lpfc_selective_reset() returns zero then the length of the buffer
657 * is returned which indicates succcess
658 *
659 * Returns:
660 * -EINVAL if the buffer does not contain the string "selective"
661 * length of buf if lpfc-selective_reset() if the call succeeds
662 * return value of lpfc_selective_reset() if the call fails
663**/
James Smart40496f02006-07-06 15:50:22 -0400664static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100665lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
666 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400667{
Tony Jonesee959b02008-02-22 00:13:36 +0100668 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
670 struct lpfc_hba *phba = vport->phba;
671
James Smart40496f02006-07-06 15:50:22 -0400672 int status = -EINVAL;
673
674 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
675 status = lpfc_selective_reset(phba);
676
677 if (status == 0)
678 return strlen(buf);
679 else
680 return status;
681}
682
James Smarte59058c2008-08-24 21:49:00 -0400683/**
James Smart3621a712009-04-06 18:47:14 -0400684 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400685 * @dev: class device that is converted into a Scsi_host.
686 * @attr: device attribute, not used.
687 * @buf: on return contains the ascii number of nport events.
688 *
689 * Returns: size of formatted string.
690 **/
dea31012005-04-17 16:05:31 -0500691static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100692lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
693 char *buf)
dea31012005-04-17 16:05:31 -0500694{
Tony Jonesee959b02008-02-22 00:13:36 +0100695 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500696 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
697 struct lpfc_hba *phba = vport->phba;
698
dea31012005-04-17 16:05:31 -0500699 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
700}
701
James Smarte59058c2008-08-24 21:49:00 -0400702/**
James Smart3621a712009-04-06 18:47:14 -0400703 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400704 * @dev: class device that is converted into a Scsi_host.
705 * @attr: device attribute, not used.
706 * @buf: on return contains the state of the adapter.
707 *
708 * Returns: size of formatted string.
709 **/
dea31012005-04-17 16:05:31 -0500710static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100711lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
712 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500713{
Tony Jonesee959b02008-02-22 00:13:36 +0100714 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
716 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500717 char * state;
718
James Smart2e0fef82007-06-17 19:56:36 -0500719 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500720 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500721 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500722 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500723 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500724 state = "offline";
725 else
726 state = "online";
727
728 return snprintf(buf, PAGE_SIZE, "%s\n", state);
729}
730
James Smarte59058c2008-08-24 21:49:00 -0400731/**
James Smart3621a712009-04-06 18:47:14 -0400732 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400733 * @dev: class device that is converted into a Scsi_host.
734 * @attr: device attribute, not used.
735 * @buf: containing one of the strings "online", "offline", "warm" or "error".
736 * @count: unused variable.
737 *
738 * Returns:
739 * -EACCES if enable hba reset not enabled
740 * -EINVAL if the buffer does not contain a valid string (see above)
741 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
742 * buf length greater than zero indicates success
743 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500744static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100745lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
746 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500747{
Tony Jonesee959b02008-02-22 00:13:36 +0100748 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500749 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
750 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500751 struct completion online_compl;
752 int status=0;
753
James Smart13815c82008-01-11 01:52:48 -0500754 if (!phba->cfg_enable_hba_reset)
755 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500756 init_completion(&online_compl);
757
James Smart46fa3112007-04-25 09:51:45 -0400758 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500759 lpfc_workq_post_event(phba, &status, &online_compl,
760 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400761 wait_for_completion(&online_compl);
762 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
763 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500764 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400765 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
766 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
767 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500768 else
769 return -EINVAL;
770
Jamie Wellnitz41415862006-02-28 19:25:27 -0500771 if (!status)
772 return strlen(buf);
773 else
774 return -EIO;
775}
776
James Smarte59058c2008-08-24 21:49:00 -0400777/**
James Smart3621a712009-04-06 18:47:14 -0400778 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400779 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400780 * @mxri: max xri count.
781 * @axri: available xri count.
782 * @mrpi: max rpi count.
783 * @arpi: available rpi count.
784 * @mvpi: max vpi count.
785 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400786 *
787 * Description:
788 * If an integer pointer for an count is not null then the value for the
789 * count is returned.
790 *
791 * Returns:
792 * zero on error
793 * one for success
794 **/
James Smart311464e2007-08-02 11:10:37 -0400795static int
James Smart858c9f62007-06-17 19:56:39 -0500796lpfc_get_hba_info(struct lpfc_hba *phba,
797 uint32_t *mxri, uint32_t *axri,
798 uint32_t *mrpi, uint32_t *arpi,
799 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500800{
James Smart04c68492009-05-22 14:52:52 -0400801 struct lpfc_sli *psli = &phba->sli;
802 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500803 LPFC_MBOXQ_t *pmboxq;
804 MAILBOX_t *pmb;
805 int rc = 0;
806
807 /*
808 * prevent udev from issuing mailbox commands until the port is
809 * configured.
810 */
811 if (phba->link_state < LPFC_LINK_DOWN ||
812 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400813 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500814 return 0;
815
816 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
817 return 0;
818
819 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
820 if (!pmboxq)
821 return 0;
822 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
823
James Smart04c68492009-05-22 14:52:52 -0400824 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500825 pmb->mbxCommand = MBX_READ_CONFIG;
826 pmb->mbxOwner = OWN_HOST;
827 pmboxq->context1 = NULL;
828
829 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -0400830 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart92d7f7b2007-06-17 19:56:38 -0500831 rc = MBX_NOT_FINISHED;
832 else
833 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
834
835 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500836 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500837 mempool_free(pmboxq, phba->mbox_mem_pool);
838 return 0;
839 }
840
James Smartda0436e2009-05-22 14:51:39 -0400841 if (phba->sli_rev == LPFC_SLI_REV4) {
842 rd_config = &pmboxq->u.mqe.un.rd_config;
843 if (mrpi)
844 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
845 if (arpi)
846 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
847 phba->sli4_hba.max_cfg_param.rpi_used;
848 if (mxri)
849 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
850 if (axri)
851 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
852 phba->sli4_hba.max_cfg_param.xri_used;
853 if (mvpi)
854 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
855 if (avpi)
856 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
857 phba->sli4_hba.max_cfg_param.vpi_used;
858 } else {
859 if (mrpi)
860 *mrpi = pmb->un.varRdConfig.max_rpi;
861 if (arpi)
862 *arpi = pmb->un.varRdConfig.avail_rpi;
863 if (mxri)
864 *mxri = pmb->un.varRdConfig.max_xri;
865 if (axri)
866 *axri = pmb->un.varRdConfig.avail_xri;
867 if (mvpi)
868 *mvpi = pmb->un.varRdConfig.max_vpi;
869 if (avpi)
870 *avpi = pmb->un.varRdConfig.avail_vpi;
871 }
James Smart92d7f7b2007-06-17 19:56:38 -0500872
873 mempool_free(pmboxq, phba->mbox_mem_pool);
874 return 1;
875}
876
James Smarte59058c2008-08-24 21:49:00 -0400877/**
James Smart3621a712009-04-06 18:47:14 -0400878 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400879 * @dev: class device that is converted into a Scsi_host.
880 * @attr: device attribute, not used.
881 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
882 *
883 * Description:
884 * Calls lpfc_get_hba_info() asking for just the mrpi count.
885 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
886 * to "Unknown" and the buffer length is returned, therefore the caller
887 * must check for "Unknown" in the buffer to detect a failure.
888 *
889 * Returns: size of formatted string.
890 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500891static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100892lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
893 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500894{
Tony Jonesee959b02008-02-22 00:13:36 +0100895 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500896 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
897 struct lpfc_hba *phba = vport->phba;
898 uint32_t cnt;
899
James Smart858c9f62007-06-17 19:56:39 -0500900 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500901 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
902 return snprintf(buf, PAGE_SIZE, "Unknown\n");
903}
904
James Smarte59058c2008-08-24 21:49:00 -0400905/**
James Smart3621a712009-04-06 18:47:14 -0400906 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400907 * @dev: class device that is converted into a Scsi_host.
908 * @attr: device attribute, not used.
909 * @buf: containing the used rpi count in decimal or "Unknown".
910 *
911 * Description:
912 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
913 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
914 * to "Unknown" and the buffer length is returned, therefore the caller
915 * must check for "Unknown" in the buffer to detect a failure.
916 *
917 * Returns: size of formatted string.
918 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500919static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100920lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
921 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500922{
Tony Jonesee959b02008-02-22 00:13:36 +0100923 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500924 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
925 struct lpfc_hba *phba = vport->phba;
926 uint32_t cnt, acnt;
927
James Smart858c9f62007-06-17 19:56:39 -0500928 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500929 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
930 return snprintf(buf, PAGE_SIZE, "Unknown\n");
931}
932
James Smarte59058c2008-08-24 21:49:00 -0400933/**
James Smart3621a712009-04-06 18:47:14 -0400934 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -0400935 * @dev: class device that is converted into a Scsi_host.
936 * @attr: device attribute, not used.
937 * @buf: on return contains the maximum xri count in decimal or "Unknown".
938 *
939 * Description:
940 * Calls lpfc_get_hba_info() asking for just the mrpi count.
941 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
942 * to "Unknown" and the buffer length is returned, therefore the caller
943 * must check for "Unknown" in the buffer to detect a failure.
944 *
945 * Returns: size of formatted string.
946 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500947static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100948lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
949 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500950{
Tony Jonesee959b02008-02-22 00:13:36 +0100951 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
953 struct lpfc_hba *phba = vport->phba;
954 uint32_t cnt;
955
James Smart858c9f62007-06-17 19:56:39 -0500956 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500957 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
958 return snprintf(buf, PAGE_SIZE, "Unknown\n");
959}
960
James Smarte59058c2008-08-24 21:49:00 -0400961/**
James Smart3621a712009-04-06 18:47:14 -0400962 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -0400963 * @dev: class device that is converted into a Scsi_host.
964 * @attr: device attribute, not used.
965 * @buf: on return contains the used xri count in decimal or "Unknown".
966 *
967 * Description:
968 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
969 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
970 * to "Unknown" and the buffer length is returned, therefore the caller
971 * must check for "Unknown" in the buffer to detect a failure.
972 *
973 * Returns: size of formatted string.
974 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500975static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100976lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
977 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500978{
Tony Jonesee959b02008-02-22 00:13:36 +0100979 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500980 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
981 struct lpfc_hba *phba = vport->phba;
982 uint32_t cnt, acnt;
983
James Smart858c9f62007-06-17 19:56:39 -0500984 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
985 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
986 return snprintf(buf, PAGE_SIZE, "Unknown\n");
987}
988
James Smarte59058c2008-08-24 21:49:00 -0400989/**
James Smart3621a712009-04-06 18:47:14 -0400990 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -0400991 * @dev: class device that is converted into a Scsi_host.
992 * @attr: device attribute, not used.
993 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
994 *
995 * Description:
996 * Calls lpfc_get_hba_info() asking for just the mvpi count.
997 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
998 * to "Unknown" and the buffer length is returned, therefore the caller
999 * must check for "Unknown" in the buffer to detect a failure.
1000 *
1001 * Returns: size of formatted string.
1002 **/
James Smart858c9f62007-06-17 19:56:39 -05001003static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001004lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1005 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001006{
Tony Jonesee959b02008-02-22 00:13:36 +01001007 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001008 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1009 struct lpfc_hba *phba = vport->phba;
1010 uint32_t cnt;
1011
1012 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1013 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1014 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1015}
1016
James Smarte59058c2008-08-24 21:49:00 -04001017/**
James Smart3621a712009-04-06 18:47:14 -04001018 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001019 * @dev: class device that is converted into a Scsi_host.
1020 * @attr: device attribute, not used.
1021 * @buf: on return contains the used vpi count in decimal or "Unknown".
1022 *
1023 * Description:
1024 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1025 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1026 * to "Unknown" and the buffer length is returned, therefore the caller
1027 * must check for "Unknown" in the buffer to detect a failure.
1028 *
1029 * Returns: size of formatted string.
1030 **/
James Smart858c9f62007-06-17 19:56:39 -05001031static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001032lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1033 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001034{
Tony Jonesee959b02008-02-22 00:13:36 +01001035 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001036 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1037 struct lpfc_hba *phba = vport->phba;
1038 uint32_t cnt, acnt;
1039
1040 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001041 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1042 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1043}
1044
James Smarte59058c2008-08-24 21:49:00 -04001045/**
James Smart3621a712009-04-06 18:47:14 -04001046 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001047 * @dev: class device that is converted into a Scsi_host.
1048 * @attr: device attribute, not used.
1049 * @buf: text that must be interpreted to determine if npiv is supported.
1050 *
1051 * Description:
1052 * Buffer will contain text indicating npiv is not suppoerted on the port,
1053 * the port is an NPIV physical port, or it is an npiv virtual port with
1054 * the id of the vport.
1055 *
1056 * Returns: size of formatted string.
1057 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001058static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001059lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1060 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001061{
Tony Jonesee959b02008-02-22 00:13:36 +01001062 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1064 struct lpfc_hba *phba = vport->phba;
1065
1066 if (!(phba->max_vpi))
1067 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1068 if (vport->port_type == LPFC_PHYSICAL_PORT)
1069 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1070 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1071}
1072
James Smarte59058c2008-08-24 21:49:00 -04001073/**
James Smart3621a712009-04-06 18:47:14 -04001074 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001075 * @dev: class device that is converted into a Scsi_host.
1076 * @attr: device attribute, not used.
1077 * @buf: on return contains the cfg_poll in hex.
1078 *
1079 * Notes:
1080 * cfg_poll should be a lpfc_polling_flags type.
1081 *
1082 * Returns: size of formatted string.
1083 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001084static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001085lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1086 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001087{
Tony Jonesee959b02008-02-22 00:13:36 +01001088 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1090 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001091
1092 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1093}
1094
James Smarte59058c2008-08-24 21:49:00 -04001095/**
James Smart3621a712009-04-06 18:47:14 -04001096 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001097 * @dev: class device that is converted into a Scsi_host.
1098 * @attr: device attribute, not used.
1099 * @buf: one or more lpfc_polling_flags values.
1100 * @count: not used.
1101 *
1102 * Notes:
1103 * buf contents converted to integer and checked for a valid value.
1104 *
1105 * Returns:
1106 * -EINVAL if the buffer connot be converted or is out of range
1107 * length of the buf on success
1108 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001109static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001110lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1111 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001112{
Tony Jonesee959b02008-02-22 00:13:36 +01001113 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1115 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001116 uint32_t creg_val;
1117 uint32_t old_val;
1118 int val=0;
1119
1120 if (!isdigit(buf[0]))
1121 return -EINVAL;
1122
1123 if (sscanf(buf, "%i", &val) != 1)
1124 return -EINVAL;
1125
1126 if ((val & 0x3) != val)
1127 return -EINVAL;
1128
James Smart2e0fef82007-06-17 19:56:36 -05001129 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001130
1131 old_val = phba->cfg_poll;
1132
1133 if (val & ENABLE_FCP_RING_POLLING) {
1134 if ((val & DISABLE_FCP_RING_INT) &&
1135 !(old_val & DISABLE_FCP_RING_INT)) {
1136 creg_val = readl(phba->HCregaddr);
1137 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1138 writel(creg_val, phba->HCregaddr);
1139 readl(phba->HCregaddr); /* flush */
1140
1141 lpfc_poll_start_timer(phba);
1142 }
1143 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001144 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001145 return -EINVAL;
1146 }
1147
1148 if (!(val & DISABLE_FCP_RING_INT) &&
1149 (old_val & DISABLE_FCP_RING_INT))
1150 {
James Smart2e0fef82007-06-17 19:56:36 -05001151 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001152 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001153 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001154 creg_val = readl(phba->HCregaddr);
1155 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1156 writel(creg_val, phba->HCregaddr);
1157 readl(phba->HCregaddr); /* flush */
1158 }
1159
1160 phba->cfg_poll = val;
1161
James Smart2e0fef82007-06-17 19:56:36 -05001162 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001163
1164 return strlen(buf);
1165}
dea31012005-04-17 16:05:31 -05001166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
James Smart3621a712009-04-06 18:47:14 -04001168 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001169 *
1170 * Description:
1171 * Macro that given an attr e.g. hba_queue_depth expands
1172 * into a function with the name lpfc_hba_queue_depth_show.
1173 *
1174 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1175 * @dev: class device that is converted into a Scsi_host.
1176 * @attr: device attribute, not used.
1177 * @buf: on return contains the attribute value in decimal.
1178 *
1179 * Returns: size of formatted string.
1180 **/
dea31012005-04-17 16:05:31 -05001181#define lpfc_param_show(attr) \
1182static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001183lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1184 char *buf) \
dea31012005-04-17 16:05:31 -05001185{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001186 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001187 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1188 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001189 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001190 val = phba->cfg_##attr;\
1191 return snprintf(buf, PAGE_SIZE, "%d\n",\
1192 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001193}
1194
James Smarte59058c2008-08-24 21:49:00 -04001195/**
James Smart3621a712009-04-06 18:47:14 -04001196 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001197 *
1198 * Description:
1199 * Macro that given an attr e.g. hba_queue_depth expands
1200 * into a function with the name lpfc_hba_queue_depth_show
1201 *
1202 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1203 * @dev: class device that is converted into a Scsi_host.
1204 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001205 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001206 *
1207 * Returns: size of formatted string.
1208 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001209#define lpfc_param_hex_show(attr) \
1210static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001211lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1212 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001213{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001214 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001215 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1216 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001217 int val = 0;\
1218 val = phba->cfg_##attr;\
1219 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1220 phba->cfg_##attr);\
1221}
1222
James Smarte59058c2008-08-24 21:49:00 -04001223/**
James Smart3621a712009-04-06 18:47:14 -04001224 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001225 *
1226 * Description:
1227 * Macro that given an attr e.g. hba_queue_depth expands
1228 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1229 * takes a default argument, a minimum and maximum argument.
1230 *
1231 * lpfc_##attr##_init: Initializes an attribute.
1232 * @phba: pointer the the adapter structure.
1233 * @val: integer attribute value.
1234 *
1235 * Validates the min and max values then sets the adapter config field
1236 * accordingly, or uses the default if out of range and prints an error message.
1237 *
1238 * Returns:
1239 * zero on success
1240 * -EINVAL if default used
1241 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001242#define lpfc_param_init(attr, default, minval, maxval) \
1243static int \
1244lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1245{ \
1246 if (val >= minval && val <= maxval) {\
1247 phba->cfg_##attr = val;\
1248 return 0;\
1249 }\
1250 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001251 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1252 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001253 phba->cfg_##attr = default;\
1254 return -EINVAL;\
1255}
1256
James Smarte59058c2008-08-24 21:49:00 -04001257/**
James Smart3621a712009-04-06 18:47:14 -04001258 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001259 *
1260 * Description:
1261 * Macro that given an attr e.g. hba_queue_depth expands
1262 * into a function with the name lpfc_hba_queue_depth_set
1263 *
1264 * lpfc_##attr##_set: Sets an attribute value.
1265 * @phba: pointer the the adapter structure.
1266 * @val: integer attribute value.
1267 *
1268 * Description:
1269 * Validates the min and max values then sets the
1270 * adapter config field if in the valid range. prints error message
1271 * and does not set the parameter if invalid.
1272 *
1273 * Returns:
1274 * zero on success
1275 * -EINVAL if val is invalid
1276 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001277#define lpfc_param_set(attr, default, minval, maxval) \
1278static int \
1279lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1280{ \
1281 if (val >= minval && val <= maxval) {\
1282 phba->cfg_##attr = val;\
1283 return 0;\
1284 }\
1285 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001286 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1287 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001288 return -EINVAL;\
1289}
1290
James Smarte59058c2008-08-24 21:49:00 -04001291/**
James Smart3621a712009-04-06 18:47:14 -04001292 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001293 *
1294 * Description:
1295 * Macro that given an attr e.g. hba_queue_depth expands
1296 * into a function with the name lpfc_hba_queue_depth_store.
1297 *
1298 * lpfc_##attr##_store: Set an sttribute value.
1299 * @dev: class device that is converted into a Scsi_host.
1300 * @attr: device attribute, not used.
1301 * @buf: contains the attribute value in ascii.
1302 * @count: not used.
1303 *
1304 * Description:
1305 * Convert the ascii text number to an integer, then
1306 * use the lpfc_##attr##_set function to set the value.
1307 *
1308 * Returns:
1309 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1310 * length of buffer upon success.
1311 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001312#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001313static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001314lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1315 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001316{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001317 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001318 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1319 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001320 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001321 if (!isdigit(buf[0]))\
1322 return -EINVAL;\
1323 if (sscanf(buf, "%i", &val) != 1)\
1324 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001325 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001326 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001327 else \
1328 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001329}
1330
James Smarte59058c2008-08-24 21:49:00 -04001331/**
James Smart3621a712009-04-06 18:47:14 -04001332 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001333 *
1334 * Description:
1335 * Macro that given an attr e.g. hba_queue_depth expands
1336 * into a function with the name lpfc_hba_queue_depth_show
1337 *
1338 * lpfc_##attr##_show: prints the attribute value in decimal.
1339 * @dev: class device that is converted into a Scsi_host.
1340 * @attr: device attribute, not used.
1341 * @buf: on return contains the attribute value in decimal.
1342 *
1343 * Returns: length of formatted string.
1344 **/
James Smart3de2a652007-08-02 11:09:59 -04001345#define lpfc_vport_param_show(attr) \
1346static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001347lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1348 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001349{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001350 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1352 int val = 0;\
1353 val = vport->cfg_##attr;\
1354 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1355}
1356
James Smarte59058c2008-08-24 21:49:00 -04001357/**
James Smart3621a712009-04-06 18:47:14 -04001358 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001359 *
1360 * Description:
1361 * Macro that given an attr e.g.
1362 * hba_queue_depth expands into a function with the name
1363 * lpfc_hba_queue_depth_show
1364 *
James Smart3621a712009-04-06 18:47:14 -04001365 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001366 * @dev: class device that is converted into a Scsi_host.
1367 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001368 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001369 *
1370 * Returns: length of formatted string.
1371 **/
James Smart3de2a652007-08-02 11:09:59 -04001372#define lpfc_vport_param_hex_show(attr) \
1373static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001374lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1375 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001376{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001377 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001378 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1379 int val = 0;\
1380 val = vport->cfg_##attr;\
1381 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1382}
1383
James Smarte59058c2008-08-24 21:49:00 -04001384/**
James Smart3621a712009-04-06 18:47:14 -04001385 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001386 *
1387 * Description:
1388 * Macro that given an attr e.g. hba_queue_depth expands
1389 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1390 * takes a default argument, a minimum and maximum argument.
1391 *
1392 * lpfc_##attr##_init: validates the min and max values then sets the
1393 * adapter config field accordingly, or uses the default if out of range
1394 * and prints an error message.
1395 * @phba: pointer the the adapter structure.
1396 * @val: integer attribute value.
1397 *
1398 * Returns:
1399 * zero on success
1400 * -EINVAL if default used
1401 **/
James Smart3de2a652007-08-02 11:09:59 -04001402#define lpfc_vport_param_init(attr, default, minval, maxval) \
1403static int \
1404lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1405{ \
1406 if (val >= minval && val <= maxval) {\
1407 vport->cfg_##attr = val;\
1408 return 0;\
1409 }\
James Smarte8b62012007-08-02 11:10:09 -04001410 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001411 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001412 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001413 vport->cfg_##attr = default;\
1414 return -EINVAL;\
1415}
1416
James Smarte59058c2008-08-24 21:49:00 -04001417/**
James Smart3621a712009-04-06 18:47:14 -04001418 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001419 *
1420 * Description:
1421 * Macro that given an attr e.g. hba_queue_depth expands
1422 * into a function with the name lpfc_hba_queue_depth_set
1423 *
1424 * lpfc_##attr##_set: validates the min and max values then sets the
1425 * adapter config field if in the valid range. prints error message
1426 * and does not set the parameter if invalid.
1427 * @phba: pointer the the adapter structure.
1428 * @val: integer attribute value.
1429 *
1430 * Returns:
1431 * zero on success
1432 * -EINVAL if val is invalid
1433 **/
James Smart3de2a652007-08-02 11:09:59 -04001434#define lpfc_vport_param_set(attr, default, minval, maxval) \
1435static int \
1436lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1437{ \
1438 if (val >= minval && val <= maxval) {\
1439 vport->cfg_##attr = val;\
1440 return 0;\
1441 }\
James Smarte8b62012007-08-02 11:10:09 -04001442 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001443 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001444 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001445 return -EINVAL;\
1446}
1447
James Smarte59058c2008-08-24 21:49:00 -04001448/**
James Smart3621a712009-04-06 18:47:14 -04001449 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001450 *
1451 * Description:
1452 * Macro that given an attr e.g. hba_queue_depth
1453 * expands into a function with the name lpfc_hba_queue_depth_store
1454 *
1455 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1456 * use the lpfc_##attr##_set function to set the value.
1457 * @cdev: class device that is converted into a Scsi_host.
1458 * @buf: contains the attribute value in decimal.
1459 * @count: not used.
1460 *
1461 * Returns:
1462 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1463 * length of buffer upon success.
1464 **/
James Smart3de2a652007-08-02 11:09:59 -04001465#define lpfc_vport_param_store(attr) \
1466static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001467lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1468 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001469{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001470 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1472 int val=0;\
1473 if (!isdigit(buf[0]))\
1474 return -EINVAL;\
1475 if (sscanf(buf, "%i", &val) != 1)\
1476 return -EINVAL;\
1477 if (lpfc_##attr##_set(vport, val) == 0) \
1478 return strlen(buf);\
1479 else \
1480 return -EINVAL;\
1481}
1482
1483
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001484#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1485static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001486module_param(lpfc_##name, int, 0);\
1487MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001488lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001489
1490#define LPFC_ATTR_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001496static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001497
1498#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1499static int lpfc_##name = defval;\
1500module_param(lpfc_##name, int, 0);\
1501MODULE_PARM_DESC(lpfc_##name, desc);\
1502lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001503lpfc_param_init(name, defval, minval, maxval)\
1504lpfc_param_set(name, defval, minval, maxval)\
1505lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001506static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1507 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001508
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001509#define LPFC_ATTR_HEX_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001515static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001516
1517#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1518static int lpfc_##name = defval;\
1519module_param(lpfc_##name, int, 0);\
1520MODULE_PARM_DESC(lpfc_##name, desc);\
1521lpfc_param_hex_show(name)\
1522lpfc_param_init(name, defval, minval, maxval)\
1523lpfc_param_set(name, defval, minval, maxval)\
1524lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001525static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1526 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001527
James Smart3de2a652007-08-02 11:09:59 -04001528#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1529static int lpfc_##name = defval;\
1530module_param(lpfc_##name, int, 0);\
1531MODULE_PARM_DESC(lpfc_##name, desc);\
1532lpfc_vport_param_init(name, defval, minval, maxval)
1533
1534#define LPFC_VPORT_ATTR_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001540static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001541
1542#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1543static int lpfc_##name = defval;\
1544module_param(lpfc_##name, int, 0);\
1545MODULE_PARM_DESC(lpfc_##name, desc);\
1546lpfc_vport_param_show(name)\
1547lpfc_vport_param_init(name, defval, minval, maxval)\
1548lpfc_vport_param_set(name, defval, minval, maxval)\
1549lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001550static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1551 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001552
1553#define LPFC_VPORT_ATTR_HEX_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001559static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001560
1561#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1562static int lpfc_##name = defval;\
1563module_param(lpfc_##name, int, 0);\
1564MODULE_PARM_DESC(lpfc_##name, desc);\
1565lpfc_vport_param_hex_show(name)\
1566lpfc_vport_param_init(name, defval, minval, maxval)\
1567lpfc_vport_param_set(name, defval, minval, maxval)\
1568lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001569static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1570 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001571
James Smart81301a92008-12-04 22:39:46 -05001572static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1573static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1574static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1575static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001576static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1577static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1578static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1579static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1580static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1581static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1582static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1583static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001584static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001585static DEVICE_ATTR(option_rom_version, S_IRUGO,
1586 lpfc_option_rom_version_show, NULL);
1587static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1588 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001589static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001590static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1591static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1592static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1593 lpfc_board_mode_show, lpfc_board_mode_store);
1594static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1595static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1596static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1597static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1598static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1599static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1600static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1601static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1602static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001603
James Smartc3f28af2006-08-18 17:47:18 -04001604
James Smarta12e07b2006-12-02 13:35:30 -05001605static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001606
James Smarte59058c2008-08-24 21:49:00 -04001607/**
James Smart3621a712009-04-06 18:47:14 -04001608 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001609 * @dev: class device that is converted into a Scsi_host.
1610 * @attr: device attribute, not used.
1611 * @buf: containing the string lpfc_soft_wwn_key.
1612 * @count: must be size of lpfc_soft_wwn_key.
1613 *
1614 * Returns:
1615 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1616 * length of buf indicates success
1617 **/
James Smartc3f28af2006-08-18 17:47:18 -04001618static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001619lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1620 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001621{
Tony Jonesee959b02008-02-22 00:13:36 +01001622 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1624 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001625 unsigned int cnt = count;
1626
1627 /*
1628 * We're doing a simple sanity check for soft_wwpn setting.
1629 * We require that the user write a specific key to enable
1630 * the soft_wwpn attribute to be settable. Once the attribute
1631 * is written, the enable key resets. If further updates are
1632 * desired, the key must be written again to re-enable the
1633 * attribute.
1634 *
1635 * The "key" is not secret - it is a hardcoded string shown
1636 * here. The intent is to protect against the random user or
1637 * application that is just writing attributes.
1638 */
1639
1640 /* count may include a LF at end of string */
1641 if (buf[cnt-1] == '\n')
1642 cnt--;
1643
James Smarta12e07b2006-12-02 13:35:30 -05001644 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1645 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001646 return -EINVAL;
1647
James Smarta12e07b2006-12-02 13:35:30 -05001648 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001649 return count;
1650}
Tony Jonesee959b02008-02-22 00:13:36 +01001651static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1652 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001653
James Smarte59058c2008-08-24 21:49:00 -04001654/**
James Smart3621a712009-04-06 18:47:14 -04001655 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001656 * @dev: class device that is converted into a Scsi_host.
1657 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001658 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001659 *
1660 * Returns: size of formatted string.
1661 **/
James Smartc3f28af2006-08-18 17:47:18 -04001662static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001663lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1664 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001665{
Tony Jonesee959b02008-02-22 00:13:36 +01001666 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1668 struct lpfc_hba *phba = vport->phba;
1669
Randy Dunlapafc071e2006-10-23 21:47:13 -07001670 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1671 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001672}
1673
James Smarte59058c2008-08-24 21:49:00 -04001674/**
James Smart3621a712009-04-06 18:47:14 -04001675 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001676 * @dev class device that is converted into a Scsi_host.
1677 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001678 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001679 * @count: number of wwpn bytes in buf
1680 *
1681 * Returns:
1682 * -EACCES hba reset not enabled, adapter over temp
1683 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1684 * -EIO error taking adapter offline or online
1685 * value of count on success
1686 **/
James Smartc3f28af2006-08-18 17:47:18 -04001687static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001688lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1689 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001690{
Tony Jonesee959b02008-02-22 00:13:36 +01001691 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1693 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001694 struct completion online_compl;
1695 int stat1=0, stat2=0;
1696 unsigned int i, j, cnt=count;
1697 u8 wwpn[8];
1698
James Smart13815c82008-01-11 01:52:48 -05001699 if (!phba->cfg_enable_hba_reset)
1700 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001701 spin_lock_irq(&phba->hbalock);
1702 if (phba->over_temp_state == HBA_OVER_TEMP) {
1703 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001704 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001705 }
1706 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001707 /* count may include a LF at end of string */
1708 if (buf[cnt-1] == '\n')
1709 cnt--;
1710
James Smarta12e07b2006-12-02 13:35:30 -05001711 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001712 ((cnt == 17) && (*buf++ != 'x')) ||
1713 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1714 return -EINVAL;
1715
James Smarta12e07b2006-12-02 13:35:30 -05001716 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001717
1718 memset(wwpn, 0, sizeof(wwpn));
1719
1720 /* Validate and store the new name */
1721 for (i=0, j=0; i < 16; i++) {
1722 if ((*buf >= 'a') && (*buf <= 'f'))
1723 j = ((j << 4) | ((*buf++ -'a') + 10));
1724 else if ((*buf >= 'A') && (*buf <= 'F'))
1725 j = ((j << 4) | ((*buf++ -'A') + 10));
1726 else if ((*buf >= '0') && (*buf <= '9'))
1727 j = ((j << 4) | (*buf++ -'0'));
1728 else
1729 return -EINVAL;
1730 if (i % 2) {
1731 wwpn[i/2] = j & 0xff;
1732 j = 0;
1733 }
1734 }
1735 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001736 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001737 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001738 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001739
1740 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1741 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1742
James Smart46fa3112007-04-25 09:51:45 -04001743 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001744 if (stat1)
1745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001746 "0463 lpfc_soft_wwpn attribute set failed to "
1747 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001748 init_completion(&online_compl);
1749 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1750 wait_for_completion(&online_compl);
1751 if (stat2)
1752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001753 "0464 lpfc_soft_wwpn attribute set failed to "
1754 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001755 return (stat1 || stat2) ? -EIO : count;
1756}
Tony Jonesee959b02008-02-22 00:13:36 +01001757static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1758 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001759
James Smarte59058c2008-08-24 21:49:00 -04001760/**
James Smart3621a712009-04-06 18:47:14 -04001761 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001762 * @dev: class device that is converted into a Scsi_host.
1763 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001764 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001765 *
1766 * Returns: size of formatted string.
1767 **/
James Smarta12e07b2006-12-02 13:35:30 -05001768static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001769lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1770 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001771{
Tony Jonesee959b02008-02-22 00:13:36 +01001772 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001773 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001774 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1775 (unsigned long long)phba->cfg_soft_wwnn);
1776}
1777
James Smarte59058c2008-08-24 21:49:00 -04001778/**
James Smart3621a712009-04-06 18:47:14 -04001779 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001780 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001781 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001782 * @count: number of wwnn bytes in buf.
1783 *
1784 * Returns:
1785 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1786 * value of count on success
1787 **/
James Smarta12e07b2006-12-02 13:35:30 -05001788static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001789lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1790 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001791{
Tony Jonesee959b02008-02-22 00:13:36 +01001792 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001793 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001794 unsigned int i, j, cnt=count;
1795 u8 wwnn[8];
1796
1797 /* count may include a LF at end of string */
1798 if (buf[cnt-1] == '\n')
1799 cnt--;
1800
1801 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1802 ((cnt == 17) && (*buf++ != 'x')) ||
1803 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1804 return -EINVAL;
1805
1806 /*
1807 * Allow wwnn to be set many times, as long as the enable is set.
1808 * However, once the wwpn is set, everything locks.
1809 */
1810
1811 memset(wwnn, 0, sizeof(wwnn));
1812
1813 /* Validate and store the new name */
1814 for (i=0, j=0; i < 16; i++) {
1815 if ((*buf >= 'a') && (*buf <= 'f'))
1816 j = ((j << 4) | ((*buf++ -'a') + 10));
1817 else if ((*buf >= 'A') && (*buf <= 'F'))
1818 j = ((j << 4) | ((*buf++ -'A') + 10));
1819 else if ((*buf >= '0') && (*buf <= '9'))
1820 j = ((j << 4) | (*buf++ -'0'));
1821 else
1822 return -EINVAL;
1823 if (i % 2) {
1824 wwnn[i/2] = j & 0xff;
1825 j = 0;
1826 }
1827 }
1828 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1829
1830 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1831 "lpfc%d: soft_wwnn set. Value will take effect upon "
1832 "setting of the soft_wwpn\n", phba->brd_no);
1833
1834 return count;
1835}
Tony Jonesee959b02008-02-22 00:13:36 +01001836static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1837 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001838
James Smartc3f28af2006-08-18 17:47:18 -04001839
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001840static int lpfc_poll = 0;
1841module_param(lpfc_poll, int, 0);
1842MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1843 " 0 - none,"
1844 " 1 - poll with interrupts enabled"
1845 " 3 - poll and disable FCP ring interrupts");
1846
Tony Jonesee959b02008-02-22 00:13:36 +01001847static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1848 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001849
James Smart92d7f7b2007-06-17 19:56:38 -05001850int lpfc_sli_mode = 0;
1851module_param(lpfc_sli_mode, int, 0);
1852MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1853 " 0 - auto (SLI-3 if supported),"
1854 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1855 " 3 - select SLI-3");
1856
James Smart7ee5d432007-10-27 13:37:17 -04001857int lpfc_enable_npiv = 0;
1858module_param(lpfc_enable_npiv, int, 0);
1859MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1860lpfc_param_show(enable_npiv);
1861lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001862static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001863 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001864
dea31012005-04-17 16:05:31 -05001865/*
James Smartc01f3202006-08-18 17:47:08 -04001866# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1867# until the timer expires. Value range is [0,255]. Default value is 30.
1868*/
1869static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1870static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1871module_param(lpfc_nodev_tmo, int, 0);
1872MODULE_PARM_DESC(lpfc_nodev_tmo,
1873 "Seconds driver will hold I/O waiting "
1874 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001875
1876/**
James Smart3621a712009-04-06 18:47:14 -04001877 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04001878 * @dev: class converted to a Scsi_host structure.
1879 * @attr: device attribute, not used.
1880 * @buf: on return contains the dev loss timeout in decimal.
1881 *
1882 * Returns: size of formatted string.
1883 **/
James Smartc01f3202006-08-18 17:47:08 -04001884static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001885lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1886 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001887{
Tony Jonesee959b02008-02-22 00:13:36 +01001888 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001889 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001890 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001891 val = vport->cfg_devloss_tmo;
1892 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001893}
1894
James Smarte59058c2008-08-24 21:49:00 -04001895/**
James Smart3621a712009-04-06 18:47:14 -04001896 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04001897 * @vport: lpfc vport structure pointer.
1898 * @val: contains the nodev timeout value.
1899 *
1900 * Description:
1901 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1902 * a kernel error message is printed and zero is returned.
1903 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1904 * Otherwise nodev tmo is set to the default value.
1905 *
1906 * Returns:
1907 * zero if already set or if val is in range
1908 * -EINVAL val out of range
1909 **/
James Smartc01f3202006-08-18 17:47:08 -04001910static int
James Smart3de2a652007-08-02 11:09:59 -04001911lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001912{
James Smart3de2a652007-08-02 11:09:59 -04001913 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1914 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1915 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001916 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001917 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001918 "parameter because devloss_tmo is "
1919 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001920 return 0;
1921 }
1922
1923 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001924 vport->cfg_nodev_tmo = val;
1925 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001926 return 0;
1927 }
James Smarte8b62012007-08-02 11:10:09 -04001928 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1929 "0400 lpfc_nodev_tmo attribute cannot be set to"
1930 " %d, allowed range is [%d, %d]\n",
1931 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001932 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001933 return -EINVAL;
1934}
1935
James Smarte59058c2008-08-24 21:49:00 -04001936/**
James Smart3621a712009-04-06 18:47:14 -04001937 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04001938 * @vport: lpfc vport structure pointer.
1939 *
1940 * Description:
1941 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1942 **/
James Smart7054a602007-04-25 09:52:34 -04001943static void
James Smart3de2a652007-08-02 11:09:59 -04001944lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001945{
James Smart858c9f62007-06-17 19:56:39 -05001946 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001947 struct lpfc_nodelist *ndlp;
1948
James Smart51ef4c22007-08-02 11:10:31 -04001949 shost = lpfc_shost_from_vport(vport);
1950 spin_lock_irq(shost->host_lock);
1951 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001952 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001953 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1954 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001955}
1956
James Smarte59058c2008-08-24 21:49:00 -04001957/**
James Smart3621a712009-04-06 18:47:14 -04001958 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04001959 * @vport: lpfc vport structure pointer.
1960 * @val: contains the tmo value.
1961 *
1962 * Description:
1963 * If the devloss tmo is already set or the vport dev loss tmo has changed
1964 * then a kernel error message is printed and zero is returned.
1965 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1966 * Otherwise nodev tmo is set to the default value.
1967 *
1968 * Returns:
1969 * zero if already set or if val is in range
1970 * -EINVAL val out of range
1971 **/
James Smartc01f3202006-08-18 17:47:08 -04001972static int
James Smart3de2a652007-08-02 11:09:59 -04001973lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001974{
James Smart3de2a652007-08-02 11:09:59 -04001975 if (vport->dev_loss_tmo_changed ||
1976 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001977 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1978 "0401 Ignoring change to nodev_tmo "
1979 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001980 return 0;
1981 }
James Smartc01f3202006-08-18 17:47:08 -04001982 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001983 vport->cfg_nodev_tmo = val;
1984 vport->cfg_devloss_tmo = val;
1985 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001986 return 0;
1987 }
James Smarte8b62012007-08-02 11:10:09 -04001988 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1989 "0403 lpfc_nodev_tmo attribute cannot be set to"
1990 "%d, allowed range is [%d, %d]\n",
1991 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001992 return -EINVAL;
1993}
1994
James Smart3de2a652007-08-02 11:09:59 -04001995lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001996
Tony Jonesee959b02008-02-22 00:13:36 +01001997static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1998 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001999
2000/*
2001# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2002# disappear until the timer expires. Value range is [0,255]. Default
2003# value is 30.
2004*/
2005module_param(lpfc_devloss_tmo, int, 0);
2006MODULE_PARM_DESC(lpfc_devloss_tmo,
2007 "Seconds driver will hold I/O waiting "
2008 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002009lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2010 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2011lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002012
2013/**
James Smart3621a712009-04-06 18:47:14 -04002014 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002015 * @vport: lpfc vport structure pointer.
2016 * @val: contains the tmo value.
2017 *
2018 * Description:
2019 * If val is in a valid range then set the vport nodev tmo,
2020 * devloss tmo, also set the vport dev loss tmo changed flag.
2021 * Else a kernel error message is printed.
2022 *
2023 * Returns:
2024 * zero if val is in range
2025 * -EINVAL val out of range
2026 **/
James Smartc01f3202006-08-18 17:47:08 -04002027static int
James Smart3de2a652007-08-02 11:09:59 -04002028lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002029{
2030 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002031 vport->cfg_nodev_tmo = val;
2032 vport->cfg_devloss_tmo = val;
2033 vport->dev_loss_tmo_changed = 1;
2034 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002035 return 0;
2036 }
2037
James Smarte8b62012007-08-02 11:10:09 -04002038 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2039 "0404 lpfc_devloss_tmo attribute cannot be set to"
2040 " %d, allowed range is [%d, %d]\n",
2041 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002042 return -EINVAL;
2043}
2044
James Smart3de2a652007-08-02 11:09:59 -04002045lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002046static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2047 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002048
2049/*
dea31012005-04-17 16:05:31 -05002050# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2051# deluged with LOTS of information.
2052# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002053# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002054*/
James Smartf4b4c682009-05-22 14:53:12 -04002055LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002056 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002057
2058/*
James Smart7ee5d432007-10-27 13:37:17 -04002059# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2060# objects that have been registered with the nameserver after login.
2061*/
2062LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2063 "Deregister nameserver objects before LOGO");
2064
2065/*
dea31012005-04-17 16:05:31 -05002066# lun_queue_depth: This parameter is used to limit the number of outstanding
2067# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2068*/
James Smart3de2a652007-08-02 11:09:59 -04002069LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2070 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002071
2072/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002073# hba_queue_depth: This parameter is used to limit the number of outstanding
2074# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2075# value is greater than the maximum number of exchanges supported by the HBA,
2076# then maximum number of exchanges supported by the HBA is used to determine
2077# the hba_queue_depth.
2078*/
2079LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2080 "Max number of FCP commands we can queue to a lpfc HBA");
2081
2082/*
James Smart92d7f7b2007-06-17 19:56:38 -05002083# peer_port_login: This parameter allows/prevents logins
2084# between peer ports hosted on the same physical port.
2085# When this parameter is set 0 peer ports of same physical port
2086# are not allowed to login to each other.
2087# When this parameter is set 1 peer ports of same physical port
2088# are allowed to login to each other.
2089# Default value of this parameter is 0.
2090*/
James Smart3de2a652007-08-02 11:09:59 -04002091LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2092 "Allow peer ports on the same physical port to login to each "
2093 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002094
2095/*
James Smart3de2a652007-08-02 11:09:59 -04002096# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002097# between Virtual Ports and remote initiators.
2098# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2099# other initiators and will attempt to PLOGI all remote ports.
2100# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2101# remote ports and will not attempt to PLOGI to other initiators.
2102# This parameter does not restrict to the physical port.
2103# This parameter does not restrict logins to Fabric resident remote ports.
2104# Default value of this parameter is 1.
2105*/
James Smart3de2a652007-08-02 11:09:59 -04002106static int lpfc_restrict_login = 1;
2107module_param(lpfc_restrict_login, int, 0);
2108MODULE_PARM_DESC(lpfc_restrict_login,
2109 "Restrict virtual ports login to remote initiators.");
2110lpfc_vport_param_show(restrict_login);
2111
James Smarte59058c2008-08-24 21:49:00 -04002112/**
James Smart3621a712009-04-06 18:47:14 -04002113 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002114 * @vport: lpfc vport structure pointer.
2115 * @val: contains the restrict login value.
2116 *
2117 * Description:
2118 * If val is not in a valid range then log a kernel error message and set
2119 * the vport restrict login to one.
2120 * If the port type is physical clear the restrict login flag and return.
2121 * Else set the restrict login flag to val.
2122 *
2123 * Returns:
2124 * zero if val is in range
2125 * -EINVAL val out of range
2126 **/
James Smart3de2a652007-08-02 11:09:59 -04002127static int
2128lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2129{
2130 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002131 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002132 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002133 "be set to %d, allowed range is [0, 1]\n",
2134 val);
James Smart3de2a652007-08-02 11:09:59 -04002135 vport->cfg_restrict_login = 1;
2136 return -EINVAL;
2137 }
2138 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2139 vport->cfg_restrict_login = 0;
2140 return 0;
2141 }
2142 vport->cfg_restrict_login = val;
2143 return 0;
2144}
2145
James Smarte59058c2008-08-24 21:49:00 -04002146/**
James Smart3621a712009-04-06 18:47:14 -04002147 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002148 * @vport: lpfc vport structure pointer.
2149 * @val: contains the restrict login value.
2150 *
2151 * Description:
2152 * If val is not in a valid range then log a kernel error message and set
2153 * the vport restrict login to one.
2154 * If the port type is physical and the val is not zero log a kernel
2155 * error message, clear the restrict login flag and return zero.
2156 * Else set the restrict login flag to val.
2157 *
2158 * Returns:
2159 * zero if val is in range
2160 * -EINVAL val out of range
2161 **/
James Smart3de2a652007-08-02 11:09:59 -04002162static int
2163lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2164{
2165 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002166 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002167 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002168 "be set to %d, allowed range is [0, 1]\n",
2169 val);
James Smart3de2a652007-08-02 11:09:59 -04002170 vport->cfg_restrict_login = 1;
2171 return -EINVAL;
2172 }
2173 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002174 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2175 "0468 lpfc_restrict_login must be 0 for "
2176 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002177 vport->cfg_restrict_login = 0;
2178 return 0;
2179 }
2180 vport->cfg_restrict_login = val;
2181 return 0;
2182}
2183lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002184static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2185 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002186
2187/*
dea31012005-04-17 16:05:31 -05002188# Some disk devices have a "select ID" or "select Target" capability.
2189# From a protocol standpoint "select ID" usually means select the
2190# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2191# annex" which contains a table that maps a "select ID" (a number
2192# between 0 and 7F) to an ALPA. By default, for compatibility with
2193# older drivers, the lpfc driver scans this table from low ALPA to high
2194# ALPA.
2195#
2196# Turning on the scan-down variable (on = 1, off = 0) will
2197# cause the lpfc driver to use an inverted table, effectively
2198# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2199#
2200# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2201# and will not work across a fabric. Also this parameter will take
2202# effect only in the case when ALPA map is not available.)
2203*/
James Smart3de2a652007-08-02 11:09:59 -04002204LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2205 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002206
2207/*
dea31012005-04-17 16:05:31 -05002208# lpfc_topology: link topology for init link
2209# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002210# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002211# 0x02 = attempt point-to-point mode only
2212# 0x04 = attempt loop mode only
2213# 0x06 = attempt point-to-point mode then loop
2214# Set point-to-point mode if you want to run as an N_Port.
2215# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2216# Default value is 0.
2217*/
James Smarte59058c2008-08-24 21:49:00 -04002218
2219/**
James Smart3621a712009-04-06 18:47:14 -04002220 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002221 * @phba: lpfc_hba pointer.
2222 * @val: topology value.
2223 *
2224 * Description:
2225 * If val is in a valid range then set the adapter's topology field and
2226 * issue a lip; if the lip fails reset the topology to the old value.
2227 *
2228 * If the value is not in range log a kernel error message and return an error.
2229 *
2230 * Returns:
2231 * zero if val is in range and lip okay
2232 * non-zero return value from lpfc_issue_lip()
2233 * -EINVAL val out of range
2234 **/
James Smarta257bf92009-04-06 18:48:10 -04002235static ssize_t
2236lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2237 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002238{
James Smarta257bf92009-04-06 18:48:10 -04002239 struct Scsi_Host *shost = class_to_shost(dev);
2240 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2241 struct lpfc_hba *phba = vport->phba;
2242 int val = 0;
2243 int nolip = 0;
2244 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002245 int err;
2246 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002247
2248 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2249 nolip = 1;
2250 val_buf = &buf[strlen("nolip ")];
2251 }
2252
2253 if (!isdigit(val_buf[0]))
2254 return -EINVAL;
2255 if (sscanf(val_buf, "%i", &val) != 1)
2256 return -EINVAL;
2257
James Smart83108bd2008-01-11 01:53:09 -05002258 if (val >= 0 && val <= 6) {
2259 prev_val = phba->cfg_topology;
2260 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002261 if (nolip)
2262 return strlen(buf);
2263
James Smart83108bd2008-01-11 01:53:09 -05002264 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002265 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002266 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002267 return -EINVAL;
2268 } else
2269 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002270 }
2271 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2272 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2273 "allowed range is [0, 6]\n",
2274 phba->brd_no, val);
2275 return -EINVAL;
2276}
2277static int lpfc_topology = 0;
2278module_param(lpfc_topology, int, 0);
2279MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2280lpfc_param_show(topology)
2281lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002282static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002283 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002284
James Smart21e9a0a2009-05-22 14:53:21 -04002285/**
2286 * lpfc_static_vport_show: Read callback function for
2287 * lpfc_static_vport sysfs file.
2288 * @dev: Pointer to class device object.
2289 * @attr: device attribute structure.
2290 * @buf: Data buffer.
2291 *
2292 * This function is the read call back function for
2293 * lpfc_static_vport sysfs file. The lpfc_static_vport
2294 * sysfs file report the mageability of the vport.
2295 **/
2296static ssize_t
2297lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2298 char *buf)
2299{
2300 struct Scsi_Host *shost = class_to_shost(dev);
2301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2302 if (vport->vport_flag & STATIC_VPORT)
2303 sprintf(buf, "1\n");
2304 else
2305 sprintf(buf, "0\n");
2306
2307 return strlen(buf);
2308}
2309
2310/*
2311 * Sysfs attribute to control the statistical data collection.
2312 */
2313static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2314 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002315
2316/**
James Smart3621a712009-04-06 18:47:14 -04002317 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002318 * @dev: Pointer to class device.
2319 * @buf: Data buffer.
2320 * @count: Size of the data buffer.
2321 *
2322 * This function get called when an user write to the lpfc_stat_data_ctrl
2323 * sysfs file. This function parse the command written to the sysfs file
2324 * and take appropriate action. These commands are used for controlling
2325 * driver statistical data collection.
2326 * Following are the command this function handles.
2327 *
2328 * setbucket <bucket_type> <base> <step>
2329 * = Set the latency buckets.
2330 * destroybucket = destroy all the buckets.
2331 * start = start data collection
2332 * stop = stop data collection
2333 * reset = reset the collected data
2334 **/
2335static ssize_t
2336lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2337 const char *buf, size_t count)
2338{
2339 struct Scsi_Host *shost = class_to_shost(dev);
2340 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2341 struct lpfc_hba *phba = vport->phba;
2342#define LPFC_MAX_DATA_CTRL_LEN 1024
2343 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2344 unsigned long i;
2345 char *str_ptr, *token;
2346 struct lpfc_vport **vports;
2347 struct Scsi_Host *v_shost;
2348 char *bucket_type_str, *base_str, *step_str;
2349 unsigned long base, step, bucket_type;
2350
2351 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002352 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002353 return -EINVAL;
2354
2355 strcpy(bucket_data, buf);
2356 str_ptr = &bucket_data[0];
2357 /* Ignore this token - this is command token */
2358 token = strsep(&str_ptr, "\t ");
2359 if (!token)
2360 return -EINVAL;
2361
2362 bucket_type_str = strsep(&str_ptr, "\t ");
2363 if (!bucket_type_str)
2364 return -EINVAL;
2365
2366 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2367 bucket_type = LPFC_LINEAR_BUCKET;
2368 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2369 bucket_type = LPFC_POWER2_BUCKET;
2370 else
2371 return -EINVAL;
2372
2373 base_str = strsep(&str_ptr, "\t ");
2374 if (!base_str)
2375 return -EINVAL;
2376 base = simple_strtoul(base_str, NULL, 0);
2377
2378 step_str = strsep(&str_ptr, "\t ");
2379 if (!step_str)
2380 return -EINVAL;
2381 step = simple_strtoul(step_str, NULL, 0);
2382 if (!step)
2383 return -EINVAL;
2384
2385 /* Block the data collection for every vport */
2386 vports = lpfc_create_vport_work_array(phba);
2387 if (vports == NULL)
2388 return -ENOMEM;
2389
James Smartf4b4c682009-05-22 14:53:12 -04002390 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002391 v_shost = lpfc_shost_from_vport(vports[i]);
2392 spin_lock_irq(v_shost->host_lock);
2393 /* Block and reset data collection */
2394 vports[i]->stat_data_blocked = 1;
2395 if (vports[i]->stat_data_enabled)
2396 lpfc_vport_reset_stat_data(vports[i]);
2397 spin_unlock_irq(v_shost->host_lock);
2398 }
2399
2400 /* Set the bucket attributes */
2401 phba->bucket_type = bucket_type;
2402 phba->bucket_base = base;
2403 phba->bucket_step = step;
2404
James Smartf4b4c682009-05-22 14:53:12 -04002405 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002406 v_shost = lpfc_shost_from_vport(vports[i]);
2407
2408 /* Unblock data collection */
2409 spin_lock_irq(v_shost->host_lock);
2410 vports[i]->stat_data_blocked = 0;
2411 spin_unlock_irq(v_shost->host_lock);
2412 }
2413 lpfc_destroy_vport_work_array(phba, vports);
2414 return strlen(buf);
2415 }
2416
2417 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2418 vports = lpfc_create_vport_work_array(phba);
2419 if (vports == NULL)
2420 return -ENOMEM;
2421
James Smartf4b4c682009-05-22 14:53:12 -04002422 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002423 v_shost = lpfc_shost_from_vport(vports[i]);
2424 spin_lock_irq(shost->host_lock);
2425 vports[i]->stat_data_blocked = 1;
2426 lpfc_free_bucket(vport);
2427 vport->stat_data_enabled = 0;
2428 vports[i]->stat_data_blocked = 0;
2429 spin_unlock_irq(shost->host_lock);
2430 }
2431 lpfc_destroy_vport_work_array(phba, vports);
2432 phba->bucket_type = LPFC_NO_BUCKET;
2433 phba->bucket_base = 0;
2434 phba->bucket_step = 0;
2435 return strlen(buf);
2436 }
2437
2438 if (!strncmp(buf, "start", strlen("start"))) {
2439 /* If no buckets configured return error */
2440 if (phba->bucket_type == LPFC_NO_BUCKET)
2441 return -EINVAL;
2442 spin_lock_irq(shost->host_lock);
2443 if (vport->stat_data_enabled) {
2444 spin_unlock_irq(shost->host_lock);
2445 return strlen(buf);
2446 }
2447 lpfc_alloc_bucket(vport);
2448 vport->stat_data_enabled = 1;
2449 spin_unlock_irq(shost->host_lock);
2450 return strlen(buf);
2451 }
2452
2453 if (!strncmp(buf, "stop", strlen("stop"))) {
2454 spin_lock_irq(shost->host_lock);
2455 if (vport->stat_data_enabled == 0) {
2456 spin_unlock_irq(shost->host_lock);
2457 return strlen(buf);
2458 }
2459 lpfc_free_bucket(vport);
2460 vport->stat_data_enabled = 0;
2461 spin_unlock_irq(shost->host_lock);
2462 return strlen(buf);
2463 }
2464
2465 if (!strncmp(buf, "reset", strlen("reset"))) {
2466 if ((phba->bucket_type == LPFC_NO_BUCKET)
2467 || !vport->stat_data_enabled)
2468 return strlen(buf);
2469 spin_lock_irq(shost->host_lock);
2470 vport->stat_data_blocked = 1;
2471 lpfc_vport_reset_stat_data(vport);
2472 vport->stat_data_blocked = 0;
2473 spin_unlock_irq(shost->host_lock);
2474 return strlen(buf);
2475 }
2476 return -EINVAL;
2477}
2478
2479
2480/**
James Smart3621a712009-04-06 18:47:14 -04002481 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002482 * @dev: Pointer to class device object.
2483 * @buf: Data buffer.
2484 *
2485 * This function is the read call back function for
2486 * lpfc_stat_data_ctrl sysfs file. This function report the
2487 * current statistical data collection state.
2488 **/
2489static ssize_t
2490lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2491 char *buf)
2492{
2493 struct Scsi_Host *shost = class_to_shost(dev);
2494 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2495 struct lpfc_hba *phba = vport->phba;
2496 int index = 0;
2497 int i;
2498 char *bucket_type;
2499 unsigned long bucket_value;
2500
2501 switch (phba->bucket_type) {
2502 case LPFC_LINEAR_BUCKET:
2503 bucket_type = "linear";
2504 break;
2505 case LPFC_POWER2_BUCKET:
2506 bucket_type = "power2";
2507 break;
2508 default:
2509 bucket_type = "No Bucket";
2510 break;
2511 }
2512
2513 sprintf(&buf[index], "Statistical Data enabled :%d, "
2514 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2515 " Bucket step :%d\nLatency Ranges :",
2516 vport->stat_data_enabled, vport->stat_data_blocked,
2517 bucket_type, phba->bucket_base, phba->bucket_step);
2518 index = strlen(buf);
2519 if (phba->bucket_type != LPFC_NO_BUCKET) {
2520 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2521 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2522 bucket_value = phba->bucket_base +
2523 phba->bucket_step * i;
2524 else
2525 bucket_value = phba->bucket_base +
2526 (1 << i) * phba->bucket_step;
2527
2528 if (index + 10 > PAGE_SIZE)
2529 break;
2530 sprintf(&buf[index], "%08ld ", bucket_value);
2531 index = strlen(buf);
2532 }
2533 }
2534 sprintf(&buf[index], "\n");
2535 return strlen(buf);
2536}
2537
2538/*
2539 * Sysfs attribute to control the statistical data collection.
2540 */
2541static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2542 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2543
2544/*
2545 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2546 */
2547
2548/*
2549 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2550 * for each target.
2551 */
2552#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2553#define MAX_STAT_DATA_SIZE_PER_TARGET \
2554 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2555
2556
2557/**
James Smart3621a712009-04-06 18:47:14 -04002558 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
James Smartea2151b2008-09-07 11:52:10 -04002559 * @kobj: Pointer to the kernel object
2560 * @bin_attr: Attribute object
2561 * @buff: Buffer pointer
2562 * @off: File offset
2563 * @count: Buffer size
2564 *
2565 * This function is the read call back function for lpfc_drvr_stat_data
2566 * sysfs file. This function export the statistical data to user
2567 * applications.
2568 **/
2569static ssize_t
2570sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2571 char *buf, loff_t off, size_t count)
2572{
2573 struct device *dev = container_of(kobj, struct device,
2574 kobj);
2575 struct Scsi_Host *shost = class_to_shost(dev);
2576 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2577 struct lpfc_hba *phba = vport->phba;
2578 int i = 0, index = 0;
2579 unsigned long nport_index;
2580 struct lpfc_nodelist *ndlp = NULL;
2581 nport_index = (unsigned long)off /
2582 MAX_STAT_DATA_SIZE_PER_TARGET;
2583
2584 if (!vport->stat_data_enabled || vport->stat_data_blocked
2585 || (phba->bucket_type == LPFC_NO_BUCKET))
2586 return 0;
2587
2588 spin_lock_irq(shost->host_lock);
2589 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2590 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2591 continue;
2592
2593 if (nport_index > 0) {
2594 nport_index--;
2595 continue;
2596 }
2597
2598 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2599 > count)
2600 break;
2601
2602 if (!ndlp->lat_data)
2603 continue;
2604
2605 /* Print the WWN */
2606 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2607 ndlp->nlp_portname.u.wwn[0],
2608 ndlp->nlp_portname.u.wwn[1],
2609 ndlp->nlp_portname.u.wwn[2],
2610 ndlp->nlp_portname.u.wwn[3],
2611 ndlp->nlp_portname.u.wwn[4],
2612 ndlp->nlp_portname.u.wwn[5],
2613 ndlp->nlp_portname.u.wwn[6],
2614 ndlp->nlp_portname.u.wwn[7]);
2615
2616 index = strlen(buf);
2617
2618 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2619 sprintf(&buf[index], "%010u,",
2620 ndlp->lat_data[i].cmd_count);
2621 index = strlen(buf);
2622 }
2623 sprintf(&buf[index], "\n");
2624 index = strlen(buf);
2625 }
2626 spin_unlock_irq(shost->host_lock);
2627 return index;
2628}
2629
2630static struct bin_attribute sysfs_drvr_stat_data_attr = {
2631 .attr = {
2632 .name = "lpfc_drvr_stat_data",
2633 .mode = S_IRUSR,
2634 .owner = THIS_MODULE,
2635 },
2636 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2637 .read = sysfs_drvr_stat_data_read,
2638 .write = NULL,
2639};
2640
dea31012005-04-17 16:05:31 -05002641/*
2642# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2643# connection.
2644# 0 = auto select (default)
2645# 1 = 1 Gigabaud
2646# 2 = 2 Gigabaud
2647# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002648# 8 = 8 Gigabaud
2649# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002650*/
James Smarte59058c2008-08-24 21:49:00 -04002651
2652/**
James Smart3621a712009-04-06 18:47:14 -04002653 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002654 * @phba: lpfc_hba pointer.
2655 * @val: link speed value.
2656 *
2657 * Description:
2658 * If val is in a valid range then set the adapter's link speed field and
2659 * issue a lip; if the lip fails reset the link speed to the old value.
2660 *
2661 * Notes:
2662 * If the value is not in range log a kernel error message and return an error.
2663 *
2664 * Returns:
2665 * zero if val is in range and lip okay.
2666 * non-zero return value from lpfc_issue_lip()
2667 * -EINVAL val out of range
2668 **/
James Smarta257bf92009-04-06 18:48:10 -04002669static ssize_t
2670lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2671 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002672{
James Smarta257bf92009-04-06 18:48:10 -04002673 struct Scsi_Host *shost = class_to_shost(dev);
2674 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2675 struct lpfc_hba *phba = vport->phba;
2676 int val = 0;
2677 int nolip = 0;
2678 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002679 int err;
2680 uint32_t prev_val;
2681
James Smarta257bf92009-04-06 18:48:10 -04002682 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2683 nolip = 1;
2684 val_buf = &buf[strlen("nolip ")];
2685 }
2686
2687 if (!isdigit(val_buf[0]))
2688 return -EINVAL;
2689 if (sscanf(val_buf, "%i", &val) != 1)
2690 return -EINVAL;
2691
James Smart83108bd2008-01-11 01:53:09 -05002692 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2693 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2694 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2695 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2696 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2697 return -EINVAL;
2698
James Smarta257bf92009-04-06 18:48:10 -04002699 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002700 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2701 prev_val = phba->cfg_link_speed;
2702 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002703 if (nolip)
2704 return strlen(buf);
2705
James Smart83108bd2008-01-11 01:53:09 -05002706 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002707 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002708 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002709 return -EINVAL;
2710 } else
2711 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002712 }
2713
2714 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2715 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2716 "allowed range is [0, 8]\n",
2717 phba->brd_no, val);
2718 return -EINVAL;
2719}
2720
2721static int lpfc_link_speed = 0;
2722module_param(lpfc_link_speed, int, 0);
2723MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2724lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002725
2726/**
James Smart3621a712009-04-06 18:47:14 -04002727 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002728 * @phba: lpfc_hba pointer.
2729 * @val: link speed value.
2730 *
2731 * Description:
2732 * If val is in a valid range then set the adapter's link speed field.
2733 *
2734 * Notes:
2735 * If the value is not in range log a kernel error message, clear the link
2736 * speed and return an error.
2737 *
2738 * Returns:
2739 * zero if val saved.
2740 * -EINVAL val out of range
2741 **/
James Smart83108bd2008-01-11 01:53:09 -05002742static int
2743lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2744{
2745 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2746 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2747 phba->cfg_link_speed = val;
2748 return 0;
2749 }
2750 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002751 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002752 "be set to %d, allowed values are "
2753 "["LPFC_LINK_SPEED_STRING"]\n", val);
2754 phba->cfg_link_speed = 0;
2755 return -EINVAL;
2756}
2757
Tony Jonesee959b02008-02-22 00:13:36 +01002758static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002759 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002760
2761/*
2762# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2763# Value range is [2,3]. Default value is 3.
2764*/
James Smart3de2a652007-08-02 11:09:59 -04002765LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2766 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002767
2768/*
2769# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2770# is [0,1]. Default value is 0.
2771*/
James Smart3de2a652007-08-02 11:09:59 -04002772LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2773 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002774
2775/*
James Smart977b5a02008-09-07 11:52:04 -04002776# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2777# depth. Default value is 0. When the value of this parameter is zero the
2778# SCSI command completion time is not used for controlling I/O queue depth. When
2779# the parameter is set to a non-zero value, the I/O queue depth is controlled
2780# to limit the I/O completion time to the parameter value.
2781# The value is set in milliseconds.
2782*/
2783static int lpfc_max_scsicmpl_time;
2784module_param(lpfc_max_scsicmpl_time, int, 0);
2785MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2786 "Use command completion time to control queue depth");
2787lpfc_vport_param_show(max_scsicmpl_time);
2788lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2789static int
2790lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2791{
2792 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2793 struct lpfc_nodelist *ndlp, *next_ndlp;
2794
2795 if (val == vport->cfg_max_scsicmpl_time)
2796 return 0;
2797 if ((val < 0) || (val > 60000))
2798 return -EINVAL;
2799 vport->cfg_max_scsicmpl_time = val;
2800
2801 spin_lock_irq(shost->host_lock);
2802 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2803 if (!NLP_CHK_NODE_ACT(ndlp))
2804 continue;
2805 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2806 continue;
2807 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2808 }
2809 spin_unlock_irq(shost->host_lock);
2810 return 0;
2811}
2812lpfc_vport_param_store(max_scsicmpl_time);
2813static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2814 lpfc_max_scsicmpl_time_show,
2815 lpfc_max_scsicmpl_time_store);
2816
2817/*
dea31012005-04-17 16:05:31 -05002818# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2819# range is [0,1]. Default value is 0.
2820*/
2821LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2822
2823/*
2824# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2825# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04002826# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05002827# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2828# cr_delay is set to 0.
2829*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002830LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05002831 "interrupt response is generated");
2832
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002833LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05002834 "interrupt response is generated");
2835
2836/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002837# lpfc_multi_ring_support: Determines how many rings to spread available
2838# cmd/rsp IOCB entries across.
2839# Value range is [1,2]. Default value is 1.
2840*/
2841LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2842 "SLI rings to spread IOCB entries across");
2843
2844/*
James Smarta4bc3372006-12-02 13:34:16 -05002845# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2846# identifies what rctl value to configure the additional ring for.
2847# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2848*/
2849LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2850 255, "Identifies RCTL for additional ring configuration");
2851
2852/*
2853# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2854# identifies what type value to configure the additional ring for.
2855# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2856*/
2857LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2858 255, "Identifies TYPE for additional ring configuration");
2859
2860/*
dea31012005-04-17 16:05:31 -05002861# lpfc_fdmi_on: controls FDMI support.
2862# 0 = no FDMI support
2863# 1 = support FDMI without attribute of hostname
2864# 2 = support FDMI with attribute of hostname
2865# Value range [0,2]. Default value is 0.
2866*/
James Smart3de2a652007-08-02 11:09:59 -04002867LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05002868
2869/*
2870# Specifies the maximum number of ELS cmds we can have outstanding (for
2871# discovery). Value range is [1,64]. Default value = 32.
2872*/
James Smart3de2a652007-08-02 11:09:59 -04002873LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05002874 "during discovery");
2875
2876/*
James Smart65a29c12006-07-06 15:50:50 -04002877# lpfc_max_luns: maximum allowed LUN.
2878# Value range is [0,65535]. Default value is 255.
2879# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05002880*/
James Smart3de2a652007-08-02 11:09:59 -04002881LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05002882
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002883/*
2884# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2885# Value range is [1,255], default value is 10.
2886*/
2887LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2888 "Milliseconds driver will wait between polling FCP ring");
2889
James Smart4ff43242006-12-02 13:34:56 -05002890/*
2891# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2892# support this feature
James Smartda0436e2009-05-22 14:51:39 -04002893# 0 = MSI disabled (default)
James Smart4ff43242006-12-02 13:34:56 -05002894# 1 = MSI enabled
James Smartda0436e2009-05-22 14:51:39 -04002895# 2 = MSI-X enabled
2896# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05002897*/
James Smartda0436e2009-05-22 14:51:39 -04002898LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05002899 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05002900
James Smart13815c82008-01-11 01:52:48 -05002901/*
James Smartda0436e2009-05-22 14:51:39 -04002902# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
2903#
2904# Value range is [636,651042]. Default value is 10000.
2905*/
2906LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
2907 "Set the maximum number of fast-path FCP interrupts per second");
2908
2909/*
2910# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
2911#
2912# Value range is [1,31]. Default value is 4.
2913*/
2914LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
2915 "Set the number of fast-path FCP work queues, if possible");
2916
2917/*
2918# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
2919#
2920# Value range is [1,7]. Default value is 1.
2921*/
2922LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
2923 "Set the number of fast-path FCP event queues, if possible");
2924
2925/*
James Smart13815c82008-01-11 01:52:48 -05002926# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2927# 0 = HBA resets disabled
2928# 1 = HBA resets enabled (default)
2929# Value range is [0,1]. Default value is 1.
2930*/
2931LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04002932
James Smart13815c82008-01-11 01:52:48 -05002933/*
2934# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2935# 0 = HBA Heartbeat disabled
2936# 1 = HBA Heartbeat enabled (default)
2937# Value range is [0,1]. Default value is 1.
2938*/
2939LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05002940
James Smart83108bd2008-01-11 01:53:09 -05002941/*
James Smart81301a92008-12-04 22:39:46 -05002942# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
2943# 0 = BlockGuard disabled (default)
2944# 1 = BlockGuard enabled
2945# Value range is [0,1]. Default value is 0.
2946*/
2947LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
2948
James Smart6fb120a2009-05-22 14:52:59 -04002949/*
2950# lpfc_enable_fip: When set, FIP is required to start discovery. If not
2951# set, the driver will add an FCF record manually if the port has no
2952# FCF records available and start discovery.
2953# Value range is [0,1]. Default value is 1 (enabled)
2954*/
2955LPFC_ATTR_RW(enable_fip, 0, 0, 1, "Enable FIP Discovery");
2956
James Smart81301a92008-12-04 22:39:46 -05002957
2958/*
2959# lpfc_prot_mask: i
2960# - Bit mask of host protection capabilities used to register with the
2961# SCSI mid-layer
2962# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
2963# - Allows you to ultimately specify which profiles to use
2964# - Default will result in registering capabilities for all profiles.
2965#
2966*/
2967unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
2968
2969module_param(lpfc_prot_mask, uint, 0);
2970MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
2971
2972/*
2973# lpfc_prot_guard: i
2974# - Bit mask of protection guard types to register with the SCSI mid-layer
2975# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
2976# - Allows you to ultimately specify which profiles to use
2977# - Default will result in registering capabilities for all guard types
2978#
2979*/
2980unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
2981module_param(lpfc_prot_guard, byte, 0);
2982MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
2983
2984
2985/*
James Smart3621a712009-04-06 18:47:14 -04002986 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05002987 * This value can be set to values between 64 and 256. The default value is
2988 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2989 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2990 */
2991LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2992 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2993
James Smart81301a92008-12-04 22:39:46 -05002994LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
2995 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
2996 "Max Protection Scatter Gather Segment Count");
2997
Tony Jonesee959b02008-02-22 00:13:36 +01002998struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05002999 &dev_attr_bg_info,
3000 &dev_attr_bg_guard_err,
3001 &dev_attr_bg_apptag_err,
3002 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003003 &dev_attr_info,
3004 &dev_attr_serialnum,
3005 &dev_attr_modeldesc,
3006 &dev_attr_modelname,
3007 &dev_attr_programtype,
3008 &dev_attr_portnum,
3009 &dev_attr_fwrev,
3010 &dev_attr_hdw,
3011 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003012 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003013 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003014 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003015 &dev_attr_lpfc_drvr_version,
3016 &dev_attr_lpfc_temp_sensor,
3017 &dev_attr_lpfc_log_verbose,
3018 &dev_attr_lpfc_lun_queue_depth,
3019 &dev_attr_lpfc_hba_queue_depth,
3020 &dev_attr_lpfc_peer_port_login,
3021 &dev_attr_lpfc_nodev_tmo,
3022 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04003023 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003024 &dev_attr_lpfc_fcp_class,
3025 &dev_attr_lpfc_use_adisc,
3026 &dev_attr_lpfc_ack0,
3027 &dev_attr_lpfc_topology,
3028 &dev_attr_lpfc_scan_down,
3029 &dev_attr_lpfc_link_speed,
3030 &dev_attr_lpfc_cr_delay,
3031 &dev_attr_lpfc_cr_count,
3032 &dev_attr_lpfc_multi_ring_support,
3033 &dev_attr_lpfc_multi_ring_rctl,
3034 &dev_attr_lpfc_multi_ring_type,
3035 &dev_attr_lpfc_fdmi_on,
3036 &dev_attr_lpfc_max_luns,
3037 &dev_attr_lpfc_enable_npiv,
3038 &dev_attr_nport_evt_cnt,
3039 &dev_attr_board_mode,
3040 &dev_attr_max_vpi,
3041 &dev_attr_used_vpi,
3042 &dev_attr_max_rpi,
3043 &dev_attr_used_rpi,
3044 &dev_attr_max_xri,
3045 &dev_attr_used_xri,
3046 &dev_attr_npiv_info,
3047 &dev_attr_issue_reset,
3048 &dev_attr_lpfc_poll,
3049 &dev_attr_lpfc_poll_tmo,
3050 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003051 &dev_attr_lpfc_fcp_imax,
3052 &dev_attr_lpfc_fcp_wq_count,
3053 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003054 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003055 &dev_attr_lpfc_soft_wwnn,
3056 &dev_attr_lpfc_soft_wwpn,
3057 &dev_attr_lpfc_soft_wwn_enable,
3058 &dev_attr_lpfc_enable_hba_reset,
3059 &dev_attr_lpfc_enable_hba_heartbeat,
3060 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003061 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003062 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003063 &dev_attr_lpfc_prot_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05003064 NULL,
3065};
3066
Tony Jonesee959b02008-02-22 00:13:36 +01003067struct device_attribute *lpfc_vport_attrs[] = {
3068 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003069 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003070 &dev_attr_num_discovered_ports,
3071 &dev_attr_lpfc_drvr_version,
3072 &dev_attr_lpfc_log_verbose,
3073 &dev_attr_lpfc_lun_queue_depth,
3074 &dev_attr_lpfc_nodev_tmo,
3075 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04003076 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003077 &dev_attr_lpfc_hba_queue_depth,
3078 &dev_attr_lpfc_peer_port_login,
3079 &dev_attr_lpfc_restrict_login,
3080 &dev_attr_lpfc_fcp_class,
3081 &dev_attr_lpfc_use_adisc,
3082 &dev_attr_lpfc_fdmi_on,
3083 &dev_attr_lpfc_max_luns,
3084 &dev_attr_nport_evt_cnt,
3085 &dev_attr_npiv_info,
3086 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003087 &dev_attr_lpfc_max_scsicmpl_time,
3088 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003089 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003090 NULL,
3091};
3092
James Smarte59058c2008-08-24 21:49:00 -04003093/**
James Smart3621a712009-04-06 18:47:14 -04003094 * sysfs_ctlreg_write - Write method for writing to ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003095 * @kobj: kernel kobject that contains the kernel class device.
3096 * @bin_attr: kernel attributes passed to us.
3097 * @buf: contains the data to be written to the adapter IOREG space.
3098 * @off: offset into buffer to beginning of data.
3099 * @count: bytes to transfer.
3100 *
3101 * Description:
3102 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3103 * Uses the adapter io control registers to send buf contents to the adapter.
3104 *
3105 * Returns:
3106 * -ERANGE off and count combo out of range
3107 * -EINVAL off, count or buff address invalid
3108 * -EPERM adapter is offline
3109 * value of count, buf contents written
3110 **/
dea31012005-04-17 16:05:31 -05003111static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003112sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3113 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003114{
3115 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003116 struct device *dev = container_of(kobj, struct device, kobj);
3117 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3119 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003120
James Smartf1126682009-06-10 17:22:44 -04003121 if (phba->sli_rev >= LPFC_SLI_REV4)
3122 return -EPERM;
3123
dea31012005-04-17 16:05:31 -05003124 if ((off + count) > FF_REG_AREA_SIZE)
3125 return -ERANGE;
3126
3127 if (count == 0) return 0;
3128
3129 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3130 return -EINVAL;
3131
James Smart2e0fef82007-06-17 19:56:36 -05003132 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003133 return -EPERM;
3134 }
3135
James Smart2e0fef82007-06-17 19:56:36 -05003136 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003137 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3138 writel(*((uint32_t *)(buf + buf_off)),
3139 phba->ctrl_regs_memmap_p + off + buf_off);
3140
James Smart2e0fef82007-06-17 19:56:36 -05003141 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003142
3143 return count;
3144}
3145
James Smarte59058c2008-08-24 21:49:00 -04003146/**
James Smart3621a712009-04-06 18:47:14 -04003147 * sysfs_ctlreg_read - Read method for reading from ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003148 * @kobj: kernel kobject that contains the kernel class device.
3149 * @bin_attr: kernel attributes passed to us.
3150 * @buf: if succesful contains the data from the adapter IOREG space.
3151 * @off: offset into buffer to beginning of data.
3152 * @count: bytes to transfer.
3153 *
3154 * Description:
3155 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3156 * Uses the adapter io control registers to read data into buf.
3157 *
3158 * Returns:
3159 * -ERANGE off and count combo out of range
3160 * -EINVAL off, count or buff address invalid
3161 * value of count, buf contents read
3162 **/
dea31012005-04-17 16:05:31 -05003163static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003164sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3165 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003166{
3167 size_t buf_off;
3168 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003169 struct device *dev = container_of(kobj, struct device, kobj);
3170 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3172 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003173
James Smartf1126682009-06-10 17:22:44 -04003174 if (phba->sli_rev >= LPFC_SLI_REV4)
3175 return -EPERM;
3176
dea31012005-04-17 16:05:31 -05003177 if (off > FF_REG_AREA_SIZE)
3178 return -ERANGE;
3179
3180 if ((off + count) > FF_REG_AREA_SIZE)
3181 count = FF_REG_AREA_SIZE - off;
3182
3183 if (count == 0) return 0;
3184
3185 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3186 return -EINVAL;
3187
James Smart2e0fef82007-06-17 19:56:36 -05003188 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003189
3190 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3191 tmp_ptr = (uint32_t *)(buf + buf_off);
3192 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3193 }
3194
James Smart2e0fef82007-06-17 19:56:36 -05003195 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003196
3197 return count;
3198}
3199
3200static struct bin_attribute sysfs_ctlreg_attr = {
3201 .attr = {
3202 .name = "ctlreg",
3203 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003204 },
3205 .size = 256,
3206 .read = sysfs_ctlreg_read,
3207 .write = sysfs_ctlreg_write,
3208};
3209
James Smarte59058c2008-08-24 21:49:00 -04003210/**
James Smart3621a712009-04-06 18:47:14 -04003211 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003212 * @phba: lpfc_hba pointer
3213 **/
dea31012005-04-17 16:05:31 -05003214static void
James Smart2e0fef82007-06-17 19:56:36 -05003215sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003216{
3217 phba->sysfs_mbox.state = SMBOX_IDLE;
3218 phba->sysfs_mbox.offset = 0;
3219
3220 if (phba->sysfs_mbox.mbox) {
3221 mempool_free(phba->sysfs_mbox.mbox,
3222 phba->mbox_mem_pool);
3223 phba->sysfs_mbox.mbox = NULL;
3224 }
3225}
3226
James Smarte59058c2008-08-24 21:49:00 -04003227/**
James Smart3621a712009-04-06 18:47:14 -04003228 * sysfs_mbox_write - Write method for writing information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003229 * @kobj: kernel kobject that contains the kernel class device.
3230 * @bin_attr: kernel attributes passed to us.
3231 * @buf: contains the data to be written to sysfs mbox.
3232 * @off: offset into buffer to beginning of data.
3233 * @count: bytes to transfer.
3234 *
3235 * Description:
3236 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3237 * Uses the sysfs mbox to send buf contents to the adapter.
3238 *
3239 * Returns:
3240 * -ERANGE off and count combo out of range
3241 * -EINVAL off, count or buff address invalid
3242 * zero if count is zero
3243 * -EPERM adapter is offline
3244 * -ENOMEM failed to allocate memory for the mail box
3245 * -EAGAIN offset, state or mbox is NULL
3246 * count number of bytes transferred
3247 **/
dea31012005-04-17 16:05:31 -05003248static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003249sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3250 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003251{
Tony Jonesee959b02008-02-22 00:13:36 +01003252 struct device *dev = container_of(kobj, struct device, kobj);
3253 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3255 struct lpfc_hba *phba = vport->phba;
3256 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003257
3258 if ((count + off) > MAILBOX_CMD_SIZE)
3259 return -ERANGE;
3260
3261 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3262 return -EINVAL;
3263
3264 if (count == 0)
3265 return 0;
3266
3267 if (off == 0) {
3268 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3269 if (!mbox)
3270 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003271 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003272 }
3273
James Smart2e0fef82007-06-17 19:56:36 -05003274 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003275
3276 if (off == 0) {
3277 if (phba->sysfs_mbox.mbox)
3278 mempool_free(mbox, phba->mbox_mem_pool);
3279 else
3280 phba->sysfs_mbox.mbox = mbox;
3281 phba->sysfs_mbox.state = SMBOX_WRITING;
3282 } else {
3283 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3284 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003285 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003286 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003287 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003288 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003289 }
3290 }
3291
James Smart04c68492009-05-22 14:52:52 -04003292 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003293 buf, count);
3294
3295 phba->sysfs_mbox.offset = off + count;
3296
James Smart2e0fef82007-06-17 19:56:36 -05003297 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003298
3299 return count;
3300}
3301
James Smarte59058c2008-08-24 21:49:00 -04003302/**
James Smart3621a712009-04-06 18:47:14 -04003303 * sysfs_mbox_read - Read method for reading information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003304 * @kobj: kernel kobject that contains the kernel class device.
3305 * @bin_attr: kernel attributes passed to us.
3306 * @buf: contains the data to be read from sysfs mbox.
3307 * @off: offset into buffer to beginning of data.
3308 * @count: bytes to transfer.
3309 *
3310 * Description:
3311 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3312 * Uses the sysfs mbox to receive data from to the adapter.
3313 *
3314 * Returns:
3315 * -ERANGE off greater than mailbox command size
3316 * -EINVAL off, count or buff address invalid
3317 * zero if off and count are zero
3318 * -EACCES adapter over temp
3319 * -EPERM garbage can value to catch a multitude of errors
3320 * -EAGAIN management IO not permitted, state or off error
3321 * -ETIME mailbox timeout
3322 * -ENODEV mailbox error
3323 * count number of bytes transferred
3324 **/
dea31012005-04-17 16:05:31 -05003325static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003326sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3327 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003328{
Tony Jonesee959b02008-02-22 00:13:36 +01003329 struct device *dev = container_of(kobj, struct device, kobj);
3330 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3332 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003333 int rc;
James Smart04c68492009-05-22 14:52:52 -04003334 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003335
James Smart1dcb58e2007-04-25 09:51:30 -04003336 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003337 return -ERANGE;
3338
James Smart1dcb58e2007-04-25 09:51:30 -04003339 if ((count + off) > MAILBOX_CMD_SIZE)
3340 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003341
3342 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3343 return -EINVAL;
3344
3345 if (off && count == 0)
3346 return 0;
3347
James Smart2e0fef82007-06-17 19:56:36 -05003348 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003349
James Smart7af67052007-10-27 13:38:11 -04003350 if (phba->over_temp_state == HBA_OVER_TEMP) {
3351 sysfs_mbox_idle(phba);
3352 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003353 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003354 }
3355
dea31012005-04-17 16:05:31 -05003356 if (off == 0 &&
3357 phba->sysfs_mbox.state == SMBOX_WRITING &&
3358 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003359 pmb = &phba->sysfs_mbox.mbox->u.mb;
3360 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003361 /* Offline only */
dea31012005-04-17 16:05:31 -05003362 case MBX_INIT_LINK:
3363 case MBX_DOWN_LINK:
3364 case MBX_CONFIG_LINK:
3365 case MBX_CONFIG_RING:
3366 case MBX_RESET_RING:
3367 case MBX_UNREG_LOGIN:
3368 case MBX_CLEAR_LA:
3369 case MBX_DUMP_CONTEXT:
3370 case MBX_RUN_DIAGS:
3371 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003372 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003373 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003374 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003375 printk(KERN_WARNING "mbox_read:Command 0x%x "
3376 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003377 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003378 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003379 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003380 return -EPERM;
3381 }
James Smarta8adb832007-10-27 13:37:53 -04003382 case MBX_WRITE_NV:
3383 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003384 case MBX_LOAD_SM:
3385 case MBX_READ_NV:
3386 case MBX_READ_CONFIG:
3387 case MBX_READ_RCONFIG:
3388 case MBX_READ_STATUS:
3389 case MBX_READ_XRI:
3390 case MBX_READ_REV:
3391 case MBX_READ_LNK_STAT:
3392 case MBX_DUMP_MEMORY:
3393 case MBX_DOWN_LOAD:
3394 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003395 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003396 case MBX_LOAD_AREA:
3397 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003398 case MBX_BEACON:
3399 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003400 case MBX_SET_VARIABLE:
3401 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003402 case MBX_PORT_CAPABILITIES:
3403 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003404 break;
3405 case MBX_READ_SPARM64:
3406 case MBX_READ_LA:
3407 case MBX_READ_LA64:
3408 case MBX_REG_LOGIN:
3409 case MBX_REG_LOGIN64:
3410 case MBX_CONFIG_PORT:
3411 case MBX_RUN_BIU_DIAG:
3412 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003413 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003414 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003415 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003416 return -EPERM;
3417 default:
3418 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003419 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003420 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003421 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003422 return -EPERM;
3423 }
3424
James Smart09372822008-01-11 01:52:54 -05003425 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003426 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003427 */
James Smartd7c255b2008-08-24 21:50:00 -04003428 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003429 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3430 pmb->mbxCommand != MBX_RESTART &&
3431 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3432 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003433 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3434 "1259 mbox: Issued mailbox cmd "
3435 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003436 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003437
James Smart92d7f7b2007-06-17 19:56:38 -05003438 phba->sysfs_mbox.mbox->vport = vport;
3439
James Smart58da1ff2008-04-07 10:15:56 -04003440 /* Don't allow mailbox commands to be sent when blocked
3441 * or when in the middle of discovery
3442 */
James Smart495a7142008-06-14 22:52:59 -04003443 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003444 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003445 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003446 return -EAGAIN;
3447 }
3448
James Smart2e0fef82007-06-17 19:56:36 -05003449 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003450 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003451
James Smart2e0fef82007-06-17 19:56:36 -05003452 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003453 rc = lpfc_sli_issue_mbox (phba,
3454 phba->sysfs_mbox.mbox,
3455 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003456 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003457
3458 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003459 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003460 rc = lpfc_sli_issue_mbox_wait (phba,
3461 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003462 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003463 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003464 }
3465
3466 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003467 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003468 phba->sysfs_mbox.mbox = NULL;
3469 }
dea31012005-04-17 16:05:31 -05003470 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003471 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003472 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003473 }
3474 phba->sysfs_mbox.state = SMBOX_READING;
3475 }
3476 else if (phba->sysfs_mbox.offset != off ||
3477 phba->sysfs_mbox.state != SMBOX_READING) {
3478 printk(KERN_WARNING "mbox_read: Bad State\n");
3479 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003480 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003481 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003482 }
3483
James Smart04c68492009-05-22 14:52:52 -04003484 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003485
3486 phba->sysfs_mbox.offset = off + count;
3487
James Smart1dcb58e2007-04-25 09:51:30 -04003488 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003489 sysfs_mbox_idle(phba);
3490
James Smart2e0fef82007-06-17 19:56:36 -05003491 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003492
3493 return count;
3494}
3495
3496static struct bin_attribute sysfs_mbox_attr = {
3497 .attr = {
3498 .name = "mbox",
3499 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003500 },
James Smart1dcb58e2007-04-25 09:51:30 -04003501 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003502 .read = sysfs_mbox_read,
3503 .write = sysfs_mbox_write,
3504};
3505
James Smarte59058c2008-08-24 21:49:00 -04003506/**
James Smart3621a712009-04-06 18:47:14 -04003507 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003508 * @vport: address of lpfc vport structure.
3509 *
3510 * Return codes:
3511 * zero on success
3512 * error return code from sysfs_create_bin_file()
3513 **/
dea31012005-04-17 16:05:31 -05003514int
James Smart2e0fef82007-06-17 19:56:36 -05003515lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003516{
James Smart2e0fef82007-06-17 19:56:36 -05003517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003518 int error;
3519
Tony Jonesee959b02008-02-22 00:13:36 +01003520 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003521 &sysfs_drvr_stat_data_attr);
3522
3523 /* Virtual ports do not need ctrl_reg and mbox */
3524 if (error || vport->port_type == LPFC_NPIV_PORT)
3525 goto out;
3526
3527 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003528 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003529 if (error)
James Smarteada2722008-12-04 22:39:13 -05003530 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003531
Tony Jonesee959b02008-02-22 00:13:36 +01003532 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003533 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003534 if (error)
3535 goto out_remove_ctlreg_attr;
3536
3537 return 0;
3538out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003539 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003540out_remove_stat_attr:
3541 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3542 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003543out:
3544 return error;
3545}
3546
James Smarte59058c2008-08-24 21:49:00 -04003547/**
James Smart3621a712009-04-06 18:47:14 -04003548 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003549 * @vport: address of lpfc vport structure.
3550 **/
dea31012005-04-17 16:05:31 -05003551void
James Smart2e0fef82007-06-17 19:56:36 -05003552lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003553{
James Smart2e0fef82007-06-17 19:56:36 -05003554 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003555 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3556 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003557 /* Virtual ports do not need ctrl_reg and mbox */
3558 if (vport->port_type == LPFC_NPIV_PORT)
3559 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003560 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3561 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003562}
3563
3564
3565/*
3566 * Dynamic FC Host Attributes Support
3567 */
3568
James Smarte59058c2008-08-24 21:49:00 -04003569/**
James Smart3621a712009-04-06 18:47:14 -04003570 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003571 * @shost: kernel scsi host pointer.
3572 **/
dea31012005-04-17 16:05:31 -05003573static void
3574lpfc_get_host_port_id(struct Scsi_Host *shost)
3575{
James Smart2e0fef82007-06-17 19:56:36 -05003576 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3577
dea31012005-04-17 16:05:31 -05003578 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003579 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003580}
3581
James Smarte59058c2008-08-24 21:49:00 -04003582/**
James Smart3621a712009-04-06 18:47:14 -04003583 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003584 * @shost: kernel scsi host pointer.
3585 **/
dea31012005-04-17 16:05:31 -05003586static void
3587lpfc_get_host_port_type(struct Scsi_Host *shost)
3588{
James Smart2e0fef82007-06-17 19:56:36 -05003589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3590 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003591
3592 spin_lock_irq(shost->host_lock);
3593
James Smart92d7f7b2007-06-17 19:56:38 -05003594 if (vport->port_type == LPFC_NPIV_PORT) {
3595 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3596 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003597 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003598 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003599 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3600 else
3601 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3602 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003603 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003604 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3605 else
3606 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3607 }
3608 } else
3609 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3610
3611 spin_unlock_irq(shost->host_lock);
3612}
3613
James Smarte59058c2008-08-24 21:49:00 -04003614/**
James Smart3621a712009-04-06 18:47:14 -04003615 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003616 * @shost: kernel scsi host pointer.
3617 **/
dea31012005-04-17 16:05:31 -05003618static void
3619lpfc_get_host_port_state(struct Scsi_Host *shost)
3620{
James Smart2e0fef82007-06-17 19:56:36 -05003621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3622 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003623
3624 spin_lock_irq(shost->host_lock);
3625
James Smart2e0fef82007-06-17 19:56:36 -05003626 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003627 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3628 else {
James Smart2e0fef82007-06-17 19:56:36 -05003629 switch (phba->link_state) {
3630 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003631 case LPFC_LINK_DOWN:
3632 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3633 break;
3634 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003635 case LPFC_CLEAR_LA:
3636 case LPFC_HBA_READY:
3637 /* Links up, beyond this port_type reports state */
3638 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3639 break;
3640 case LPFC_HBA_ERROR:
3641 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3642 break;
3643 default:
3644 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3645 break;
3646 }
3647 }
3648
3649 spin_unlock_irq(shost->host_lock);
3650}
3651
James Smarte59058c2008-08-24 21:49:00 -04003652/**
James Smart3621a712009-04-06 18:47:14 -04003653 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003654 * @shost: kernel scsi host pointer.
3655 **/
dea31012005-04-17 16:05:31 -05003656static void
3657lpfc_get_host_speed(struct Scsi_Host *shost)
3658{
James Smart2e0fef82007-06-17 19:56:36 -05003659 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3660 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003661
3662 spin_lock_irq(shost->host_lock);
3663
James Smart2e0fef82007-06-17 19:56:36 -05003664 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003665 switch(phba->fc_linkspeed) {
3666 case LA_1GHZ_LINK:
3667 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3668 break;
3669 case LA_2GHZ_LINK:
3670 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3671 break;
3672 case LA_4GHZ_LINK:
3673 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3674 break;
James Smartb87eab32007-04-25 09:53:28 -04003675 case LA_8GHZ_LINK:
3676 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3677 break;
James Smartf4b4c682009-05-22 14:53:12 -04003678 case LA_10GHZ_LINK:
3679 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3680 break;
dea31012005-04-17 16:05:31 -05003681 default:
3682 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3683 break;
3684 }
James Smart09372822008-01-11 01:52:54 -05003685 } else
3686 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003687
3688 spin_unlock_irq(shost->host_lock);
3689}
3690
James Smarte59058c2008-08-24 21:49:00 -04003691/**
James Smart3621a712009-04-06 18:47:14 -04003692 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04003693 * @shost: kernel scsi host pointer.
3694 **/
dea31012005-04-17 16:05:31 -05003695static void
3696lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3697{
James Smart2e0fef82007-06-17 19:56:36 -05003698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3699 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003700 u64 node_name;
dea31012005-04-17 16:05:31 -05003701
3702 spin_lock_irq(shost->host_lock);
3703
James Smart2e0fef82007-06-17 19:56:36 -05003704 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003705 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003706 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003707 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003708 else
3709 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003710 node_name = 0;
dea31012005-04-17 16:05:31 -05003711
3712 spin_unlock_irq(shost->host_lock);
3713
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003714 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003715}
3716
James Smarte59058c2008-08-24 21:49:00 -04003717/**
James Smart3621a712009-04-06 18:47:14 -04003718 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04003719 * @shost: kernel scsi host pointer.
3720 *
3721 * Notes:
3722 * NULL on error for link down, no mbox pool, sli2 active,
3723 * management not allowed, memory allocation error, or mbox error.
3724 *
3725 * Returns:
3726 * NULL for error
3727 * address of the adapter host statistics
3728 **/
dea31012005-04-17 16:05:31 -05003729static struct fc_host_statistics *
3730lpfc_get_stats(struct Scsi_Host *shost)
3731{
James Smart2e0fef82007-06-17 19:56:36 -05003732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3733 struct lpfc_hba *phba = vport->phba;
3734 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003735 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003736 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003737 LPFC_MBOXQ_t *pmboxq;
3738 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003739 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003740 int rc = 0;
dea31012005-04-17 16:05:31 -05003741
James Smart92d7f7b2007-06-17 19:56:38 -05003742 /*
3743 * prevent udev from issuing mailbox commands until the port is
3744 * configured.
3745 */
James Smart2e0fef82007-06-17 19:56:36 -05003746 if (phba->link_state < LPFC_LINK_DOWN ||
3747 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04003748 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003749 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003750
3751 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003752 return NULL;
3753
dea31012005-04-17 16:05:31 -05003754 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3755 if (!pmboxq)
3756 return NULL;
3757 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3758
James Smart04c68492009-05-22 14:52:52 -04003759 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05003760 pmb->mbxCommand = MBX_READ_STATUS;
3761 pmb->mbxOwner = OWN_HOST;
3762 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003763 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003764
James Smart2e0fef82007-06-17 19:56:36 -05003765 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart04c68492009-05-22 14:52:52 -04003766 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003767 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003768 else
dea31012005-04-17 16:05:31 -05003769 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3770
3771 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003772 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003773 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003774 return NULL;
3775 }
3776
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003777 memset(hs, 0, sizeof (struct fc_host_statistics));
3778
dea31012005-04-17 16:05:31 -05003779 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3780 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3781 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3782 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3783
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003784 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003785 pmb->mbxCommand = MBX_READ_LNK_STAT;
3786 pmb->mbxOwner = OWN_HOST;
3787 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003788 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003789
James Smart2e0fef82007-06-17 19:56:36 -05003790 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003791 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003792 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003793 else
dea31012005-04-17 16:05:31 -05003794 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3795
3796 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003797 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003798 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003799 return NULL;
3800 }
3801
3802 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3803 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3804 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3805 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3806 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3807 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3808 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3809
James Smart64ba8812006-08-02 15:24:34 -04003810 hs->link_failure_count -= lso->link_failure_count;
3811 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3812 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3813 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3814 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3815 hs->invalid_crc_count -= lso->invalid_crc_count;
3816 hs->error_frames -= lso->error_frames;
3817
James Smart4d9ab992009-10-02 15:16:39 -04003818 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
3819 hs->lip_count = -1;
3820 hs->nos_count = (phba->link_events >> 1);
3821 hs->nos_count -= lso->link_events;
3822 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05003823 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003824 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003825 hs->nos_count = -1;
3826 } else {
3827 hs->lip_count = -1;
3828 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003829 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003830 }
3831
3832 hs->dumped_frames = -1;
3833
James Smart64ba8812006-08-02 15:24:34 -04003834 seconds = get_seconds();
3835 if (seconds < psli->stats_start)
3836 hs->seconds_since_last_reset = seconds +
3837 ((unsigned long)-1 - psli->stats_start);
3838 else
3839 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05003840
James Smart1dcb58e2007-04-25 09:51:30 -04003841 mempool_free(pmboxq, phba->mbox_mem_pool);
3842
dea31012005-04-17 16:05:31 -05003843 return hs;
3844}
3845
James Smarte59058c2008-08-24 21:49:00 -04003846/**
James Smart3621a712009-04-06 18:47:14 -04003847 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04003848 * @shost: kernel scsi host pointer.
3849 **/
James Smart64ba8812006-08-02 15:24:34 -04003850static void
3851lpfc_reset_stats(struct Scsi_Host *shost)
3852{
James Smart2e0fef82007-06-17 19:56:36 -05003853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3854 struct lpfc_hba *phba = vport->phba;
3855 struct lpfc_sli *psli = &phba->sli;
3856 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04003857 LPFC_MBOXQ_t *pmboxq;
3858 MAILBOX_t *pmb;
3859 int rc = 0;
3860
James Smart2e0fef82007-06-17 19:56:36 -05003861 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003862 return;
3863
James Smart64ba8812006-08-02 15:24:34 -04003864 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3865 if (!pmboxq)
3866 return;
3867 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3868
James Smart04c68492009-05-22 14:52:52 -04003869 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04003870 pmb->mbxCommand = MBX_READ_STATUS;
3871 pmb->mbxOwner = OWN_HOST;
3872 pmb->un.varWords[0] = 0x1; /* reset request */
3873 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003874 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003875
James Smart2e0fef82007-06-17 19:56:36 -05003876 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003877 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04003878 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3879 else
3880 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3881
3882 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003883 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003884 mempool_free(pmboxq, phba->mbox_mem_pool);
3885 return;
3886 }
3887
3888 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3889 pmb->mbxCommand = MBX_READ_LNK_STAT;
3890 pmb->mbxOwner = OWN_HOST;
3891 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003892 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003893
James Smart2e0fef82007-06-17 19:56:36 -05003894 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003895 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04003896 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3897 else
3898 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3899
3900 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003901 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003902 mempool_free( pmboxq, phba->mbox_mem_pool);
3903 return;
3904 }
3905
3906 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3907 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3908 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3909 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3910 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3911 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3912 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04003913 if (phba->hba_flag & HBA_FCOE_SUPPORT)
3914 lso->link_events = (phba->link_events >> 1);
3915 else
3916 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003917
3918 psli->stats_start = get_seconds();
3919
James Smart1dcb58e2007-04-25 09:51:30 -04003920 mempool_free(pmboxq, phba->mbox_mem_pool);
3921
James Smart64ba8812006-08-02 15:24:34 -04003922 return;
3923}
dea31012005-04-17 16:05:31 -05003924
3925/*
3926 * The LPFC driver treats linkdown handling as target loss events so there
3927 * are no sysfs handlers for link_down_tmo.
3928 */
James Smart685f0bf2007-04-25 09:53:08 -04003929
James Smarte59058c2008-08-24 21:49:00 -04003930/**
James Smart3621a712009-04-06 18:47:14 -04003931 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04003932 * @starget: kernel scsi target pointer.
3933 *
3934 * Returns:
3935 * address of the node list if found
3936 * NULL target not found
3937 **/
James Smart685f0bf2007-04-25 09:53:08 -04003938static struct lpfc_nodelist *
3939lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05003940{
James Smart2e0fef82007-06-17 19:56:36 -05003941 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3942 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04003943 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003944
3945 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003946 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05003947 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003948 if (NLP_CHK_NODE_ACT(ndlp) &&
3949 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04003950 starget->id == ndlp->nlp_sid) {
3951 spin_unlock_irq(shost->host_lock);
3952 return ndlp;
dea31012005-04-17 16:05:31 -05003953 }
3954 }
3955 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003956 return NULL;
3957}
dea31012005-04-17 16:05:31 -05003958
James Smarte59058c2008-08-24 21:49:00 -04003959/**
James Smart3621a712009-04-06 18:47:14 -04003960 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04003961 * @starget: kernel scsi target pointer.
3962 **/
James Smart685f0bf2007-04-25 09:53:08 -04003963static void
3964lpfc_get_starget_port_id(struct scsi_target *starget)
3965{
3966 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3967
3968 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05003969}
3970
James Smarte59058c2008-08-24 21:49:00 -04003971/**
James Smart3621a712009-04-06 18:47:14 -04003972 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04003973 * @starget: kernel scsi target pointer.
3974 *
3975 * Description: Set the target node name to the ndlp node name wwn or zero.
3976 **/
dea31012005-04-17 16:05:31 -05003977static void
3978lpfc_get_starget_node_name(struct scsi_target *starget)
3979{
James Smart685f0bf2007-04-25 09:53:08 -04003980 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003981
James Smart685f0bf2007-04-25 09:53:08 -04003982 fc_starget_node_name(starget) =
3983 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003984}
3985
James Smarte59058c2008-08-24 21:49:00 -04003986/**
James Smart3621a712009-04-06 18:47:14 -04003987 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04003988 * @starget: kernel scsi target pointer.
3989 *
3990 * Description: set the target port name to the ndlp port name wwn or zero.
3991 **/
dea31012005-04-17 16:05:31 -05003992static void
3993lpfc_get_starget_port_name(struct scsi_target *starget)
3994{
James Smart685f0bf2007-04-25 09:53:08 -04003995 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003996
James Smart685f0bf2007-04-25 09:53:08 -04003997 fc_starget_port_name(starget) =
3998 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003999}
4000
James Smarte59058c2008-08-24 21:49:00 -04004001/**
James Smart3621a712009-04-06 18:47:14 -04004002 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004003 * @rport: fc rport address.
4004 * @timeout: new value for dev loss tmo.
4005 *
4006 * Description:
4007 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4008 * dev_loss_tmo to one.
4009 **/
dea31012005-04-17 16:05:31 -05004010static void
dea31012005-04-17 16:05:31 -05004011lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4012{
dea31012005-04-17 16:05:31 -05004013 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004014 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004015 else
James Smartc01f3202006-08-18 17:47:08 -04004016 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004017}
4018
James Smarte59058c2008-08-24 21:49:00 -04004019/**
James Smart3621a712009-04-06 18:47:14 -04004020 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004021 *
4022 * Description:
4023 * Macro that uses field to generate a function with the name lpfc_show_rport_
4024 *
4025 * lpfc_show_rport_##field: returns the bytes formatted in buf
4026 * @cdev: class converted to an fc_rport.
4027 * @buf: on return contains the target_field or zero.
4028 *
4029 * Returns: size of formatted string.
4030 **/
dea31012005-04-17 16:05:31 -05004031#define lpfc_rport_show_function(field, format_string, sz, cast) \
4032static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004033lpfc_show_rport_##field (struct device *dev, \
4034 struct device_attribute *attr, \
4035 char *buf) \
dea31012005-04-17 16:05:31 -05004036{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004037 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004038 struct lpfc_rport_data *rdata = rport->hostdata; \
4039 return snprintf(buf, sz, format_string, \
4040 (rdata->target) ? cast rdata->target->field : 0); \
4041}
4042
4043#define lpfc_rport_rd_attr(field, format_string, sz) \
4044 lpfc_rport_show_function(field, format_string, sz, ) \
4045static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4046
James Smarteada2722008-12-04 22:39:13 -05004047/**
James Smart3621a712009-04-06 18:47:14 -04004048 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004049 * @fc_vport: The fc_vport who's symbolic name has been changed.
4050 *
4051 * Description:
4052 * This function is called by the transport after the @fc_vport's symbolic name
4053 * has been changed. This function re-registers the symbolic name with the
4054 * switch to propogate the change into the fabric if the vport is active.
4055 **/
4056static void
4057lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4058{
4059 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4060
4061 if (vport->port_state == LPFC_VPORT_READY)
4062 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4063}
dea31012005-04-17 16:05:31 -05004064
James Smartf4b4c682009-05-22 14:53:12 -04004065/**
4066 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4067 * @phba: Pointer to lpfc_hba struct.
4068 *
4069 * This function is called by the lpfc_get_cfgparam() routine to set the
4070 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4071 * log messsage according to the module's lpfc_log_verbose parameter setting
4072 * before hba port or vport created.
4073 **/
4074static void
4075lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4076{
4077 phba->cfg_log_verbose = verbose;
4078}
4079
dea31012005-04-17 16:05:31 -05004080struct fc_function_template lpfc_transport_functions = {
4081 /* fixed attributes the driver supports */
4082 .show_host_node_name = 1,
4083 .show_host_port_name = 1,
4084 .show_host_supported_classes = 1,
4085 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004086 .show_host_supported_speeds = 1,
4087 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004088 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004089
4090 /* dynamic attributes the driver supports */
4091 .get_host_port_id = lpfc_get_host_port_id,
4092 .show_host_port_id = 1,
4093
4094 .get_host_port_type = lpfc_get_host_port_type,
4095 .show_host_port_type = 1,
4096
4097 .get_host_port_state = lpfc_get_host_port_state,
4098 .show_host_port_state = 1,
4099
4100 /* active_fc4s is shown but doesn't change (thus no get function) */
4101 .show_host_active_fc4s = 1,
4102
4103 .get_host_speed = lpfc_get_host_speed,
4104 .show_host_speed = 1,
4105
4106 .get_host_fabric_name = lpfc_get_host_fabric_name,
4107 .show_host_fabric_name = 1,
4108
4109 /*
4110 * The LPFC driver treats linkdown handling as target loss events
4111 * so there are no sysfs handlers for link_down_tmo.
4112 */
4113
4114 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004115 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004116
4117 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4118 .show_rport_maxframe_size = 1,
4119 .show_rport_supported_classes = 1,
4120
dea31012005-04-17 16:05:31 -05004121 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4122 .show_rport_dev_loss_tmo = 1,
4123
4124 .get_starget_port_id = lpfc_get_starget_port_id,
4125 .show_starget_port_id = 1,
4126
4127 .get_starget_node_name = lpfc_get_starget_node_name,
4128 .show_starget_node_name = 1,
4129
4130 .get_starget_port_name = lpfc_get_starget_port_name,
4131 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004132
4133 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004134 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4135 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004136
James Smart92d7f7b2007-06-17 19:56:38 -05004137 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004138
4139 .vport_disable = lpfc_vport_disable,
4140
4141 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004142
4143 .bsg_request = lpfc_bsg_request,
4144 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004145};
4146
James Smart98c9ea52007-10-27 13:37:33 -04004147struct fc_function_template lpfc_vport_transport_functions = {
4148 /* fixed attributes the driver supports */
4149 .show_host_node_name = 1,
4150 .show_host_port_name = 1,
4151 .show_host_supported_classes = 1,
4152 .show_host_supported_fc4s = 1,
4153 .show_host_supported_speeds = 1,
4154 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004155 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004156
4157 /* dynamic attributes the driver supports */
4158 .get_host_port_id = lpfc_get_host_port_id,
4159 .show_host_port_id = 1,
4160
4161 .get_host_port_type = lpfc_get_host_port_type,
4162 .show_host_port_type = 1,
4163
4164 .get_host_port_state = lpfc_get_host_port_state,
4165 .show_host_port_state = 1,
4166
4167 /* active_fc4s is shown but doesn't change (thus no get function) */
4168 .show_host_active_fc4s = 1,
4169
4170 .get_host_speed = lpfc_get_host_speed,
4171 .show_host_speed = 1,
4172
4173 .get_host_fabric_name = lpfc_get_host_fabric_name,
4174 .show_host_fabric_name = 1,
4175
4176 /*
4177 * The LPFC driver treats linkdown handling as target loss events
4178 * so there are no sysfs handlers for link_down_tmo.
4179 */
4180
4181 .get_fc_host_stats = lpfc_get_stats,
4182 .reset_fc_host_stats = lpfc_reset_stats,
4183
4184 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4185 .show_rport_maxframe_size = 1,
4186 .show_rport_supported_classes = 1,
4187
4188 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4189 .show_rport_dev_loss_tmo = 1,
4190
4191 .get_starget_port_id = lpfc_get_starget_port_id,
4192 .show_starget_port_id = 1,
4193
4194 .get_starget_node_name = lpfc_get_starget_node_name,
4195 .show_starget_node_name = 1,
4196
4197 .get_starget_port_name = lpfc_get_starget_port_name,
4198 .show_starget_port_name = 1,
4199
4200 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4201 .terminate_rport_io = lpfc_terminate_rport_io,
4202
4203 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004204
4205 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004206};
4207
James Smarte59058c2008-08-24 21:49:00 -04004208/**
James Smart3621a712009-04-06 18:47:14 -04004209 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004210 * @phba: lpfc_hba pointer.
4211 **/
dea31012005-04-17 16:05:31 -05004212void
4213lpfc_get_cfgparam(struct lpfc_hba *phba)
4214{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004215 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4216 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004217 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004218 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4219 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004220 lpfc_ack0_init(phba, lpfc_ack0);
4221 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004222 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004223 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004224 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004225 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004226 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4227 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4228 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004229 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4230 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004231 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004232 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004233 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004234 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004235 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004236 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004237 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004238 lpfc_enable_fip_init(phba, lpfc_enable_fip);
4239 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4240
James Smart3de2a652007-08-02 11:09:59 -04004241 return;
4242}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004243
James Smarte59058c2008-08-24 21:49:00 -04004244/**
James Smart3621a712009-04-06 18:47:14 -04004245 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004246 * @vport: lpfc_vport pointer.
4247 **/
James Smart3de2a652007-08-02 11:09:59 -04004248void
4249lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4250{
James Smarte8b62012007-08-02 11:10:09 -04004251 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004252 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4253 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4254 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4255 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4256 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4257 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4258 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004259 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004260 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4261 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4262 lpfc_max_luns_init(vport, lpfc_max_luns);
4263 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004264 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004265 return;
4266}